xref: /freebsd/contrib/bmake/mk/init.mk (revision 4b15965daa99044daf184221b7c283bf7f2d7e66)
1# SPDX-License-Identifier: BSD-2-Clause
2#
3# $Id: init.mk,v 1.41 2025/04/18 20:49:54 sjg Exp $
4#
5#	@(#) Copyright (c) 2002-2024, Simon J. Gerraty
6#
7#	This file is provided in the hope that it will
8#	be of use.  There is absolutely NO WARRANTY.
9#	Permission to copy, redistribute or otherwise
10#	use this file is hereby granted provided that
11#	the above copyright notice and this notice are
12#	left intact.
13#
14#	Please send copies of changes and bug-fixes to:
15#	sjg@crufty.net
16#
17
18# should be set properly in sys.mk
19_this ?= ${.PARSEFILE:S,bsd.,,}
20
21.if !target(__${_this}__)
22__${_this}__: .NOTMAIN
23
24.if ${MAKE_VERSION:U0} > 20100408
25_this_mk_dir := ${.PARSEDIR:tA}
26.else
27_this_mk_dir := ${.PARSEDIR}
28.endif
29
30.-include <local.init.mk>
31.-include <${.CURDIR:H}/Makefile.inc>
32.include <own.mk>
33.include <compiler.mk>
34
35# should have been set by sys.mk
36CXX_SUFFIXES ?= .cc .cpp .cxx .C
37CCM_SUFFIXES ?= .ccm
38PCM ?= .pcm
39# ${PICO} is used for PIC object files.
40PICO ?= .pico
41
42# SRCS which do not end up in OBJS
43NO_OBJS_SRCS_SUFFIXES ?= .h ${CCM_SUFFIXES} .sh
44OBJS_SRCS_PRE_FILTER += ${NO_OBJS_SRCS_SUFFIXES:@x@N*$x@}
45# makefiles that actually *want* .o's in subdirs
46# (it can be useful if multiple SRCS have same basename)
47# can just set OBJS_SRCS_FILTER =
48# we apply this as ${OBJS_SRCS_FILTER:ts:}
49OBJS_SRCS_FILTER ?= T
50OBJS_SRCS_FILTER += ${OBJS_SRCS_PRE_FILTER}
51OBJS_SRCS_FILTER += R
52
53.if defined(PROG_CXX) || ${SRCS:Uno:${CXX_SUFFIXES:S,^,N*,:ts:}} != ${SRCS:Uno:N/}
54_CCLINK ?=	${CXX}
55.endif
56_CCLINK ?=	${CC}
57
58.if !empty(WARNINGS_SET) || !empty(WARNINGS_SET_${MACHINE_ARCH})
59.include <warnings.mk>
60.endif
61
62# these are applied in order, least specific to most
63VAR_QUALIFIER_LIST += \
64	${TARGET_SPEC_VARS:UMACHINE:@v@${$v}@} \
65	${COMPILER_TYPE} \
66	${.TARGET:T:R} \
67	${.TARGET:T} \
68	${.IMPSRC:T} \
69	${VAR_QUALIFIER_XTRA_LIST}
70
71QUALIFIED_VAR_LIST += \
72	CFLAGS \
73	COPTS \
74	CPPFLAGS \
75	CPUFLAGS \
76	LDFLAGS \
77	SRCS \
78
79# a final :U avoids errors if someone uses :=
80.for V in ${QUALIFIED_VAR_LIST:O:u:@q@$q $q_LAST@}
81.for Q in ${VAR_QUALIFIER_LIST:u}
82$V += ${$V_$Q:U${$V.$Q:U}} ${V_$Q_${COMPILER_TYPE}:U${$V.$Q.${COMPILER_TYPE}:U}}
83.endfor
84.endfor
85
86CC_PG?= -pg
87CXX_PG?= ${CC_PG}
88CC_PIC?= -DPIC
89CXX_PIC?= ${CC_PIC}
90PROFFLAGS?= -DGPROF -DPROF
91
92.if ${.MAKE.LEVEL:U1} == 0 && ${MK_DIRDEPS_BUILD:Uno} == "yes"
93.if ${RELDIR} == "."
94# top-level targets that are ok at level 0
95DIRDEPS_BUILD_LEVEL0_TARGETS += clean* destroy*
96M_ListToSkip?= O:u:S,^,N,:ts:
97.if ${.TARGETS:Uall:${DIRDEPS_BUILD_LEVEL0_TARGETS:${M_ListToSkip}}} != ""
98# this tells lib.mk and prog.mk to not actually build anything
99_SKIP_BUILD = not building at level 0
100.endif
101.elif ${.TARGETS:U:Nall} == ""
102_SKIP_BUILD = not building at level 0
103# first .MAIN is what counts
104.MAIN: dirdeps
105.endif
106.endif
107
108.MAIN:		all
109
110.if !defined(.PARSEDIR)
111# no-op is the best we can do if not bmake.
112.WAIT:
113.endif
114
115# allow makefiles to set ONLY_*_LIST and NOT_*_LIST
116# to control _SKIP_BUILD
117SKIP_BUILD_VAR_LIST += TARGET_SPEC ${TARGET_SPEC_VARS:UMACHINE}
118.for v in ${SKIP_BUILD_VAR_LIST}
119.if !empty(ONLY_$v_LIST) && ${ONLY_$v_LIST:Uno:M${$v}} == ""
120_SKIP_BUILD ?= ${$v} not in ONLY_$v_LIST (${ONLY_$v_LIST})
121.if ${MAKE_VERSION} > 20220924
122.break
123.endif
124.elif !empty(NOT_$v_LIST) && ${NOT_$v_LIST:U:M${$v}} != ""
125_SKIP_BUILD ?= ${$v} in NOT_$v_LIST (${NOT_$v_LIST})
126.if ${MAKE_VERSION} > 20220924
127.break
128.endif
129.endif
130.endfor
131
132# define this once for consistency
133.if !defined(_SKIP_BUILD)
134# beforebuild is a hook for things that must be done early
135all: beforebuild .WAIT realbuild
136.else
137all: .PHONY
138.if !empty(_SKIP_BUILD) && ${.MAKEFLAGS:M-V} == ""
139.warning Skipping ${RELDIR} ${_SKIP_BUILD}
140.endif
141.endif
142beforebuild:
143realbuild:
144
145.endif
146