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