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