xref: /minix3/tools/Makefile.gnuhost (revision 10f4c3fbb17a47912ebb19eb36bdc859ab463671)
1#	$NetBSD: Makefile.gnuhost,v 1.39 2012/06/19 21:48:33 hans 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
29# AL - MINIX /usr/src does not have the sources for the GNU utilities
30# in-tree (they are much bigger than Minix itself!) So to successfully
31# use them while cross-compiling, we have to fetch them. The success of
32# that operation is indicated by the presence of a .gitignore file in
33# the corresponding ${.CURDIR}, which also conveniently hides from git.
34.if exists(${GNUHOSTDIST:H}/fetch.sh)
35${GNUHOSTDIST:H}/.gitignore: ${GNUHOSTDIST:H}/fetch.sh
36	${HOST_SH} ${GNUHOSTDIST:H}/fetch.sh
37	@test -e ${GNUHOSTDIST}/configure
38	@echo "${MODULE:U${.CURDIR:T:C,^gcc[0-9]*$,gcc,}}-*.tar.*z*" > $@
39	@echo ${GNUHOSTDIST:T} >> $@
40_gnu_get_src=${GNUHOSTDIST:H}/.gitignore
41.endif # exists(GNUHOSTDIST:H/fetch.sh) on MINIX
42
43FIND_ARGS+=	\! \( -type d \( \
44			-name 'CVS' -o \
45			-name 'config' -o \
46			-name 'doc' -o \
47			-name 'po' -o \
48			-name 'nbsd.mt' -o \
49			-name 'tests*' \
50		\) -prune \)
51
52# Do this "find" only if actually building something.
53# AL - ... and on MINIX, if the source has already being fetched
54.if (${USETOOLS} == "yes") && empty(.MAKEFLAGS:M-V*) && \
55    (make(all) || make(realall) || (!make(clean) && !make(cleandir) && !make(obj))) && \
56    !defined(_GNU_CFGSRC) && exists(${GNUHOSTDIST}/configure)
57
58_GNU_CFGSRC!=	find ${GNUHOSTDIST} ${FIND_ARGS} \
59		-type f \( -name 'config*' -o -name '*.in' \) -print
60.MAKEOVERRIDES+= _GNU_CFGSRC
61.endif
62
63CONFIGURE_ENV+= \
64		AR=${HOST_AR:Q} \
65		AWK=${TOOL_AWK:Q} \
66		CC=${HOST_CC:Q} \
67		CFLAGS=${HOST_CFLAGS:Q} \
68		CPPFLAGS=${HOST_CPPFLAGS:Q} \
69		CXX=${HOST_CXX:Q} \
70		CXXFLAGS=${HOST_CXXFLAGS:Q} \
71		INSTALL=${HOST_INSTALL_FILE:Q} \
72		LDFLAGS=${HOST_LDFLAGS:Q} \
73		LEX=${LEX:Q} \
74		M4=${TOOL_M4:Q} \
75		MAKE=${MAKE_PROGRAM:Q} \
76		PATH="${TOOLDIR}/bin:$$PATH" \
77		RANLIB=${HOST_RANLIB:Q} \
78		YACC=${YACC:Q}
79
80BUILD_ENV+=	${CONFIGURE_ENV}
81
82CONFIGURE_ARGS+=--prefix=${TOOLDIR}
83.if ${MKPIC} == "no"
84CONFIGURE_ARGS+=--disable-shared
85.endif
86
87.if ${MAKE_PROGRAM} == ${MAKE}
88.ifndef _NOWRAPPER
89# Some systems have a small ARG_MAX.  On such systems, prevent Make
90# variables set on the command line from being exported in the
91# environment (they will still be set in MAKEOVERRIDES).
92.if ${BUILD_OSTYPE} == "Darwin" || ${BUILD_OSTYPE} == "FreeBSD"
93__noenvexport=	-X
94.endif
95MAKE_ARGS:=	${__noenvexport} -f ${.PARSEDIR}/Makefile.gnuwrap ${MAKE_ARGS}
96.else
97MAKE_ARGS+=	_NOWRAPPER=1
98.endif
99BUILD_COMMAND=	${BUILD_ENV} ${MAKE} ${MAKE_ARGS}
100.else
101
102# gmake version of this puts MAKE_ARGS in the environment to be sure that
103# sub-gmake's get them, otherwise tools/gcc tries to build libgcc and
104# fails.  it also uses "env -i" to entirely clear out MAKEFLAGS.
105GMAKE_J_ARGS?=	${MAKEFLAGS:[*]:M*-j*:C/.*(-j ?[0-9]*).*/\1/W}
106BUILD_COMMAND=	/usr/bin/env -i ${BUILD_ENV} ${MAKE_ARGS} ${TOOL_GMAKE} ${GMAKE_J_ARGS} -e ${MAKE_ARGS}
107
108.endif
109
110MAKE_ARGS+=	BISON=true DESTDIR= INSTALL=${HOST_INSTALL_FILE:Q}
111
112ALL_TARGET?=	all
113INSTALL_TARGET?=install
114
115BUILD_PLATFORM!= uname -srm | tr ' ()' '-'
116CONFIGURE_PLATFORM!= if [ -s .configure_done ]; then cat .configure_done; else echo none; fi
117.if "${BUILD_PLATFORM}" != "${CONFIGURE_PLATFORM}"
118configure_cleanup:
119	@mkdir build 2>/dev/null || true
120	@(echo "Cleaning stale cache files ${BUILD_PLATFORM} != ${CONFIGURE_PLATFORM}")
121	@(cd build && find . -name config.cache | xargs rm -f)
122configure_cleanup=configure_cleanup
123.endif
124
125# AL For MINIX, fetch the source if not there
126.configure_done: ${_gnu_get_src} .WAIT ${_GNU_CFGSRC} ${.CURDIR}/Makefile ${configure_cleanup}
127	@mkdir build 2>/dev/null || true
128	@(cd build && ${CONFIGURE_ENV} ${HOST_SH} ${GNUHOSTDIST}/configure ${CONFIGURE_ARGS})
129	@echo ${BUILD_PLATFORM} > $@
130
131# The .build_done timestamp is only updated if a file actually changes
132# in the build tree during "make all".  This way, if nothing has changed,
133# a "make install MKUPDATE=yes" will do nothing.
134
135.build_done: .configure_done
136	@(cd build && ${BUILD_COMMAND} ${ALL_TARGET})
137	@if [ ! -f $@ ] || [ -n "$$(find build -type f -newer .build_done -print)" ]; \
138		then touch $@; fi
139
140.install_done! ${BUILD:D.build_done}
141	@(cd ${.OBJDIR}/build && ${BUILD_COMMAND} ${INSTALL_TARGET})
142	@touch $@
143
144# Mapping to standard targets.
145
146.if ${USETOOLS} == "yes"
147realall: .build_done
148realinstall: .install_done
149.endif
150
151clean: clean.gnu
152clean.gnu:
153	-rm -r -f .*_done build
154
155# AL - Special target for MINIX, reset the source tree as pristine
156.if ${CLEANFETCHED:Uno} == "yes" && exists(${GNUHOSTDIST:H}/fetch.sh)
157cleandir: clean_gnu_src
158clean_gnu_src:
159	-rm -r -f ${GNUHOSTDIST} ${GNUHOSTDIST:H}/.gitignore
160# XXX CHECKME: could have used the content of .gitignore as well?
161.endif # CLEANFETCHED == yes
162
163.include <bsd.hostprog.mk>
164