Makefile.gnuhost revision 1.42
1#	$NetBSD: Makefile.gnuhost,v 1.42 2013/08/13 20:41:25 drochner 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.
21BUILD_OSTYPE!= uname -s
22.if ${BUILD_OSTYPE} == "Darwin"
23HOST_CFLAGS+=-O2 -no-cpp-precomp
24.endif
25MAKE_PROGRAM?=	${MAKE}
26
27GNUHOSTDIST?=	${.CURDIR}/../../gnu/dist/${MODULE}
28
29FIND_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
48CONFIGURE_ENV+= \
49		AR=${HOST_AR:Q} \
50		AWK=${TOOL_AWK:Q} \
51		CC=${HOST_CC:Q} \
52		CFLAGS=${HOST_CFLAGS:Q} \
53		CONFIG_SHELL=${HOST_SH:Q} \
54		CPPFLAGS=${HOST_CPPFLAGS:Q} \
55		CXX=${HOST_CXX:Q} \
56		CXXFLAGS=${HOST_CXXFLAGS:Q} \
57		INSTALL=${HOST_INSTALL_FILE:Q} \
58		LDFLAGS=${HOST_LDFLAGS:Q} \
59		LEX=${LEX:Q} \
60		M4=${TOOL_M4:Q} \
61		MAKE=${MAKE_PROGRAM:Q} \
62		PATH="${TOOLDIR}/bin:$$PATH" \
63		RANLIB=${HOST_RANLIB:Q} \
64		YACC=${YACC:Q}
65
66BUILD_ENV+=	${CONFIGURE_ENV}
67
68CONFIGURE_ARGS+=--prefix=${TOOLDIR}
69.if ${MKPIC} == "no"
70CONFIGURE_ARGS+=--disable-shared
71.endif
72
73.if ${MAKE_PROGRAM} == ${MAKE}
74.ifndef _NOWRAPPER
75# Some systems have a small ARG_MAX.  On such systems, prevent Make
76# variables set on the command line from being exported in the
77# environment (they will still be set in MAKEOVERRIDES).
78.if ${BUILD_OSTYPE} == "Darwin" || ${BUILD_OSTYPE} == "FreeBSD"
79__noenvexport=	-X
80.endif
81MAKE_ARGS:=	${__noenvexport} -f ${.PARSEDIR}/Makefile.gnuwrap ${MAKE_ARGS}
82.else
83MAKE_ARGS+=	_NOWRAPPER=1
84.endif
85BUILD_COMMAND=	${BUILD_ENV} ${MAKE} ${MAKE_ARGS}
86.else
87
88# gmake version of this puts MAKE_ARGS in the environment to be sure that
89# sub-gmake's get them, otherwise tools/gcc tries to build libgcc and
90# fails.  it also uses "env -i" to entirely clear out MAKEFLAGS.
91GMAKE_J_ARGS?=	${MAKEFLAGS:[*]:M*-j*:C/.*(-j ?[0-9]*).*/\1/W}
92BUILD_COMMAND=	/usr/bin/env -i ${BUILD_ENV} ${MAKE_ARGS} ${TOOL_GMAKE} ${GMAKE_J_ARGS} -e ${MAKE_ARGS}
93
94.endif
95
96MAKE_ARGS+=	BISON=true DESTDIR= INSTALL=${HOST_INSTALL_FILE:Q}
97
98ALL_TARGET?=	all
99INSTALL_TARGET?=install
100
101BUILD_PLATFORM!= uname -srm | tr ' ()' '-'
102CONFIGURE_PLATFORM!= if [ -s .configure_done ]; then cat .configure_done; else echo none; fi
103.if "${BUILD_PLATFORM}" != "${CONFIGURE_PLATFORM}"
104configure_cleanup:
105	@mkdir build 2>/dev/null || true
106	@(echo "Cleaning stale cache files ${BUILD_PLATFORM} != ${CONFIGURE_PLATFORM}")
107	@(cd build && find . -name config.cache | xargs rm -f)
108configure_cleanup=configure_cleanup
109.endif
110
111.configure_done: ${_GNU_CFGSRC} ${.CURDIR}/Makefile ${configure_cleanup}
112	@mkdir build 2>/dev/null || true
113	@(cd build && ${CONFIGURE_ENV} ${HOST_SH} ${GNUHOSTDIST}/configure ${CONFIGURE_ARGS})
114	@echo ${BUILD_PLATFORM} > $@
115
116# The .build_done timestamp is only updated if a file actually changes
117# in the build tree during "make all".  This way, if nothing has changed,
118# a "make install MKUPDATE=yes" will do nothing.
119
120.build_done: .configure_done
121	@(cd build && ${BUILD_COMMAND} ${ALL_TARGET})
122	@if [ ! -f $@ ] || [ -n "$$(find build -type f -newer .build_done -print)" ]; \
123		then touch $@; fi
124
125.install_done! ${BUILD:D.build_done}
126	@(cd ${.OBJDIR}/build && ${BUILD_COMMAND} ${INSTALL_TARGET})
127	@touch $@
128
129# Mapping to standard targets.
130
131.if ${USETOOLS} == "yes"
132realall: .build_done
133realinstall: .install_done
134.endif
135
136clean: clean.gnu
137clean.gnu:
138	-rm -r -f .*_done build
139
140.include <bsd.hostprog.mk>
141