1# $FreeBSD$
2
3# local configuration specific to meta mode
4# XXX some of this should be in meta.sys.mk
5# we assume that MK_DIRDEPS_BUILD=yes
6
7# we need this until there is an alternative
8MK_INSTALL_AS_USER= yes
9
10.if !defined(HOST_TARGET) || !defined(HOST_MACHINE)
11# we need HOST_TARGET etc below.
12.include <host-target.mk>
13.export HOST_TARGET
14.endif
15
16# from src/Makefile (for universe)
17TARGET_ARCHES_arm?=     arm armv6 armv7
18TARGET_ARCHES_arm64?=   aarch64
19TARGET_ARCHES_mips?=    mipsel mips mips64el mips64 mipsn32 mipsn32el
20TARGET_ARCHES_powerpc?= powerpc powerpc64 powerpcspe
21TARGET_ARCHES_riscv?=   riscv64 riscv64sf
22
23# some corner cases
24BOOT_MACHINE_DIR.amd64 = boot/i386
25MACHINE_ARCH.host = ${_HOST_ARCH}
26
27# the list of machines we support
28ALL_MACHINE_LIST?= amd64 arm arm64 i386 mips powerpc riscv sparc64
29.for m in ${ALL_MACHINE_LIST:O:u}
30MACHINE_ARCH_LIST.$m?= ${TARGET_ARCHES_${m}:U$m}
31MACHINE_ARCH.$m?= ${MACHINE_ARCH_LIST.$m:[1]}
32BOOT_MACHINE_DIR.$m ?= boot/$m
33.endfor
34
35.ifndef _TARGET_SPEC
36.if empty(MACHINE_ARCH)
37.if !empty(TARGET_ARCH)
38MACHINE_ARCH= ${TARGET_ARCH}
39.else
40MACHINE_ARCH= ${MACHINE_ARCH.${MACHINE}}
41.endif
42.endif
43MACHINE_ARCH?= ${MACHINE_ARCH.${MACHINE}}
44MACHINE_ARCH:= ${MACHINE_ARCH}
45.else
46# we got here via dirdeps
47MACHINE_ARCH:= ${MACHINE_ARCH.${MACHINE}}
48.endif
49
50# now because for universe we want to potentially
51# build for multiple MACHINE_ARCH per MACHINE
52# we need more than MACHINE in TARGET_SPEC
53TARGET_SPEC_VARS= MACHINE MACHINE_ARCH
54# see dirdeps.mk
55.if ${TARGET_SPEC:Uno:M*,*} != ""
56_tspec := ${TARGET_SPEC:S/,/ /g}
57MACHINE := ${_tspec:[1]}
58MACHINE_ARCH := ${_tspec:[2]}
59# etc.
60# We need to stop that TARGET_SPEC affecting any submakes
61# and deal with MACHINE=${TARGET_SPEC} in the environment.
62TARGET_SPEC=
63# export but do not track
64.export-env TARGET_SPEC 
65.export ${TARGET_SPEC_VARS}
66.for v in ${TARGET_SPEC_VARS:O:u}
67.if empty($v)
68.undef $v
69.endif
70.endfor
71.endif
72# make sure we know what TARGET_SPEC is
73# as we may need it to find Makefile.depend*
74TARGET_SPEC = ${TARGET_SPEC_VARS:@v@${$v:U}@:ts,}
75
76# to be consistent with src/Makefile just concatenate with '.'s
77TARGET_OBJ_SPEC:= ${TARGET_SPEC:S;,;.;g}
78OBJTOP:= ${OBJROOT}${TARGET_OBJ_SPEC}
79
80.if defined(MAKEOBJDIR)
81.if ${MAKEOBJDIR:M/*} == ""
82.error Cannot use MAKEOBJDIR=${MAKEOBJDIR}${.newline}Unset MAKEOBJDIR to get default:  MAKEOBJDIR='${_default_makeobjdir}'
83.endif
84.endif
85
86HOST_OBJTOP ?= ${OBJROOT}${HOST_TARGET}
87
88.if ${OBJTOP} == ${HOST_OBJTOP} || ${REQUESTED_MACHINE:U${MACHINE}} == "host"
89MACHINE= host
90.if ${TARGET_MACHINE:Uno} == ${HOST_TARGET}
91# not what we want
92TARGET_MACHINE= host
93.endif
94.endif
95.if ${MACHINE} == "host"
96OBJTOP := ${HOST_OBJTOP}
97.endif
98
99.if ${.MAKE.LEVEL} == 0 || empty(PYTHON)
100PYTHON ?= /usr/local/bin/python
101.export PYTHON
102# this works best if share/mk is ready for it.
103BUILD_AT_LEVEL0= no
104# _SKIP_BUILD is not 100% as it requires wrapping all 'all:' targets to avoid
105# building in MAKELEVEL0.  Just prohibit 'all' entirely in this case to avoid
106# problems.
107.if ${MK_DIRDEPS_BUILD} == "yes" && \
108    ${.MAKE.LEVEL} == 0 && ${BUILD_AT_LEVEL0:Uyes:tl} == "no"
109.MAIN: dirdeps
110.if make(all)
111.error DIRDEPS_BUILD: Please run '${MAKE}' instead of '${MAKE} all'.
112.endif
113.endif
114.endif
115
116# we want to end up with a singe stage tree for all machines
117.if ${MK_STAGING} == "yes"
118.if empty(STAGE_ROOT)
119STAGE_ROOT?= ${OBJROOT}stage
120.export STAGE_ROOT
121.endif
122.endif
123
124.if ${MK_STAGING} == "yes"
125.if ${MACHINE} == "host"
126STAGE_MACHINE= ${HOST_TARGET}
127.else
128STAGE_MACHINE:= ${TARGET_OBJ_SPEC}
129.endif
130STAGE_OBJTOP:= ${STAGE_ROOT}/${STAGE_MACHINE}
131STAGE_COMMON_OBJTOP:= ${STAGE_ROOT}/common
132STAGE_TARGET_OBJTOP:= ${STAGE_ROOT}/${TARGET_OBJ_SPEC}
133STAGE_HOST_OBJTOP:= ${STAGE_ROOT}/${HOST_TARGET}
134# These are exported for hooking in out-of-tree builds.  They will always
135# be overridden in sub-makes above when building in-tree.
136.if ${.MAKE.LEVEL} > 0
137.export STAGE_OBJTOP STAGE_TARGET_OBJTOP STAGE_HOST_OBJTOP
138.endif
139
140# Use tools/install.sh which can avoid the need for xinstall for simple cases.
141INSTALL?=	sh ${SRCTOP}/tools/install.sh
142# This is for stage-install to pickup from the environment.
143REAL_INSTALL:=	${INSTALL}
144.export REAL_INSTALL
145STAGE_INSTALL=	sh ${.PARSEDIR:tA}/stage-install.sh OBJDIR=${.OBJDIR:tA}
146
147STAGE_LIBDIR= ${STAGE_OBJTOP}${_LIBDIR:U${LIBDIR:U/lib}}
148STAGE_INCLUDEDIR= ${STAGE_OBJTOP}${INCLUDEDIR:U/usr/include}
149# this is not the same as INCLUDEDIR
150STAGE_INCSDIR= ${STAGE_OBJTOP}${INCSDIR:U/include}
151# the target is usually an absolute path
152STAGE_SYMLINKS_DIR= ${STAGE_OBJTOP}
153
154#LDFLAGS_LAST+= -Wl,-rpath-link,${STAGE_LIBDIR}
155.if ${MK_SYSROOT} == "yes"
156SYSROOT?= ${STAGE_OBJTOP}
157.else
158LDFLAGS_LAST+= -L${STAGE_LIBDIR}
159.endif
160
161.endif				# MK_STAGING
162
163.-include "local.toolchain.mk"
164
165# this is sufficient for most of the tree.
166.MAKE.DEPENDFILE_DEFAULT = ${.MAKE.DEPENDFILE_PREFIX}
167
168# but if we have a machine qualified file it should be used in preference
169.MAKE.DEPENDFILE_PREFERENCE = \
170	${.MAKE.DEPENDFILE_PREFIX}.${MACHINE} \
171	${.MAKE.DEPENDFILE_PREFIX}
172
173.undef .MAKE.DEPENDFILE
174
175.include "sys.dependfile.mk"
176
177.if ${.MAKE.LEVEL} > 0 && ${MACHINE} == "host" && ${.MAKE.DEPENDFILE:E} != "host"
178# we can use this but should not update it.
179UPDATE_DEPENDFILE= NO
180.endif
181
182# define the list of places that contain files we are responsible for
183.MAKE.META.BAILIWICK = ${SB} ${OBJROOT} ${STAGE_ROOT}
184
185CSU_DIR.${MACHINE_ARCH} ?= csu/${MACHINE_ARCH}
186CSU_DIR := ${CSU_DIR.${MACHINE_ARCH}}
187
188.if !empty(TIME_STAMP)
189TRACER= ${TIME_STAMP} ${:U}
190.endif
191.if !defined(_RECURSING_PROGS) && !defined(_RECURSING_CRUNCH) && \
192    !make(print-dir)
193WITH_META_STATS= t
194.endif
195
196# toolchains can be a pain - especially bootstrappping them
197.if ${MACHINE} == "host"
198MK_SHARED_TOOLCHAIN= no
199.endif
200TOOLCHAIN_VARS=	AS AR CC CLANG_TBLGEN CXX CPP LD NM OBJCOPY RANLIB \
201		STRINGS SIZE LLVM_TBLGEN
202_toolchain_bin_CLANG_TBLGEN=	/usr/bin/clang-tblgen
203_toolchain_bin_LLVM_TBLGEN=	/usr/bin/llvm-tblgen
204_toolchain_bin_CXX=		/usr/bin/c++
205.ifdef WITH_TOOLSDIR
206TOOLSDIR?= ${HOST_OBJTOP}/tools
207.elif defined(STAGE_HOST_OBJTOP)
208TOOLSDIR?= ${STAGE_HOST_OBJTOP}
209.endif
210# Only define if it exists in case user didn't run bootstrap-tools.  Otherwise
211# the tool will be built during the build.  Building it assumes it is
212# TARGET==MACHINE.
213.if exists(${HOST_OBJTOP}/tools${.CURDIR})
214BTOOLSPATH= ${HOST_OBJTOP}/tools${.CURDIR}
215.endif
216
217# Don't use the bootstrap tools logic on itself.
218.if ${.TARGETS:Mbootstrap-tools} == "" && \
219    !make(test-system-*) && !make(showconfig) && !make(print-dir) && \
220    !defined(BOOTSTRAPPING_TOOLS) && !empty(TOOLSDIR) && ${.MAKE.LEVEL} == 0
221.for dir in /sbin /bin /usr/sbin /usr/bin
222PATH:= ${TOOLSDIR}${dir}:${PATH}
223.endfor
224.export PATH
225# Prefer the TOOLSDIR version of the toolchain if present vs the host version.
226.for var in ${TOOLCHAIN_VARS}
227_toolchain_bin.${var}=	${TOOLSDIR}${_toolchain_bin_${var}:U/usr/bin/${var:tl}}
228.if exists(${_toolchain_bin.${var}})
229HOST_${var}?=	${_toolchain_bin.${var}}
230.export		HOST_${var}
231.endif
232.endfor
233.endif
234
235.for var in ${TOOLCHAIN_VARS}
236HOST_${var}?=	${_toolchain_bin_${var}:U/usr/bin/${var:tl}}
237.endfor
238
239.if ${MACHINE} == "host"
240.for var in ${TOOLCHAIN_VARS}
241${var}=		${HOST_${var}}
242.endfor
243.endif
244
245.if ${MACHINE:Nhost:Ncommon} != "" && ${MACHINE} != ${HOST_MACHINE}
246# cross-building
247.if !defined(FREEBSD_REVISION)
248FREEBSD_REVISION!= sed -n '/^REVISION=/{s,.*=,,;s,",,g;p; }' ${SRCTOP}/sys/conf/newvers.sh
249.export FREEBSD_REVISION
250.endif
251CROSS_TARGET_FLAGS= -target ${MACHINE_ARCH}-unknown-freebsd${FREEBSD_REVISION}
252CFLAGS+= ${CROSS_TARGET_FLAGS}
253ACFLAGS+= ${CROSS_TARGET_FLAGS}
254LDFLAGS+= -Wl,-m -Wl,elf_${MACHINE_ARCH}_fbsd
255.endif
256
257META_MODE+=	missing-meta=yes
258.if empty(META_MODE:Mnofilemon)
259META_MODE+=	missing-filemon=yes
260.endif
261