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