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