xref: /freebsd/contrib/bmake/mk/init.mk (revision 62a52c15422470f97fc7b311d89c83f910bcc1b1)
1# $Id: init.mk,v 1.30 2023/10/03 16:25:01 sjg Exp $
2#
3#	@(#) Copyright (c) 2002, Simon J. Gerraty
4#
5#	This file is provided in the hope that it will
6#	be of use.  There is absolutely NO WARRANTY.
7#	Permission to copy, redistribute or otherwise
8#	use this file is hereby granted provided that
9#	the above copyright notice and this notice are
10#	left intact.
11#
12#	Please send copies of changes and bug-fixes to:
13#	sjg@crufty.net
14#
15
16.if !target(__${.PARSEFILE}__)
17__${.PARSEFILE}__: .NOTMAIN
18
19.if ${MAKE_VERSION:U0} > 20100408
20_this_mk_dir := ${.PARSEDIR:tA}
21.else
22_this_mk_dir := ${.PARSEDIR}
23.endif
24
25.-include <local.init.mk>
26.-include <${.CURDIR:H}/Makefile.inc>
27.include <own.mk>
28.include <compiler.mk>
29
30.MAIN:		all
31
32# should have been set by sys.mk
33CXX_SUFFIXES?= .cc .cpp .cxx .C
34
35.if defined(PROG_CXX) || ${SRCS:Uno:${CXX_SUFFIXES:S,^,N*,:ts:}} != ${SRCS:Uno:N/}
36_CCLINK ?=	${CXX}
37.endif
38_CCLINK ?=	${CC}
39
40.if !empty(WARNINGS_SET) || !empty(WARNINGS_SET_${MACHINE_ARCH})
41.include <warnings.mk>
42.endif
43
44# these are applied in order, least specific to most
45VAR_QUALIFIER_LIST += \
46	${TARGET_SPEC_VARS:UMACHINE:@v@${$v}@} \
47	${COMPILER_TYPE} \
48	${.TARGET:T:R} \
49	${.TARGET:T} \
50	${.IMPSRC:T} \
51	${VAR_QUALIFIER_XTRA_LIST}
52
53QUALIFIED_VAR_LIST += \
54	CFLAGS \
55	COPTS \
56	CPPFLAGS \
57	CPUFLAGS \
58	LDFLAGS \
59	SRCS \
60
61# a final :U avoids errors if someone uses :=
62.for V in ${QUALIFIED_VAR_LIST:O:u:@q@$q $q_LAST@}
63.for Q in ${VAR_QUALIFIER_LIST:u}
64$V += ${$V.$Q:U} ${$V.$Q.${COMPILER_TYPE}:U}
65.endfor
66.endfor
67
68CC_PG?= -pg
69CXX_PG?= ${CC_PG}
70CC_PIC?= -DPIC
71CXX_PIC?= ${CC_PIC}
72PROFFLAGS?= -DGPROF -DPROF
73
74.if ${.MAKE.LEVEL:U1} == 0 && ${MK_DIRDEPS_BUILD:Uno} == "yes"
75.if ${RELDIR} == "."
76# top-level targets that are ok at level 0
77DIRDEPS_BUILD_LEVEL0_TARGETS += clean* destroy*
78M_ListToSkip?= O:u:S,^,N,:ts:
79.if ${.TARGETS:Uall:${DIRDEPS_BUILD_LEVEL0_TARGETS:${M_ListToSkip}}} != ""
80# this tells lib.mk and prog.mk to not actually build anything
81_SKIP_BUILD = not building at level 0
82.endif
83.elif ${.TARGETS:U:Nall} == ""
84_SKIP_BUILD = not building at level 0
85.endif
86.endif
87
88.if !defined(.PARSEDIR)
89# no-op is the best we can do if not bmake.
90.WAIT:
91.endif
92
93# define this once for consistency
94.if !defined(_SKIP_BUILD)
95# beforebuild is a hook for things that must be done early
96all: beforebuild .WAIT realbuild
97.else
98all: .PHONY
99.if !empty(_SKIP_BUILD) && ${.MAKEFLAGS:M-V} == ""
100.warning ${_SKIP_BUILD}
101.endif
102.endif
103beforebuild:
104realbuild:
105
106.endif
107