diff --git a/graphics/gd/Makefile b/graphics/gd/Makefile index 5aa0c8d80e74..686796921c90 100644 --- a/graphics/gd/Makefile +++ b/graphics/gd/Makefile @@ -1,133 +1,135 @@ PORTNAME= libgd PORTVERSION= 2.3.3 PORTREVISION= 5 PORTEPOCH= 1 CATEGORIES+= graphics MASTER_SITES= https://github.com/${PORTNAME}/${PORTNAME}/releases/download/gd-${PORTVERSION}/ MAINTAINER?= dinoex@FreeBSD.org COMMENT?= Graphics library for fast creation of images WWW= https://libgd.github.io/ LICENSE= MIT LICENSE_FILE= ${WRKSRC}/COPYING CONFLICTS_INSTALL= libgd ??-libgd USES= cpe tar:xz pkgconfig pathfix libtool:keepla shebangfix SHEBANG_FILES= ${WRKSRC}/src/bdftogd GNU_CONFIGURE= yes CONFIGURE_ARGS= --enable-gd-formats TMPDIR?= /tmp MAKE_ENV= TMPDIR=${TMPDIR} SUB_FILES= gdlib-config USE_LDCONFIG= yes TEST_TARGET= check -OPTIONS_DEFINE= PNG JPEG WEBP TIFF XPM HEIF AVIF LIQ FREETYPE FONTCONFIG RAQM ICONV +OPTIONS_DEFINE= PNG JPEG WEBP TIFF XPM HEIF AVIF LIQ FREETYPE FONTCONFIG RAQM ICONV THREADS OPTIONS_DEFAULT=PNG JPEG WEBP TIFF FREETYPE FONTCONFIG ICONV NO_OPTIONS_SORT=yes OPTIONS_SUB= yes PNG_LIB_DEPENDS= libpng.so:graphics/png PNG_CONFIGURE_OFF= --without-png PNG_CPPFLAGS= -I${LOCALBASE}/include JPEG_USES= jpeg JPEG_CONFIGURE_OFF= --without-jpeg JPEG_CPPFLAGS= -I${LOCALBASE}/include WEBP_LIB_DEPENDS= libwebp.so:graphics/webp WEBP_CONFIGURE_OFF= --without-webp WEBP_CPPFLAGS= -I${LOCALBASE}/include TIFF_LIB_DEPENDS= libtiff.so:graphics/tiff TIFF_CONFIGURE_OFF= --without-tiff TIFF_CPPFLAGS= -I${LOCALBASE}/include HEIF_LIB_DEPENDS= libheif.so:graphics/libheif HEIF_CONFIGURE_OFF= --without-heif HEIF_CPPFLAGS= -I${LOCALBASE}/include AVIF_LIB_DEPENDS= libavif.so:graphics/libavif AVIF_CONFIGURE_OFF= --without-avif AVIF_CPPFLAGS= -I${LOCALBASE}/include AVIF_USES= autoreconf AVIF_BROKEN= option AVIF has a circular dependency loop LIQ_DESC= libimagequant color conversion support LIQ_LIB_DEPENDS= libimagequant.so:graphics/libimagequant LIQ_CONFIGURE_OFF= --with-liq=no LIQ_CPPFLAGS= -I${LOCALBASE}/include FREETYPE_LIB_DEPENDS= libfreetype.so:print/freetype2 FREETYPE_CONFIGURE_OFF= --without-freetype FREETYPE_CPPFLAGS= -I${LOCALBASE}/include FONTCONFIG_LIB_DEPENDS+= libfontconfig.so:x11-fonts/fontconfig FONTCONFIG_CONFIGURE_OFF= --with-fontconfig=no FONTCONFIG_CPPFLAGS= -I${LOCALBASE}/include RAQM_DESC= Raqm text layout support RAQM_LIB_DEPENDS= libraqm.so:print/libraqm RAQM_CONFIGURE_OFF= --with-raqm=no RAQM_CPPFLAGS= -I${LOCALBASE}/include XPM_USES= xorg XPM_USE= xorg=xpm,x11 XPM_CONFIGURE_ON= --with-x XPM_CONFIGURE_OFF= --with-xpm=no ICONV_USES= iconv ICONV_CONFIGURE_ON= ${ICONV_CONFIGURE_ARG} +THREADS_EXTRA_PATCHES= ${PATCHDIR}/extra-patch-threads +THREADS_USES= autoreconf .include .if ${PORT_OPTIONS:MFREETYPE} # bin/annotate CONFLICTS_INSTALL+= mummer .endif # force gdlib-config --ldflags LDFLAGS+= -L${LOCALBASE}/lib # The GD_FONTS environment variable can be set to specify the gzipped # tar-ball containing the fonts in bdf format and the bdf file names. # The tarball is the first argument, the tiny, small, medium-bold, # large, and giant fonts follow. # # For example: # GD_FONTS="/usr/ports/distfiles/x-koi8u.tgz koi6x10.bdf koi8x13.bdf \ # koi9x15.bdf koi12x24.bdf koi10x20.bdf" # .if defined(GD_FONTS) USES+= perl5 USE_PERL5= build WRKFONTS= ${WRKSRC}/src .endif pre-extract:: @${ECHO_MSG} "" @${ECHO_MSG} "GD_FONTS can be set to specify an alternative list of .bdf files" @${ECHO_MSG} "" post-extract: .if defined(GD_FONTS) cd ${WRKFONTS} && ${SH} ${FILESDIR}/makefonts extract ${GD_FONTS} .endif pre-configure: .if defined(GD_FONTS) cd ${WRKFONTS} && ${SH} ${FILESDIR}/makefonts configure ${GD_FONTS} .endif # bump shlib version ${REINPLACE_CMD} \ -e 's|^GDLIB_LT_CURRENT=3|GDLIB_LT_CURRENT=6|' \ ${WRKSRC}/configure ${WRKSRC}/config/getlib.sh pre-configure-ICONV-off: ${REINPLACE_CMD} \ -e 's|iconv|noiconv|' \ ${WRKSRC}/configure .if defined(GD_FONTS) pre-build: cd ${WRKFONTS} && ${SH} ${FILESDIR}/makefonts build ${GD_FONTS} .endif post-install: ${INSTALL_DATA} ${WRKSRC}/src/gdhelpers.h \ ${STAGEDIR}${PREFIX}/include/ ${STRIP_CMD} ${STAGEDIR}${PREFIX}/lib/libgd.so.6* ${INSTALL_SCRIPT} ${WRKDIR}/gdlib-config \ ${STAGEDIR}${PREFIX}/bin/ .include diff --git a/graphics/gd/files/extra-patch-threads b/graphics/gd/files/extra-patch-threads new file mode 100644 index 000000000000..d09a69ea46de --- /dev/null +++ b/graphics/gd/files/extra-patch-threads @@ -0,0 +1,154 @@ +--- configure.ac.orig 2021-09-11 04:43:11 UTC ++++ configure.ac +@@ -101,6 +101,8 @@ AC_CHECK_FUNC(sin,,[AC_CHECK_LIB(m,sin)]) + AX_PTHREAD() + AX_OPENMP() + ++AM_CONDITIONAL([HAVE_PTHREAD], [test "x$ax_pthread_ok" = "xyes"]) ++ + dnl We should default this to off in future releases. + AC_MSG_CHECKING([whether to support gd image formats]) + AC_ARG_ENABLE([gd-formats], +--- src/Makefile.am.orig 2021-09-11 04:43:11 UTC ++++ src/Makefile.am +@@ -129,4 +129,9 @@ libgd_la_LDFLAGS = -version-info $(GDLIB_LT_CURRENT):$ + + libgd_la_LIBADD = $(LTLIBICONV) + ++if HAVE_PTHREAD ++libgd_la_SOURCES += \ ++ gdinitfini.c ++endif ++ + LDADD = libgd.la $(LIBICONV) +--- src/gdft.c.orig 2021-09-11 04:43:11 UTC ++++ src/gdft.c +@@ -890,7 +890,17 @@ BGD_DECLARE(void) gdFreeFontCache () + */ + BGD_DECLARE(void) gdFontCacheShutdown () + { ++#if defined(HAVE_PTHREAD) ++ /* referring to bundled with php */ ++ gdMutexLock(gdFontCacheMutex); + if (fontCache) { ++ gdCacheDelete(fontCache); ++ fontCache = NULL; ++ FT_Done_FreeType(library); ++ } ++ gdMutexUnlock(gdFontCacheMutex); ++#else ++ if (fontCache) { + gdMutexLock(gdFontCacheMutex); + gdCacheDelete (fontCache); + /* 2.0.16: Gustavo Scotti: make sure we don't free this twice */ +@@ -899,6 +909,7 @@ BGD_DECLARE(void) gdFontCacheShutdown () + gdMutexShutdown (gdFontCacheMutex); + FT_Done_FreeType (library); + } ++#endif + } + + /** +@@ -948,11 +959,18 @@ BGD_DECLARE(int) gdFontCacheSetup (void) + /* Already set up */ + return 0; + } ++#if defined(HAVE_PTHREAD) ++ /* referring to bundled with php */ ++ if (FT_Init_FreeType (&library)) { ++ return -1; ++ } ++#else + gdMutexSetup (gdFontCacheMutex); + if (FT_Init_FreeType (&library)) { + gdMutexShutdown (gdFontCacheMutex); + return -1; + } ++#endif + fontCache = gdCacheCreate (FONTCACHESIZE, fontTest, fontFetch, fontRelease); + if (!fontCache) { + return -2; +@@ -1144,6 +1162,10 @@ BGD_DECLARE(char *) gdImageStringFTEx (gdImagePtr im, + tweenColorRelease); + + /***** initialize font library and font cache on first call ******/ ++#if defined(HAVE_PTHREAD) ++ /* referring to bundled with php */ ++ gdMutexLock(gdFontCacheMutex); ++#endif + if (!fontCache) { + if (gdFontCacheSetup () != 0) { + gdCacheDelete (tc_cache); +@@ -1151,7 +1173,11 @@ BGD_DECLARE(char *) gdImageStringFTEx (gdImagePtr im, + } + } + /*****/ ++#if defined(HAVE_PTHREAD) ++ /* referring to bundled with php */ ++#else + gdMutexLock (gdFontCacheMutex); ++#endif + /* get the font (via font cache) */ + fontkey.fontlist = fontlist; + if (strex) +--- src/gdhelpers.h.orig 2021-09-11 04:43:11 UTC ++++ src/gdhelpers.h +@@ -51,11 +51,22 @@ extern "C" { + # define gdMutexUnlock(x) LeaveCriticalSection(&x) + #elif defined(HAVE_PTHREAD) + # include ++# include "gd_errors.h" + # define gdMutexDeclare(x) pthread_mutex_t x + # define gdMutexSetup(x) pthread_mutex_init(&x, 0) + # define gdMutexShutdown(x) pthread_mutex_destroy(&x) +-# define gdMutexLock(x) pthread_mutex_lock(&x) +-# define gdMutexUnlock(x) pthread_mutex_unlock(&x) ++# define gdMutexLock(x) do {\ ++ int pten = 0;\ ++ if ((pten = pthread_mutex_lock(&x)) != 0) {\ ++ gd_error_ex(GD_DEBUG, "gdMutexLock(%s<%p>) %s\n", #x, x, strerror(pten));\ ++ }\ ++ } while (0) ++# define gdMutexUnlock(x) do {\ ++ int pten = 0;\ ++ if ((pten = pthread_mutex_unlock(&x)) != 0) {\ ++ gd_error_ex(GD_DEBUG, "gdMutexUnlock(%s<%p>) %s\n", #x, x, strerror(pten));\ ++ }\ ++ } while (0) + #else + # define gdMutexDeclare(x) + # define gdMutexSetup(x) +--- src/gdinitfini.c.orig 1970-01-01 00:00:00 UTC ++++ src/gdinitfini.c +@@ -0,0 +1,31 @@ ++#include ++#include "gd.h" ++#include "gd_errors.h" ++#include "gdhelpers.h" ++ ++#if defined(CPP_SHARP) ++#elif defined(_WIN32) ++#elif defined(HAVE_PTHREAD) ++ ++extern gdMutexDeclare(gdFontCacheMutex); ++ ++void ++_init() ++{ ++ int pten = 0; ++ if ((pten = gdMutexSetup(gdFontCacheMutex)) != 0) { ++ gd_error_ex(GD_ERROR, "%s gdMutexSetup %s\n", __func__, strerror(pten)); ++ } ++} ++ ++void ++_fini() ++{ ++ int pten = 0; ++ if ((pten = gdMutexShutdown(gdFontCacheMutex)) != 0) { ++ gd_error_ex(GD_ERROR, "%s gdMutexShutdown %s\n", __func__, strerror(pten)); ++ } ++} ++ ++#else ++#endif