1 # $Id: bsd.after-import.mk,v 1.9 2012/09/20 00:30:15 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.
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
44 # .../share/mk will find ${SRCTOP}/share/mk
45 # if we are within ${SRCTOP}
46 DEFAULT_SYS_PATH= .../share/mk:/usr/share/mk
49 --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 ${BOOTSTRAP_ARGS} ${BOOTSTRAP_XTRAS}
59 # Makefiles need a little more tweaking than say config.h
60 MAKEFILE_SED = sed -e '/^MACHINE/d' \
61 -e '/^PROG/ { s,=,?=,;s,bmake,$${.CURDIR:T},; }' \
62 -e 's,^.-include,.sinclude,' \
63 -e 's,${SRCTOP},$${SRCTOP},g'
65 # These are the simple files we want to capture
66 configured_files= config.h unit-tests/Makefile
68 after-import: bootstrap ${MAKEFILE}
69 .for f in ${configured_files:N*Makefile}
71 @mkdir -p ${${.CURDIR}/$f:L:H}
72 @cmp -s ${.CURDIR}/$f ${HOST_OS}/$f || \
73 cp ${HOST_OS}/$f ${.CURDIR}/$f
75 .for f in ${configured_files:M*Makefile}
77 @mkdir -p ${${.CURDIR}/$f:L:H}
78 @(echo '# This is a generated file, do NOT edit!'; \
79 echo '# See ${_this:S,${SRCTOP}/,,}'; \
80 echo '#'; echo '# $$${OS}$$'; echo; \
81 echo 'SRCTOP?= $${.CURDIR:${${.CURDIR}/$f:L:H:S,${SRCTOP}/,,:C,[^/]+,H,g:S,/,:,g}}'; echo; \
82 ${MAKEFILE_SED} ${HOST_OS}/$f ) > ${.CURDIR}/$f
85 # this needs the most work
86 _makefile: bootstrap ${MAKEFILE}
87 @echo Generating ${.CURDIR}/Makefile
88 @(echo '# This is a generated file, do NOT edit!'; \
89 echo '# See ${_this:S,${SRCTOP}/,,}'; \
90 echo '#'; echo '# $$${OS}$$'; \
91 echo; echo '.sinclude "Makefile.inc"'; \
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 ${MAKEFILE_SED} ${HOST_OS}/Makefile; \
96 echo; echo '# override some simple things'; \
97 echo 'BINDIR= /usr/bin'; \
98 echo 'MANDIR= ${MANDIR:U/usr/share/man}'; \
99 echo; echo '# make sure we get this'; \
100 echo 'CFLAGS+= $${COPTS.$${.IMPSRC:T}}'; \
101 echo 'CLEANFILES+= bootstrap'; \
102 echo; echo 'after-import: ${_this:S,${SRCTOP},\${SRCTOP},}'; \
103 echo ' cd $${.CURDIR} && $${.MAKE} -f ${_this:S,${SRCTOP},\${SRCTOP},}'; \
105 @cmp -s ${.TARGET} ${.CURDIR}/Makefile || \
106 mv ${.TARGET} ${.CURDIR}/Makefile
108 .include <bsd.obj.mk>