diff --git a/share/mk/local.dirdeps.mk b/share/mk/local.dirdeps.mk index 246c9cdef114..d0ae1c0171cb 100644 --- a/share/mk/local.dirdeps.mk +++ b/share/mk/local.dirdeps.mk @@ -1,222 +1,231 @@ # $FreeBSD$ .if !target(_DIRDEP_USE) # we are the 1st makefile .if !defined(MK_CLANG) .include "${SRCTOP}/share/mk/src.opts.mk" .endif # making universe is special .if defined(UNIVERSE_GUARD) # these should be done by now DIRDEPS_FILTER+= N*.host .endif # pseudo machines get no qualification .for m in host common M_dep_qual_fixes += C;($m),[^/.,]*$$;\1; .endfor #.info M_dep_qual_fixes=${M_dep_qual_fixes} # Cheat for including src.libnames.mk ____: # Pull in _INTERNALLIBS .include # Host libraries should mostly be excluded from the build so the # host version in /usr/lib is used. Internal libraries need to be # allowed to be built though since they are never installed. _need_host_libs= .for lib in ${_INTERNALLIBS} _need_host_libs+= ${LIB${lib:tu}DIR:S,^${OBJTOP}/,,} .endfor N_host_libs:= ${cd ${SRCTOP} && echo lib/lib*:L:sh:${_need_host_libs:${M_ListToSkip}}:${M_ListToSkip}} DIRDEPS_FILTER.host = \ ${N_host_libs} \ Ninclude* \ Nlib/csu* \ Nlib/libc \ Nlib/[mn]* \ Ngnu/lib/lib[a-r]* \ Nsecure/lib* \ Nusr.bin/xinstall* \ DIRDEPS_FILTER+= \ Nbin/cat.host \ ${DIRDEPS_FILTER.xtras:U} # Cleanup a buildworld's WORLDTMP so that any files generated from it # or using it will rebuild with the DIRDEPS SYSROOT. Otherwise existing # object .meta files may still reference those directories and not be # rebuilt and lead to incorrect Makefile.depend files due to lack of # .dirdep files. .if !defined(NO_CLEANUP_WORLDTMP) && exists(${OBJTOP}/tmp/_worldtmp) cleanup_worldtmp: .PHONY .NOMETA @echo "Cleaning leftover WORLDTMP from buildworld." -rm -rf ${OBJTOP}/tmp/* -chflags -R 0 ${OBJTOP}/tmp/* rm -rf ${OBJTOP}/tmp beforedirdeps: cleanup_worldtmp .endif -.endif + +# pseudo option for building host tools on old or non-FreeBSD host +# allows us to leverage Makefile.depend.options with +# DIRDEPS_OPTIONS = host_egacy +# dirdeps-options.mk will qualify with ${DEP_MACHINE} (and others) +# before looking at the bare option. +MK_host_egacy.host= ${MK_host_egacy} + +.endif # !target(_DIRDEP_USE) # reset this each time DIRDEPS_FILTER.xtras= .if ${DEP_MACHINE:Npkgs*} != "" DIRDEPS_FILTER.xtras+= Nusr.bin/clang/clang.host .endif .if ${DEP_MACHINE} != "host" +MK_host_egacy.${DEP_MACHINE}= no # this is how we can handle optional dependencies .if ${DEP_RELDIR} == "lib/libc" DIRDEPS += lib/libc_nonshared .if ${MK_SSP:Uno} != "no" DIRDEPS += lib/libssp_nonshared .endif .else DIRDEPS_FILTER.xtras+= Nlib/libc_nonshared .endif # some optional things .if ${MK_CTF} == "yes" && ${DEP_RELDIR:Mcddl/usr.bin/ctf*} == "" DIRDEPS += \ cddl/usr.bin/ctfconvert.host \ cddl/usr.bin/ctfmerge.host .endif # Add in proper libgcc (gnu or LLVM) if not building libcc and libc is needed. # Add both gcc_s and gcc_eh as dependencies as the decision to build # -static or not is not known here. .if ${DEP_RELDIR:M*libgcc*} == "" && ${DIRDEPS:U:Mlib/libc} != "" DIRDEPS+= \ lib/libgcc_eh \ lib/libgcc_s .endif # Bootstrap support. Give hints to DIRDEPS if there is no Makefile.depend* # generated yet. This can be based on things such as SRC files and LIBADD. # These hints will not factor into the final Makefile.depend as only what is # used will be added in and handled via [local.]gendirdeps.mk. This is not # done for MACHINE=host builds. # XXX: Include this in local.autodep.mk as well for gendirdeps without filemon. # Only do this for main build target .if ${RELDIR} == ${DEP_RELDIR} && !defined(_RECURSING_PROGS) .for _depfile in ${.MAKE.DEPENDFILE_PREFERENCE:T} .if !defined(_have_depfile) && exists(${.CURDIR}/${_depfile}) _have_depfile= .endif .endfor .if !defined(_have_depfile) # KMOD does not use any stdlibs. .if !defined(KMOD) # Gather PROGS dependencies first .if !empty(PROGS) _PROGS_LIBADD= _PROGS_DPADD= _PROGS_SRCS= .for _prog in ${PROGS} .for s in . _ .if !empty(LIBADD${s}${_prog}) _PROGS_LIBADD+= ${LIBADD${s}${_prog}} .endif .if !empty(DPADD${s}${_prog}) _PROGS_DPADD+= ${DPADD${s}${_prog}} .endif .if !empty(SRCS${s}${_prog}) _PROGS_SRCS+= ${SRCS${s}${_prog}} .endif .endfor # .for s in . _ # Add in assumed source (bsd.prog.mk) .if !target(${_prog}) .if defined(PROG_CXX) _PROGS_SRCS+= ${_prog}.cc .else _PROGS_SRCS+= ${_prog}.c .endif .endif # !target(${_prog}) .endfor # .for _prog in ${PROGS} .endif # !empty(PROGS) _SRCS= ${SRCS} ${_PROGS_SRCS} # Has C files. The C_DIRDEPS are shared with C++ files as well. C_DIRDEPS= \ include \ include/arpa \ include/protocols \ include/rpc \ include/rpcsvc \ include/xlocale \ lib/${CSU_DIR} \ lib/libc \ lib/libcompiler_rt \ # libgcc is needed as well but is added later. .if ${MK_GSSAPI} != "no" C_DIRDEPS+= include/gssapi .endif .if !empty(_SRCS:M*.c) DIRDEPS+= ${C_DIRDEPS} .endif # Has C++ files .if !empty(_SRCS:M*.cc) || !empty(_SRCS:M*.C) || !empty(_SRCS:M*.cpp) || \ !empty(_SRCS:M*.cxx) DIRDEPS+= ${C_DIRDEPS} .if ${MK_CLANG} == "yes" DIRDEPS+= lib/libc++ lib/libcxxrt .endif # XXX: Clang and GCC always adds -lm currently, even when not needed. DIRDEPS+= lib/msun .endif # CXX .endif # !defined(KMOD) # Has yacc files. .if !empty(_SRCS:M*.y) DIRDEPS+= usr.bin/yacc.host .endif _DPADD= ${DPADD} ${_PROGS_DPADD} .if !empty(_DPADD) # This only works for DPADD with full OBJ/SRC paths, which is mostly just # _INTERNALLIBS. _DP_DIRDEPS= \ ${_DPADD:O:u:M${OBJTOP}*:H:N.:tA:C,${OBJTOP}[^/]*/,,:N.:O:u} \ ${_DPADD:O:u:M${OBJROOT}*:N${OBJTOP}*:N${STAGE_ROOT}/*:H:S,${OBJROOT},,:C,^([^/]+)/(.*),\2.\1,:S,${HOST_TARGET}$,host,:N.*:O:u} # Resolve the paths to RELDIRs .if !empty(_DP_DIRDEPS) DIRDEPS+= ${_DP_DIRDEPS:C,^,${SRCTOP}/,:tA:C,^${SRCTOP}/,,} .endif .endif # !empty(DPADD) _ALL_LIBADD= ${LIBADD} ${_PROGS_LIBADD} .if !empty(_ALL_LIBADD) # Also handle LIBADD for non-internal libraries. .for _lib in ${_ALL_LIBADD:O:u} _lib${_lib}reldir= ${LIB${_lib:tu}DIR:C,${OBJTOP}/,,} .if defined(LIB${_lib:tu}DIR) && ${DIRDEPS:M${_lib${_lib}reldir}} == "" && \ exists(${SRCTOP}/${_lib${_lib}reldir}) DIRDEPS+= ${_lib${_lib}reldir} .endif .endfor .endif # !empty(LIBADD) .endif # no Makefile.depend* .endif # ${RELDIR} == ${DEP_RELDIR} .endif # ${DEP_MACHINE} != "host" .if ${MK_STAGING} == "yes" # we need targets/pseudo/stage to prep the stage tree .if ${DEP_RELDIR:N.:N${SRCTOP}:N*pseudo/stage} != "" DIRDEPS += targets/pseudo/stage .endif .endif DEP_MACHINE_ARCH = ${MACHINE_ARCH.${DEP_MACHINE}} DEP_MACHINE_CPUARCH = ${DEP_MACHINE_ARCH:${__TO_CPUARCH}} CSU_DIR.${DEP_MACHINE_ARCH} ?= csu/${DEP_MACHINE_ARCH} CSU_DIR := ${CSU_DIR.${DEP_MACHINE_ARCH}} BOOT_MACHINE_DIR:= ${BOOT_MACHINE_DIR.${DEP_MACHINE}} KERNEL_NAME:= ${KERNEL_NAME.${DEP_MACHINE}} .-include diff --git a/share/mk/local.init.mk b/share/mk/local.init.mk index c8072004697f..1d165c339ff0 100644 --- a/share/mk/local.init.mk +++ b/share/mk/local.init.mk @@ -1,41 +1,44 @@ # $FreeBSD$ .if !target(__${_this}__) __${_this}__: .if ${.MAKE.MODE:Mmeta*} != "" .if !empty(SUBDIR) && !defined(LIB) && !defined(PROG) && ${.MAKE.MAKEFILES:M*bsd.prog.mk} == "" .if ${.MAKE.MODE:Mleaf*} != "" # we only want leaf dirs to build in meta mode... and we are not one .MAKE.MODE = normal .endif .endif .endif # XXX: This should be combined with external compiler support in Makefile.inc1 # and local.meta.sys.mk (CROSS_TARGET_FLAGS) .if ${MK_SYSROOT} == "yes" && !empty(SYSROOT) && ${MACHINE} != "host" CFLAGS_LAST+= --sysroot=${SYSROOT} CXXFLAGS_LAST+= --sysroot=${SYSROOT} LDADD+= --sysroot=${SYSROOT} .elif ${MK_STAGING} == "yes" -CFLAGS+= -isystem ${STAGE_INCLUDEDIR} +ISYSTEM?= ${STAGE_INCLUDEDIR} +# no space after -isystem makes it easier to +# grep the flag out of command lines (in meta files) to see its value. +CFLAGS+= -isystem${ISYSTEM} # XXX: May be needed for GCC to build with libc++ rather than libstdc++. See Makefile.inc1 #CXXFLAGS+= -std=gnu++11 #LDADD+= -L${STAGE_LIBDIR}/libc++ #CXXFLAGS+= -I${STAGE_INCLUDEDIR}/usr/include/c++/v1 LDADD+= -L${STAGE_LIBDIR} .endif .if ${MACHINE} == "host" .if ${.MAKE.DEPENDFILE:E} != "host" UPDATE_DEPENDFILE?= no .endif HOST_CFLAGS+= -DHOSTPROG CFLAGS+= ${HOST_CFLAGS} .endif .-include "src.init.mk" .-include .-include "${.CURDIR}/local.init.mk" .endif diff --git a/share/mk/local.sys.mk b/share/mk/local.sys.mk index 1817f6393949..1aac5014b737 100644 --- a/share/mk/local.sys.mk +++ b/share/mk/local.sys.mk @@ -1,116 +1,124 @@ # $FreeBSD$ .if !target(_${_this}_) _${_this}_: .NOTMAIN .if ${MK_DIRDEPS_BUILD} == "yes" || ${MK_META_MODE} == "yes" # Not in the below list as it may make sense for non-meta mode # eventually. meta.sys.mk (DIRDEPS_BUILD) also already adds these in. .if ${MK_DIRDEPS_BUILD} == "no" && ${MK_META_MODE} == "yes" MAKE_PRINT_VAR_ON_ERROR += \ .ERROR_TARGET \ .ERROR_META_FILE \ .MAKE.LEVEL \ MAKEFILE \ .MAKE.MODE .endif _ERROR_CMD_EXEC= ${sed -n '/^CMD/s,^CMD \(.*\),\1;,p' ${.ERROR_META_FILE}:L:sh} _ERROR_CMD= ${!empty(.ERROR_META_FILE):?${_ERROR_CMD_EXEC}:.PHONY} MAKE_PRINT_VAR_ON_ERROR+= \ _ERROR_CMD \ .CURDIR \ .MAKE \ .OBJDIR \ .TARGETS \ CPUTYPE \ DESTDIR \ LD_LIBRARY_PATH \ MACHINE \ MACHINE_ARCH \ MACHINE_CPUARCH \ MAKEOBJDIRPREFIX \ MAKESYSPATH \ MAKE_VERSION \ PATH \ SRCTOP \ OBJTOP \ ${MAKE_PRINT_VAR_ON_ERROR_XTRAS} # Meta mode may rebuild targets that then fail. The next build won't detect # the meta mode change. Not all targets have a 'rm ${.TARGET}' in them # so force it. .DELETE_ON_ERROR: .if ${.MAKE.LEVEL} > 0 MAKE_PRINT_VAR_ON_ERROR += .MAKE.MAKEFILES .PATH .endif .endif .if !empty(.OBJDIR) OBJTOP?= ${.OBJDIR:S,${.CURDIR},,}${SRCTOP} .endif .if !empty(LIBDIR) _PREMK_LIBDIR:= ${LIBDIR} .endif .include "src.sys.mk" .-include .if make(*-jobs) && empty(JOB_MAX) # provide a reasonable? default for JOB_MAX based on ncpu JOB_MAX_FACTOR?= 1.33 NPROC?= ${(type nproc) 2> /dev/null:L:sh:M/*:[1]} NPROC:= ${NPROC} .if !empty(NPROC) ncpu!= ${NPROC} .elif ${.MAKE.OS:NDarwin:NFreeBSD} == "" ncpu!= sysctl -n hw.ncpu .endif .if ${ncpu:U0} > 1 .if ${JOB_MAX_FACTOR} == 1 JOB_MAX:= ${ncpu} .else jm!= echo ${ncpu} \* ${JOB_MAX_FACTOR} | bc JOB_MAX:= ${jm:R} .endif .endif .endif +.if ${MK_DIRDEPS_BUILD} == "yes" +.if ${.MAKE.OS} != "FreeBSD" || ${_HOST_OSREL:R} < ${OS_REVISION:R} +# a pseudo option to indicate we need libegacy for host +MK_host_egacy= yes +.endif +.endif +MK_host_egacy?= no + .if ${.MAKE.MODE:Mmeta*} != "" # we can afford to use cookies to prevent some targets # re-running needlessly but only when using filemon. # Targets that should support the meta mode cookie handling should just be # added to META_TARGETS. If bsd.sys.mk cannot be included then ${META_DEPS} # should be added as a target dependency as well. Otherwise the target # is added to in bsd.sys.mk since it comes last. .if ${.MAKE.MODE:Mnofilemon} == "" # Prepend .OBJDIR if not already there. _META_COOKIE_COND= "${.TARGET:M${.OBJDIR}/*}" == "" _META_COOKIE_DEFAULT= ${${_META_COOKIE_COND}:?${.OBJDIR}/${.TARGET}:${.TARGET}} # Use the default if COOKIE.${.TARGET} is not defined. META_COOKIE= ${COOKIE.${.TARGET}:U${_META_COOKIE_DEFAULT}} META_COOKIE_RM= @rm -f ${META_COOKIE} META_COOKIE_TOUCH= @touch ${META_COOKIE} CLEANFILES+= ${META_TARGETS} _meta_dep_before: .USEBEFORE .NOTMAIN ${META_COOKIE_RM} _meta_dep_after: .USE .NOTMAIN ${META_COOKIE_TOUCH} # Attach this to a target to allow it to benefit from meta mode's # not rerunning a command if it doesn't need to be considering its # metafile/filemon-tracked dependencies. META_DEPS= _meta_dep_before _meta_dep_after .META .endif .else # some targets need to be .PHONY - but not in meta mode META_NOPHONY= .PHONY .endif META_NOPHONY?= META_COOKIE_RM?= META_COOKIE_TOUCH?= META_DEPS+= ${META_NOPHONY} .endif diff --git a/share/mk/src.init.linux.mk b/share/mk/src.init.linux.mk new file mode 100644 index 000000000000..1e351e1b41f6 --- /dev/null +++ b/share/mk/src.init.linux.mk @@ -0,0 +1,15 @@ +# We want to build some host tools (eg makefs, mkimg) for Linux +# This only gets included during DIRDEPS_BUILD when MACHINE is "host" + +CFLAGS+= -I${SRCTOP}/tools/build/cross-build/include/linux + +WARNS= 0 + +.ifdef PROG +LOCAL_LIBRARIES+= bsd egacy +LIBADD+= egacy m +.endif + +# Bring in the full GNU namespace +CFLAGS+= -D_GNU_SOURCE + diff --git a/share/mk/src.init.mk b/share/mk/src.init.mk index 2067dcdbbabc..148dc7a3e960 100644 --- a/share/mk/src.init.mk +++ b/share/mk/src.init.mk @@ -1,11 +1,42 @@ # $FreeBSD$ .if !target(____) ____: .if !target(buildenv) buildenv: .PHONY ${_+_}@env BUILDENV_DIR=${.CURDIR} ${MAKE} -C ${SRCTOP} buildenv .endif +.if ${MACHINE:Nhost*} == "" +.if ${.MAKE.OS} != "FreeBSD" +# these won't work anyway - see tools/build/mk/Makefile.boot.pre +MK_DEBUG_FILES= no +MK_MAN= no +MK_PIE= no +MK_RETPOLINE= no +NO_SHARED= no +MK_TESTS= no + +.-include + +CFLAGS+= \ + -DHAVE_NBTOOL_CONFIG_H=1 \ + -I${SRCTOP}/tools/build/cross-build/include/common \ + +.endif + +.if ${MK_host_egacy} == "yes" +.ifdef PROG +LOCAL_LIBRARIES+= egacy +LIBADD+= egacy +.endif +.endif + +.if ${MK_STAGING} == "yes" +ISYSTEM= /usr/include +CFLAGS+= -I${STAGE_INCLUDEDIR} +.endif +.endif + .endif # !target(____)