Add results from pkg-config to config.h

This commit is contained in:
Christophe de Dinechin 2018-04-10 22:15:28 +02:00
parent 6dd6537407
commit 0ae490d5fd
3 changed files with 31 additions and 20 deletions

View File

@ -132,27 +132,31 @@ MIQ_CFGLFLAGS= $(MIQ_LDFLAGS) \
MIQ_CFGFLAGS= $(MIQ_CFGLFLAGS) \
$(shell $(CAT) $(MIQ_PKGCFLAGS) $(MIQ_PKGLDFLAGS))
MIQ_CFGSET= && MIQ_CFGRC=1 || MIQ_CFGRC=0;
MIQ_CFGTEST= "$<" -o "$<".exe > "$<".err 2>&1 && \
[ -x "$<".exe ] && \
"$<".exe > "$<".out && MIQ_CFGRC=1 || MIQ_CFGRC=0;
"$<".exe > "$<".out \
$(MIQ_CFGSET)
MIQ_CFGUNDEF0= $$MIQ_CFGRC \
| sed -e 's|^\#define \(.*\) 0$$|/* \#undef \1 */|g' > "$@"; \
[ -f "$<".out ] && cat >> "$@" "$<".out; true
MIQ_CFGDEF= echo '\#define'
MIQ_CFGCFLAGS= $(MIQ_CFLAGS) $(MIQ_CFGFLAGS) $(CFLAGS_CONFIG_$*)
MIQ_CFGCXXFLAGS=$(MIQCXXFLAGS) $(MIQ_CFGFLAGS) $(CFLAGS_CONFIG_$*)
MIQ_CFGCFLAGS= $(CFLAGS) $(CFLAGS_CONFIG_$*)
MIQ_CFGCXXFLAGS=$(CXXFLAGS) $(CFLAGS_CONFIG_$*)
MIQ_CFGCC_CMD= $(CC) $(MIQ_CFGCFLAGS) $(MIQ_CFGTEST)
MIQ_CFGCXX_CMD= $(CXX) $(MIQ_CFGCXXFLAGS) $(MIQ_CFGTEST)
MIQ_CFGLIB_CMD= $(CC) $(MIQ_CFGLFLAGS) -l$* $(MIQ_CFGTEST)
MIQ_CFGFN_CMD= $(CC) $(MIQ_CFGCFLAGS) $(CFLAGS_CONFIG_$*) $(MIQ_CFGTEST)
MIQ_CFGCC_CMD= $(CC) $(MIQ_CFGCFLAGS) $(MIQ_CFGTEST)
MIQ_CFGCXX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^ ]*\) \(.*\)$$|\1=\2|g' \
-e 's|.*undef.*||g' < "$<" > "$@"

View File

@ -65,7 +65,7 @@ NOT_PARALLEL?= .NOTPARALLEL
GIT_REVISION:= $(shell git rev-parse --short HEAD 2> /dev/null || echo "unknown")
# Package installation directory
PACKAGE_DIR=$(PACKAGE_NAME:%=%/)
PACKAGE_DIR?=$(PACKAGE_NAME:%=%/)
PACKAGE_LIBS=$(MIQ_PRODLIB)
PACKAGE_DLLS=$(MIQ_PRODDLL)

View File

