bsd.after-import.mk revision 240330
1240330Smarcel# $Id: bsd.after-import.mk,v 1.7 2012/07/06 03:03:44 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 \ 51236769Sobrien --share /usr/share \ 52236769Sobrien --mksrc none 53236769Sobrien 54236769Sobrien# run boot-strap with minimal influence 55236769Sobrienbootstrap: ${BMAKE_SRC}/boot-strap ${MAKEFILE} 56236769Sobrien HOME=/ ${BMAKE_SRC}/boot-strap ${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' \ 61236769Sobrien -e '/^PROG/s,bmake,${.CURDIR:T},' \ 62237578Sobrien -e 's,^.-include,.sinclude,' \ 63236769Sobrien -e 's,${SRCTOP},$${SRCTOP},g' 64236769Sobrien 65236769Sobrien# These are the simple files we want to capture 66236769Sobrienconfigured_files= config.h unit-tests/Makefile 67236769Sobrien 68236769Sobrienafter-import: bootstrap ${MAKEFILE} 69236769Sobrien.for f in ${configured_files:N*Makefile} 70236769Sobrien @echo Capturing $f 71237578Sobrien @mkdir -p ${${.CURDIR}/$f:L:H} 72236769Sobrien @cmp -s ${.CURDIR}/$f ${HOST_OS}/$f || \ 73236769Sobrien cp ${HOST_OS}/$f ${.CURDIR}/$f 74236769Sobrien.endfor 75236769Sobrien.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}/,,}'; \ 80240330Smarcel echo '#'; echo '# $$${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}/,,}'; \ 90237578Sobrien echo '#'; echo '# $$${OS}$$'; echo; \ 91237578Sobrien echo 'SRCTOP?= $${.CURDIR:${.CURDIR:S,${SRCTOP}/,,:C,[^/]+,H,g:S,/,:,g}}'; echo; \ 92236769Sobrien echo; echo '# look here first for config.h'; \ 93236769Sobrien echo 'CFLAGS+= -I$${.CURDIR}'; echo; \ 94236769Sobrien ${MAKEFILE_SED} ${HOST_OS}/Makefile; \ 95236769Sobrien echo; echo '# override some simple things'; \ 96236769Sobrien echo 'BINDIR= /usr/bin'; \ 97236769Sobrien echo 'MANDIR= /usr/share/man'; \ 98236769Sobrien echo; echo '# make sure we get this'; \ 99236769Sobrien echo 'CFLAGS+= $${COPTS.$${.IMPSRC:T}}'; \ 100236769Sobrien echo 'CLEANFILES+= bootstrap'; \ 101236769Sobrien echo; echo 'after-import: ${_this:S,${SRCTOP},\${SRCTOP},}'; \ 102236769Sobrien echo ' cd $${.CURDIR} && $${.MAKE} -f ${_this:S,${SRCTOP},\${SRCTOP},}'; \ 103237578Sobrien echo; echo '.sinclude "Makefile.inc"'; \ 104238152Sobrien echo ) > ${.TARGET} 105238152Sobrien @cmp -s ${.TARGET} ${.CURDIR}/Makefile || \ 106238152Sobrien mv ${.TARGET} ${.CURDIR}/Makefile 107236769Sobrien 108236769Sobrien.include <bsd.obj.mk> 109236769Sobrien 110