Makefile.gnuhost revision 1.58 1 # $NetBSD: Makefile.gnuhost,v 1.58 2026/10/10 01:41:05 tls 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 HOST_COMPILER_CLANG!= if ${HOST_CC} --version | grep -q -s clang; then echo yes; else echo no; fi
23 .if ${HOST_COMPILER_CLANG} == "yes"
24 HOST_CFLAGS+=-O2 -no-cpp-precomp
25 .endif
26
27 # Allow selection of Xcode target OS version
28 .if ${BUILD_OSTYPE} == "Darwin" && defined(SDKROOT)
29 CONFIGURE_ENV+= SDKROOT=${SDKROOT:Q}
30 .endif
31
32 MAKE_PROGRAM?= ${MAKE}
33
34 .for i in 3 2
35 .if exists(${.CURDIR}/../../external/gpl${i}/${MODULE}/dist)
36 GNUHOSTDIST?= ${.CURDIR}/../../external/gpl${i}/${MODULE}/dist
37 .endif
38 .endfor
39
40 FIND_ARGS+= \! \( -type d \( \
41 -name 'CVS' -o \
42 -name 'config' -o \
43 -name 'doc' -o \
44 -name 'po' -o \
45 -name 'nbsd.mt' -o \
46 -name 'tests*' \
47 \) -prune \)
48
49 # Do this "find" only if actually building something.
50 .if (${USETOOLS} == "yes") && empty(.MAKEFLAGS:M-V*) && \
51 (make(all) || make(realall) || (!make(clean) && !make(cleandir) && !make(obj))) && \
52 !defined(_GNU_CFGSRC)
53
54 _GNU_CFGSRC!= find ${GNUHOSTDIST} ${FIND_ARGS} \
55 -type f \( -name 'config*' -o -name '*.in' \) -print
56 .MAKEOVERRIDES+= _GNU_CFGSRC
57 .endif
58
59 CONFIGURE_ENV+= \
60 AR=${HOST_AR:Q} \
61 AWK=${TOOL_AWK:Q} \
62 CC=${HOST_CC:Q} \
63 CFLAGS=${HOST_CFLAGS:Q} \
64 CONFIG_SHELL=${HOST_SH:Q} \
65 CPPFLAGS=${HOST_CPPFLAGS:Q} \
66 CXX=${HOST_CXX:Q} \
67 CXXFLAGS=${HOST_CXXFLAGS:Q} \
68 INSTALL=${HOST_INSTALL_FILE:Q} \
69 LDFLAGS=${HOST_LDFLAGS:Q} \
70 LEX=${LEX:Q} \
71 FLEX=${LEX:Q} \
72 M4=${TOOL_M4:Q} \
73 MAKE=${MAKE_PROGRAM:Q} \
74 PATH="${TOOLDIR}/bin:$$PATH" \
75 RANLIB=${HOST_RANLIB:Q} \
76 YACC=${YACC:Q}
77
78 BUILD_ENV+= ${CONFIGURE_ENV}
79
80 CONFIGURE_ARGS+=--prefix=${TOOLDIR}
81 .if ${MKPIC} == "no"
82 CONFIGURE_ARGS+=--disable-shared
83 .endif
84
85 .if ${MAKEVERBOSE} == 0
86 CONFIGURE_ARGS+=--silent
87 .endif
88
89
90 .if ${MAKE_PROGRAM} == ${MAKE}
91 .ifndef _NOWRAPPER
92 # Some systems have a small ARG_MAX. On such systems, prevent Make
93 # variables set on the command line from being exported in the
94 # environment (they will still be set in MAKEOVERRIDES).
95 .if ${BUILD_OSTYPE} == "Darwin" || ${BUILD_OSTYPE} == "FreeBSD"
96 __noenvexport= -X
97 .endif
98 MAKE_ARGS:= ${__noenvexport} -f ${.PARSEDIR}/Makefile.gnuwrap ${MAKE_ARGS}
99 .else
100 MAKE_ARGS+= _NOWRAPPER=1
101 .endif
102 BUILD_COMMAND= ${BUILD_ENV} ${MAKE} ${MAKE_ARGS}
103 .else
104
105 # gmake version of this puts MAKE_ARGS in the environment to be sure that
106 # sub-gmake's get them, otherwise tools/gcc tries to build libgcc and
107 # fails. it also uses "env -i" to entirely clear out MAKEFLAGS.
108 GMAKE_J_ARGS?= ${MAKEFLAGS:[*]:M*-j*:C/(^|.* )(-j ?[0-9][0-9]*).*/\2/W}
109 BUILD_COMMAND= /usr/bin/env -i ${BUILD_ENV} ${MAKE_ARGS:N-*} ${TOOL_GMAKE} ${GMAKE_J_ARGS} -e ${MAKE_ARGS}
110
111 .endif
112
113 MAKE_ARGS+= BISON=true DESTDIR= INSTALL=${HOST_INSTALL_FILE:Q}
114
115 .if ${MAKEVERBOSE} < 2
116 MAKE_ARGS+= -s V=0
117 .else
118 MAKE_ARGS+= V=1
119 .endif
120
121 ALL_TARGET?= all
122 INSTALL_TARGET?=install
123
124 BUILD_PLATFORM!= uname -srm | tr ' ()' '-'
125 CONFIGURE_PLATFORM!= if [ -s .configure_done ]; then cat .configure_done; else echo none; fi
126 .if "${BUILD_PLATFORM}" != "${CONFIGURE_PLATFORM}"
127 configure_cleanup:
128 @mkdir build 2>/dev/null || true
129 @(echo "Cleaning stale cache files ${BUILD_PLATFORM} != ${CONFIGURE_PLATFORM}")
130 @(cd build && find . -name config.cache | xargs rm -f)
131 configure_cleanup=configure_cleanup
132 .endif
133
134 .configure_done: ${_GNU_CFGSRC} ${.CURDIR}/Makefile ${configure_cleanup}
135 @mkdir build 2>/dev/null || true
136 @(cd build && ${CONFIGURE_ENV} ${HOST_SH} ${GNUHOSTDIST}/configure ${CONFIGURE_ARGS})
137 @echo ${BUILD_PLATFORM} > $@
138
139 # The .build_done timestamp is only updated if a file actually changes
140 # in the build tree during "make all". This way, if nothing has changed,
141 # a "make install MKUPDATE=yes" will do nothing.
142
143 .build_done: .configure_done
144 @${:D make}(cd build && ${BUILD_COMMAND} ${ALL_TARGET})
145 @if [ ! -f $@ ] || [ -n "$$(find build -type f -newer .build_done -print)" ]; \
146 then touch $@; fi
147
148 .install_done! ${BUILD:D.build_done}
149 @${:D make}(cd ${.OBJDIR}/build && ${BUILD_COMMAND} ${INSTALL_TARGET})
150 @touch $@
151
152 # Mapping to standard targets.
153
154 .if ${USETOOLS} == "yes"
155 realall: .build_done
156 realinstall: .install_done
157 .endif
158
159 clean: clean.gnu
160 clean.gnu:
161 -rm -r -f .*_done build
162
163 .include <bsd.hostprog.mk>
164