@ -436,7 +436,9 @@ $(MIQ_OUTEXE): $(MIQ_TOLINK) $$(MIQ_TOLINK) $(MIQ_MAKEDEPS)
# Package configuration file
MIQ_PKGCFLAGS= $(PKGCONFIGS:%=$(MIQ_OBJDIR)%.pkg-config.cflags)
MIQ_PKGLDFLAGS= $(PKGCONFIGS:%=$(MIQ_OBJDIR)%.pkg-config.ldflags)
MIQ_PKGLIBS= $(patsubst %,$(OBJDIR)%.cfg.ldflags,$(filter lib%,$(CONFIG)))
MIQ_PKGCONFIGS= $(PKGCONFIGS:%?=%)
MIQ_PKGCFG= $(MIQ_PKGONFIGS:%=$(MIQ_OBJDIR)CFG_HAVE_PACKAGE_%.h)
MIQ_PKGLIBS= $(patsubst %,$(MIQ_OBJDIR)%.cfg.ldflags,$(filter lib%,$(CONFIG)))
MIQ_PKGDEPS= $(MIQ_MAKEDEPS) $(MIQ_OBJDIR).mkdir
# Build the package config from cflags, ldflags and libs config
@ -467,7 +469,7 @@ $(MIQ_OBJDIR)lib%.cfg.ldflags: $(MIQ_OBJDIR)CFG_HAVE_lib%.h $(MIQ_PKGDEPS)
#------------------------------------------------------------------------------
# Normalize header configuration name (turn <foo.h> into .lt.foo.h.gt. and back)
MIQ_NORMCONFIG=$(subst <,.lt.,$(subst >,.gt.,$(subst /,.sl.,$(CONFIG))))
MIQ_NORMCONFIG=$(subst <,.lt.,$(subst >,.gt.,$(subst /,.sl.,$(CONFIG) $(PKGCONFIGS:%=PACKAGE_%))))
MIQ_ORIGTARGET=$(subst .lt.,<,$(subst .gt.,>,$(subst .sl.,/,$*)))
MIQ_CONFIGDEPS= $(MIQ_PKGDEPS) \
$(PKGCONFIGS:%=$(MIQ_OBJDIR)pkg-config.mk) \
@ -479,39 +481,44 @@ config.h: $(MIQ_NORMCONFIG:%=$(MIQ_OBJDIR)CFG_HAVE_%.h)
# Build makefile configuration files from generated .h files
$(MIQ_OBJDIR)CFG_HAVE_%.mk: $(MIQ_OBJDIR)CFG_HAVE_%.h $(MIQ_MAKEDEPS)
$(PRINT_COMMAND) $(MAKE_CONFIG)
$(PRINT_COMMAND) $(MIQ_MK_CFG)
-include $(MIQ_NORMCONFIG:%=$(MIQ_OBJDIR)CFG_HAVE_%.mk)
# C standard headers, e.g. HAVE_<stdio.h>
$(MIQ_OBJDIR)CFG_HAVE_.lt.%.h.gt..h: $(MIQ_OBJDIR)CFGCH%.c $(MIQ_CONFIGDEPS)
$(PRINT_CONFIG) $(CC_CONFIG)
$(PRINT_CONFIG) $(MIQ_CC_CFG)
$(MIQ_OBJDIR)CFGCH%.c: $(MIQ_OBJDIR).mkdir $(MIQ_CONFIGDEPS)
$(PRINT_COMMAND) (echo '#include' "<$(MIQ_ORIGTARGET).h>" && echo 'int main() { return 0; }') > "$@"
.PRECIOUS: $(MIQ_OBJDIR)CFGCH%.c
# C++ Standard headers, e.g. HAVE_<iostream>
$(MIQ_OBJDIR)CFG_HAVE_.lt.%.gt..h: $(MIQ_OBJDIR)CFGCPPH%.cpp $(MIQ_CONFIGDEPS)
$(PRINT_CONFIG) $(CXX_CONFIG)
$(PRINT_CONFIG) $(MIQ_CXX_CFG)
$(MIQ_OBJDIR)CFGCPPH%.cpp: $(MIQ_OBJDIR).mkdir $(MIQ_CONFIGDEPS)
$(PRINT_COMMAND) (echo '#include' "<$(MIQ_ORIGTARGET)>" && echo 'int main() { return 0; }') > "$@"
.PRECIOUS: $(MIQ_OBJDIR)CFGCPPH%.cpp
# Library, e.g. libm
$(MIQ_OBJDIR)CFG_HAVE_lib%.h: $(MIQ_OBJDIR)CFGLIB%.c $(MIQ_PKGDEPS)
$(PRINT_LIBCONFIG) $(LIB_CONFIG)
$(PRINT_CONFIG) $(MIQ_LIB_CFG)
$(MIQ_OBJDIR)CFGLIB%.c: $(MIQ_PKGDEPS)
$(PRINT_COMMAND) echo 'int main() { return 0; }' > "$@"
.PRECIOUS: $(MIQ_OBJDIR)CFGLIB%.c
# Check if a function is present (code to test in config/check_foo.c)
$(MIQ_OBJDIR)CFG_HAVE_%.h: $(MIQ_OBJDIR)CFGFN%.c $(MIQ_CONFIGDEPS)
$(PRINT_CONFIG) $(FN_CONFIG)
$(PRINT_CONFIG) $(MIQ_FN_CFG)
$(MIQ_OBJDIR)CFGFN%.c: $(CONFIG_SOURCES)check_%.c $(MIQ_CONFIGDEPS)
$(PRINT_COMMAND) cp $< $@
$(MIQ_OBJDIR)CFGFN%.c: config/check_%.c $(MIQ_CONFIGDEPS)
$(PRINT_COMMAND) cp $< $@
.PRECIOUS: $(MIQ_OBJDIR)CFGFN%.c
# Packages
$(MIQ_OBJDIR)CFG_HAVE_PACKAGE_%?.h: $(MIQ_CONFIGDEPS)
$(PRINT_CONFIG) $(MIQ_PK_CFG)
$(MIQ_OBJDIR)CFG_HAVE_PACKAGE_%.h: $(MIQ_CONFIGDEPS)
$(PRINT_CONFIG) $(MIQ_PK_CFG)
endif