:: commit 82f0edcd1fa6b7c1c59c41571f705c9c3c2aa42a

mintsuki <mintsuki@protonmail.com> — 2023-10-23 23:06

parents: de7dff1d4f

build: Backport misc autoconf/pkgconf improvements

diff --git a/.gitignore b/.gitignore
index ffa9737b..5f648363 100644
--- a/.gitignore
+++ b/.gitignore
@@ -30,6 +30,7 @@
 /configure
 /configure.ac.save
 /build-aux
+/aclocal.m4
 /*~
 /config.status
 /config.log
diff --git a/GNUmakefile.in b/GNUmakefile.in
index 5ecda103..363d8f10 100644
--- a/GNUmakefile.in
+++ b/GNUmakefile.in
@@ -72,15 +72,18 @@ export AWK
 
 override DEFAULT_CPPFLAGS := @CPPFLAGS@
 $(eval $(call DEFAULT_VAR,CPPFLAGS,$(DEFAULT_CPPFLAGS)))
+override CPPFLAGS := @PKGCONF_CPPFLAGS@ $(CPPFLAGS)
 export CPPFLAGS
 override DEFAULT_CFLAGS := @CFLAGS@
 $(eval $(call DEFAULT_VAR,CFLAGS,$(DEFAULT_CFLAGS)))
+override CFLAGS += @PKGCONF_CFLAGS@
 export CFLAGS
 override DEFAULT_LDFLAGS := @LDFLAGS@
 $(eval $(call DEFAULT_VAR,LDFLAGS,$(DEFAULT_LDFLAGS)))
 export LDFLAGS
 override DEFAULT_LIBS := @LIBS@
 $(eval $(call DEFAULT_VAR,LIBS,$(DEFAULT_LIBS)))
+override LIBS += @PKGCONF_LIBS@
 export LIBS
 
 override WERROR_FLAG := @WERROR_FLAG@
@@ -333,7 +336,7 @@ distclean: clean
 
 .PHONY: maintainer-clean
 maintainer-clean: distclean
-	cd '$(call SHESCAPE,$(SRCDIR))' && rm -rf common/flanterm common/stb/stb_image.h decompressor/tinf freestanding-headers libgcc-binaries limine-efi freestanding-toolchain configure build-aux *'~' autom4te.cache *.tar.xz *.tar.gz
+	cd '$(call SHESCAPE,$(SRCDIR))' && rm -rf common/flanterm common/stb/stb_image.h decompressor/tinf freestanding-headers libgcc-binaries limine-efi freestanding-toolchain configure build-aux *'~' autom4te.cache aclocal.m4 *.tar.xz *.tar.gz
 
 .PHONY: common-uefi-x86-64
 common-uefi-x86-64:
diff --git a/configure.ac b/configure.ac
index f29b27bb..ea2c41bc 100644
--- a/configure.ac
+++ b/configure.ac
@@ -51,28 +51,60 @@ if ! test "x$FIND_FOUND" = "xyes"; then
     AC_MSG_ERROR([find not found, please install find before configuring])
 fi
 
-STRIP="$($CC -dumpmachine)"-strip
-AC_CHECK_PROG([STRIP_FOUND], [$STRIP], [yes])
-if ! test "x$STRIP_FOUND" = "xyes"; then
-    STRIP=strip
+AC_ARG_VAR([STRIP], [strip command])
+
+if ! test -z "$STRIP"; then
+    AC_CHECK_PROG([STRIP_USER_FOUND], [$STRIP], [yes])
+    if ! test "x$STRIP_USER_FOUND" = "xyes"; then
+        AC_MSG_ERROR([$STRIP not found, please install $STRIP before configuring])
+    fi
+else
+    STRIP="$($CC -dumpmachine)"-strip
+    AC_CHECK_PROG([STRIP_FOUND], [$STRIP], [yes])
+    if ! test "x$STRIP_FOUND" = "xyes"; then
+        STRIP=strip
+        AC_CHECK_PROG([STRIP_DEFAULT_FOUND], [$STRIP], [yes])
+        if ! test "x$STRIP_DEFAULT_FOUND" = "xyes"; then
+            AC_MSG_ERROR([$STRIP not found, please install $STRIP before configuring])
+        fi
+    fi
 fi
+
 AC_SUBST([STRIP])
 
-PKGCONFIG="$($CC -dumpmachine)"-pkg-config
-AC_CHECK_PROG([PKGCONFIG_FOUND], [$PKGCONFIG], [yes])
-if ! test "x$PKGCONFIG_FOUND" = "xyes"; then
-    PKGCONFIG=pkg-config
-fi
+PKGCONF_LIBS_LIST=""
+
+PKG_PROG_PKG_CONFIG
+
+for lib in $PKGCONF_LIBS_LIST; do
+    set -e
+    $PKG_CONFIG --exists --print-errors "$lib"
+    set +e
+done
 
-PKGCONFIG_LIBS=""
+PKGCONF_CFLAGS="$($PKG_CONFIG --cflags-only-other $PKGCONF_LIBS_LIST 2>/dev/null)"
+PKGCONF_CPPFLAGS="$($PKG_CONFIG --cflags-only-I $PKGCONF_LIBS_LIST 2>/dev/null)"
+PKGCONF_LIBS="$($PKG_CONFIG --libs $PKGCONF_LIBS_LIST 2>/dev/null)"
 
-CFLAGS="$CFLAGS $($PKGCONFIG --cflags-only-other $PKGCONFIG_LIBS 2>/dev/null)"
-CPPFLAGS="$($PKGCONFIG --cflags-only-I $PKGCONFIG_LIBS 2>/dev/null) $CPPFLAGS"
-LIBS="$LIBS $($PKGCONFIG --libs $PKGCONFIG_LIBS 2>/dev/null)"
+AC_SUBST([PKGCONF_CFLAGS])
+AC_SUBST([PKGCONF_CPPFLAGS])
+AC_SUBST([PKGCONF_LIBS])
+
+OLD_CFLAGS="$CFLAGS"
+OLD_CPPFLAGS="$CPPFLAGS"
+OLD_LIBS="$LIBS"
+
+CFLAGS="$CFLAGS $PKGCONF_CFLAGS"
+CPPFLAGS="$PKGCONF_CPPFLAGS $CPPFLAGS"
+LIBS="$LIBS $PKGCONF_LIBS"
 
 AC_CHECK_HEADERS([stdint.h stddef.h stdbool.h limits.h inttypes.h stdio.h stdlib.h string.h],
     [], [AC_MSG_ERROR([required header not found])])
 
+CFLAGS="$OLD_CFLAGS"
+CPPFLAGS="$OLD_CPPFLAGS"
+LIBS="$OLD_LIBS"
+
 AC_ARG_VAR([TOOLCHAIN_FOR_TARGET], [alternative toolchain prefix for Limine (or 'llvm', or 'gnu')])
 AC_ARG_VAR([CC_FOR_TARGET], [C compiler command for Limine])
 AC_ARG_VAR([LD_FOR_TARGET], [linker command for Limine])
tab: 248 wrap: offon