Makefile.gnuhost revision 1.19
1#	$NetBSD: Makefile.gnuhost,v 1.19 2003/07/18 08:26:12 lukem 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
20GNUHOSTDIST?=	${.CURDIR}/../../gnu/dist/${MODULE}
21
22FIND_ARGS+=	\! \( -type d \( \
23			-name 'CVS' -o \
24			-name 'config' -o \
25			-name 'doc' -o \
26			-name 'po' -o \
27			-name 'nbsd.mt' -o \
28			-name 'tests*' \
29		\) -prune \)
30
31# Do this "find" only if actually building something.
32.if (${USETOOLS} == "yes") && empty(.MAKEFLAGS:M-V*) && \
33    (make(all) || make(realall) || (!make(clean) && !make(cleandir) && !make(obj))) && \
34    !defined(_GNU_CFGSRC)
35
36_GNU_CFGSRC!=	find ${GNUHOSTDIST} ${FIND_ARGS} \
37		-type f \( -name 'config*' -o -name '*.in' \) -print
38.MAKEOVERRIDES+= _GNU_CFGSRC
39.endif
40
41CONFIGURE_ENV+=	CC=${HOST_CC:Q} \
42		CFLAGS=${HOST_CFLAGS:Q} \
43		CPPFLAGS=${HOST_CPPFLAGS:Q} \
44		CXX=${HOST_CXX:Q} \
45		CXXFLAGS=${HOST_CXXFLAGS:Q} \
46		INSTALL=${HOST_INSTALL_FILE:Q} \
47		LDFLAGS=${HOST_LDFLAGS:Q} \
48		LEX=${LEX:Q} \
49		PATH="${TOOLDIR}/bin:$$PATH" \
50		YACC=${YACC:Q}
51
52CONFIGURE_ARGS+=--prefix=${TOOLDIR} --disable-shared
53
54.ifndef _NOWRAPPER
55# Some systems have a small ARG_MAX.  On such systems, prevent Make
56# variables set on the command line from being exported in the
57# environment (they will still be set in MAKEOVERRIDES).
58BUILD_OSTYPE!=	uname -s
59.if ${BUILD_OSTYPE} == "Darwin" || ${BUILD_OSTYPE} == "FreeBSD"
60__noenvexport=	-X
61.endif
62MAKE_ARGS:=	${__noenvexport} -f ${.PARSEDIR}/Makefile.gnuwrap ${MAKE_ARGS}
63.else
64MAKE_ARGS+=	_NOWRAPPER=1
65.endif
66
67MAKE_ARGS+=	BISON=true DESTDIR= INSTALL=${HOST_INSTALL_FILE:Q}
68
69ALL_TARGET?=	all
70INSTALL_TARGET?=install
71
72.configure_done: ${_GNU_CFGSRC} ${.CURDIR}/Makefile
73	@mkdir build 2>/dev/null || true
74	@(cd build && ${CONFIGURE_ENV} sh ${GNUHOSTDIST}/configure ${CONFIGURE_ARGS})
75	@touch $@
76
77# The .build_done timestamp is only updated if a file actually changes
78# in the build tree during "make all".  This way, if nothing has changed,
79# a "make install MKUPDATE=yes" will do nothing.
80
81.build_done: .configure_done
82	@(cd build && ${MAKE} ${MAKE_ARGS} ${ALL_TARGET})
83	@if [ ! -f $@ ] || [ -n "$$(find build -type f -newer .build_done -print)" ]; \
84		then touch $@; fi
85
86.install_done: ${BUILD:D.build_done}
87.if ${MKUPDATE} != "no"
88	@cd ${.OBJDIR}; \
89	if [ ! -f .install_done ] || [ ! -f .build_done ] || \
90	[ -n "$$(find .build_done -prune -newer .install_done -print)" ]; then \
91		(cd build && ${MAKE} ${MAKE_ARGS} ${INSTALL_TARGET}); \
92	fi
93.else
94	@(cd ${.OBJDIR}/build && ${MAKE} ${MAKE_ARGS} ${INSTALL_TARGET})
95.endif
96	@touch $@
97
98.PHONY: .build_done .install_done
99
100# Mapping to standard targets.
101
102.if ${USETOOLS} == "yes"
103realall: .build_done
104realinstall: .install_done
105.endif
106
107clean: clean.gnu
108clean.gnu:
109	-rm -r -f .*_done build
110
111.include <bsd.hostprog.mk>
112