Makefile.gnuhost revision 1.36 1 # $NetBSD: Makefile.gnuhost,v 1.36 2012/01/20 23:01:05 christos Exp $
2 #
3 # Rules used when building a GNU host package. Expects MODULE to be set.
4 #
5 # There's not a lot we can do to build reliably in the face of many
6 # available configuration options. To be as low-overhead as possible,
7 # we follow the following scheme:
8 #
9 # * Configuration is only re-run when an autoconf source file (such as
10 # "configure" or "config.sub") is changed.
11 #
12 # * "config.status" is run to rebuild Makefiles and .h files if an
13 # autoconf-parsed file (such as Makefile.in) is changed.
14 #
15 # * If MKUPDATE != "no", "make install" is only run if a build has happened
16 # since the last install in the current directory.
17
18 .include <bsd.own.mk>
19
20 # Disable use of pre-compiled headers on Darwin.
21 BUILD_OSTYPE!= uname -s
22 .if ${BUILD_OSTYPE} == "Darwin"
23 HOST_CFLAGS+=-O2 -no-cpp-precomp
24 .endif
25 MAKE_PROGRAM?= ${MAKE}
26
27 GNUHOSTDIST?= ${.CURDIR}/../../gnu/dist/${MODULE}
28
29 FIND_ARGS+= \! \( -type d \( \
30 -name 'CVS' -o \
31 -name 'config' -o \
32 -name 'doc' -o \
33 -name 'po' -o \
34 -name 'nbsd.mt' -o \
35 -name 'tests*' \
36 \) -prune \)
37
38 # Do this "find" only if actually building something.
39 .if (${USETOOLS} == "yes") && empty(.MAKEFLAGS:M-V*) && \
40 (make(all) || make(realall) || (!make(clean) && !make(cleandir) && !make(obj))) && \
41 !defined(_GNU_CFGSRC)
42
43 _GNU_CFGSRC!= find ${GNUHOSTDIST} ${FIND_ARGS} \
44 -type f \( -name 'config*' -o -name '*.in' \) -print
45 .MAKEOVERRIDES+= _GNU_CFGSRC
46 .endif
47
48 CONFIGURE_ENV+= \
49 AR=${HOST_AR:Q} \
50 AWK=${TOOL_AWK:Q} \
51 CC=${HOST_CC:Q} \
52 CFLAGS=${HOST_CFLAGS:Q} \
53 CPPFLAGS=${HOST_CPPFLAGS:Q} \
54 CXX=${HOST_CXX:Q} \
55 CXXFLAGS=${HOST_CXXFLAGS:Q} \
56 INSTALL=${HOST_INSTALL_FILE:Q} \
57 LDFLAGS=${HOST_LDFLAGS:Q} \
58 LEX=${LEX:Q} \
59 M4=${TOOL_M4:Q} \
60 MAKE=${MAKE_PROGRAM:Q} \
61 PATH="${TOOLDIR}/bin:$$PATH" \
62 RANLIB=${HOST_RANLIB:Q} \
63 YACC=${YACC:Q}
64
65 BUILD_ENV+= ${CONFIGURE_ENV}
66
67 CONFIGURE_ARGS+=--prefix=${TOOLDIR}
68 .if ${MKPIC} == "no"
69 CONFIGURE_ARGS+=--disable-shared
70 .endif
71
72 .if ${MAKE_PROGRAM} == ${MAKE}
73 .ifndef _NOWRAPPER
74 # Some systems have a small ARG_MAX. On such systems, prevent Make
75 # variables set on the command line from being exported in the
76 # environment (they will still be set in MAKEOVERRIDES).
77 .if ${BUILD_OSTYPE} == "Darwin" || ${BUILD_OSTYPE} == "FreeBSD"
78 __noenvexport= -X
79 .endif
80 MAKE_ARGS:= ${__noenvexport} -f ${.PARSEDIR}/Makefile.gnuwrap ${MAKE_ARGS}
81 .else
82 MAKE_ARGS+= _NOWRAPPER=1
83 .endif
84 BUILD_COMMAND= ${BUILD_ENV} ${MAKE} ${MAKE_ARGS}
85 .else
86
87 # gmake version of this puts MAKE_ARGS in the environment to be sure that
88 # sub-gmake's get them, otherwise tools/gcc tries to build libgcc and
89 # fails. it also uses "env -i" to entirely clear out MAKEFLAGS.
90 GMAKE_J_ARGS?= ${MAKEFLAGS:[*]:M*-j*:C/.*(-j ?[0-9]*).*/\1/W}
91 BUILD_COMMAND= /usr/bin/env -i ${BUILD_ENV} ${MAKE_ARGS} ${TOOL_GMAKE} ${GMAKE_J_ARGS} -e ${MAKE_ARGS}
92
93 .endif
94
95 MAKE_ARGS+= BISON=true DESTDIR= INSTALL=${HOST_INSTALL_FILE:Q}
96
97 ALL_TARGET?= all
98 INSTALL_TARGET?=install
99
100 BUILD_PLATFORM!= uname -srm | tr ' ' '-'
101 CONFIGURE_PLATFORM!= if [ -s .configure_done ]; then cat .configure_done; else echo none; fi
102 .if "${BUILD_PLATFORM}" != "${CONFIGURE_PLATFORM}"
103 configure_cleanup:
104 @mkdir build 2>/dev/null || true
105 @(echo "Cleaning stale cache files ${BUILD_PLATFORM} != ${CONFIGURE_PLATFORM}")
106 @(cd build && find . -name config.cache -print0 | xargs -0 rm -f)
107 configure_cleanup=configure_cleanup
108 .endif
109
110 BUILD_PLATFORM!= uname -srm | tr ' ' '-'
111 CONFIGURE_PLATFORM!= if [ -s .configure_done ]; then cat .configure_done; else echo none; fi
112 .if "${BUILD_PLATFORM}" != "${CONFIGURE_PLATFORM}"
113 configure_cleanup:
114 @mkdir build 2>/dev/null || true
115 @(echo "Cleaning stale cache files ${BUILD_PLATFORM} != ${CONFIGURE_PLATFORM}")
116 @(cd build && find . -name config.cache -print0 | xargs -0 rm -f)
117 configure_cleanup=configure_cleanup
118 .endif
119
120 .configure_done: ${_GNU_CFGSRC} ${.CURDIR}/Makefile ${configure_cleanup}
121 @mkdir build 2>/dev/null || true
122 @(cd build && ${CONFIGURE_ENV} ${HOST_SH} ${GNUHOSTDIST}/configure ${CONFIGURE_ARGS})
123 @echo ${BUILD_PLATFORM} > $@
124
125 # The .build_done timestamp is only updated if a file actually changes
126 # in the build tree during "make all". This way, if nothing has changed,
127 # a "make install MKUPDATE=yes" will do nothing.
128
129 .build_done: .configure_done
130 @(cd build && ${BUILD_COMMAND} ${ALL_TARGET})
131 @if [ ! -f $@ ] || [ -n "$$(find build -type f -newer .build_done -print)" ]; \
132 then touch $@; fi
133
134 .install_done! ${BUILD:D.build_done}
135 @(cd ${.OBJDIR}/build && ${BUILD_COMMAND} ${INSTALL_TARGET})
136 @touch $@
137
138 # Mapping to standard targets.
139
140 .if ${USETOOLS} == "yes"
141 realall: .build_done
142 realinstall: .install_done
143 .endif
144
145 clean: clean.gnu
146 clean.gnu:
147 -rm -r -f .*_done build
148
149 .include <bsd.hostprog.mk>
150