xref: /freebsd/share/mk/local.sys.mk (revision 7cd2dcf07629713e5a3d60472cfe4701b705a167)
1WITH_INSTALL_AS_USER= yes
2
3.if defined(.PARSEDIR)		# bmake
4
5# some handy macros
6_this = ${.PARSEDIR:tA}/${.PARSEFILE}
7# some useful modifiers
8
9# A useful trick for testing multiple :M's against something
10# :L says to use the variable's name as its value - ie. literal
11# got = ${clean* destroy:${M_ListToMatch:S,V,.TARGETS,}}
12M_ListToMatch = L:@m@$${V:M$$m}@
13# match against our initial targets (see above)
14M_L_TARGETS = ${M_ListToMatch:S,V,_TARGETS,}
15
16# turn a list into a set of :N modifiers
17# NskipFoo = ${Foo:${M_ListToSkip}}
18M_ListToSkip= O:u:ts::S,:,:N,g:S,^,N,
19
20# type should be a builtin in any sh since about 1980,
21# AUTOCONF := ${autoconf:L:${M_whence}}
22M_type = @x@(type $$x 2> /dev/null); echo;@:sh:[0]:N* found*:[@]:C,[()],,g
23M_whence = ${M_type}:M/*
24
25# convert a path to a valid shell variable
26M_P2V = tu:C,[./-],_,g
27
28# convert path to absolute
29.if ${MAKE_VERSION:U0} > 20100408
30M_tA = tA
31.else
32M_tA = C,.*,('cd' & \&\& 'pwd') 2> /dev/null || echo &,:sh
33.endif
34
35# this is handy for forcing a space into something.
36AnEmptyVar=
37
38# absoulte path to what we are reading.
39_PARSEDIR = ${.PARSEDIR:${M_tA}}
40
41.if !empty(SB)
42SB_SRC ?= ${SB}/src
43SB_OBJROOT ?= ${SB}/obj
44# this is what we use below
45SRCTOP ?= ${SB_SRC}
46OBJROOT ?= ${SB_OBJROOT}
47.endif
48
49.if empty(SRCTOP)
50SRCTOP := ${_PARSEDIR:H:H}
51.export SRCTOP
52OBJROOT ?= ${SRCTOP:H}/obj/
53.endif
54
55# we need HOST_TARGET etc below.
56.include <host-target.mk>
57
58OBJTOP ?= ${OBJROOT}${MACHINE}
59
60.if !defined(_TARGETS)
61# some things we do only once
62_TARGETS := ${.TARGETS}
63.-include <sys.env.mk>
64.if !empty(OBJROOT)
65.if ${OBJROOT:M*/} != ""
66OBJROOT:= ${OBJROOT:tA}/
67.else
68OBJROOT:= ${OBJROOT:H:tA}/${OBJROOT:T}
69.endif
70.export OBJROOT
71.endif
72.endif
73
74.if !empty(SRCTOP)
75.if ${.CURDIR} == ${SRCTOP}
76RELDIR = .
77.elif ${.CURDIR:M${SRCTOP}/*}
78RELDIR := ${.CURDIR:S,${SRCTOP}/,,}
79.endif
80.endif
81
82HOST_OBJTOP ?= ${OBJROOT}${HOST_TARGET}
83
84.if ${OBJTOP} == ${HOST_OBJTOP} || ${REQUESTED_MACHINE:U${MACHINE}} == "host"
85MACHINE= host
86.endif
87.if ${MACHINE} == "host"
88OBJTOP := ${HOST_OBJTOP}
89.endif
90
91# if you want objdirs make them automatic
92.if ${MKOBJDIRS:Uno} == "auto"
93WITH_AUTO_OBJ= yes
94.include <auto.obj.mk>
95.endif
96
97.ifndef WITHOUT_META_MODE
98WITH_META_MODE= yes
99
100.ifndef WITHOUT_STAGING
101WITH_STAGING= yes
102.endif
103
104PYTHON ?= /usr/local/bin/python
105
106.if ${.MAKE.LEVEL} == 0
107# this works best if share/mk is ready for it.
108BUILD_AT_LEVEL0= no
109# By default only MACHINE0 updates dependencies
110# see local.autodep.mk
111MACHINE0 := ${MACHINE}
112.export MACHINE0
113.export PYTHON
114.endif
115
116# we want to end up with a singe stage tree for all machines
117.ifndef WITHOUT_STAGING
118.if empty(STAGE_ROOT)
119STAGE_ROOT?= ${OBJROOT}stage
120.export STAGE_ROOT
121.endif
122.endif
123
124.if !empty(STAGE_ROOT)
125.if ${MACHINE} == "host"
126STAGE_MACHINE= ${HOST_TARGET}
127.else
128STAGE_MACHINE= ${MACHINE}
129.endif
130STAGE_OBJTOP= ${STAGE_ROOT}/${STAGE_MACHINE}
131STAGE_COMMON_OBJTOP= ${STAGE_ROOT}/common
132STAGE_HOST_OBJTOP= ${STAGE_ROOT}/${HOST_TARGET}
133
134STAGE_LIBDIR= ${STAGE_OBJTOP}${LIBDIR:U/lib}
135# this is not the same as INCLUDEDIR
136STAGE_INCSDIR= ${STAGE_OBJTOP}${INCSDIR:U/include}
137
138.ifndef WITH_SYSROOT
139.if ${MACHINE} != "host"
140CFLAGS_LAST+= -nostdinc
141.endif
142CFLAGS_LAST+= -isystem ${STAGE_OBJTOP}/usr/include -isystem ${STAGE_OBJTOP}/include
143LDFLAGS+= -B${STAGE_LIBDIR} -L${STAGE_LIBDIR}
144.else
145# if ld suppored sysroot, this would suffice
146CFLAGS_LAST+= --sysroot=${STAGE_OBJTOP} -isystem ${STAGE_OBJTOP}/include
147.endif
148.endif
149
150.include "meta.sys.mk"
151
152# most dirs can be satisfied with one Makefile.depend ?
153.undef .MAKE.DEPENDFILE
154.MAKE.DEPENDFILE_PREFERENCE = \
155	${.MAKE.DEPENDFILE_PREFIX} \
156	${.MAKE.DEPENDFILE_PREFIX}.${MACHINE}
157
158.include "sys.dependfile.mk"
159
160.if ${MACHINE} == "host"
161# need a machine specific file
162.MAKE.DEPENDFILE= ${.MAKE.DEPENDFILE_PREFIX}.${MACHINE}
163.endif
164
165.MAKE.META.BAILIWICK = ${SB} ${OBJROOT} ${STAGE_ROOT}
166
167.endif				# meta mode
168
169# ensure we have a value
170.MAKE.MODE ?= normal
171
172# don't rely on MACHINE_ARCH being set or valid
173
174MACHINE_ARCH.host = ${_HOST_ARCH}
175MACHINE_ARCH.${MACHINE} ?= ${MACHINE}
176MACHINE_ARCH := ${MACHINE_ARCH.${MACHINE}}
177
178CSU_DIR.i386 = csu/i386-elf
179CSU_DIR.${MACHINE_ARCH} ?= csu/${MACHINE_ARCH}
180CSU_DIR := ${CSU_DIR.${MACHINE_ARCH}}
181
182MAKE_PRINT_VAR_ON_ERROR+= \
183	.CURDIR \
184	.MAKE \
185	.OBJDIR \
186	.TARGETS \
187	DESTDIR \
188	LD_LIBRARY_PATH \
189	MACHINE \
190	MACHINE_ARCH \
191	MAKEOBJDIRPREFIX \
192	MAKESYSPATH \
193	MAKE_VERSION\
194	OBJTOP \
195	${MAKE_PRINT_VAR_ON_ERROR_XTRAS}
196
197.endif				# bmake
198