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