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