1132718Skan# $Id: libs.mk,v 1.3 2013/08/02 18:28:48 sjg Exp $
2169689Skan#
3169689Skan#	@(#) Copyright (c) 2006, Simon J. Gerraty
4132718Skan#
5169689Skan#	This file is provided in the hope that it will
6169689Skan#	be of use.  There is absolutely NO WARRANTY.
7169689Skan#	Permission to copy, redistribute or otherwise
8169689Skan#	use this file is hereby granted provided that 
9132718Skan#	the above copyright notice and this notice are
10132718Skan#	left intact. 
11169689Skan#      
12169689Skan#	Please send copies of changes and bug-fixes to:
13132718Skan#	sjg@crufty.net
14169689Skan#
15169689Skan
16169689Skan.MAIN: all
17169689Skan
18132718Skan.if defined(LIBS)
19169689Skan
20169689Skan# In meta mode, we can capture dependenices for _one_ of the progs.
21169689Skan# if makefile doesn't nominate one, we use the first.
22132718Skan.ifndef UPDATE_DEPENDFILE_LIB
23169689SkanUPDATE_DEPENDFILE_LIB = ${LIBS:[1]}
24169689Skan.export UPDATE_DEPENDFILE_LIB
25132718Skan.endif
26132718Skan
27132718Skan.ifndef LIB
28169689Skan# They may have asked us to build just one
29169689Skan.for t in ${LIBS:R:T:S,^lib,,}
30169689Skan.if make(lib$t)
31169689SkanLIB?= $t
32169689Skanlib$t: all
33169689Skan.endif
34169689Skan.endfor
35169689Skan.endif
36169689Skan
37169689Skan.if defined(LIB)
38169689Skan# just one of many
39169689SkanLIB_VARS += \
40169689Skan	LIBDIR \
41169689Skan	CFLAGS \
42169689Skan	COPTS \
43169689Skan	CPPFLAGS \
44169689Skan	CXXFLAGS \
45169689Skan	DPADD \
46169689Skan	DPLIBS \
47169689Skan	LDADD \
48169689Skan	LDFLAGS \
49169689Skan	MAN \
50169689Skan	SRCS
51169689Skan
52169689Skan.for v in ${LIB_VARS:O:u}
53169689Skan.if defined(${v}.${LIB}) || defined(${v}_${LIB})
54169689Skan$v += ${${v}_${LIB}:U${${v}.${LIB}}}
55169689Skan.endif
56169689Skan.endfor
57169689Skan
58169689Skan# for meta mode, there can be only one!
59169689Skan.if ${LIB} == ${UPDATE_DEPENDFILE_LIB:Uno}
60169689SkanUPDATE_DEPENDFILE ?= yes
61169689Skan.endif
62169689SkanUPDATE_DEPENDFILE ?= NO
63169689Skan
64169689Skan# ensure that we don't clobber each other's dependencies
65169689SkanDEPENDFILE?= .depend.${LIB}
66169689Skan# lib.mk will do the rest
67169689Skan.else
68169689Skanall: ${LIBS:S,^lib,,:@t@lib$t.a@} .MAKE
69169689Skan
70169689Skan# We cannot capture dependencies for meta mode here
71169689SkanUPDATE_DEPENDFILE = NO
72169689Skan# nor can we safely run in parallel.
73169689Skan.NOTPARALLEL:
74169689Skan.endif
75169689Skan.endif
76169689Skan
77169689Skan# handle being called [bsd.]libs.mk
78169689Skan.include <${.PARSEFILE:S,libs,lib,}>
79169689Skan
80169689Skan.ifndef LIB
81169689Skan# tell libs.mk we might want to install things
82169689SkanLIBS_TARGETS+= cleandepend cleandir cleanobj depend install
83169689Skan
84169689Skan.for b in ${LIBS:R:T:S,^lib,,}
85169689Skanlib$b.a: ${SRCS} ${DPADD} ${SRCS_lib$b} ${DPADD_lib$b} 
86169689Skan	(cd ${.CURDIR} && ${.MAKE} -f ${MAKEFILE} LIB=$b)
87169689Skan
88169689Skan.for t in ${LIBS_TARGETS:O:u}
89169689Skan$b.$t: .PHONY .MAKE
90169689Skan	(cd ${.CURDIR} && ${.MAKE} -f ${MAKEFILE} LIB=$b ${@:E})
91169689Skan.endfor
92169689Skan.endfor
93169689Skan.endif
94169689Skan