xref: /freebsd/contrib/bmake/bsd.after-import.mk (revision 5e53a4f90f82c4345f277dd87cc9292f26e04a29)
1# $Id: bsd.after-import.mk,v 1.13 2017/08/13 00:56:10 sjg Exp $
2
3# This makefile is for use when integrating bmake into a BSD build
4# system.  Use this makefile after importing bmake.
5# It will bootstrap the new version,
6# capture the generated files we need, and add an after-import
7# target to allow the process to be easily repeated.
8
9# The goal is to allow the benefits of autoconf without
10# the overhead of running configure.
11
12all: _makefile
13all: after-import
14
15# we rely on bmake
16.if !defined(.PARSEDIR)
17.error this makefile requires bmake
18.endif
19
20_this := ${MAKEFILE:tA}
21BMAKE_SRC := ${.PARSEDIR}
22
23# it helps to know where the top of the tree is.
24.if !defined(SRCTOP)
25srctop := ${.MAKE.MAKEFILES:M*src/share/mk/sys.mk:H:H:H}
26.if empty(srctop)
27# likely locations?
28.for d in contrib/bmake external/bsd/bmake/dist
29.if ${BMAKE_SRC:M*/$d} != ""
30srctop := ${BMAKE_SRC:tA:S,/$d,,}
31.endif
32.endfor
33.endif
34.if !empty(srctop)
35SRCTOP := ${srctop}
36.endif
37.endif
38
39# This lets us match what boot-strap does
40.if !defined(HOST_OS)
41HOST_OS!= uname
42.endif
43
44BOOTSTRAP_ARGS = \
45	--prefix /usr \
46	--share /usr/share
47
48.if !empty(DEFAULT_SYS_PATH)
49BOOTSTRAP_ARGS += --with-default-sys-path='${DEFAULT_SYS_PATH}'
50.endif
51
52# run boot-strap with minimal influence
53bootstrap:	${BMAKE_SRC}/boot-strap ${MAKEFILE}
54	HOME=/ ${BMAKE_SRC}/boot-strap -o ${HOST_OS} ${BOOTSTRAP_ARGS} ${BOOTSTRAP_XTRAS}
55	touch ${.TARGET}
56
57# Makefiles need a little more tweaking than say config.h
58MAKEFILE_SED = 	sed -e '/^MACHINE/d' \
59	-e '/include.*VERSION/d' \
60	-e '/^PROG/ { s,=,?=,;s,bmake,$${.CURDIR:T},; }' \
61	-e 's,^.-include,.sinclude,' \
62	-e '/^\..*include  *</ { s,<,<bsd.,;/autoconf/d; }' \
63	-e 's,${SRCTOP},$${SRCTOP},g'
64
65# These are the simple files we want to capture
66configured_files= config.h Makefile.config unit-tests/Makefile
67
68after-import: bootstrap ${MAKEFILE}
69.for f in ${configured_files:M*.[ch]}
70	@echo Capturing $f
71	@mkdir -p ${${.CURDIR}/$f:L:H}
72	@(echo '/* $$${HOST_OS}$$ */'; cat ${HOST_OS}/$f) > ${.CURDIR}/$f
73.endfor
74.for f in ${configured_files:M*Makefile*}
75	@echo Capturing $f
76	@mkdir -p ${${.CURDIR}/$f:L:H}
77	@(echo '# This is a generated file, do NOT edit!'; \
78	echo '# See ${_this:S,${SRCTOP}/,,}'; \
79	echo '#'; echo '# $$${HOST_OS}$$'; echo; \
80	echo 'SRCTOP?= $${.CURDIR:${${.CURDIR}/$f:L:H:S,${SRCTOP}/,,:C,[^/]+,H,g:S,/,:,g}}'; echo; \
81	${MAKEFILE_SED} ${HOST_OS}/$f ) > ${.CURDIR}/$f
82.endfor
83
84# this needs the most work
85_makefile:	bootstrap ${MAKEFILE}
86	@echo Generating ${.CURDIR}/Makefile
87	@(echo '# This is a generated file, do NOT edit!'; \
88	echo '# See ${_this:S,${SRCTOP}/,,}'; \
89	echo '#'; echo '# $$${HOST_OS}$$'; \
90	echo; echo '.sinclude "Makefile.inc"'; \
91	echo; echo 'SRCTOP?= $${.CURDIR:${.CURDIR:S,${SRCTOP}/,,:C,[^/]+,H,g:S,/,:,g}}'; \
92	echo; echo '# look here first for config.h'; \
93	echo 'CFLAGS+= -I$${.CURDIR}'; echo; \
94	echo '# for after-import'; \
95	echo 'CLEANDIRS+= ${HOST_OS}'; \
96	echo 'CLEANFILES+= bootstrap'; echo; \
97	${MAKEFILE_SED} \
98	${1 2:L:@n@-e '/start-delete$n/,/end-delete$n/d'@} \
99	${BMAKE_SRC}/Makefile; \
100	echo; echo '# override some simple things'; \
101	echo 'BINDIR= /usr/bin'; \
102	echo 'MANDIR= ${MANDIR:U/usr/share/man}'; \
103	echo; echo '# make sure we get this'; \
104	echo 'CFLAGS+= $${COPTS.$${.IMPSRC:T}}'; \
105	echo; echo 'after-import: ${_this:S,${SRCTOP},\${SRCTOP},}'; \
106	echo '	cd $${.CURDIR} && $${.MAKE} -f ${_this:S,${SRCTOP},\${SRCTOP},}'; \
107	echo ) > ${.TARGET}
108	@cmp -s ${.TARGET} ${.CURDIR}/Makefile || \
109	    mv ${.TARGET} ${.CURDIR}/Makefile
110
111.include <bsd.obj.mk>
112
113