1276305Sngie# $Id: bsd.after-import.mk,v 1.12 2014/02/14 23:45:49 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 44236769SobrienBOOTSTRAP_ARGS = \ 45236769Sobrien --prefix /usr \ 46246223Ssjg --share /usr/share 47236769Sobrien 48276305Sngie.if !empty(DEFAULT_SYS_PATH) 49276305SngieBOOTSTRAP_ARGS += --with-default-sys-path='${DEFAULT_SYS_PATH}' 50276305Sngie.endif 51246223Ssjg 52236769Sobrien# run boot-strap with minimal influence 53236769Sobrienbootstrap: ${BMAKE_SRC}/boot-strap ${MAKEFILE} 54246223Ssjg HOME=/ ${BMAKE_SRC}/boot-strap -o ${HOST_OS} ${BOOTSTRAP_ARGS} ${BOOTSTRAP_XTRAS} 55236769Sobrien touch ${.TARGET} 56236769Sobrien 57236769Sobrien# Makefiles need a little more tweaking than say config.h 58236769SobrienMAKEFILE_SED = sed -e '/^MACHINE/d' \ 59242102Ssjg -e '/^PROG/ { s,=,?=,;s,bmake,$${.CURDIR:T},; }' \ 60237578Sobrien -e 's,^.-include,.sinclude,' \ 61246223Ssjg -e '/^\..*include *</ { s,<,<bsd.,;/autoconf/d; }' \ 62236769Sobrien -e 's,${SRCTOP},$${SRCTOP},g' 63236769Sobrien 64236769Sobrien# These are the simple files we want to capture 65246223Ssjgconfigured_files= config.h Makefile.config unit-tests/Makefile 66236769Sobrien 67236769Sobrienafter-import: bootstrap ${MAKEFILE} 68246223Ssjg.for f in ${configured_files:M*.[ch]} 69236769Sobrien @echo Capturing $f 70237578Sobrien @mkdir -p ${${.CURDIR}/$f:L:H} 71246223Ssjg @(echo '/* $$${HOST_OS}$$ */'; cat ${HOST_OS}/$f) > ${.CURDIR}/$f 72236769Sobrien.endfor 73246223Ssjg.for f in ${configured_files:M*Makefile*} 74236769Sobrien @echo Capturing $f 75237578Sobrien @mkdir -p ${${.CURDIR}/$f:L:H} 76240330Smarcel @(echo '# This is a generated file, do NOT edit!'; \ 77240330Smarcel echo '# See ${_this:S,${SRCTOP}/,,}'; \ 78246223Ssjg echo '#'; echo '# $$${HOST_OS}$$'; echo; \ 79240330Smarcel echo 'SRCTOP?= $${.CURDIR:${${.CURDIR}/$f:L:H:S,${SRCTOP}/,,:C,[^/]+,H,g:S,/,:,g}}'; echo; \ 80240330Smarcel ${MAKEFILE_SED} ${HOST_OS}/$f ) > ${.CURDIR}/$f 81236769Sobrien.endfor 82236769Sobrien 83236769Sobrien# this needs the most work 84238152Sobrien_makefile: bootstrap ${MAKEFILE} 85238152Sobrien @echo Generating ${.CURDIR}/Makefile 86236769Sobrien @(echo '# This is a generated file, do NOT edit!'; \ 87236769Sobrien echo '# See ${_this:S,${SRCTOP}/,,}'; \ 88246223Ssjg echo '#'; echo '# $$${HOST_OS}$$'; \ 89242102Ssjg echo; echo '.sinclude "Makefile.inc"'; \ 90242102Ssjg echo; echo 'SRCTOP?= $${.CURDIR:${.CURDIR:S,${SRCTOP}/,,:C,[^/]+,H,g:S,/,:,g}}'; \ 91236769Sobrien echo; echo '# look here first for config.h'; \ 92236769Sobrien echo 'CFLAGS+= -I$${.CURDIR}'; echo; \ 93246223Ssjg echo '# for after-import'; \ 94246223Ssjg echo 'CLEANDIRS+= ${HOST_OS}'; \ 95246223Ssjg echo 'CLEANFILES+= bootstrap'; echo; \ 96246223Ssjg ${MAKEFILE_SED} \ 97246223Ssjg ${1 2:L:@n@-e '/start-delete$n/,/end-delete$n/d'@} \ 98246223Ssjg ${BMAKE_SRC}/Makefile; \ 99236769Sobrien echo; echo '# override some simple things'; \ 100236769Sobrien echo 'BINDIR= /usr/bin'; \ 101242102Ssjg echo 'MANDIR= ${MANDIR:U/usr/share/man}'; \ 102236769Sobrien echo; echo '# make sure we get this'; \ 103236769Sobrien echo 'CFLAGS+= $${COPTS.$${.IMPSRC:T}}'; \ 104236769Sobrien echo; echo 'after-import: ${_this:S,${SRCTOP},\${SRCTOP},}'; \ 105236769Sobrien echo ' cd $${.CURDIR} && $${.MAKE} -f ${_this:S,${SRCTOP},\${SRCTOP},}'; \ 106238152Sobrien echo ) > ${.TARGET} 107238152Sobrien @cmp -s ${.TARGET} ${.CURDIR}/Makefile || \ 108238152Sobrien mv ${.TARGET} ${.CURDIR}/Makefile 109236769Sobrien 110236769Sobrien.include <bsd.obj.mk> 111236769Sobrien 112