1*2c3632d1SSimon J. Gerraty# $Id: bsd.after-import.mk,v 1.16 2020/07/12 03:39:01 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 12*2c3632d1SSimon J. Gerratyall: _makefile _utmakefile 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 40*2c3632d1SSimon J. Gerraty.if defined(.MAKE.OS) 41*2c3632d1SSimon J. GerratyHOST_OS:= ${.MAKE.OS} 42*2c3632d1SSimon J. Gerraty.elif !defined(HOST_OS) 433955d011SMarcel MoolenaarHOST_OS!= uname 443955d011SMarcel Moolenaar.endif 453955d011SMarcel Moolenaar 463955d011SMarcel MoolenaarBOOTSTRAP_ARGS = \ 473955d011SMarcel Moolenaar --prefix /usr \ 483cbdda60SSimon J. Gerraty --share /usr/share 493cbdda60SSimon J. Gerraty 505bcb7424SSimon J. Gerraty.if !empty(DEFAULT_SYS_PATH) 515bcb7424SSimon J. GerratyBOOTSTRAP_ARGS += --with-default-sys-path='${DEFAULT_SYS_PATH}' 525bcb7424SSimon J. Gerraty.endif 533955d011SMarcel Moolenaar 543955d011SMarcel Moolenaar# run boot-strap with minimal influence 553955d011SMarcel Moolenaarbootstrap: ${BMAKE_SRC}/boot-strap ${MAKEFILE} 563cbdda60SSimon J. Gerraty HOME=/ ${BMAKE_SRC}/boot-strap -o ${HOST_OS} ${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' \ 61e22fef7dSSimon J. Gerraty -e '/include.*VERSION/d' \ 6293036677SSimon J. Gerraty -e '/^PROG/ { s,=,?=,;s,bmake,$${.CURDIR:T},; }' \ 633955d011SMarcel Moolenaar -e 's,^.-include,.sinclude,' \ 643cbdda60SSimon J. Gerraty -e '/^\..*include *</ { s,<,<bsd.,;/autoconf/d; }' \ 653955d011SMarcel Moolenaar -e 's,${SRCTOP},$${SRCTOP},g' 663955d011SMarcel Moolenaar 673955d011SMarcel Moolenaar# These are the simple files we want to capture 6849caa483SSimon J. Gerratyconfigured_files= config.h Makefile.config unit-tests/Makefile.config 693955d011SMarcel Moolenaar 703955d011SMarcel Moolenaarafter-import: bootstrap ${MAKEFILE} 713cbdda60SSimon J. Gerraty.for f in ${configured_files:M*.[ch]} 723955d011SMarcel Moolenaar @echo Capturing $f 733955d011SMarcel Moolenaar @mkdir -p ${${.CURDIR}/$f:L:H} 743cbdda60SSimon J. Gerraty @(echo '/* $$${HOST_OS}$$ */'; cat ${HOST_OS}/$f) > ${.CURDIR}/$f 753955d011SMarcel Moolenaar.endfor 763cbdda60SSimon J. Gerraty.for f in ${configured_files:M*Makefile*} 773955d011SMarcel Moolenaar @echo Capturing $f 783955d011SMarcel Moolenaar @mkdir -p ${${.CURDIR}/$f:L:H} 793955d011SMarcel Moolenaar @(echo '# This is a generated file, do NOT edit!'; \ 803955d011SMarcel Moolenaar echo '# See ${_this:S,${SRCTOP}/,,}'; \ 813cbdda60SSimon J. Gerraty echo '#'; echo '# $$${HOST_OS}$$'; echo; \ 823955d011SMarcel Moolenaar echo 'SRCTOP?= $${.CURDIR:${${.CURDIR}/$f:L:H:S,${SRCTOP}/,,:C,[^/]+,H,g:S,/,:,g}}'; echo; \ 833955d011SMarcel Moolenaar ${MAKEFILE_SED} ${HOST_OS}/$f ) > ${.CURDIR}/$f 843955d011SMarcel Moolenaar.endfor 853955d011SMarcel Moolenaar 863955d011SMarcel Moolenaar# this needs the most work 873955d011SMarcel Moolenaar_makefile: bootstrap ${MAKEFILE} 883955d011SMarcel Moolenaar @echo Generating ${.CURDIR}/Makefile 893955d011SMarcel Moolenaar @(echo '# This is a generated file, do NOT edit!'; \ 903955d011SMarcel Moolenaar echo '# See ${_this:S,${SRCTOP}/,,}'; \ 913cbdda60SSimon J. Gerraty echo '#'; echo '# $$${HOST_OS}$$'; \ 9293036677SSimon 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; \ 953cbdda60SSimon J. Gerraty echo '# for after-import'; \ 963cbdda60SSimon J. Gerraty echo 'CLEANDIRS+= ${HOST_OS}'; \ 973cbdda60SSimon J. Gerraty echo 'CLEANFILES+= bootstrap'; echo; \ 983cbdda60SSimon J. Gerraty ${MAKEFILE_SED} \ 993cbdda60SSimon J. Gerraty ${1 2:L:@n@-e '/start-delete$n/,/end-delete$n/d'@} \ 1003cbdda60SSimon J. Gerraty ${BMAKE_SRC}/Makefile; \ 1013955d011SMarcel Moolenaar echo; echo '# override some simple things'; \ 1023955d011SMarcel Moolenaar echo 'BINDIR= /usr/bin'; \ 10393036677SSimon J. Gerraty echo 'MANDIR= ${MANDIR:U/usr/share/man}'; \ 1043955d011SMarcel Moolenaar echo; echo '# make sure we get this'; \ 1053955d011SMarcel Moolenaar echo 'CFLAGS+= $${COPTS.$${.IMPSRC:T}}'; \ 1063955d011SMarcel Moolenaar echo; echo 'after-import: ${_this:S,${SRCTOP},\${SRCTOP},}'; \ 1073955d011SMarcel Moolenaar echo ' cd $${.CURDIR} && $${.MAKE} -f ${_this:S,${SRCTOP},\${SRCTOP},}'; \ 1083955d011SMarcel Moolenaar echo ) > ${.TARGET} 1093955d011SMarcel Moolenaar @cmp -s ${.TARGET} ${.CURDIR}/Makefile || \ 1103955d011SMarcel Moolenaar mv ${.TARGET} ${.CURDIR}/Makefile 1113955d011SMarcel Moolenaar 112*2c3632d1SSimon J. Gerraty_utmakefile: bootstrap ${MAKEFILE} 113*2c3632d1SSimon J. Gerraty @echo Generating ${.CURDIR}/unit-tests/Makefile 114*2c3632d1SSimon J. Gerraty @mkdir -p ${.CURDIR}/unit-tests 115*2c3632d1SSimon J. Gerraty @(echo '# This is a generated file, do NOT edit!'; \ 116*2c3632d1SSimon J. Gerraty echo '# See ${_this:S,${SRCTOP}/,,}'; \ 117*2c3632d1SSimon J. Gerraty echo '#'; echo '# $$${HOST_OS}$$'; \ 118*2c3632d1SSimon J. Gerraty ${MAKEFILE_SED} \ 119*2c3632d1SSimon J. Gerraty -e '/^UNIT_TESTS/s,=.*,= $${srcdir},' \ 120*2c3632d1SSimon J. Gerraty ${BMAKE_SRC}/unit-tests/Makefile ) > ${.TARGET} 121*2c3632d1SSimon J. Gerraty @cmp -s ${.TARGET} ${.CURDIR}/unit-tests/Makefile || \ 122*2c3632d1SSimon J. Gerraty mv ${.TARGET} ${.CURDIR}/unit-tests/Makefile 123*2c3632d1SSimon J. Gerraty 124*2c3632d1SSimon J. Gerraty 1253955d011SMarcel Moolenaar.include <bsd.obj.mk> 1263955d011SMarcel Moolenaar 127