1246223Ssjg# $Id: bsd.after-import.mk,v 1.11 2012/12/29 19:32:25 sjg Exp $
2236769Sobrien
3236769Sobrien# This makefile is for use when integrating bmake into a BSD build
4236769Sobrien# system.  Use this makefile after importing bmake.
5236769Sobrien# It will bootstrap the new version,
6236769Sobrien# capture the generated files we need, and add an after-import
7236769Sobrien# target to allow the process to be easily repeated.
8236769Sobrien
9236769Sobrien# The goal is to allow the benefits of autoconf without
10236769Sobrien# the overhead of running configure.
11236769Sobrien
12238152Sobrienall: _makefile
13236769Sobrienall: after-import
14236769Sobrien
15236769Sobrien# we rely on bmake
16240330Smarcel.if !defined(.PARSEDIR)
17237578Sobrien.error this makefile requires bmake
18237578Sobrien.endif
19237578Sobrien
20236769Sobrien_this := ${MAKEFILE:tA} 
21236769SobrienBMAKE_SRC := ${.PARSEDIR}
22236769Sobrien
23236769Sobrien# it helps to know where the top of the tree is.
24236769Sobrien.if !defined(SRCTOP)
25236769Sobriensrctop := ${.MAKE.MAKEFILES:M*src/share/mk/sys.mk:H:H:H}
26237578Sobrien.if empty(srctop)
27237578Sobrien# likely locations?
28237578Sobrien.for d in contrib/bmake external/bsd/bmake/dist
29237578Sobrien.if ${BMAKE_SRC:M*/$d} != ""
30237578Sobriensrctop := ${BMAKE_SRC:tA:S,/$d,,}
31237578Sobrien.endif
32237578Sobrien.endfor
33237578Sobrien.endif
34236769Sobrien.if !empty(srctop)
35236769SobrienSRCTOP := ${srctop}
36236769Sobrien.endif
37236769Sobrien.endif
38236769Sobrien
39236769Sobrien# This lets us match what boot-strap does
40236769Sobrien.if !defined(HOST_OS)
41236769SobrienHOST_OS!= uname
42236769Sobrien.endif
43236769Sobrien
44236769Sobrien# .../share/mk will find ${SRCTOP}/share/mk
45236769Sobrien# if we are within ${SRCTOP}
46236769SobrienDEFAULT_SYS_PATH= .../share/mk:/usr/share/mk
47236769Sobrien
48236769SobrienBOOTSTRAP_ARGS = \
49236769Sobrien	--with-default-sys-path='${DEFAULT_SYS_PATH}' \
50236769Sobrien	--prefix /usr \
51246223Ssjg	--share /usr/share
52236769Sobrien
53246223Ssjg
54236769Sobrien# run boot-strap with minimal influence
55236769Sobrienbootstrap:	${BMAKE_SRC}/boot-strap ${MAKEFILE}
56246223Ssjg	HOME=/ ${BMAKE_SRC}/boot-strap -o ${HOST_OS} ${BOOTSTRAP_ARGS} ${BOOTSTRAP_XTRAS}
57236769Sobrien	touch ${.TARGET}
58236769Sobrien
59236769Sobrien# Makefiles need a little more tweaking than say config.h
60236769SobrienMAKEFILE_SED = 	sed -e '/^MACHINE/d' \
61242102Ssjg	-e '/^PROG/ { s,=,?=,;s,bmake,$${.CURDIR:T},; }' \
62237578Sobrien	-e 's,^.-include,.sinclude,' \
63246223Ssjg	-e '/^\..*include  *</ { s,<,<bsd.,;/autoconf/d; }' \
64236769Sobrien	-e 's,${SRCTOP},$${SRCTOP},g'
65236769Sobrien
66236769Sobrien# These are the simple files we want to capture
67246223Ssjgconfigured_files= config.h Makefile.config unit-tests/Makefile
68236769Sobrien
69236769Sobrienafter-import: bootstrap ${MAKEFILE}
70246223Ssjg.for f in ${configured_files:M*.[ch]}
71236769Sobrien	@echo Capturing $f
72237578Sobrien	@mkdir -p ${${.CURDIR}/$f:L:H}
73246223Ssjg	@(echo '/* $$${HOST_OS}$$ */'; cat ${HOST_OS}/$f) > ${.CURDIR}/$f
74236769Sobrien.endfor
75246223Ssjg.for f in ${configured_files:M*Makefile*}
76236769Sobrien	@echo Capturing $f
77237578Sobrien	@mkdir -p ${${.CURDIR}/$f:L:H}
78240330Smarcel	@(echo '# This is a generated file, do NOT edit!'; \
79240330Smarcel	echo '# See ${_this:S,${SRCTOP}/,,}'; \
80246223Ssjg	echo '#'; echo '# $$${HOST_OS}$$'; echo; \
81240330Smarcel	echo 'SRCTOP?= $${.CURDIR:${${.CURDIR}/$f:L:H:S,${SRCTOP}/,,:C,[^/]+,H,g:S,/,:,g}}'; echo; \
82240330Smarcel	${MAKEFILE_SED} ${HOST_OS}/$f ) > ${.CURDIR}/$f
83236769Sobrien.endfor
84236769Sobrien
85236769Sobrien# this needs the most work
86238152Sobrien_makefile:	bootstrap ${MAKEFILE}
87238152Sobrien	@echo Generating ${.CURDIR}/Makefile
88236769Sobrien	@(echo '# This is a generated file, do NOT edit!'; \
89236769Sobrien	echo '# See ${_this:S,${SRCTOP}/,,}'; \
90246223Ssjg	echo '#'; echo '# $$${HOST_OS}$$'; \
91242102Ssjg	echo; echo '.sinclude "Makefile.inc"'; \
92242102Ssjg	echo; echo 'SRCTOP?= $${.CURDIR:${.CURDIR:S,${SRCTOP}/,,:C,[^/]+,H,g:S,/,:,g}}'; \
93236769Sobrien	echo; echo '# look here first for config.h'; \
94236769Sobrien	echo 'CFLAGS+= -I$${.CURDIR}'; echo; \
95246223Ssjg	echo '# for after-import'; \
96246223Ssjg	echo 'CLEANDIRS+= ${HOST_OS}'; \
97246223Ssjg	echo 'CLEANFILES+= bootstrap'; echo; \
98246223Ssjg	${MAKEFILE_SED} \
99246223Ssjg	${1 2:L:@n@-e '/start-delete$n/,/end-delete$n/d'@} \
100246223Ssjg	${BMAKE_SRC}/Makefile; \
101236769Sobrien	echo; echo '# override some simple things'; \
102236769Sobrien	echo 'BINDIR= /usr/bin'; \
103242102Ssjg	echo 'MANDIR= ${MANDIR:U/usr/share/man}'; \
104236769Sobrien	echo; echo '# make sure we get this'; \
105236769Sobrien	echo 'CFLAGS+= $${COPTS.$${.IMPSRC:T}}'; \
106236769Sobrien	echo; echo 'after-import: ${_this:S,${SRCTOP},\${SRCTOP},}'; \
107236769Sobrien	echo '	cd $${.CURDIR} && $${.MAKE} -f ${_this:S,${SRCTOP},\${SRCTOP},}'; \
108238152Sobrien	echo ) > ${.TARGET}
109238152Sobrien	@cmp -s ${.TARGET} ${.CURDIR}/Makefile || \
110238152Sobrien	    mv ${.TARGET} ${.CURDIR}/Makefile
111236769Sobrien
112236769Sobrien.include <bsd.obj.mk>
113236769Sobrien
114