1*d5e0a182SSimon J. Gerraty# $Id: bsd.after-import.mk,v 1.18 2023/09/18 05:29:23 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 122c3632d1SSimon 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 402c3632d1SSimon J. Gerraty.if defined(.MAKE.OS) 412c3632d1SSimon J. GerratyHOST_OS:= ${.MAKE.OS} 422c3632d1SSimon 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' \ 6212904384SSimon J. Gerraty -e '/^CC=/s,=,?=,' \ 6393036677SSimon J. Gerraty -e '/^PROG/ { s,=,?=,;s,bmake,$${.CURDIR:T},; }' \ 643955d011SMarcel Moolenaar -e 's,^.-include,.sinclude,' \ 653cbdda60SSimon J. Gerraty -e '/^\..*include *</ { s,<,<bsd.,;/autoconf/d; }' \ 663955d011SMarcel Moolenaar -e 's,${SRCTOP},$${SRCTOP},g' 673955d011SMarcel Moolenaar 683955d011SMarcel Moolenaar# These are the simple files we want to capture 6949caa483SSimon J. Gerratyconfigured_files= config.h Makefile.config unit-tests/Makefile.config 703955d011SMarcel Moolenaar 71*d5e0a182SSimon J. Gerraty# FreeBSD has dropped their tag with svn 72*d5e0a182SSimon J. Gerraty.if ${HOST_OS:NFreeBSD} == "" 73*d5e0a182SSimon J. GerratyECHO_TAG= : 74*d5e0a182SSimon J. Gerraty.else 75*d5e0a182SSimon J. GerratyECHO_TAG?= echo 76*d5e0a182SSimon J. Gerraty.endif 77*d5e0a182SSimon J. Gerraty 783955d011SMarcel Moolenaarafter-import: bootstrap ${MAKEFILE} 793cbdda60SSimon J. Gerraty.for f in ${configured_files:M*.[ch]} 803955d011SMarcel Moolenaar @echo Capturing $f 813955d011SMarcel Moolenaar @mkdir -p ${${.CURDIR}/$f:L:H} 82*d5e0a182SSimon J. Gerraty @(${ECHO_TAG} '/* $$${HOST_OS}$$ */'; cat ${HOST_OS}/$f) > ${.CURDIR}/$f 833955d011SMarcel Moolenaar.endfor 843cbdda60SSimon J. Gerraty.for f in ${configured_files:M*Makefile*} 853955d011SMarcel Moolenaar @echo Capturing $f 863955d011SMarcel Moolenaar @mkdir -p ${${.CURDIR}/$f:L:H} 873955d011SMarcel Moolenaar @(echo '# This is a generated file, do NOT edit!'; \ 883955d011SMarcel Moolenaar echo '# See ${_this:S,${SRCTOP}/,,}'; \ 89*d5e0a182SSimon J. Gerraty echo '#'; ${ECHO_TAG} '# $$${HOST_OS}$$'; echo; \ 903955d011SMarcel Moolenaar echo 'SRCTOP?= $${.CURDIR:${${.CURDIR}/$f:L:H:S,${SRCTOP}/,,:C,[^/]+,H,g:S,/,:,g}}'; echo; \ 913955d011SMarcel Moolenaar ${MAKEFILE_SED} ${HOST_OS}/$f ) > ${.CURDIR}/$f 923955d011SMarcel Moolenaar.endfor 933955d011SMarcel Moolenaar 943955d011SMarcel Moolenaar# this needs the most work 953955d011SMarcel Moolenaar_makefile: bootstrap ${MAKEFILE} 963955d011SMarcel Moolenaar @echo Generating ${.CURDIR}/Makefile 973955d011SMarcel Moolenaar @(echo '# This is a generated file, do NOT edit!'; \ 983955d011SMarcel Moolenaar echo '# See ${_this:S,${SRCTOP}/,,}'; \ 99*d5e0a182SSimon J. Gerraty echo '#'; ${ECHO_TAG} '# $$${HOST_OS}$$'; \ 10093036677SSimon J. Gerraty echo; echo 'SRCTOP?= $${.CURDIR:${.CURDIR:S,${SRCTOP}/,,:C,[^/]+,H,g:S,/,:,g}}'; \ 1013955d011SMarcel Moolenaar echo; echo '# look here first for config.h'; \ 1023955d011SMarcel Moolenaar echo 'CFLAGS+= -I$${.CURDIR}'; echo; \ 1033cbdda60SSimon J. Gerraty echo '# for after-import'; \ 1043cbdda60SSimon J. Gerraty echo 'CLEANDIRS+= ${HOST_OS}'; \ 1053cbdda60SSimon J. Gerraty echo 'CLEANFILES+= bootstrap'; echo; \ 1063cbdda60SSimon J. Gerraty ${MAKEFILE_SED} \ 1073cbdda60SSimon J. Gerraty ${1 2:L:@n@-e '/start-delete$n/,/end-delete$n/d'@} \ 1083cbdda60SSimon J. Gerraty ${BMAKE_SRC}/Makefile; \ 1093955d011SMarcel Moolenaar echo; echo '# override some simple things'; \ 1103955d011SMarcel Moolenaar echo 'BINDIR= /usr/bin'; \ 11193036677SSimon J. Gerraty echo 'MANDIR= ${MANDIR:U/usr/share/man}'; \ 1123955d011SMarcel Moolenaar echo; echo '# make sure we get this'; \ 1133955d011SMarcel Moolenaar echo 'CFLAGS+= $${COPTS.$${.IMPSRC:T}}'; \ 1143955d011SMarcel Moolenaar echo; echo 'after-import: ${_this:S,${SRCTOP},\${SRCTOP},}'; \ 1153955d011SMarcel Moolenaar echo ' cd $${.CURDIR} && $${.MAKE} -f ${_this:S,${SRCTOP},\${SRCTOP},}'; \ 1163955d011SMarcel Moolenaar echo ) > ${.TARGET} 1173955d011SMarcel Moolenaar @cmp -s ${.TARGET} ${.CURDIR}/Makefile || \ 1183955d011SMarcel Moolenaar mv ${.TARGET} ${.CURDIR}/Makefile 1193955d011SMarcel Moolenaar 1202c3632d1SSimon J. Gerraty_utmakefile: bootstrap ${MAKEFILE} 1212c3632d1SSimon J. Gerraty @echo Generating ${.CURDIR}/unit-tests/Makefile 1222c3632d1SSimon J. Gerraty @mkdir -p ${.CURDIR}/unit-tests 1232c3632d1SSimon J. Gerraty @(echo '# This is a generated file, do NOT edit!'; \ 1242c3632d1SSimon J. Gerraty echo '# See ${_this:S,${SRCTOP}/,,}'; \ 125*d5e0a182SSimon J. Gerraty echo '#'; ${ECHO_TAG} '# $$${HOST_OS}$$'; \ 1262c3632d1SSimon J. Gerraty ${MAKEFILE_SED} \ 1272c3632d1SSimon J. Gerraty -e '/^UNIT_TESTS/s,=.*,= $${srcdir},' \ 1282c3632d1SSimon J. Gerraty ${BMAKE_SRC}/unit-tests/Makefile ) > ${.TARGET} 1292c3632d1SSimon J. Gerraty @cmp -s ${.TARGET} ${.CURDIR}/unit-tests/Makefile || \ 1302c3632d1SSimon J. Gerraty mv ${.TARGET} ${.CURDIR}/unit-tests/Makefile 1312c3632d1SSimon J. Gerraty 1322c3632d1SSimon J. Gerraty 1333955d011SMarcel Moolenaar.include <bsd.obj.mk> 1343955d011SMarcel Moolenaar 135