Home | History | Annotate | Line # | Download | only in tools
      1 #	$NetBSD: Makefile.gnuhost,v 1.57 2025/05/25 06:06:57 rillig 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 HOST_COMPILER_CLANG!= if ${HOST_CC} --version | grep -q -s clang; then echo yes; else echo no; fi
     23 .if ${HOST_COMPILER_CLANG} == "yes"
     24 HOST_CFLAGS+=-O2 -no-cpp-precomp
     25 .endif
     26 
     27 MAKE_PROGRAM?=	${MAKE}
     28 
     29 .for i in 3 2
     30 .if exists(${.CURDIR}/../../external/gpl${i}/${MODULE}/dist)
     31 GNUHOSTDIST?=	${.CURDIR}/../../external/gpl${i}/${MODULE}/dist
     32 .endif
     33 .endfor
     34 
     35 FIND_ARGS+=	\! \( -type d \( \
     36 			-name 'CVS' -o \
     37 			-name 'config' -o \
     38 			-name 'doc' -o \
     39 			-name 'po' -o \
     40 			-name 'nbsd.mt' -o \
     41 			-name 'tests*' \
     42 		\) -prune \)
     43 
     44 # Do this "find" only if actually building something.
     45 .if (${USETOOLS} == "yes") && empty(.MAKEFLAGS:M-V*) && \
     46     (make(all) || make(realall) || (!make(clean) && !make(cleandir) && !make(obj))) && \
     47     !defined(_GNU_CFGSRC)
     48 
     49 _GNU_CFGSRC!=	find ${GNUHOSTDIST} ${FIND_ARGS} \
     50 		-type f \( -name 'config*' -o -name '*.in' \) -print
     51 .MAKEOVERRIDES+= _GNU_CFGSRC
     52 .endif
     53 
     54 CONFIGURE_ENV+= \
     55 		AR=${HOST_AR:Q} \
     56 		AWK=${TOOL_AWK:Q} \
     57 		CC=${HOST_CC:Q} \
     58 		CFLAGS=${HOST_CFLAGS:Q} \
     59 		CONFIG_SHELL=${HOST_SH:Q} \
     60 		CPPFLAGS=${HOST_CPPFLAGS:Q} \
     61 		CXX=${HOST_CXX:Q} \
     62 		CXXFLAGS=${HOST_CXXFLAGS:Q} \
     63 		INSTALL=${HOST_INSTALL_FILE:Q} \
     64 		LDFLAGS=${HOST_LDFLAGS:Q} \
     65 		LEX=${LEX:Q} \
     66 		FLEX=${LEX:Q} \
     67 		M4=${TOOL_M4:Q} \
     68 		MAKE=${MAKE_PROGRAM:Q} \
     69 		PATH="${TOOLDIR}/bin:$$PATH" \
     70 		RANLIB=${HOST_RANLIB:Q} \
     71 		YACC=${YACC:Q}
     72 
     73 BUILD_ENV+=	${CONFIGURE_ENV}
     74 
     75 CONFIGURE_ARGS+=--prefix=${TOOLDIR}
     76 .if ${MKPIC} == "no"
     77 CONFIGURE_ARGS+=--disable-shared
     78 .endif
     79 
     80 .if ${MAKEVERBOSE} == 0
     81 CONFIGURE_ARGS+=--silent
     82 .endif
     83 
     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][0-9]*).*/\2/W}
    104 BUILD_COMMAND=	/usr/bin/env -i ${BUILD_ENV} ${MAKE_ARGS:N-*} ${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 .if ${MAKEVERBOSE} < 2
    111 MAKE_ARGS+=	-s V=0
    112 .else
    113 MAKE_ARGS+=	V=1
    114 .endif
    115 
    116 ALL_TARGET?=	all
    117 INSTALL_TARGET?=install
    118 
    119 BUILD_PLATFORM!= uname -srm | tr ' ()' '-'
    120 CONFIGURE_PLATFORM!= if [ -s .configure_done ]; then cat .configure_done; else echo none; fi
    121 .if "${BUILD_PLATFORM}" != "${CONFIGURE_PLATFORM}"
    122 configure_cleanup:
    123 	@mkdir build 2>/dev/null || true
    124 	@(echo "Cleaning stale cache files ${BUILD_PLATFORM} != ${CONFIGURE_PLATFORM}")
    125 	@(cd build && find . -name config.cache | xargs rm -f)
    126 configure_cleanup=configure_cleanup
    127 .endif
    128 
    129 .configure_done: ${_GNU_CFGSRC} ${.CURDIR}/Makefile ${configure_cleanup}
    130 	@mkdir build 2>/dev/null || true
    131 	@(cd build && ${CONFIGURE_ENV} ${HOST_SH} ${GNUHOSTDIST}/configure ${CONFIGURE_ARGS})
    132 	@echo ${BUILD_PLATFORM} > $@
    133 
    134 # The .build_done timestamp is only updated if a file actually changes
    135 # in the build tree during "make all".  This way, if nothing has changed,
    136 # a "make install MKUPDATE=yes" will do nothing.
    137 
    138 .build_done: .configure_done
    139 	@${:D make}(cd build && ${BUILD_COMMAND} ${ALL_TARGET})
    140 	@if [ ! -f $@ ] || [ -n "$$(find build -type f -newer .build_done -print)" ]; \
    141 		then touch $@; fi
    142 
    143 .install_done! ${BUILD:D.build_done}
    144 	@${:D make}(cd ${.OBJDIR}/build && ${BUILD_COMMAND} ${INSTALL_TARGET})
    145 	@touch $@
    146 
    147 # Mapping to standard targets.
    148 
    149 .if ${USETOOLS} == "yes"
    150 realall: .build_done
    151 realinstall: .install_done
    152 .endif
    153 
    154 clean: clean.gnu
    155 clean.gnu:
    156 	-rm -r -f .*_done build
    157 
    158 .include <bsd.hostprog.mk>
    159