1 # $Id: bsd.after-import.mk,v 1.16 2020/07/12 03:39:01 sjg Exp $
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.
9 # The goal is to allow the benefits of autoconf without
10 # the overhead of running configure.
12 all: _makefile _utmakefile
16 .if !defined(.PARSEDIR)
17 .error this makefile requires bmake
20 _this := ${MAKEFILE:tA}
21 BMAKE_SRC := ${.PARSEDIR}
23 # it helps to know where the top of the tree is.
25 srctop := ${.MAKE.MAKEFILES:M*src/share/mk/sys.mk:H:H:H}
28 .for d in contrib/bmake external/bsd/bmake/dist
29 .if ${BMAKE_SRC:M*/$d} != ""
30 srctop := ${BMAKE_SRC:tA:S,/$d,,}
39 # This lets us match what boot-strap does
42 .elif !defined(HOST_OS)
50 .if !empty(DEFAULT_SYS_PATH)
51 BOOTSTRAP_ARGS += --with-default-sys-path='${DEFAULT_SYS_PATH}'
54 # run boot-strap with minimal influence
55 bootstrap: ${BMAKE_SRC}/boot-strap ${MAKEFILE}
56 HOME=/ ${BMAKE_SRC}/boot-strap -o ${HOST_OS} ${BOOTSTRAP_ARGS} ${BOOTSTRAP_XTRAS}
59 # Makefiles need a little more tweaking than say config.h
60 MAKEFILE_SED = sed -e '/^MACHINE/d' \
61 -e '/include.*VERSION/d' \
62 -e '/^PROG/ { s,=,?=,;s,bmake,$${.CURDIR:T},; }' \
63 -e 's,^.-include,.sinclude,' \
64 -e '/^\..*include *</ { s,<,<bsd.,;/autoconf/d; }' \
65 -e 's,${SRCTOP},$${SRCTOP},g'
67 # These are the simple files we want to capture
68 configured_files= config.h Makefile.config unit-tests/Makefile.config
70 after-import: bootstrap ${MAKEFILE}
71 .for f in ${configured_files:M*.[ch]}
73 @mkdir -p ${${.CURDIR}/$f:L:H}
74 @(echo '/* $$${HOST_OS}$$ */'; cat ${HOST_OS}/$f) > ${.CURDIR}/$f
76 .for f in ${configured_files:M*Makefile*}
78 @mkdir -p ${${.CURDIR}/$f:L:H}
79 @(echo '# This is a generated file, do NOT edit!'; \
80 echo '# See ${_this:S,${SRCTOP}/,,}'; \
81 echo '#'; echo '# $$${HOST_OS}$$'; echo; \
82 echo 'SRCTOP?= $${.CURDIR:${${.CURDIR}/$f:L:H:S,${SRCTOP}/,,:C,[^/]+,H,g:S,/,:,g}}'; echo; \
83 ${MAKEFILE_SED} ${HOST_OS}/$f ) > ${.CURDIR}/$f
86 # this needs the most work
87 _makefile: bootstrap ${MAKEFILE}
88 @echo Generating ${.CURDIR}/Makefile
89 @(echo '# This is a generated file, do NOT edit!'; \
90 echo '# See ${_this:S,${SRCTOP}/,,}'; \
91 echo '#'; echo '# $$${HOST_OS}$$'; \
92 echo; echo 'SRCTOP?= $${.CURDIR:${.CURDIR:S,${SRCTOP}/,,:C,[^/]+,H,g:S,/,:,g}}'; \
93 echo; echo '# look here first for config.h'; \
94 echo 'CFLAGS+= -I$${.CURDIR}'; echo; \
95 echo '# for after-import'; \
96 echo 'CLEANDIRS+= ${HOST_OS}'; \
97 echo 'CLEANFILES+= bootstrap'; echo; \
99 ${1 2:L:@n@-e '/start-delete$n/,/end-delete$n/d'@} \
100 ${BMAKE_SRC}/Makefile; \
101 echo; echo '# override some simple things'; \
102 echo 'BINDIR= /usr/bin'; \
103 echo 'MANDIR= ${MANDIR:U/usr/share/man}'; \
104 echo; echo '# make sure we get this'; \
105 echo 'CFLAGS+= $${COPTS.$${.IMPSRC:T}}'; \
106 echo; echo 'after-import: ${_this:S,${SRCTOP},\${SRCTOP},}'; \
107 echo ' cd $${.CURDIR} && $${.MAKE} -f ${_this:S,${SRCTOP},\${SRCTOP},}'; \
109 @cmp -s ${.TARGET} ${.CURDIR}/Makefile || \
110 mv ${.TARGET} ${.CURDIR}/Makefile
112 _utmakefile: bootstrap ${MAKEFILE}
113 @echo Generating ${.CURDIR}/unit-tests/Makefile
114 @mkdir -p ${.CURDIR}/unit-tests
115 @(echo '# This is a generated file, do NOT edit!'; \
116 echo '# See ${_this:S,${SRCTOP}/,,}'; \
117 echo '#'; echo '# $$${HOST_OS}$$'; \
119 -e '/^UNIT_TESTS/s,=.*,= $${srcdir},' \
120 ${BMAKE_SRC}/unit-tests/Makefile ) > ${.TARGET}
121 @cmp -s ${.TARGET} ${.CURDIR}/unit-tests/Makefile || \
122 mv ${.TARGET} ${.CURDIR}/unit-tests/Makefile
125 .include <bsd.obj.mk>