summaryrefslogtreecommitdiffstats
path: root/build/config.mk
blob: 6296168c415596c2470af01716f9f16f4c12e8cf (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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# Copyright © Tavian Barnes <tavianator@tavianator.com>
# SPDX-License-Identifier: 0BSD

# Makefile that implements `./configure`

include build/prelude.mk
include build/exports.mk

# All configuration steps
config: gen/config.mk
.PHONY: config

# Makefile fragments generated by `./configure`
MKS := \
    gen/vars.mk \
    gen/flags.mk \
    gen/pkgs.mk

# The main configuration file, which includes the others
gen/config.mk: ${MKS} gen/config.h
	${MSG} "[ GEN] $@"
	@printf '# %s\n' "$@" >$@
	@printf 'include %s\n' ${MKS} >>$@
	${VCAT} gen/config.mk
.PHONY: gen/config.mk

# Saves the configurable variables
gen/vars.mk::
	@${MKDIR} ${@D}
	${MSG} "[ GEN] $@"
	@printf '# %s\n' "$@" >$@
	@printf 'PREFIX := %s\n' "$$XPREFIX" >>$@
	@printf 'MANDIR := %s\n' "$$XMANDIR" >>$@
	@printf 'OS := %s\n' "$${OS:-$$(uname)}" >>$@
	@printf 'CC := %s\n' "$$XCC" >>$@
	@printf 'INSTALL := %s\n' "$$XINSTALL" >>$@
	@printf 'MKDIR := %s\n' "$$XMKDIR" >>$@
	@printf 'PKG_CONFIG := %s\n' "$$XPKG_CONFIG" >>$@
	@printf 'RM := %s\n' "$$XRM" >>$@
	@test -z "$$VERSION" || printf 'export VERSION=%s\n' "$$VERSION" >>$@
	${VCAT} $@

# Sets the build flags.  This depends on vars.mk and uses a recursive make so
# that the default flags can depend on variables like ${OS}.
gen/flags.mk: gen/vars.mk
	@+XMAKEFLAGS="$$MAKEFLAGS" ${MAKE} -sf build/flags.mk $@
.PHONY: gen/flags.mk

# Auto-detect dependencies and their build flags
gen/pkgs.mk: gen/flags.mk
	@+XMAKEFLAGS="$$MAKEFLAGS" ${MAKE} -sf build/pkgs.mk $@
.PHONY: gen/pkgs.mk

# Compile-time feature detection
gen/config.h: gen/pkgs.mk
	@+XMAKEFLAGS="$$MAKEFLAGS" ${MAKE} -sf build/header.mk $@
.PHONY: gen/config.h