xref: /netbsd-src/tools/Makefile.gmakehost (revision 74809f044aa1c34df701bf79c7bfb9794896fdf8)
1#	$NetBSD: Makefile.gmakehost,v 1.4 2008/07/07 10:57:03 apb Exp $
2#
3# Rules used when building a GNU host package.  Expects MODULE to be set.
4# This version runs ${TOOL_GMAKE} instead of ${MAKE}
5#
6# There's not a lot we can do to build reliably in the face of many
7# available configuration options.  To be as low-overhead as possible,
8# we follow the following scheme:
9#
10# * Configuration is only re-run when an autoconf source file (such as
11#   "configure" or "config.sub") is changed.
12#
13# * "config.status" is run to rebuild Makefiles and .h files if an
14#   autoconf-parsed file (such as Makefile.in) is changed.
15#
16# * If MKUPDATE != "no", "make install" is only run if a build has happened
17#   since the last install in the current directory.
18
19.include <bsd.own.mk>
20
21# Disable use of pre-compiled headers on Darwin.
22BUILD_OSTYPE!=  uname -s
23.if ${BUILD_OSTYPE} == "Darwin"
24HOST_CFLAGS+=-O2 -no-cpp-precomp
25.endif
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+=	CC=${HOST_CC:Q} \
49		CFLAGS=${HOST_CFLAGS:Q} \
50		CPPFLAGS=${HOST_CPPFLAGS:Q} \
51		CXX=${HOST_CXX:Q} \
52		CXXFLAGS=${HOST_CXXFLAGS:Q} \
53		INSTALL=${HOST_INSTALL_FILE:Q} \
54		LDFLAGS=${HOST_LDFLAGS:Q} \
55		AR=${HOST_AR:Q} \
56		RANLIB=${HOST_RANLIB:Q} \
57		LEX=${LEX:Q} \
58		MAKE=${TOOL_GMAKE:Q} \
59		PATH="${TOOLDIR}/bin:$$PATH" \
60		YACC=${YACC:Q}
61
62BUILD_ENV+=	${CONFIGURE_ENV}
63
64CONFIGURE_ARGS+=--prefix=${TOOLDIR}
65.if ${MKPIC} == "no"
66CONFIGURE_ARGS+=--disable-shared
67.endif
68
69# don't need this for gmake? i hope.  might need gmake equiv of -X?
70##.ifndef _NOWRAPPER
71### Some systems have a small ARG_MAX.  On such systems, prevent Make
72### variables set on the command line from being exported in the
73### environment (they will still be set in MAKEOVERRIDES).
74##BUILD_OSTYPE!=	uname -s
75##.if ${BUILD_OSTYPE} == "Darwin" || ${BUILD_OSTYPE} == "FreeBSD"
76##__noenvexport=	-X
77##.endif
78##MAKE_ARGS:=	${__noenvexport} -f ${.PARSEDIR}/Makefile.gnuwrap ${MAKE_ARGS}
79##.else
80##MAKE_ARGS+=	_NOWRAPPER=1
81##.endif
82
83MAKE_ARGS+=	BISON=true DESTDIR= INSTALL=${HOST_INSTALL_FILE:Q}
84
85ALL_TARGET?=	all
86INSTALL_TARGET?=install
87
88.configure_done: ${_GNU_CFGSRC} ${.CURDIR}/Makefile
89	@mkdir build 2>/dev/null || true
90	@(cd build && /usr/bin/env ${CONFIGURE_ENV} ${HOST_SH} ${GNUHOSTDIST}/configure ${CONFIGURE_ARGS})
91	@touch $@
92
93# The .build_done timestamp is only updated if a file actually changes
94# in the build tree during "make all".  This way, if nothing has changed,
95# a "make install MKUPDATE=yes" will do nothing.
96
97# gmake version of this puts MAKE_ARGS in the environment to be sure that
98# sub-gmake's get them, otherwise tools/gcc tries to build libgcc and
99# fails.  it also uses "env -i" to entirely clear out MAKEFLAGS.
100
101GMAKE_J_ARGS?=	${MAKEFLAGS:[*]:M*-j*:C/.*(-j ?[0-9]*).*/\1/W}
102
103.build_done: .configure_done
104	@(cd build && /usr/bin/env -i ${BUILD_ENV} ${MAKE_ARGS} ${TOOL_GMAKE} ${GMAKE_J_ARGS} -e ${MAKE_ARGS} ${ALL_TARGET})
105	@if [ ! -f $@ ] || [ -n "$$(find build -type f -newer .build_done -print)" ]; \
106		then touch $@; fi
107
108.install_done! ${BUILD:D.build_done}
109	@(cd ${.OBJDIR}/build && /usr/bin/env -i ${BUILD_ENV} ${MAKE_ARGS} ${TOOL_GMAKE} -e ${MAKE_ARGS} ${INSTALL_TARGET})
110	@touch $@
111
112.PHONY: .build_done .install_done
113
114# Mapping to standard targets.
115
116.if ${USETOOLS} == "yes"
117realall: .build_done
118realinstall: .install_done
119.endif
120
121clean: clean.gnu
122clean.gnu:
123	-rm -r -f .*_done build
124
125.include <bsd.hostprog.mk>
126