xref: /freebsd/contrib/bmake/mk/dpadd.mk (revision c59c3bf34db360695f07735bebc76a768cac5afc)
1*c59c3bf3SSimon J. Gerraty# SPDX-License-Identifier: BSD-2-Clause
2*c59c3bf3SSimon J. Gerraty#
3*c59c3bf3SSimon J. Gerraty# $Id: dpadd.mk,v 1.33 2024/02/17 17:26:57 sjg Exp $
43cbdda60SSimon J. Gerraty#
5d5e0a182SSimon J. Gerraty#	@(#) Copyright (c) 2004-2023, Simon J. Gerraty
63cbdda60SSimon J. Gerraty#
73cbdda60SSimon J. Gerraty#	This file is provided in the hope that it will
83cbdda60SSimon J. Gerraty#	be of use.  There is absolutely NO WARRANTY.
93cbdda60SSimon J. Gerraty#	Permission to copy, redistribute or otherwise
103cbdda60SSimon J. Gerraty#	use this file is hereby granted provided that
113cbdda60SSimon J. Gerraty#	the above copyright notice and this notice are
123cbdda60SSimon J. Gerraty#	left intact.
133cbdda60SSimon J. Gerraty#
143cbdda60SSimon J. Gerraty#	Please send copies of changes and bug-fixes to:
153cbdda60SSimon J. Gerraty#	sjg@crufty.net
163cbdda60SSimon J. Gerraty#
173cbdda60SSimon J. Gerraty
1849caa483SSimon J. Gerraty##
1949caa483SSimon J. Gerraty# DESCRIPTION:
2049caa483SSimon J. Gerraty#	This makefile manages a number of variables that simplify
2149caa483SSimon J. Gerraty#	dealing with libs in a build.
2249caa483SSimon J. Gerraty#
2349caa483SSimon J. Gerraty#	Primary inputs are DPLIBS, DPADD and SRC_LIBS:
2449caa483SSimon J. Gerraty#
2549caa483SSimon J. Gerraty#	DPLIBS
2649caa483SSimon J. Gerraty#		List of LIB* that we will actually link with
2749caa483SSimon J. Gerraty#		should be in correct link order.
2849caa483SSimon J. Gerraty#		DPLIBS is a short-cut to ensure that DPADD and LDADD are
2949caa483SSimon J. Gerraty#		kept in sync.
3049caa483SSimon J. Gerraty#
3149caa483SSimon J. Gerraty#	DPADD	List of LIB* that should already be built.
3249caa483SSimon J. Gerraty#
3349caa483SSimon J. Gerraty#	SRC_LIBS
3449caa483SSimon J. Gerraty#		List of LIB* that we want headers from, we do *not*
3549caa483SSimon J. Gerraty#		require that such libs have been built.
3649caa483SSimon J. Gerraty#
3749caa483SSimon J. Gerraty#	The above all get added to DPMAGIC_LIBS which is what we
3849caa483SSimon J. Gerraty#	process.
3949caa483SSimon J. Gerraty#
4049caa483SSimon J. Gerraty#	We expect LIB* to be set to absolute path of a library -
4149caa483SSimon J. Gerraty#	suitable for putting in DPADD.
4249caa483SSimon J. Gerraty#	eg.
4349caa483SSimon J. Gerraty#
4449caa483SSimon J. Gerraty#		LIBC ?= ${OBJTOP}/lib/libc/libc.a
4549caa483SSimon J. Gerraty#
4649caa483SSimon J. Gerraty#	From such a path we can derrive a number of other variables
4749caa483SSimon J. Gerraty#	for which we can supply sensible default values.
4849caa483SSimon J. Gerraty#	We name all these variables for the basename of the library
4949caa483SSimon J. Gerraty#	(libc in our example above -- ${__lib:T:R} in below):
5049caa483SSimon J. Gerraty#
5149caa483SSimon J. Gerraty#	LDADD_${__lib:T:R}:
5249caa483SSimon J. Gerraty#		What should be added to LDADD (eg -lc)
5349caa483SSimon J. Gerraty#
5449caa483SSimon J. Gerraty#	OBJ_${__lib:T:R}:
5549caa483SSimon J. Gerraty#		This is trivial - just the dirname of the built library.
5649caa483SSimon J. Gerraty#
5749caa483SSimon J. Gerraty#	SRC_${__lib:T:R}:
5849caa483SSimon J. Gerraty#		Where the src for ${__lib} is, if LIB* is set as above
5949caa483SSimon J. Gerraty#		we can simply substitute ${SRCTOP} for ${OBJTOP} in
6049caa483SSimon J. Gerraty#		the dirname.
6149caa483SSimon J. Gerraty#
6249caa483SSimon J. Gerraty#	INCLUDES_${__lib:T:R}:
6349caa483SSimon J. Gerraty#		What should be added to CFLAGS
6449caa483SSimon J. Gerraty#
6549caa483SSimon J. Gerraty#		If the directory ${SRC_${__lib:T:R}}/h exists we will
6649caa483SSimon J. Gerraty#		only add -I${SRC_${__lib:T:R}}/h on the basis that
6749caa483SSimon J. Gerraty#		this is where the public api is kept.
6849caa483SSimon J. Gerraty#
6949caa483SSimon J. Gerraty#		Otherwise default will be -I${OBJ_${__lib:T:R}}
7049caa483SSimon J. Gerraty#		-I${SRC_${__lib:T:R}}
7149caa483SSimon J. Gerraty#
7249caa483SSimon J. Gerraty#	Note much of the above is skipped for staged libs
7349caa483SSimon J. Gerraty#	eg.
7449caa483SSimon J. Gerraty#		LIBC ?= ${STAGE_OBJTOP}/usr/lib/libc.a
7549caa483SSimon J. Gerraty#
7649caa483SSimon J. Gerraty#	Since we can safely assume that -I${STAGE_OBJTOP}/usr/include
7749caa483SSimon J. Gerraty#	and -L${STAGE_OBJTOP}/usr/lib are sufficient, and we should
7849caa483SSimon J. Gerraty#	have no need of anything else.
7949caa483SSimon J. Gerraty#
80d5e0a182SSimon J. Gerraty#	Sometimes things are more complicated so allow for
81d5e0a182SSimon J. Gerraty#	DPLIBS to be qualified with each of the variables in
82d5e0a182SSimon J. Gerraty#	DPLIBS_QUALIFIER_LIST (default is VAR_QUALIFIER_LIST same as
83d5e0a182SSimon J. Gerraty#	init.mk)
8449caa483SSimon J. Gerraty
853cbdda60SSimon J. Gerraty.if !target(__${.PARSEFILE}__)
8612904384SSimon J. Gerraty__${.PARSEFILE}__: .NOTMAIN
873cbdda60SSimon J. Gerraty
883cbdda60SSimon J. Gerraty# sometimes we play games with .CURDIR etc
893cbdda60SSimon J. Gerraty# _* hold the original values of .*
903cbdda60SSimon J. Gerraty_OBJDIR?= ${.OBJDIR}
913cbdda60SSimon J. Gerraty_CURDIR?= ${.CURDIR}
923cbdda60SSimon J. Gerraty
93e48f47ddSSimon J. Gerraty.if ${_CURDIR} == ${SRCTOP}
943cbdda60SSimon J. GerratyRELDIR=.
953cbdda60SSimon J. GerratyRELTOP=.
963cbdda60SSimon J. Gerraty.else
97e48f47ddSSimon J. GerratyRELDIR?= ${_CURDIR:S,${SRCTOP}/,,}
98e48f47ddSSimon J. Gerraty.if ${RELDIR} == ${_CURDIR}
99e48f47ddSSimon J. GerratyRELDIR?= ${_OBJDIR:S,${OBJTOP}/,,}
1003cbdda60SSimon J. Gerraty.endif
1013cbdda60SSimon J. GerratyRELTOP?= ${RELDIR:C,[^/]+,..,g}
1023cbdda60SSimon J. Gerraty.endif
1033cbdda60SSimon J. GerratyRELOBJTOP?= ${OBJTOP}
1043cbdda60SSimon J. GerratyRELSRCTOP?= ${SRCTOP}
1053cbdda60SSimon J. Gerraty
106e48f47ddSSimon J. Gerraty# we get included just about everywhere so this is handy...
107e48f47ddSSimon J. Gerraty# C*DEBUG_XTRA are for defining on cmd line etc
108e48f47ddSSimon J. Gerraty# so do not use in makefiles.
109e48f47ddSSimon J. Gerraty.ifdef CFLAGS_DEBUG_XTRA
110e48f47ddSSimon J. GerratyCFLAGS_LAST += ${CFLAGS_DEBUG_XTRA}
111e48f47ddSSimon J. Gerraty.endif
112e48f47ddSSimon J. Gerraty.ifdef CXXFLAGS_DEBUG_XTRA
113e48f47ddSSimon J. GerratyCXXFLAGS_LAST += ${CXXFLAGS_DEBUG_XTRA}
114e48f47ddSSimon J. Gerraty.endif
115e48f47ddSSimon J. Gerraty
116e48f47ddSSimon J. Gerraty.-include <local.dpadd.mk>
117e48f47ddSSimon J. Gerraty
118e48f47ddSSimon J. Gerraty# DPLIBS helps us ensure we keep DPADD and LDADD in sync
119d5e0a182SSimon J. GerratyDPLIBS_QUALIFIER_LIST ?= ${VAR_QUALIFIER_LIST}
120d5e0a182SSimon J. GerratyDPLIBS += ${DPLIBS_QUALIFIER_LIST:u:@Q@${DPLIBS.$Q:U}@}
121d5e0a182SSimon J. GerratyDPLIBS+= ${DPLIBS_LAST} ${DPLIBS_QUALIFIER_LIST:u:@Q@${DPLIBS_LAST.$Q:U}@}
122e48f47ddSSimon J. GerratyDPADD+= ${DPLIBS:N-*}
1231ce939a7SSimon J. Gerraty.for __lib in ${DPLIBS}
12449caa483SSimon J. Gerraty.if "${__lib:M-*}" != ""
125e48f47ddSSimon J. GerratyLDADD += ${__lib}
126e48f47ddSSimon J. Gerraty.else
1271ce939a7SSimon J. GerratyLDADD += ${LDADD_${__lib:T:R}:U${__lib:T:R:S/lib/-l/:C/\.so.*//}}
128e48f47ddSSimon J. Gerraty.endif
129e48f47ddSSimon J. Gerraty.endfor
130e48f47ddSSimon J. Gerraty
131e48f47ddSSimon J. Gerraty# DPADD can contain things other than libs
132e48f47ddSSimon J. Gerraty__dpadd_libs := ${DPADD:M*/lib*}
133e48f47ddSSimon J. Gerraty
13450d2e745SSimon J. Gerraty.if defined(PROG) && ${MK_PROG_LDORDER_MK:Uno} != "no"
135e48f47ddSSimon J. Gerraty# some libs have dependencies...
136e48f47ddSSimon J. Gerraty# DPLIBS_* allows bsd.libnames.mk to flag libs which must be included
137e48f47ddSSimon J. Gerraty# in DPADD for a given library.
138e48f47ddSSimon J. Gerraty# Gather all such dependencies into __ldadd_all_xtras
139e48f47ddSSimon J. Gerraty# dups will be dealt with later.
140e48f47ddSSimon J. Gerraty# Note: libfoo_pic uses DPLIBS_libfoo
141e48f47ddSSimon J. Gerraty__ldadd_all_xtras=
142d5e0a182SSimon J. Gerraty.for __lib in ${__dpadd_libs:@d@${DPLIBS_${d:T:R:S,_pic,,}} ${DPLIBS_QUALIFIER_LIST:u:@Q@${DPLIBS_${d:T:R:S,_pic,,}.$Q:U}@}@}
143e48f47ddSSimon J. Gerraty__ldadd_all_xtras+= ${LDADD_${__lib}:U${__lib:T:R:S/lib/-l/:C/\.so.*//}}
144e48f47ddSSimon J. Gerraty.if "${DPADD:M${__lib}}" == ""
145e48f47ddSSimon J. GerratyDPADD+= ${__lib}
146e48f47ddSSimon J. Gerraty.endif
147e48f47ddSSimon J. Gerraty.endfor
14850d2e745SSimon J. Gerraty.endif
149e48f47ddSSimon J. Gerraty# Last of all... for libc and libgcc
150e48f47ddSSimon J. GerratyDPADD+= ${DPADD_LAST}
151e48f47ddSSimon J. Gerraty
152e48f47ddSSimon J. Gerraty# de-dupuplicate __ldadd_all_xtras into __ldadd_xtras
153e48f47ddSSimon J. Gerraty# in reverse order so that libs end up listed after all that needed them.
154e48f47ddSSimon J. Gerraty__ldadd_xtras=
155e48f47ddSSimon J. Gerraty.for __lib in ${__ldadd_all_xtras:[-1..1]}
156e48f47ddSSimon J. Gerraty.if "${__ldadd_xtras:M${__lib}}" == "" || ${NEED_IMPLICIT_LDADD:tl:Uno} != "no"
157e48f47ddSSimon J. Gerraty__ldadd_xtras+= ${__lib}
158e48f47ddSSimon J. Gerraty.endif
159e48f47ddSSimon J. Gerraty.endfor
160e48f47ddSSimon J. Gerraty
161e48f47ddSSimon J. Gerraty.if !empty(__ldadd_xtras)
162e48f47ddSSimon J. Gerraty# now back to the original order
163e48f47ddSSimon J. Gerraty__ldadd_xtras:= ${__ldadd_xtras:[-1..1]}
164e48f47ddSSimon J. GerratyLDADD+= ${__ldadd_xtras}
165e48f47ddSSimon J. Gerraty.endif
166e48f47ddSSimon J. Gerraty
167e48f47ddSSimon J. Gerraty# Convert DPADD into -I and -L options and add them to CPPFLAGS and LDADD
168e48f47ddSSimon J. Gerraty# For the -I's convert the path to a relative one.  For separate objdirs
169e48f47ddSSimon J. Gerraty# the DPADD paths will be to the obj tree so we need to subst anyway.
170e48f47ddSSimon J. Gerraty
171e48f47ddSSimon J. Gerraty# update this
172e48f47ddSSimon J. Gerraty__dpadd_libs := ${DPADD:M*/lib*}
173e48f47ddSSimon J. Gerraty
174e48f47ddSSimon J. Gerraty# Order -L's to search ours first.
175e48f47ddSSimon J. Gerraty# Avoids picking up old versions already installed.
176b778b302SSimon J. Gerraty__dpadd_libdirs := ${__dpadd_libs:R:H:S/^/-L/g:O:u:N-L}
177e48f47ddSSimon J. GerratyLDADD += ${__dpadd_libdirs:M-L${OBJTOP}/*}
178e48f47ddSSimon J. GerratyLDADD += ${__dpadd_libdirs:N-L${OBJTOP}/*:N-L${HOST_LIBDIR:U/usr/lib}}
179e48f47ddSSimon J. Gerraty.if defined(HOST_LIBDIR) && ${HOST_LIBDIR} != "/usr/lib"
180e48f47ddSSimon J. GerratyLDADD+= -L${HOST_LIBDIR}
181e48f47ddSSimon J. Gerraty.endif
182e48f47ddSSimon J. Gerraty
1833cbdda60SSimon J. Gerraty.if !make(dpadd)
1843cbdda60SSimon J. Gerraty.ifdef LIB
1853cbdda60SSimon J. Gerraty# Each lib is its own src_lib, we want to include it in SRC_LIBS
1863cbdda60SSimon J. Gerraty# so that the correct INCLUDES_* will be picked up automatically.
1873cbdda60SSimon J. GerratySRC_LIBS+= ${_OBJDIR}/lib${LIB}.a
1883cbdda60SSimon J. Gerraty.endif
1893cbdda60SSimon J. Gerraty.endif
1903cbdda60SSimon J. Gerraty
1913cbdda60SSimon J. Gerraty#
1923cbdda60SSimon J. Gerraty# This little bit of magic, assumes that SRC_libfoo will be
1933cbdda60SSimon J. Gerraty# set if it cannot be correctly derrived from ${LIBFOO}
1943cbdda60SSimon J. Gerraty# Note that SRC_libfoo and INCLUDES_libfoo should be named for the
1955bcb7424SSimon J. Gerraty# actual library name not the variable name that might refer to it.
1963cbdda60SSimon J. Gerraty# 99% of the time the two are the same, but the DPADD logic
1975bcb7424SSimon J. Gerraty# only has the library name available, so stick to that.
1983cbdda60SSimon J. Gerraty#
1993cbdda60SSimon J. Gerraty
2003cbdda60SSimon J. GerratySRC_LIBS?=
20150d2e745SSimon J. Gerraty# magic_libs includes those we want to link with
20250d2e745SSimon J. Gerraty# as well as those we might look at
20350d2e745SSimon J. Gerraty__dpadd_magic_libs += ${__dpadd_libs} ${SRC_LIBS}
20450d2e745SSimon J. GerratyDPMAGIC_LIBS += ${__dpadd_magic_libs} \
20550d2e745SSimon J. Gerraty	${__dpadd_magic_libs:@d@${DPMAGIC_LIBS_${d:T:R}}@}
2063cbdda60SSimon J. Gerraty
207e48f47ddSSimon J. Gerraty# we skip this for staged libs
208e48f47ddSSimon J. Gerraty.for __lib in ${DPMAGIC_LIBS:O:u:N${STAGE_OBJTOP:Unot}*/lib/*}
2093cbdda60SSimon J. Gerraty#
2103cbdda60SSimon J. Gerraty# if SRC_libfoo is not set, then we assume that the srcdir corresponding
2113cbdda60SSimon J. Gerraty# to where we found the library is correct.
2123cbdda60SSimon J. Gerraty#
2133cbdda60SSimon J. GerratySRC_${__lib:T:R} ?= ${__lib:H:S,${OBJTOP},${RELSRCTOP},}
2143cbdda60SSimon J. Gerraty#
2153cbdda60SSimon J. Gerraty# This is a no-brainer but just to be complete...
2163cbdda60SSimon J. Gerraty#
2173cbdda60SSimon J. GerratyOBJ_${__lib:T:R} ?= ${__lib:H:S,${OBJTOP},${RELOBJTOP},}
2183cbdda60SSimon J. Gerraty#
2193cbdda60SSimon J. Gerraty# If INCLUDES_libfoo is not set, then we'll use ${SRC_libfoo}/h if it exists,
2203cbdda60SSimon J. Gerraty# else just ${SRC_libfoo}.
2213cbdda60SSimon J. Gerraty#
222b0c40a00SSimon J. Gerraty.if !empty(SRC_${__lib:T:R})
2233cbdda60SSimon J. GerratyINCLUDES_${__lib:T:R} ?= -I${exists(${SRC_${__lib:T:R}}/h):?${SRC_${__lib:T:R}}/h:${SRC_${__lib:T:R}}}
224b0c40a00SSimon J. Gerraty.endif
2253cbdda60SSimon J. Gerraty.endfor
2263cbdda60SSimon J. Gerraty
227e48f47ddSSimon J. Gerraty# even for staged libs we sometimes
228e48f47ddSSimon J. Gerraty# need to allow direct -I to avoid cicular dependencies
229e48f47ddSSimon J. Gerraty.for __lib in ${DPMAGIC_LIBS:O:u:T:R}
230e48f47ddSSimon J. Gerraty.if !empty(SRC_${__lib}) && empty(INCLUDES_${__lib})
231e48f47ddSSimon J. Gerraty# must be a staged lib
232e48f47ddSSimon J. Gerraty.if exists(${SRC_${__lib}}/h)
233e48f47ddSSimon J. GerratyINCLUDES_${__lib} = -I${SRC_${__lib}}/h
234e48f47ddSSimon J. Gerraty.else
235e48f47ddSSimon J. GerratyINCLUDES_${__lib} = -I${SRC_${__lib}}
236e48f47ddSSimon J. Gerraty.endif
237e48f47ddSSimon J. Gerraty.endif
238e48f47ddSSimon J. Gerraty.endfor
239e48f47ddSSimon J. Gerraty
240e48f47ddSSimon J. Gerraty# when linking a shared lib, avoid non pic libs
241e48f47ddSSimon J. GerratySHLDADD+= ${LDADD:N-[lL]*}
242e48f47ddSSimon J. Gerraty.for __lib in ${__dpadd_libs:u}
243e48f47ddSSimon J. Gerraty.if defined(SHLIB_NAME) && ${LDADD:M-l${__lib:T:R:S,lib,,}} != ""
244e48f47ddSSimon J. Gerraty.if ${__lib:T:N*_pic.a:N*.so} == "" || exists(${__lib:R}.so)
245e48f47ddSSimon J. GerratySHLDADD+= -l${__lib:T:R:S,lib,,}
246e48f47ddSSimon J. Gerraty.elif exists(${__lib:R}_pic.a)
247e48f47ddSSimon J. GerratySHLDADD+= -l${__lib:T:R:S,lib,,}_pic
248e48f47ddSSimon J. Gerraty.else
249e48f47ddSSimon J. Gerraty.warning ${RELDIR}.${TARGET_SPEC} needs ${__lib:T:R}_pic.a
250e48f47ddSSimon J. GerratySHLDADD+= -l${__lib:T:R:S,lib,,}
251e48f47ddSSimon J. Gerraty.endif
252e48f47ddSSimon J. GerratySHLDADD+= -L${__lib:H}
253e48f47ddSSimon J. Gerraty.endif
254e48f47ddSSimon J. Gerraty.endfor
255e48f47ddSSimon J. Gerraty
2563cbdda60SSimon J. Gerraty# Now for the bits we actually need
2573cbdda60SSimon J. Gerraty__dpadd_incs=
2583cbdda60SSimon J. Gerraty.for __lib in ${__dpadd_libs:u}
259*c59c3bf3SSimon J. Gerraty.if (make(${PROG:U}_p) || defined(NEED_GPROF)) && exists(${__lib:R}_p.a)
2603cbdda60SSimon J. Gerraty__ldadd=-l${__lib:T:R:S,lib,,}
2613cbdda60SSimon J. GerratyLDADD := ${LDADD:S,^${__ldadd}$,${__ldadd}_p,g}
2623cbdda60SSimon J. Gerraty.endif
263e48f47ddSSimon J. Gerraty.endfor
2643cbdda60SSimon J. Gerraty
2653cbdda60SSimon J. Gerraty#
2663cbdda60SSimon J. Gerraty# We take care of duplicate suppression later.
267e48f47ddSSimon J. Gerraty# don't apply :T:R too early
26850d2e745SSimon J. Gerraty__dpadd_incs += ${__dpadd_magic_libs:u:@x@${INCLUDES_${x:T:R}}@}
26950d2e745SSimon J. Gerraty__dpadd_incs += ${__dpadd_magic_libs:O:u:@s@${SRC_LIBS_${s:T:R}:U}@:@x@${INCLUDES_${x:T:R}}@}
270e48f47ddSSimon J. Gerraty
27150d2e745SSimon J. Gerraty__dpadd_last_incs += ${__dpadd_magic_libs:u:@x@${INCLUDES_LAST_${x:T:R}}@}
27250d2e745SSimon J. Gerraty__dpadd_last_incs += ${__dpadd_magic_libs:O:u:@s@${SRC_LIBS_${s:T:R}:U}@:@x@${INCLUDES_LAST_${x:T:R}}@}
273e48f47ddSSimon J. Gerraty
274e22fef7dSSimon J. Gerraty.if defined(HOSTPROG) || ${MACHINE:Nhost*} == ""
275e48f47ddSSimon J. Gerraty# we want any -I/usr/* last
276e48f47ddSSimon J. Gerraty__dpadd_last_incs := \
277e48f47ddSSimon J. Gerraty	${__dpadd_last_incs:N-I/usr/*} \
278e48f47ddSSimon J. Gerraty	${__dpadd_incs:M-I/usr/*} \
279e48f47ddSSimon J. Gerraty	${__dpadd_last_incs:M-I/usr/*}
280e48f47ddSSimon J. Gerraty__dpadd_incs := ${__dpadd_incs:N-I/usr/*}
281e48f47ddSSimon J. Gerraty.endif
2823cbdda60SSimon J. Gerraty
2833cbdda60SSimon J. Gerraty#
2843cbdda60SSimon J. Gerraty# eliminate any duplicates - but don't mess with the order
2853cbdda60SSimon J. Gerraty# force evaluation now - to avoid giving make a headache
2863cbdda60SSimon J. Gerraty#
2873cbdda60SSimon J. Gerraty.for t in CFLAGS CXXFLAGS
2883cbdda60SSimon J. Gerraty# avoid duplicates
2893cbdda60SSimon J. Gerraty__$t_incs:=${$t:M-I*:O:u}
2903cbdda60SSimon J. Gerraty.for i in ${__dpadd_incs}
2913cbdda60SSimon J. Gerraty.if "${__$t_incs:M$i}" == ""
2923cbdda60SSimon J. Gerraty$t+= $i
2933cbdda60SSimon J. Gerraty__$t_incs+= $i
2943cbdda60SSimon J. Gerraty.endif
2953cbdda60SSimon J. Gerraty.endfor
2963cbdda60SSimon J. Gerraty.endfor
2973cbdda60SSimon J. Gerraty
298e48f47ddSSimon J. Gerraty.for t in CFLAGS_LAST CXXFLAGS_LAST
299e48f47ddSSimon J. Gerraty# avoid duplicates
300e48f47ddSSimon J. Gerraty__$t_incs:=${$t:M-I*:u}
301e48f47ddSSimon J. Gerraty.for i in ${__dpadd_last_incs}
302e48f47ddSSimon J. Gerraty.if "${__$t_incs:M$i}" == ""
303e48f47ddSSimon J. Gerraty$t+= $i
304e48f47ddSSimon J. Gerraty__$t_incs+= $i
305e48f47ddSSimon J. Gerraty.endif
306e48f47ddSSimon J. Gerraty.endfor
307e48f47ddSSimon J. Gerraty.endfor
308e48f47ddSSimon J. Gerraty
3093cbdda60SSimon J. Gerraty# This target is used to gather a list of
3103cbdda60SSimon J. Gerraty# dir: ${DPADD}
3113cbdda60SSimon J. Gerraty# entries
3123cbdda60SSimon J. Gerraty.if make(*dpadd*)
3133cbdda60SSimon J. Gerraty.if !target(dpadd)
3143cbdda60SSimon J. Gerratydpadd:	.NOTMAIN
3153cbdda60SSimon J. Gerraty.if defined(DPADD) && ${DPADD} != ""
3163cbdda60SSimon J. Gerraty	@echo "${RELDIR}: ${DPADD:S,${OBJTOP}/,,}"
3173cbdda60SSimon J. Gerraty.endif
3183cbdda60SSimon J. Gerraty.endif
3193cbdda60SSimon J. Gerraty.endif
3203cbdda60SSimon J. Gerraty
3213cbdda60SSimon J. Gerraty.ifdef SRC_PATHADD
3223cbdda60SSimon J. Gerraty# We don't want to assume that we need to .PATH every element of
3233cbdda60SSimon J. Gerraty# SRC_LIBS, but the Makefile cannot do
3243cbdda60SSimon J. Gerraty# .PATH: ${SRC_libfoo}
3253cbdda60SSimon J. Gerraty# since the value of SRC_libfoo must be available at the time .PATH:
3263cbdda60SSimon J. Gerraty# is read - and we only just worked it out.
3273cbdda60SSimon J. Gerraty# Further, they can't wait until after include of {lib,prog}.mk as
3283cbdda60SSimon J. Gerraty# the .PATH is needed before then.
3293cbdda60SSimon J. Gerraty# So we let the Makefile do
3303cbdda60SSimon J. Gerraty# SRC_PATHADD+= ${SRC_libfoo}
3313cbdda60SSimon J. Gerraty# and we defer the .PATH: until now so that SRC_libfoo will be available.
3323cbdda60SSimon J. Gerraty.PATH: ${SRC_PATHADD}
3333cbdda60SSimon J. Gerraty.endif
3343cbdda60SSimon J. Gerraty
335e48f47ddSSimon J. Gerraty# after all that, if doing -n we don't care
336e48f47ddSSimon J. Gerraty.if ${.MAKEFLAGS:Ux:M-n} != ""
337e48f47ddSSimon J. GerratyDPADD =
338e48f47ddSSimon J. Gerraty.elif ${.MAKE.MODE:Mmeta*} != "" && exists(${.MAKE.DEPENDFILE})
339e48f47ddSSimon J. GerratyDPADD_CLEAR_DPADD ?= yes
340e48f47ddSSimon J. Gerraty.if ${DPADD_CLEAR_DPADD} == "yes"
341e48f47ddSSimon J. Gerraty# save this
342e48f47ddSSimon J. Gerraty__dpadd_libs := ${__dpadd_libs}
343e48f47ddSSimon J. Gerraty# we have made what use of it we can of DPADD
344e48f47ddSSimon J. GerratyDPADD =
345e48f47ddSSimon J. Gerraty.endif
346e48f47ddSSimon J. Gerraty.endif
347e48f47ddSSimon J. Gerraty
3483cbdda60SSimon J. Gerraty.endif
349