summaryrefslogtreecommitdiffstats
path: root/build/pkgs.mk
blob: 5de9ac2fabcfe7884ee6827d70e21c63ba8f8da0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# Copyright © Tavian Barnes <tavianator@tavianator.com>
# SPDX-License-Identifier: 0BSD

# Makefile that generates gen/pkgs.mk

include build/prelude.mk
include gen/vars.mk
include gen/flags.mk
include build/exports.mk

HEADERS := ${ALL_PKGS:%=gen/with/%.h}

gen/pkgs.mk: ${HEADERS}
	${MSG} "[ GEN] $@"
	@printf '# %s\n' "$@" >$@
	@gen() { \
	    printf 'PKGS := %s\n' "$$*"; \
	    printf '_CFLAGS += %s\n' "$$(build/pkgconf.sh --cflags "$$@")"; \
	    printf '_LDFLAGS += %s\n' "$$(build/pkgconf.sh --ldflags "$$@")"; \
	    printf '_LDLIBS := %s $${_LDLIBS}\n' "$$(build/pkgconf.sh --ldlibs "$$@")"; \
	}; \
	gen $$(grep -l ' true$$' ${.ALLSRC} | sed 's|.*/\(.*\)\.h|\1|') >>$@
	${VCAT} $@

.PHONY: gen/pkgs.mk

# Convert gen/with/foo.h to foo
PKG = ${@:gen/with/%.h=%}

${HEADERS}::
	@${MKDIR} ${@D}
	@build/define-if.sh with/${PKG} build/pkgconf.sh ${PKG} >$@ 2>$@.log; \
	    build/msg-if.sh "[ CC ] with/${PKG}.c" test $$? -eq 0;