1 # $Id: bsd.after-import.mk,v 1.12 2014/02/14 23:45:49 sjg Exp $
3 # This makefile is for use when integrating bmake into a BSD build
4 # system. Use this makefile after importing bmake.
5 # It will bootstrap the new version,
6 # capture the generated files we need, and add an after-import
7 # target to allow the process to be easily repeated.
9 # The goal is to allow the benefits of autoconf without
10 # the overhead of running configure.
16 .if
!defined
(.PARSEDIR
)
17 .error this makefile requires bmake
20 _this
:= ${MAKEFILE
:tA
}
21 BMAKE_SRC
:= ${.PARSEDIR
}
23 # it helps to know where the top of the tree is.
25 srctop
:= ${.MAKE.MAKEFILES
:M
*src
/share
/mk
/sys.mk
:H
:H
:H
}
28 .for d in contrib
/bmake external
/bsd
/bmake
/dist
29 .if
${BMAKE_SRC
:M
*/$d} != ""
30 srctop
:= ${BMAKE_SRC
:tA
:S
,/$d,,}
39 # This lets us match what boot-strap does
48 .if
!empty
(DEFAULT_SYS_PATH
)
49 BOOTSTRAP_ARGS
+= --with-default-sys-path
='${DEFAULT_SYS_PATH}'
52 # run boot-strap with minimal influence
53 bootstrap
: ${BMAKE_SRC}/boot-strap
${MAKEFILE}
54 HOME
=/ ${BMAKE_SRC}/boot-strap
-o
${HOST_OS} ${BOOTSTRAP_ARGS} ${BOOTSTRAP_XTRAS}
57 # Makefiles need a little more tweaking than say config.h
58 MAKEFILE_SED
= sed
-e
'/^MACHINE/d' \
59 -e
'/^PROG/ { s,=,?=,;s,bmake,$${.CURDIR:T},; }' \
60 -e
's,^.-include,.sinclude,' \
61 -e
'/^\..*include *</ { s,<,<bsd.,;/autoconf/d; }' \
62 -e
's,${SRCTOP},$${SRCTOP},g'
64 # These are the simple files we want to capture
65 configured_files
= config.h Makefile.config unit-tests
/Makefile
67 after-import
: bootstrap
${MAKEFILE}
68 .for f in
${configured_files
:M
*.
[ch
]}
70 @mkdir
-p
${${.CURDIR
}/$f:L
:H
}
71 @
(echo
'/* $$${HOST_OS}$$ */'; cat
${HOST_OS}/$f) > ${.CURDIR
}/$f
73 .for f in
${configured_files
:M
*Makefile
*}
75 @mkdir
-p
${${.CURDIR
}/$f:L
:H
}
76 @
(echo
'# This is a generated file, do NOT edit!'; \
77 echo
'# See ${_this:S,${SRCTOP}/,,}'; \
78 echo
'#'; echo
'# $$${HOST_OS}$$'; echo
; \
79 echo
'SRCTOP?= $${.CURDIR:${${.CURDIR}/$f:L:H:S,${SRCTOP}/,,:C,[^/]+,H,g:S,/,:,g}}'; echo
; \
80 ${MAKEFILE_SED} ${HOST_OS}/$f ) > ${.CURDIR
}/$f
83 # this needs the most work
84 _makefile
: bootstrap
${MAKEFILE}
85 @echo Generating
${.CURDIR
}/Makefile
86 @
(echo
'# This is a generated file, do NOT edit!'; \
87 echo
'# See ${_this:S,${SRCTOP}/,,}'; \
88 echo
'#'; echo
'# $$${HOST_OS}$$'; \
89 echo
; echo
'.sinclude "Makefile.inc"'; \
90 echo
; echo
'SRCTOP?= $${.CURDIR:${.CURDIR:S,${SRCTOP}/,,:C,[^/]+,H,g:S,/,:,g}}'; \
91 echo
; echo
'# look here first for config.h'; \
92 echo
'CFLAGS+= -I$${.CURDIR}'; echo
; \
93 echo
'# for after-import'; \
94 echo
'CLEANDIRS+= ${HOST_OS}'; \
95 echo
'CLEANFILES+= bootstrap'; echo
; \
97 ${1 2:L
:@n@
-e
'/start-delete$n/,/end-delete$n/d'@
} \
98 ${BMAKE_SRC}/Makefile
; \
99 echo
; echo
'# override some simple things'; \
100 echo
'BINDIR= /usr/bin'; \
101 echo
'MANDIR= ${MANDIR:U/usr/share/man}'; \
102 echo
; echo
'# make sure we get this'; \
103 echo
'CFLAGS+= $${COPTS.$${.IMPSRC:T}}'; \
104 echo
; echo
'after-import: ${_this:S,${SRCTOP},\${SRCTOP},}'; \
105 echo
' cd $${.CURDIR} && $${.MAKE} -f ${_this:S,${SRCTOP},\${SRCTOP},}'; \
107 @cmp
-s
${.TARGET
} ${.CURDIR
}/Makefile || \
108 mv
${.TARGET
} ${.CURDIR
}/Makefile
110 .
include <bsd.obj.mk
>