dpadd.mk revision 246149
1218822Sdim# $Id: dpadd.mk,v 1.18 2011/11/10 05:13:37 sjg Exp $ 2130561Sobrien# 384865Sobrien# @(#) Copyright (c) 2004, Simon J. Gerraty 484865Sobrien# 584865Sobrien# This file is provided in the hope that it will 684865Sobrien# be of use. There is absolutely NO WARRANTY. 784865Sobrien# Permission to copy, redistribute or otherwise 884865Sobrien# use this file is hereby granted provided that 984865Sobrien# the above copyright notice and this notice are 1084865Sobrien# left intact. 1184865Sobrien# 1284865Sobrien# Please send copies of changes and bug-fixes to: 1384865Sobrien# sjg@crufty.net 1484865Sobrien# 1584865Sobrien 1684865Sobrien.if !target(__${.PARSEFILE}__) 1784865Sobrien__${.PARSEFILE}__: 1884865Sobrien 19218822Sdim# sometimes we play games with .CURDIR etc 2084865Sobrien# _* hold the original values of .* 2184865Sobrien_OBJDIR?= ${.OBJDIR} 2284865Sobrien_CURDIR?= ${.CURDIR} 2389857Sobrien 2484865Sobrien# DPLIBS helps us ensure we keep DPADD and LDADD in sync 2584865SobrienDPLIBS+= ${DPLIBS_LAST} 2684865SobrienDPADD+= ${DPLIBS} 2784865Sobrien.for __lib in ${DPLIBS:T:R} 2884865SobrienLDADD+= ${LDADD_${__lib}:U${__lib:T:R:S/lib/-l/:C/\.so.*//}} 2984865Sobrien.endfor 3084865Sobrien 3184865Sobrien# DPADD can contain things other than libs 3284865Sobrien__dpadd_libs = ${DPADD:M*/lib*} 3384865Sobrien 3484865Sobrien# some libs have dependencies... 3584865Sobrien# DPLIBS_* allows bsd.libnames.mk to flag libs which must be included 3684865Sobrien# in DPADD for a given library. 3784865Sobrien.for __lib in ${__dpadd_libs:@d@${DPLIBS_${d:T:R}}@} 3884865Sobrien.if "${DPADD:M${__lib}}" == "" 3984865SobrienDPADD+= ${__lib} 4084865SobrienLDADD+= ${LDADD_${__lib}:U${__lib:T:R:S/lib/-l/:C/\.so.*//}} 4184865Sobrien.endif 4284865Sobrien.endfor 4384865Sobrien# Last of all... for libc and libgcc 4484865SobrienDPADD+= ${DPADD_LAST} 4584865Sobrien 4684865Sobrien# Convert DPADD into -I and -L options and add them to CPPFLAGS and LDADD 4784865Sobrien# For the -I's convert the path to a relative one. For separate objdirs 4884865Sobrien# the DPADD paths will be to the obj tree so we need to subst anyway. 4984865Sobrien 5084865Sobrien# If USE_PROFILE is yes, then check for profiled versions of libs 5184865Sobrien# and use them. 5284865Sobrien 5384865SobrienUSE_PROFILE?=no 5484865Sobrien.if defined(LIBDL) && exists(${LIBDL}) 5584865Sobrien.if defined(PROG) && (make(${PROG}_p) || ${USE_PROFILE} == yes) && \ 5684865Sobrien defined(LDFLAGS) && ${LDFLAGS:M-export-dynamic} 5784865Sobrien# building profiled version of a prog that needs dlopen to work 5884865SobrienDPLIBS+= ${LIBDL} 5984865Sobrien.endif 6084865Sobrien.endif 6184865Sobrien 6284865Sobrien.if defined(LIBDMALLOC) && exists(${LIBDMALLOC}) 6384865Sobrien.if defined(USE_DMALLOC) && ${USE_DMALLOC} != no 6484865Sobrien.if !defined(NO_DMALLOC) 6584865SobrienCPPFLAGS+= -DUSE_DMALLOC 6684865Sobrien.endif 6784865SobrienDPLIBS+= ${LIBDMALLOC} 6884865Sobrien.endif 6984865Sobrien.endif 7084865Sobrien 7184865Sobrien# Order -L's to seach ours first. 7284865Sobrien# Avoids picking up old versions already installed. 7384865Sobrien__dpadd_libdirs := ${__dpadd_libs:R:H:S/^/-L/g:O:u:N-L} 7484865SobrienLDADD += ${__dpadd_libdirs:M-L${OBJTOP}/*} 7584865SobrienLDADD += ${__dpadd_libdirs:N-L${OBJTOP}/*} 7684865Sobrien 7784865Sobrien.if ${.CURDIR} == ${SRCTOP} 7884865SobrienRELDIR=. 7984865SobrienRELTOP=. 8084865Sobrien.else 8184865SobrienRELDIR?= ${.CURDIR:S,${SRCTOP}/,,} 8284865Sobrien.if ${RELDIR} == ${.CURDIR} 8384865SobrienRELDIR?= ${.OBJDIR:S,${OBJTOP}/,,} 8484865Sobrien.endif 8584865SobrienRELTOP?= ${RELDIR:C,[^/]+,..,g} 8684865Sobrien.endif 8784865SobrienRELOBJTOP?= ${OBJTOP} 8884865SobrienRELSRCTOP?= ${SRCTOP} 8984865Sobrien 9084865Sobrien.if !make(dpadd) 9184865Sobrien.ifdef LIB 9284865Sobrien# Each lib is its own src_lib, we want to include it in SRC_LIBS 9384865Sobrien# so that the correct INCLUDES_* will be picked up automatically. 9484865SobrienSRC_LIBS+= ${_OBJDIR}/lib${LIB}.a 9584865Sobrien.endif 9684865Sobrien.endif 9784865Sobrien 9884865Sobrien# 9984865Sobrien# This little bit of magic, assumes that SRC_libfoo will be 10084865Sobrien# set if it cannot be correctly derrived from ${LIBFOO} 10184865Sobrien# Note that SRC_libfoo and INCLUDES_libfoo should be named for the 10284865Sobrien# actual libary name not the variable name that might refer to it. 10384865Sobrien# 99% of the time the two are the same, but the DPADD logic 10484865Sobrien# only has the libary name available, so stick to that. 10584865Sobrien# 10684865Sobrien 10784865SobrienSRC_LIBS?= 10884865Sobrien__dpadd_libs += ${SRC_LIBS} 10984865SobrienDPMAGIC_LIBS += ${__dpadd_libs} \ 11084865Sobrien ${__dpadd_libs:@d@${DPMAGIC_LIBS_${d:T:R}}@} 11184865Sobrien 11284865Sobrien.for __lib in ${DPMAGIC_LIBS:O:u} 11384865Sobrien# 11484865Sobrien# if SRC_libfoo is not set, then we assume that the srcdir corresponding 11584865Sobrien# to where we found the library is correct. 11684865Sobrien# 117218822SdimSRC_${__lib:T:R} ?= ${__lib:H:S,${OBJTOP},${RELSRCTOP},} 118218822Sdim# 119218822Sdim# This is a no-brainer but just to be complete... 120218822Sdim# 121218822SdimOBJ_${__lib:T:R} ?= ${__lib:H:S,${OBJTOP},${RELOBJTOP},} 122218822Sdim# 123218822Sdim# If INCLUDES_libfoo is not set, then we'll use ${SRC_libfoo}/h if it exists, 124218822Sdim# else just ${SRC_libfoo}. 125218822Sdim# 126218822SdimINCLUDES_${__lib:T:R}?= -I${exists(${SRC_${__lib:T:R}}/h):?${SRC_${__lib:T:R}}/h:${SRC_${__lib:T:R}}} 127218822Sdim 128218822Sdim.endfor 129218822Sdim 130218822Sdim# Now for the bits we actually need 131218822Sdim__dpadd_incs= 132218822Sdim.for __lib in ${__dpadd_libs:u} 133218822Sdim.if (make(${PROG}_p) || defined(NEED_GPROF)) && exists(${__lib:R}_p.a) 134218822Sdim__ldadd=-l${__lib:T:R:S,lib,,} 135218822SdimLDADD := ${LDADD:S,^${__ldadd}$,${__ldadd}_p,g} 136218822Sdim.endif 137218822Sdim 138218822Sdim# 139218822Sdim# Some libs generate headers, so we potentially need both 14084865Sobrien# the src dir and the obj dir. 14184865Sobrien# If ${INCLUDES_libfoo} contains a word ending in /h, we assume that either 14284865Sobrien# 1. it does not generate headers or 14384865Sobrien# 2. INCLUDES_libfoo will have been set correctly 14484865Sobrien# XXX it gets ugly avoiding duplicates... 14584865Sobrien# use :? to ensure .for does not prevent correct evaluation 14684865Sobrien# 14784865Sobrien# We take care of duplicate suppression later. 14884865Sobrien__dpadd_incs += ${"${INCLUDES_${__lib:T:R}:M*/h}":? :-I${OBJ_${__lib:T:R}}} 14984865Sobrien__dpadd_incs += ${INCLUDES_${__lib:T:R}} 15084865Sobrien.endfor 15184865Sobrien 15284865Sobrien# 15384865Sobrien# eliminate any duplicates - but don't mess with the order 15484865Sobrien# force evaluation now - to avoid giving make a headache 15584865Sobrien# 15684865Sobrien.for t in CFLAGS CXXFLAGS 15784865Sobrien# avoid duplicates 15884865Sobrien__$t_incs:=${$t:M-I*:O:u} 15984865Sobrien.for i in ${__dpadd_incs} 16084865Sobrien.if "${__$t_incs:M$i}" == "" 16184865Sobrien$t+= $i 16284865Sobrien__$t_incs+= $i 16384865Sobrien.endif 16484865Sobrien.endfor 16584865Sobrien.endfor 16684865Sobrien 16784865Sobrien# This target is used to gather a list of 16884865Sobrien# dir: ${DPADD} 16984865Sobrien# entries 17084865Sobrien.if make(*dpadd*) 17184865Sobrien# allow overrides 17284865Sobrien.-include "dpadd++.mk" 17384865Sobrien 17484865Sobrien.if !target(dpadd) 17584865Sobriendpadd: .NOTMAIN 17684865Sobrien.if defined(DPADD) && ${DPADD} != "" 17784865Sobrien @echo "${RELDIR}: ${DPADD:S,${OBJTOP}/,,}" 17884865Sobrien.endif 17984865Sobrien.endif 18084865Sobrien.endif 18184865Sobrien 18284865Sobrien.ifdef SRC_PATHADD 18384865Sobrien# We don't want to assume that we need to .PATH every element of 18484865Sobrien# SRC_LIBS, but the Makefile cannot do 18584865Sobrien# .PATH: ${SRC_libfoo} 18684865Sobrien# since the value of SRC_libfoo must be available at the time .PATH: 18784865Sobrien# is read - and we only just worked it out. 188130561Sobrien# Further, they can't wait until after include of {lib,prog}.mk as 189130561Sobrien# the .PATH is needed before then. 19084865Sobrien# So we let the Makefile do 19184865Sobrien# SRC_PATHADD+= ${SRC_libfoo} 19284865Sobrien# and we defer the .PATH: until now so that SRC_libfoo will be available. 19384865Sobrien.PATH: ${SRC_PATHADD} 19484865Sobrien.endif 19584865Sobrien 19684865Sobrien.endif 19784865Sobrien