bsd.after-import.mk revision 246223
11573Srgrimes# $Id: bsd.after-import.mk,v 1.11 2012/12/29 19:32:25 sjg Exp $
21573Srgrimes
31573Srgrimes# This makefile is for use when integrating bmake into a BSD build
41573Srgrimes# system.  Use this makefile after importing bmake.
51573Srgrimes# It will bootstrap the new version,
61573Srgrimes# capture the generated files we need, and add an after-import
71573Srgrimes# target to allow the process to be easily repeated.
81573Srgrimes
91573Srgrimes# The goal is to allow the benefits of autoconf without
101573Srgrimes# the overhead of running configure.
111573Srgrimes
121573Srgrimesall: _makefile
131573Srgrimesall: after-import
141573Srgrimes
151573Srgrimes# we rely on bmake
161573Srgrimes.if !defined(.PARSEDIR)
171573Srgrimes.error this makefile requires bmake
181573Srgrimes.endif
191573Srgrimes
201573Srgrimes_this := ${MAKEFILE:tA} 
211573SrgrimesBMAKE_SRC := ${.PARSEDIR}
221573Srgrimes
231573Srgrimes# it helps to know where the top of the tree is.
241573Srgrimes.if !defined(SRCTOP)
251573Srgrimessrctop := ${.MAKE.MAKEFILES:M*src/share/mk/sys.mk:H:H:H}
261573Srgrimes.if empty(srctop)
271573Srgrimes# likely locations?
281573Srgrimes.for d in contrib/bmake external/bsd/bmake/dist
291573Srgrimes.if ${BMAKE_SRC:M*/$d} != ""
301573Srgrimessrctop := ${BMAKE_SRC:tA:S,/$d,,}
311573Srgrimes.endif
321573Srgrimes.endfor
331573Srgrimes.endif
341573Srgrimes.if !empty(srctop)
351573SrgrimesSRCTOP := ${srctop}
361573Srgrimes.endif
371573Srgrimes.endif
381573Srgrimes
391573Srgrimes# This lets us match what boot-strap does
4090045Sobrien.if !defined(HOST_OS)
4190045SobrienHOST_OS!= uname
421573Srgrimes.endif
431573Srgrimes
441573Srgrimes# .../share/mk will find ${SRCTOP}/share/mk
451573Srgrimes# if we are within ${SRCTOP}
461573SrgrimesDEFAULT_SYS_PATH= .../share/mk:/usr/share/mk
471573Srgrimes
481573SrgrimesBOOTSTRAP_ARGS = \
491573Srgrimes	--with-default-sys-path='${DEFAULT_SYS_PATH}' \
501573Srgrimes	--prefix /usr \
511573Srgrimes	--share /usr/share
521573Srgrimes
531573Srgrimes
541573Srgrimes# run boot-strap with minimal influence
551573Srgrimesbootstrap:	${BMAKE_SRC}/boot-strap ${MAKEFILE}
561573Srgrimes	HOME=/ ${BMAKE_SRC}/boot-strap -o ${HOST_OS} ${BOOTSTRAP_ARGS} ${BOOTSTRAP_XTRAS}
571573Srgrimes	touch ${.TARGET}
581573Srgrimes
591573Srgrimes# Makefiles need a little more tweaking than say config.h
601573SrgrimesMAKEFILE_SED = 	sed -e '/^MACHINE/d' \
611573Srgrimes	-e '/^PROG/ { s,=,?=,;s,bmake,$${.CURDIR:T},; }' \
621573Srgrimes	-e 's,^.-include,.sinclude,' \
638870Srgrimes	-e '/^\..*include  *</ { s,<,<bsd.,;/autoconf/d; }' \
641573Srgrimes	-e 's,${SRCTOP},$${SRCTOP},g'
651573Srgrimes
661573Srgrimes# These are the simple files we want to capture
671573Srgrimesconfigured_files= config.h Makefile.config unit-tests/Makefile
68132817Stjr
69132817Stjrafter-import: bootstrap ${MAKEFILE}
70132817Stjr.for f in ${configured_files:M*.[ch]}
71132817Stjr	@echo Capturing $f
72132817Stjr	@mkdir -p ${${.CURDIR}/$f:L:H}
73132817Stjr	@(echo '/* $$${HOST_OS}$$ */'; cat ${HOST_OS}/$f) > ${.CURDIR}/$f
74132817Stjr.endfor
75132817Stjr.for f in ${configured_files:M*Makefile*}
76132817Stjr	@echo Capturing $f
77132817Stjr	@mkdir -p ${${.CURDIR}/$f:L:H}
781573Srgrimes	@(echo '# This is a generated file, do NOT edit!'; \
791573Srgrimes	echo '# See ${_this:S,${SRCTOP}/,,}'; \
801573Srgrimes	echo '#'; echo '# $$${HOST_OS}$$'; echo; \
811573Srgrimes	echo 'SRCTOP?= $${.CURDIR:${${.CURDIR}/$f:L:H:S,${SRCTOP}/,,:C,[^/]+,H,g:S,/,:,g}}'; echo; \
821573Srgrimes	${MAKEFILE_SED} ${HOST_OS}/$f ) > ${.CURDIR}/$f
831573Srgrimes.endfor
841573Srgrimes
85132817Stjr# this needs the most work
861573Srgrimes_makefile:	bootstrap ${MAKEFILE}
87132817Stjr	@echo Generating ${.CURDIR}/Makefile
881573Srgrimes	@(echo '# This is a generated file, do NOT edit!'; \
891573Srgrimes	echo '# See ${_this:S,${SRCTOP}/,,}'; \
901573Srgrimes	echo '#'; echo '# $$${HOST_OS}$$'; \
911573Srgrimes	echo; echo '.sinclude "Makefile.inc"'; \
92132817Stjr	echo; echo 'SRCTOP?= $${.CURDIR:${.CURDIR:S,${SRCTOP}/,,:C,[^/]+,H,g:S,/,:,g}}'; \
931573Srgrimes	echo; echo '# look here first for config.h'; \
9419276Sache	echo 'CFLAGS+= -I$${.CURDIR}'; echo; \
9519276Sache	echo '# for after-import'; \
961573Srgrimes	echo 'CLEANDIRS+= ${HOST_OS}'; \
971573Srgrimes	echo 'CLEANFILES+= bootstrap'; echo; \
981573Srgrimes	${MAKEFILE_SED} \
991573Srgrimes	${1 2:L:@n@-e '/start-delete$n/,/end-delete$n/d'@} \
1001573Srgrimes	${BMAKE_SRC}/Makefile; \
1011573Srgrimes	echo; echo '# override some simple things'; \
1021573Srgrimes	echo 'BINDIR= /usr/bin'; \
1031573Srgrimes	echo 'MANDIR= ${MANDIR:U/usr/share/man}'; \
1041573Srgrimes	echo; echo '# make sure we get this'; \
1051573Srgrimes	echo 'CFLAGS+= $${COPTS.$${.IMPSRC:T}}'; \
1061573Srgrimes	echo; echo 'after-import: ${_this:S,${SRCTOP},\${SRCTOP},}'; \
1071573Srgrimes	echo '	cd $${.CURDIR} && $${.MAKE} -f ${_this:S,${SRCTOP},\${SRCTOP},}'; \
1081573Srgrimes	echo ) > ${.TARGET}
1091573Srgrimes	@cmp -s ${.TARGET} ${.CURDIR}/Makefile || \
1101573Srgrimes	    mv ${.TARGET} ${.CURDIR}/Makefile
1111573Srgrimes
1121573Srgrimes.include <bsd.obj.mk>
1131573Srgrimes
1141573Srgrimes