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