xref: /freebsd/contrib/bmake/mk/own.mk (revision a03411e84728e9b267056fd31c7d1d9d1dc1b01e)
1# $Id: own.mk,v 1.45 2023/12/30 02:10:38 sjg Exp $
2
3.if !target(__${.PARSEFILE}__)
4__${.PARSEFILE}__: .NOTMAIN
5
6.if !target(__init.mk__)
7.include "init.mk"
8.endif
9
10.if !defined(NOMAKECONF) && !defined(NO_MAKECONF)
11MAKECONF?=	/etc/mk.conf
12.-include "${MAKECONF}"
13.endif
14
15.include <host-target.mk>
16
17TARGET_OSNAME?= ${_HOST_OSNAME}
18TARGET_OSREL?= ${_HOST_OSREL}
19TARGET_OSTYPE?= ${HOST_OSTYPE}
20TARGET_HOST?= ${HOST_TARGET}
21
22# these may or may not exist
23.-include <${TARGET_HOST}.mk>
24.-include <config.mk>
25
26RM?= rm
27LN?= ln
28INSTALL?= install
29
30prefix?=	/usr
31.if exists(${prefix}/lib)
32libprefix?=	${prefix}
33.else
34libprefix?=	/usr
35.endif
36
37# FreeBSD at least does not set this
38MACHINE_ARCH?=	${MACHINE}
39# we need to make sure these are defined too in case sys.mk fails to.
40COMPILE.s?=	${CC} ${AFLAGS} -c
41LINK.s?=	${CC} ${AFLAGS} ${LDFLAGS}
42COMPILE.S?=	${CC} ${AFLAGS} ${CPPFLAGS} -c -traditional-cpp
43LINK.S?=	${CC} ${AFLAGS} ${CPPFLAGS} ${LDFLAGS}
44COMPILE.c?=	${CC} ${CFLAGS} ${CPPFLAGS} -c
45LINK.c?=	${CC} ${CFLAGS} ${CPPFLAGS} ${LDFLAGS}
46CXXFLAGS?=	${CFLAGS}
47COMPILE.cc?=	${CXX} ${CXXFLAGS} ${CPPFLAGS} -c
48LINK.cc?=	${CXX} ${CXXFLAGS} ${CPPFLAGS} ${LDFLAGS}
49COMPILE.m?=	${OBJC} ${OBJCFLAGS} ${CPPFLAGS} -c
50LINK.m?=	${OBJC} ${OBJCFLAGS} ${CPPFLAGS} ${LDFLAGS}
51COMPILE.f?=	${FC} ${FFLAGS} -c
52LINK.f?=	${FC} ${FFLAGS} ${LDFLAGS}
53COMPILE.F?=	${FC} ${FFLAGS} ${CPPFLAGS} -c
54LINK.F?=	${FC} ${FFLAGS} ${CPPFLAGS} ${LDFLAGS}
55COMPILE.r?=	${FC} ${FFLAGS} ${RFLAGS} -c
56LINK.r?=	${FC} ${FFLAGS} ${RFLAGS} ${LDFLAGS}
57LEX.l?=		${LEX} ${LFLAGS}
58COMPILE.p?=	${PC} ${PFLAGS} ${CPPFLAGS} -c
59LINK.p?=	${PC} ${PFLAGS} ${CPPFLAGS} ${LDFLAGS}
60YACC.y?=	${YACC} ${YFLAGS}
61
62# for suffix rules
63IMPFLAGS?=	${COPTS.${.IMPSRC:T}} ${CPUFLAGS.${.IMPSRC:T}} ${CPPFLAGS.${.IMPSRC:T}}
64.for s in .c .cc
65COMPILE.$s += ${IMPFLAGS}
66LINK.$s +=  ${IMPFLAGS}
67.endfor
68
69PRINT.VAR.MAKE = MAKESYSPATH=${MAKESYSPATH:U${.PARSEDIR}} ${.MAKE}
70.if empty(.MAKEFLAGS:M-V*)
71.if defined(MAKEOBJDIRPREFIX) || defined(MAKEOBJDIR)
72PRINTOBJDIR=	${PRINT.VAR.MAKE} -r -V .OBJDIR -f /dev/null xxx
73.else
74PRINTOBJDIR=	${PRINT.VAR.MAKE} -V .OBJDIR
75.endif
76.else
77PRINTOBJDIR=	echo # prevent infinite recursion
78.endif
79
80# we really like to have SRCTOP and OBJTOP defined...
81.if !defined(SRCTOP) || !defined(OBJTOP)
82.-include <srctop.mk>
83.endif
84
85.if !defined(SRCTOP) || !defined(OBJTOP)
86# dpadd.mk is rather pointless without these
87OPTIONS_DEFAULT_NO+= DPADD_MK
88.endif
89
90# process options
91OPTIONS_DEFAULT_NO+= \
92	INSTALL_AS_USER \
93	GPROF \
94	PROG_LDORDER_MK \
95	LIBTOOL \
96	LINT \
97
98OPTIONS_DEFAULT_YES+= \
99	ARCHIVE \
100	AUTODEP \
101	CRYPTO \
102	DOC \
103	DPADD_MK \
104	GDB \
105	KERBEROS \
106	LINKLIB \
107	MAN \
108	NLS \
109	OBJ \
110	PIC \
111	SHARE \
112	SKEY \
113	YP \
114
115OPTIONS_DEFAULT_DEPENDENT+= \
116	CATPAGES/MAN \
117	LDORDER_MK/PROG_LDORDER_MK \
118	OBJDIRS/OBJ \
119	PICINSTALL/LINKLIB \
120	PICLIB/PIC \
121	PROFILE/LINKLIB \
122	STAGING_MAN/STAGING \
123	STAGING_PROG/STAGING \
124
125.include <options.mk>
126
127.if ${MK_INSTALL_AS_USER} == "yes"
128# We ignore this if user is root.
129_uid:= ${.MAKE.UID:U${id -u:L:sh}}
130.if ${_uid} != 0
131.if !defined(USERGRP)
132USERGRP:=  ${.MAKE.GID:U${id -g:L:sh}}
133.export USERGRP
134.endif
135.for x in BIN CONF DOC INC INFO FILES KMOD LIB MAN NLS PROG SHARE
136$xOWN=  ${USER}
137$xGRP=  ${USERGRP}
138$x_INSTALL_OWN=
139.endfor
140.endif
141.endif
142
143# override this in sys.mk
144ROOT_GROUP?=	wheel
145BINGRP?=	${ROOT_GROUP}
146BINOWN?=	root
147BINMODE?=	555
148NONBINMODE?=	444
149DIRMODE?=	755
150
151INCLUDEDIR?=	${prefix}/include
152INCDIR?=	${INCLUDEDIR}
153
154# Define MANZ to have the man pages compressed (gzip)
155#MANZ=		1
156
157MANTARGET?= cat
158MANDIR?=	${prefix}/share/man/${MANTARGET}
159MANGRP?=	${BINGRP}
160MANOWN?=	${BINOWN}
161MANMODE?=	${NONBINMODE}
162
163INCLUDEDIR?=	${libprefix}/include
164LIBDIR?=	${libprefix}/lib
165SHLIBDIR?=	${libprefix}/lib
166.if ${USE_SHLIBDIR:Uno} == "yes"
167_LIBSODIR?=	${SHLIBDIR}
168.else
169_LIBSODIR?=	${LIBDIR}
170.endif
171# this is where ld.*so lives
172SHLINKDIR?=	/usr/libexec
173LINTLIBDIR?=	${libprefix}/libdata/lint
174LIBGRP?=	${BINGRP}
175LIBOWN?=	${BINOWN}
176LIBMODE?=	${NONBINMODE}
177
178DOCDIR?=        ${prefix}/share/doc
179DOCGRP?=	${BINGRP}
180DOCOWN?=	${BINOWN}
181DOCMODE?=       ${NONBINMODE}
182
183NLSDIR?=	${prefix}/share/nls
184NLSGRP?=	${BINGRP}
185NLSOWN?=	${BINOWN}
186NLSMODE?=	${NONBINMODE}
187
188KMODDIR?=	${prefix}/lkm
189KMODGRP?=	${BINGRP}
190KMODOWN?=	${BINOWN}
191KMODMODE?=	${NONBINMODE}
192
193SHAREGRP?=	${BINGRP}
194SHAREOWN?=	${BINOWN}
195SHAREMODE?=	${NONBINMODE}
196
197COPY?=		-c
198STRIP_FLAG?=	-s
199
200.if ${TARGET_OSNAME} == "NetBSD"
201.if exists(/usr/libexec/ld.elf_so)
202OBJECT_FMT=ELF
203.endif
204OBJECT_FMT?=a.out
205.endif
206# sys.mk should set something appropriate if need be.
207OBJECT_FMT?=ELF
208
209.if (${_HOST_OSNAME} == "FreeBSD")
210CFLAGS+= ${CPPFLAGS}
211.endif
212
213# allow for per target flags
214# apply the :T:R first, so the more specific :T can override if needed
215CPPFLAGS += ${CPPFLAGS_${.TARGET:T:R}} ${CPPFLAGS_${.TARGET:T}}
216CFLAGS += ${CFLAGS_${.TARGET:T:R}} ${CFLAGS_${.TARGET:T}}
217
218# Define SYS_INCLUDE to indicate whether you want symbolic links to the system
219# source (``symlinks''), or a separate copy (``copies''); (latter useful
220# in environments where it's not possible to keep /sys publicly readable)
221#SYS_INCLUDE= 	symlinks
222
223# don't try to generate PIC versions of libraries on machines
224# which don't support PIC.
225.if  (${MACHINE_ARCH} == "vax") || \
226    ((${MACHINE_ARCH} == "mips") && defined(STATIC_TOOLCHAIN)) || \
227    ((${MACHINE_ARCH} == "alpha") && defined(ECOFF_TOOLCHAIN))
228MK_PIC=no
229.endif
230
231# No lint, for now.
232NOLINT=
233
234
235.if ${MK_LINKLIB} == "no"
236MK_PICINSTALL=	no
237MK_PROFILE=	no
238.endif
239
240.if ${MK_MAN} == "no"
241MK_CATPAGES=	no
242.endif
243
244.if ${MK_OBJ} == "no"
245MK_OBJDIRS=	no
246MK_AUTO_OBJ=	no
247.endif
248
249.if ${MK_SHARE} == "no"
250MK_CATPAGES=	no
251MK_DOC=		no
252MK_INFO=	no
253MK_MAN=		no
254MK_NLS=		no
255.endif
256
257# :U incase not using our sys.mk
258.if ${MK_META_MODE:Uno} == "yes"
259# should all be set by sys.mk if not default
260TARGET_SPEC_VARS ?= MACHINE
261.if ${MAKE_VERSION} >= 20120325
262.if ${TARGET_SPEC_VARS:[#]} > 1
263TARGET_SPEC_VARS_REV := ${TARGET_SPEC_VARS:[-1..1]}
264.else
265TARGET_SPEC_VARS_REV = ${TARGET_SPEC_VARS}
266.endif
267.endif
268.if ${MK_STAGING} == "yes"
269STAGE_ROOT?= ${OBJROOT}/stage
270STAGE_OBJTOP?= ${STAGE_ROOT}/${TARGET_SPEC_VARS_REV:ts/}
271.endif
272.endif
273
274.endif
275