1 # $Id: dpadd.mk,v 1.18 2011/11/10 05:13:37 sjg Exp $
3 # @(#) Copyright (c) 2004, Simon J. Gerraty
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
12 # Please send copies of changes and bug-fixes to:
16 .if !target(__${.PARSEFILE}__)
19 # sometimes we play games with .CURDIR etc
20 # _* hold the original values of .*
24 # DPLIBS helps us ensure we keep DPADD and LDADD in sync
25 DPLIBS+= ${DPLIBS_LAST}
27 .for __lib in ${DPLIBS:T:R}
28 LDADD+= ${LDADD_${__lib}:U${__lib:T:R:S/lib/-l/:C/\.so.*//}}
31 # DPADD can contain things other than libs
32 __dpadd_libs = ${DPADD:M*/lib*}
34 # some libs have dependencies...
35 # DPLIBS_* allows bsd.libnames.mk to flag libs which must be included
36 # in DPADD for a given library.
37 .for __lib in ${__dpadd_libs:@d@${DPLIBS_${d:T:R}}@}
38 .if "${DPADD:M${__lib}}" == ""
40 LDADD+= ${LDADD_${__lib}:U${__lib:T:R:S/lib/-l/:C/\.so.*//}}
43 # Last of all... for libc and libgcc
46 # Convert DPADD into -I and -L options and add them to CPPFLAGS and LDADD
47 # For the -I's convert the path to a relative one. For separate objdirs
48 # the DPADD paths will be to the obj tree so we need to subst anyway.
50 # If USE_PROFILE is yes, then check for profiled versions of libs
54 .if defined(LIBDL) && exists(${LIBDL})
55 .if defined(PROG) && (make(${PROG}_p) || ${USE_PROFILE} == yes) && \
56 defined(LDFLAGS) && ${LDFLAGS:M-export-dynamic}
57 # building profiled version of a prog that needs dlopen to work
62 .if defined(LIBDMALLOC) && exists(${LIBDMALLOC})
63 .if defined(USE_DMALLOC) && ${USE_DMALLOC} != no
64 .if !defined(NO_DMALLOC)
65 CPPFLAGS+= -DUSE_DMALLOC
67 DPLIBS+= ${LIBDMALLOC}
71 # Order -L's to seach ours first.
72 # Avoids picking up old versions already installed.
73 __dpadd_libdirs := ${__dpadd_libs:R:H:S/^/-L/g:O:u:N-L}
74 LDADD += ${__dpadd_libdirs:M-L${OBJTOP}/*}
75 LDADD += ${__dpadd_libdirs:N-L${OBJTOP}/*}
77 .if ${.CURDIR} == ${SRCTOP}
81 RELDIR?= ${.CURDIR:S,${SRCTOP}/,,}
82 .if ${RELDIR} == ${.CURDIR}
83 RELDIR?= ${.OBJDIR:S,${OBJTOP}/,,}
85 RELTOP?= ${RELDIR:C,[^/]+,..,g}
92 # Each lib is its own src_lib, we want to include it in SRC_LIBS
93 # so that the correct INCLUDES_* will be picked up automatically.
94 SRC_LIBS+= ${_OBJDIR}/lib${LIB}.a
99 # This little bit of magic, assumes that SRC_libfoo will be
100 # set if it cannot be correctly derrived from ${LIBFOO}
101 # Note that SRC_libfoo and INCLUDES_libfoo should be named for the
102 # actual libary name not the variable name that might refer to it.
103 # 99% of the time the two are the same, but the DPADD logic
104 # only has the libary name available, so stick to that.
108 __dpadd_libs += ${SRC_LIBS}
109 DPMAGIC_LIBS += ${__dpadd_libs} \
110 ${__dpadd_libs:@d@${DPMAGIC_LIBS_${d:T:R}}@}
112 .for __lib in ${DPMAGIC_LIBS:O:u}
114 # if SRC_libfoo is not set, then we assume that the srcdir corresponding
115 # to where we found the library is correct.
117 SRC_${__lib:T:R} ?= ${__lib:H:S,${OBJTOP},${RELSRCTOP},}
119 # This is a no-brainer but just to be complete...
121 OBJ_${__lib:T:R} ?= ${__lib:H:S,${OBJTOP},${RELOBJTOP},}
123 # If INCLUDES_libfoo is not set, then we'll use ${SRC_libfoo}/h if it exists,
124 # else just ${SRC_libfoo}.
126 INCLUDES_${__lib:T:R}?= -I${exists(${SRC_${__lib:T:R}}/h):?${SRC_${__lib:T:R}}/h:${SRC_${__lib:T:R}}}
130 # Now for the bits we actually need
132 .for __lib in ${__dpadd_libs:u}
133 .if (make(${PROG}_p) || defined(NEED_GPROF)) && exists(${__lib:R}_p.a)
134 __ldadd=-l${__lib:T:R:S,lib,,}
135 LDADD := ${LDADD:S,^${__ldadd}$,${__ldadd}_p,g}
139 # Some libs generate headers, so we potentially need both
140 # the src dir and the obj dir.
141 # If ${INCLUDES_libfoo} contains a word ending in /h, we assume that either
142 # 1. it does not generate headers or
143 # 2. INCLUDES_libfoo will have been set correctly
144 # XXX it gets ugly avoiding duplicates...
145 # use :? to ensure .for does not prevent correct evaluation
147 # We take care of duplicate suppression later.
148 __dpadd_incs += ${"${INCLUDES_${__lib:T:R}:M*/h}":? :-I${OBJ_${__lib:T:R}}}
149 __dpadd_incs += ${INCLUDES_${__lib:T:R}}
153 # eliminate any duplicates - but don't mess with the order
154 # force evaluation now - to avoid giving make a headache
156 .for t in CFLAGS CXXFLAGS
158 __$t_incs:=${$t:M-I*:O:u}
159 .for i in ${__dpadd_incs}
160 .if "${__$t_incs:M$i}" == ""
167 # This target is used to gather a list of
172 .-include "dpadd++.mk"
176 .if defined(DPADD) && ${DPADD} != ""
177 @echo "${RELDIR}: ${DPADD:S,${OBJTOP}/,,}"
183 # We don't want to assume that we need to .PATH every element of
184 # SRC_LIBS, but the Makefile cannot do
185 # .PATH: ${SRC_libfoo}
186 # since the value of SRC_libfoo must be available at the time .PATH:
187 # is read - and we only just worked it out.
188 # Further, they can't wait until after include of {lib,prog}.mk as
189 # the .PATH is needed before then.
190 # So we let the Makefile do
191 # SRC_PATHADD+= ${SRC_libfoo}
192 # and we defer the .PATH: until now so that SRC_libfoo will be available.
193 .PATH: ${SRC_PATHADD}