xref: /freebsd/contrib/bmake/bsd.after-import.mk (revision 93036677b5ff3738ff1ee47c7209303fdef4d519)
1*93036677SSimon J. Gerraty# $Id: bsd.after-import.mk,v 1.9 2012/09/20 00:30:15 sjg Exp $
23955d011SMarcel Moolenaar
33955d011SMarcel Moolenaar# This makefile is for use when integrating bmake into a BSD build
43955d011SMarcel Moolenaar# system.  Use this makefile after importing bmake.
53955d011SMarcel Moolenaar# It will bootstrap the new version,
63955d011SMarcel Moolenaar# capture the generated files we need, and add an after-import
73955d011SMarcel Moolenaar# target to allow the process to be easily repeated.
83955d011SMarcel Moolenaar
93955d011SMarcel Moolenaar# The goal is to allow the benefits of autoconf without
103955d011SMarcel Moolenaar# the overhead of running configure.
113955d011SMarcel Moolenaar
123955d011SMarcel Moolenaarall: _makefile
133955d011SMarcel Moolenaarall: after-import
143955d011SMarcel Moolenaar
153955d011SMarcel Moolenaar# we rely on bmake
163955d011SMarcel Moolenaar.if !defined(.PARSEDIR)
173955d011SMarcel Moolenaar.error this makefile requires bmake
183955d011SMarcel Moolenaar.endif
193955d011SMarcel Moolenaar
203955d011SMarcel Moolenaar_this := ${MAKEFILE:tA}
213955d011SMarcel MoolenaarBMAKE_SRC := ${.PARSEDIR}
223955d011SMarcel Moolenaar
233955d011SMarcel Moolenaar# it helps to know where the top of the tree is.
243955d011SMarcel Moolenaar.if !defined(SRCTOP)
253955d011SMarcel Moolenaarsrctop := ${.MAKE.MAKEFILES:M*src/share/mk/sys.mk:H:H:H}
263955d011SMarcel Moolenaar.if empty(srctop)
273955d011SMarcel Moolenaar# likely locations?
283955d011SMarcel Moolenaar.for d in contrib/bmake external/bsd/bmake/dist
293955d011SMarcel Moolenaar.if ${BMAKE_SRC:M*/$d} != ""
303955d011SMarcel Moolenaarsrctop := ${BMAKE_SRC:tA:S,/$d,,}
313955d011SMarcel Moolenaar.endif
323955d011SMarcel Moolenaar.endfor
333955d011SMarcel Moolenaar.endif
343955d011SMarcel Moolenaar.if !empty(srctop)
353955d011SMarcel MoolenaarSRCTOP := ${srctop}
363955d011SMarcel Moolenaar.endif
373955d011SMarcel Moolenaar.endif
383955d011SMarcel Moolenaar
393955d011SMarcel Moolenaar# This lets us match what boot-strap does
403955d011SMarcel Moolenaar.if !defined(HOST_OS)
413955d011SMarcel MoolenaarHOST_OS!= uname
423955d011SMarcel Moolenaar.endif
433955d011SMarcel Moolenaar
443955d011SMarcel Moolenaar# .../share/mk will find ${SRCTOP}/share/mk
453955d011SMarcel Moolenaar# if we are within ${SRCTOP}
463955d011SMarcel MoolenaarDEFAULT_SYS_PATH= .../share/mk:/usr/share/mk
473955d011SMarcel Moolenaar
483955d011SMarcel MoolenaarBOOTSTRAP_ARGS = \
493955d011SMarcel Moolenaar	--with-default-sys-path='${DEFAULT_SYS_PATH}' \
503955d011SMarcel Moolenaar	--prefix /usr \
513955d011SMarcel Moolenaar	--share /usr/share \
523955d011SMarcel Moolenaar	--mksrc none
533955d011SMarcel Moolenaar
543955d011SMarcel Moolenaar# run boot-strap with minimal influence
553955d011SMarcel Moolenaarbootstrap:	${BMAKE_SRC}/boot-strap ${MAKEFILE}
563955d011SMarcel Moolenaar	HOME=/ ${BMAKE_SRC}/boot-strap ${BOOTSTRAP_ARGS} ${BOOTSTRAP_XTRAS}
573955d011SMarcel Moolenaar	touch ${.TARGET}
583955d011SMarcel Moolenaar
593955d011SMarcel Moolenaar# Makefiles need a little more tweaking than say config.h
603955d011SMarcel MoolenaarMAKEFILE_SED = 	sed -e '/^MACHINE/d' \
61*93036677SSimon J. Gerraty	-e '/^PROG/ { s,=,?=,;s,bmake,$${.CURDIR:T},; }' \
623955d011SMarcel Moolenaar	-e 's,^.-include,.sinclude,' \
633955d011SMarcel Moolenaar	-e 's,${SRCTOP},$${SRCTOP},g'
643955d011SMarcel Moolenaar
653955d011SMarcel Moolenaar# These are the simple files we want to capture
663955d011SMarcel Moolenaarconfigured_files= config.h unit-tests/Makefile
673955d011SMarcel Moolenaar
683955d011SMarcel Moolenaarafter-import: bootstrap ${MAKEFILE}
693955d011SMarcel Moolenaar.for f in ${configured_files:N*Makefile}
703955d011SMarcel Moolenaar	@echo Capturing $f
713955d011SMarcel Moolenaar	@mkdir -p ${${.CURDIR}/$f:L:H}
723955d011SMarcel Moolenaar	@cmp -s ${.CURDIR}/$f ${HOST_OS}/$f || \
733955d011SMarcel Moolenaar	    cp ${HOST_OS}/$f ${.CURDIR}/$f
743955d011SMarcel Moolenaar.endfor
753955d011SMarcel Moolenaar.for f in ${configured_files:M*Makefile}
763955d011SMarcel Moolenaar	@echo Capturing $f
773955d011SMarcel Moolenaar	@mkdir -p ${${.CURDIR}/$f:L:H}
783955d011SMarcel Moolenaar	@(echo '# This is a generated file, do NOT edit!'; \
793955d011SMarcel Moolenaar	echo '# See ${_this:S,${SRCTOP}/,,}'; \
803955d011SMarcel Moolenaar	echo '#'; echo '# $$${OS}$$'; echo; \
813955d011SMarcel Moolenaar	echo 'SRCTOP?= $${.CURDIR:${${.CURDIR}/$f:L:H:S,${SRCTOP}/,,:C,[^/]+,H,g:S,/,:,g}}'; echo; \
823955d011SMarcel Moolenaar	${MAKEFILE_SED} ${HOST_OS}/$f ) > ${.CURDIR}/$f
833955d011SMarcel Moolenaar.endfor
843955d011SMarcel Moolenaar
853955d011SMarcel Moolenaar# this needs the most work
863955d011SMarcel Moolenaar_makefile:	bootstrap ${MAKEFILE}
873955d011SMarcel Moolenaar	@echo Generating ${.CURDIR}/Makefile
883955d011SMarcel Moolenaar	@(echo '# This is a generated file, do NOT edit!'; \
893955d011SMarcel Moolenaar	echo '# See ${_this:S,${SRCTOP}/,,}'; \
90*93036677SSimon J. Gerraty	echo '#'; echo '# $$${OS}$$'; \
91*93036677SSimon J. Gerraty	echo; echo '.sinclude "Makefile.inc"'; \
92*93036677SSimon J. Gerraty	echo; echo 'SRCTOP?= $${.CURDIR:${.CURDIR:S,${SRCTOP}/,,:C,[^/]+,H,g:S,/,:,g}}'; \
933955d011SMarcel Moolenaar	echo; echo '# look here first for config.h'; \
943955d011SMarcel Moolenaar	echo 'CFLAGS+= -I$${.CURDIR}'; echo; \
953955d011SMarcel Moolenaar	${MAKEFILE_SED} ${HOST_OS}/Makefile; \
963955d011SMarcel Moolenaar	echo; echo '# override some simple things'; \
973955d011SMarcel Moolenaar	echo 'BINDIR= /usr/bin'; \
98*93036677SSimon J. Gerraty	echo 'MANDIR= ${MANDIR:U/usr/share/man}'; \
993955d011SMarcel Moolenaar	echo; echo '# make sure we get this'; \
1003955d011SMarcel Moolenaar	echo 'CFLAGS+= $${COPTS.$${.IMPSRC:T}}'; \
1013955d011SMarcel Moolenaar	echo 'CLEANFILES+= bootstrap'; \
1023955d011SMarcel Moolenaar	echo; echo 'after-import: ${_this:S,${SRCTOP},\${SRCTOP},}'; \
1033955d011SMarcel Moolenaar	echo '	cd $${.CURDIR} && $${.MAKE} -f ${_this:S,${SRCTOP},\${SRCTOP},}'; \
1043955d011SMarcel Moolenaar	echo ) > ${.TARGET}
1053955d011SMarcel Moolenaar	@cmp -s ${.TARGET} ${.CURDIR}/Makefile || \
1063955d011SMarcel Moolenaar	    mv ${.TARGET} ${.CURDIR}/Makefile
1073955d011SMarcel Moolenaar
1083955d011SMarcel Moolenaar.include <bsd.obj.mk>
1093955d011SMarcel Moolenaar
110