1 # $Id: dpadd.mk,v 1.23 2017/02/13 16:46:01 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 .if
${_CURDIR} == ${SRCTOP}
28 RELDIR?
= ${_CURDIR
:S
,${SRCTOP}/,,}
29 .if
${RELDIR} == ${_CURDIR}
30 RELDIR?
= ${_OBJDIR
:S
,${OBJTOP}/,,}
32 RELTOP?
= ${RELDIR
:C
,[^
/]+,..
,g
}
37 # we get included just about everywhere so this is handy...
38 # C*DEBUG_XTRA are for defining on cmd line etc
39 # so do not use in makefiles.
40 .
ifdef CFLAGS_DEBUG_XTRA
41 CFLAGS_LAST
+= ${CFLAGS_DEBUG_XTRA}
43 .
ifdef CXXFLAGS_DEBUG_XTRA
44 CXXFLAGS_LAST
+= ${CXXFLAGS_DEBUG_XTRA}
47 .
-include <local.dpadd.mk
>
49 # DPLIBS helps us ensure we keep DPADD and LDADD in sync
50 DPLIBS
+= ${DPLIBS_LAST}
52 .for __lib in
${DPLIBS}
53 .if
"${_lib:M-*}" != ""
56 LDADD
+= ${LDADD_
${__lib
:T
:R
}:U
${__lib
:T
:R
:S
/lib
/-l
/:C
/\.so.
*//}}
60 # DPADD can contain things other than libs
61 __dpadd_libs
:= ${DPADD
:M
*/lib
*}
63 # some libs have dependencies...
64 # DPLIBS_* allows bsd.libnames.mk to flag libs which must be included
65 # in DPADD for a given library.
66 # Gather all such dependencies into __ldadd_all_xtras
67 # dups will be dealt with later.
68 # Note: libfoo_pic uses DPLIBS_libfoo
70 .for __lib in
${__dpadd_libs
:@d@
${DPLIBS_
${d
:T
:R
:S
,_pic
,,}}@
}
71 __ldadd_all_xtras
+= ${LDADD_
${__lib}:U
${__lib
:T
:R
:S
/lib
/-l
/:C
/\.so.
*//}}
72 .if
"${DPADD:M${__lib}}" == ""
76 # Last of all... for libc and libgcc
79 # de-dupuplicate __ldadd_all_xtras into __ldadd_xtras
80 # in reverse order so that libs end up listed after all that needed them.
82 .for __lib in
${__ldadd_all_xtras
:[-1.
.1]}
83 .if
"${__ldadd_xtras:M${__lib}}" == "" ||
${NEED_IMPLICIT_LDADD
:tl
:Uno
} != "no"
84 __ldadd_xtras
+= ${__lib}
88 .if
!empty
(__ldadd_xtras
)
89 # now back to the original order
90 __ldadd_xtras
:= ${__ldadd_xtras
:[-1.
.1]}
91 LDADD
+= ${__ldadd_xtras}
94 # Convert DPADD into -I and -L options and add them to CPPFLAGS and LDADD
95 # For the -I's convert the path to a relative one. For separate objdirs
96 # the DPADD paths will be to the obj tree so we need to subst anyway.
99 __dpadd_libs
:= ${DPADD
:M
*/lib
*}
101 # Order -L's to search ours first.
102 # Avoids picking up old versions already installed.
103 __dpadd_libdirs
:= ${__dpadd_libs
:R
:H
:S
/^
/-L
/g
:O
:u
:N-L
}
104 LDADD
+= ${__dpadd_libdirs
:M-L
${OBJTOP}/*}
105 LDADD
+= ${__dpadd_libdirs
:N-L
${OBJTOP}/*:N-L
${HOST_LIBDIR
:U
/usr
/lib
}}
106 .if defined
(HOST_LIBDIR
) && ${HOST_LIBDIR} != "/usr/lib"
107 LDADD
+= -L
${HOST_LIBDIR}
112 # Each lib is its own src_lib, we want to include it in SRC_LIBS
113 # so that the correct INCLUDES_* will be picked up automatically.
114 SRC_LIBS
+= ${_OBJDIR}/lib
${LIB}.a
119 # This little bit of magic, assumes that SRC_libfoo will be
120 # set if it cannot be correctly derrived from ${LIBFOO}
121 # Note that SRC_libfoo and INCLUDES_libfoo should be named for the
122 # actual library name not the variable name that might refer to it.
123 # 99% of the time the two are the same, but the DPADD logic
124 # only has the library name available, so stick to that.
128 __dpadd_libs
+= ${SRC_LIBS}
129 DPMAGIC_LIBS
+= ${__dpadd_libs} \
130 ${__dpadd_libs
:@d@
${DPMAGIC_LIBS_
${d
:T
:R
}}@
}
132 # we skip this for staged libs
133 .for __lib in
${DPMAGIC_LIBS
:O
:u
:N
${STAGE_OBJTOP
:Unot
}*/lib
/*}
135 # if SRC_libfoo is not set, then we assume that the srcdir corresponding
136 # to where we found the library is correct.
138 SRC_
${__lib
:T
:R
} ?
= ${__lib
:H
:S
,${OBJTOP},${RELSRCTOP},}
140 # This is a no-brainer but just to be complete...
142 OBJ_
${__lib
:T
:R
} ?
= ${__lib
:H
:S
,${OBJTOP},${RELOBJTOP},}
144 # If INCLUDES_libfoo is not set, then we'll use ${SRC_libfoo}/h if it exists,
145 # else just ${SRC_libfoo}.
147 INCLUDES_
${__lib
:T
:R
}?
= -I
${exists
(${SRC_
${__lib
:T
:R
}}/h
):?
${SRC_
${__lib
:T
:R
}}/h
:${SRC_
${__lib
:T
:R
}}}
151 # even for staged libs we sometimes
152 # need to allow direct -I to avoid cicular dependencies
153 .for __lib in
${DPMAGIC_LIBS
:O
:u
:T
:R
}
154 .if
!empty
(SRC_
${__lib}) && empty
(INCLUDES_
${__lib})
155 # must be a staged lib
156 .if exists
(${SRC_
${__lib}}/h
)
157 INCLUDES_
${__lib} = -I
${SRC_
${__lib}}/h
159 INCLUDES_
${__lib} = -I
${SRC_
${__lib}}
164 # when linking a shared lib, avoid non pic libs
165 SHLDADD
+= ${LDADD
:N-
[lL
]*}
166 .for __lib in
${__dpadd_libs
:u
}
167 .if defined
(SHLIB_NAME
) && ${LDADD
:M-l
${__lib
:T
:R
:S
,lib
,,}} != ""
168 .if
${__lib
:T
:N
*_pic.a
:N
*.so
} == "" || exists
(${__lib
:R
}.so
)
169 SHLDADD
+= -l
${__lib
:T
:R
:S
,lib
,,}
170 .elif exists
(${__lib
:R
}_pic.a
)
171 SHLDADD
+= -l
${__lib
:T
:R
:S
,lib
,,}_pic
173 .warning
${RELDIR}.
${TARGET_SPEC} needs
${__lib
:T
:R
}_pic.a
174 SHLDADD
+= -l
${__lib
:T
:R
:S
,lib
,,}
176 SHLDADD
+= -L
${__lib
:H
}
180 # Now for the bits we actually need
182 .for __lib in
${__dpadd_libs
:u
}
183 .if
(make
(${PROG}_p
) || defined
(NEED_GPROF
)) && exists
(${__lib
:R
}_p.a
)
184 __ldadd
=-l
${__lib
:T
:R
:S
,lib
,,}
185 LDADD
:= ${LDADD
:S
,^
${__ldadd}$,${__ldadd}_p
,g
}
190 # We take care of duplicate suppression later.
191 # don't apply :T:R too early
192 __dpadd_incs
+= ${__dpadd_libs
:u
:@x@
${INCLUDES_
${x
:T
:R
}}@
}
193 __dpadd_incs
+= ${__dpadd_libs
:O
:u
:@s@
${SRC_LIBS_
${s
:T
:R
}:U
}@
:@x@
${INCLUDES_
${x
:T
:R
}}@
}
195 __dpadd_last_incs
+= ${__dpadd_libs
:u
:@x@
${INCLUDES_LAST_
${x
:T
:R
}}@
}
196 __dpadd_last_incs
+= ${__dpadd_libs
:O
:u
:@s@
${SRC_LIBS_
${s
:T
:R
}:U
}@
:@x@
${INCLUDES_LAST_
${x
:T
:R
}}@
}
198 .if defined
(HOSTPROG
) ||
${MACHINE} == "host"
199 # we want any -I/usr/* last
200 __dpadd_last_incs
:= \
201 ${__dpadd_last_incs
:N-I
/usr
/*} \
202 ${__dpadd_incs
:M-I
/usr
/*} \
203 ${__dpadd_last_incs
:M-I
/usr
/*}
204 __dpadd_incs
:= ${__dpadd_incs
:N-I
/usr
/*}
208 # eliminate any duplicates - but don't mess with the order
209 # force evaluation now - to avoid giving make a headache
211 .for t in CFLAGS CXXFLAGS
213 __
$t_incs:=${$t:M-I
*:O
:u
}
214 .for i in
${__dpadd_incs}
215 .if
"${__$t_incs:M$i}" == ""
222 .for t in CFLAGS_LAST CXXFLAGS_LAST
224 __
$t_incs:=${$t:M-I
*:u
}
225 .for i in
${__dpadd_last_incs}
226 .if
"${__$t_incs:M$i}" == ""
233 # This target is used to gather a list of
239 .if defined
(DPADD
) && ${DPADD} != ""
240 @echo
"${RELDIR}: ${DPADD:S,${OBJTOP}/,,}"
246 # We don't want to assume that we need to .PATH every element of
247 # SRC_LIBS, but the Makefile cannot do
248 # .PATH: ${SRC_libfoo}
249 # since the value of SRC_libfoo must be available at the time .PATH:
250 # is read - and we only just worked it out.
251 # Further, they can't wait until after include of {lib,prog}.mk as
252 # the .PATH is needed before then.
253 # So we let the Makefile do
254 # SRC_PATHADD+= ${SRC_libfoo}
255 # and we defer the .PATH: until now so that SRC_libfoo will be available.
256 .PATH
: ${SRC_PATHADD}
259 # after all that, if doing -n we don't care
260 .if
${.MAKEFLAGS
:Ux
:M-n
} != ""
262 .elif
${.MAKE.MODE
:Mmeta
*} != "" && exists
(${.MAKE.DEPENDFILE
})
263 DPADD_CLEAR_DPADD ?
= yes
264 .if
${DPADD_CLEAR_DPADD} == "yes"
266 __dpadd_libs
:= ${__dpadd_libs}
267 # we have made what use of it we can of DPADD