xref: /freebsd/contrib/bmake/mk/libs.mk (revision c60f6422ffae3ea85e7b10bad950ad27c463af18)
1# $Id: libs.mk,v 1.9 2025/08/09 22:42:24 sjg Exp $
2#
3#	@(#) Copyright (c) 2006, 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.MAIN: all
12
13.if defined(LIBS)
14
15# In meta mode, we can capture dependenices for _one_ of the progs.
16# if makefile doesn't nominate one, we use the first.
17.ifndef UPDATE_DEPENDFILE_LIB
18UPDATE_DEPENDFILE_LIB = ${LIBS:[1]}
19.export UPDATE_DEPENDFILE_LIB
20.endif
21
22.ifndef LIB
23# They may have asked us to build just one
24.for t in ${LIBS:R:T:S,^lib,,}
25.if make(lib$t)
26LIB?= $t
27lib$t: all
28.endif
29.endfor
30.endif
31
32.if defined(LIB)
33# just one of many
34LIB_VARS += \
35	LIBDIR \
36	CFLAGS \
37	COPTS \
38	CPPFLAGS \
39	CXXFLAGS \
40	DPADD \
41	DPLIBS \
42	LDADD \
43	LDFLAGS \
44	MAN \
45	SRCS
46
47.for v in ${LIB_VARS:O:u}
48.if defined(${v}.${LIB}) || defined(${v}_${LIB})
49$v += ${${v}_${LIB}:U${${v}.${LIB}}}
50.endif
51.endfor
52
53# for meta mode, there can be only one!
54.if ${LIB} == ${UPDATE_DEPENDFILE_LIB:Uno}
55UPDATE_DEPENDFILE ?= ${MK_UPDATE_DEPENDFILE:Uyes}
56.endif
57UPDATE_DEPENDFILE ?= NO
58
59# ensure that we don't clobber each other's dependencies
60DEPENDFILE?= .depend.${LIB}
61# lib.mk will do the rest
62.else
63all: ${LIBS:S,^lib,,:@t@lib$t.a@} .MAKE
64
65# We cannot capture dependencies for meta mode here
66UPDATE_DEPENDFILE = NO
67# nor can we safely run in parallel.
68.NOTPARALLEL:
69.endif
70.endif
71
72# handle being called [bsd.]libs.mk
73.include <${.PARSEFILE:S,libs,lib,}>
74
75.ifndef LIB
76# tell libs.mk we might want to install things
77LIBS_TARGETS+= cleandepend cleandir cleanobj depend install
78
79.for b in ${LIBS:R:T:S,^lib,,}
80lib$b.a: ${SRCS} ${DPADD} ${SRCS_lib$b} ${DPADD_lib$b}
81	(cd ${.CURDIR} && ${.MAKE} -f ${MAKEFILE} LIB=$b -DWITHOUT_META_STATS)
82
83.for t in ${LIBS_TARGETS:O:u}
84$b.$t: .PHONY .MAKE
85	(cd ${.CURDIR} && ${.MAKE} -f ${MAKEFILE} LIB=$b ${@:E} -DWITHOUT_META_STATS)
86.endfor
87.endfor
88
89.if !defined(WITHOUT_META_STATS) && ${.MAKE.LEVEL} > 0
90.END: _reldir_finish
91.ERROR: _reldir_failed
92.endif
93
94.endif
95