1253883Ssjg# $Id: lib.mk,v 1.49 2013/07/18 05:46:24 sjg Exp $
2246149Ssjg
3246149Ssjg.if !target(__${.PARSEFILE}__)
4246149Ssjg__${.PARSEFILE}__:
5246149Ssjg
6246149Ssjg.include <init.mk>
7246149Ssjg
8246149Ssjg.if ${OBJECT_FMT} == "ELF"
9246149SsjgNEED_SOLINKS?= yes
10246149Ssjg.endif
11246149Ssjg
12246149Ssjg.if exists(${.CURDIR}/shlib_version)
13246149SsjgSHLIB_MAJOR != . ${.CURDIR}/shlib_version ; echo $$major
14246149SsjgSHLIB_MINOR != . ${.CURDIR}/shlib_version ; echo $$minor
15246149Ssjg.endif
16246149Ssjg
17246149Ssjgprint-shlib-major:
18246149Ssjg.if defined(SHLIB_MAJOR) && ${MK_PIC} != "no"
19246149Ssjg	@echo ${SHLIB_MAJOR}
20246149Ssjg.else
21246149Ssjg	@false
22246149Ssjg.endif
23246149Ssjg
24246149Ssjgprint-shlib-minor:
25246149Ssjg.if defined(SHLIB_MINOR) && ${MK_PIC} != "no"
26246149Ssjg	@echo ${SHLIB_MINOR}
27246149Ssjg.else
28246149Ssjg	@false
29246149Ssjg.endif
30246149Ssjg
31246149Ssjgprint-shlib-teeny:
32246149Ssjg.if defined(SHLIB_TEENY) && ${MK_PIC} != "no"
33246149Ssjg	@echo ${SHLIB_TEENY}
34246149Ssjg.else
35246149Ssjg	@false
36246149Ssjg.endif
37246149Ssjg
38246149SsjgSHLIB_FULLVERSION ?= ${${SHLIB_MAJOR} ${SHLIB_MINOR} ${SHLIB_TEENY}:L:ts.}
39246149SsjgSHLIB_FULLVERSION := ${SHLIB_FULLVERSION}
40246149Ssjg
41246149Ssjg# add additional suffixes not exported.
42246149Ssjg# .po is used for profiling object files.
43246149Ssjg# .so is used for PIC object files.
44246149Ssjg.SUFFIXES: .out .a .ln .so .po .o .s .S .c .cc .C .m .F .f .r .y .l .cl .p .h
45246149Ssjg.SUFFIXES: .sh .m4 .m
46246149Ssjg
47246149SsjgCFLAGS+=	${COPTS}
48246149Ssjg
49246149Ssjg# Derrived from NetBSD-1.6
50246149Ssjg
51246149Ssjg# Set PICFLAGS to cc flags for producing position-independent code,
52246149Ssjg# if not already set.  Includes -DPIC, if required.
53246149Ssjg
54246149Ssjg# Data-driven table using make variables to control how shared libraries
55246149Ssjg# are built for different platforms and object formats.
56246149Ssjg# OBJECT_FMT:		currently either "ELF" or "a.out", from <bsd.own.mk>
57246149Ssjg# SHLIB_SOVERSION:	version number to be compiled into a shared library
58246149Ssjg#			via -soname. Usualy ${SHLIB_MAJOR} on ELF.
59246149Ssjg#			NetBSD/pmax used to use ${SHLIB_MAJOR}[.${SHLIB_MINOR}
60246149Ssjg#			[.${SHLIB_TEENY}]]
61246149Ssjg# SHLIB_SHFLAGS:	Flags to tell ${LD} to emit shared library.
62246149Ssjg#			with ELF, also set shared-lib version for ld.so.
63246149Ssjg# SHLIB_LDSTARTFILE:	support .o file, call C++ file-level constructors
64246149Ssjg# SHLIB_LDENDFILE:	support .o file, call C++ file-level destructors
65246149Ssjg# FPICFLAGS:		flags for ${FC} to compile .[fF] files to .so objects.
66246149Ssjg# CPPICFLAGS:		flags for ${CPP} to preprocess .[sS] files for ${AS}
67246149Ssjg# CPICFLAGS:		flags for ${CC} to compile .[cC] files to .so objects.
68246149Ssjg# CAPICFLAGS		flags for {$CC} to compiling .[Ss] files
69246149Ssjg#		 	(usually just ${CPPPICFLAGS} ${CPICFLAGS})
70246149Ssjg# APICFLAGS:		flags for ${AS} to assemble .[sS] to .so objects.
71246149Ssjg
72246149Ssjg.if ${TARGET_OSNAME} == "NetBSD"
73246149Ssjg.if ${MACHINE_ARCH} == "alpha"
74246149Ssjg		# Alpha-specific shared library flags
75246149SsjgFPICFLAGS ?= -fPIC
76246149SsjgCPICFLAGS ?= -fPIC -DPIC
77246149SsjgCPPPICFLAGS?= -DPIC 
78246149SsjgCAPICFLAGS?= ${CPPPICFLAGS} ${CPICFLAGS}
79246149SsjgAPICFLAGS ?=
80246149Ssjg.elif ${MACHINE_ARCH} == "mipsel" || ${MACHINE_ARCH} == "mipseb"
81246149Ssjg		# mips-specific shared library flags
82246149Ssjg
83246149Ssjg# On mips, all libs are compiled with ABIcalls, not just sharedlibs.
84246149SsjgMKPICLIB= no
85246149Ssjg
86246149Ssjg# so turn shlib PIC flags on for ${AS}.
87246149SsjgAINC+=-DABICALLS
88246149SsjgAFLAGS+= -fPIC
89246149SsjgAS+=	-KPIC
90246149Ssjg
91246149Ssjg.elif ${MACHINE_ARCH} == "vax" && ${OBJECT_FMT} == "ELF"
92246149Ssjg# On the VAX, all object are PIC by default, not just sharedlibs.
93246149SsjgMKPICLIB= no
94246149Ssjg
95246149Ssjg.elif (${MACHINE_ARCH} == "sparc" || ${MACHINE_ARCH} == "sparc64") && \
96246149Ssjg       ${OBJECT_FMT} == "ELF"
97246149Ssjg# If you use -fPIC you need to define BIGPIC to turn on 32-bit 
98246149Ssjg# relocations in asm code
99246149SsjgFPICFLAGS ?= -fPIC
100246149SsjgCPICFLAGS ?= -fPIC -DPIC
101246149SsjgCPPPICFLAGS?= -DPIC -DBIGPIC
102246149SsjgCAPICFLAGS?= ${CPPPICFLAGS} ${CPICFLAGS}
103246149SsjgAPICFLAGS ?= -KPIC
104246149Ssjg
105246149Ssjg.else
106246149Ssjg
107246149Ssjg# Platform-independent flags for NetBSD a.out shared libraries
108246149SsjgSHLIB_SOVERSION=${SHLIB_FULLVERSION}
109246149SsjgSHLIB_SHFLAGS=
110246149SsjgFPICFLAGS ?= -fPIC
111246149SsjgCPICFLAGS?= -fPIC -DPIC
112246149SsjgCPPPICFLAGS?= -DPIC 
113246149SsjgCAPICFLAGS?= ${CPPPICFLAGS} ${CPICFLAGS}
114246149SsjgAPICFLAGS?= -k
115246149Ssjg
116246149Ssjg.endif
117246149Ssjg
118246149Ssjg# Platform-independent linker flags for ELF shared libraries
119246149Ssjg.if ${OBJECT_FMT} == "ELF"
120246149SsjgSHLIB_SOVERSION=	${SHLIB_MAJOR}
121246149SsjgSHLIB_SHFLAGS=		-soname lib${LIB}.so.${SHLIB_SOVERSION}
122246149SsjgSHLIB_LDSTARTFILE?=	/usr/lib/crtbeginS.o
123246149SsjgSHLIB_LDENDFILE?=	/usr/lib/crtendS.o
124246149Ssjg.endif
125246149Ssjg
126246149Ssjg# for compatability with the following
127246149SsjgCC_PIC?= ${CPICFLAGS}
128246149SsjgLD_shared=${SHLIB_SHFLAGS}
129246149Ssjg
130246149Ssjg.endif # NetBSD
131246149Ssjg
132246149Ssjg.if ${TARGET_OSNAME} == "FreeBSD"
133246149Ssjg.if ${OBJECT_FMT} == "ELF"
134246149SsjgSHLIB_SOVERSION=	${SHLIB_MAJOR}
135246149SsjgSHLIB_SHFLAGS=		-soname lib${LIB}.so.${SHLIB_SOVERSION}
136246149Ssjg.else
137246149SsjgSHLIB_SHFLAGS=		-assert pure-text
138246149Ssjg.endif
139246149SsjgSHLIB_LDSTARTFILE=
140246149SsjgSHLIB_LDENDFILE=
141246149SsjgCC_PIC?= -fpic
142246149SsjgLD_shared=${SHLIB_SHFLAGS}
143246149Ssjg
144246149Ssjg.endif # FreeBSD
145246149Ssjg
146246149SsjgMKPICLIB?= yes
147246149Ssjg
148246149Ssjg# sys.mk can override these
149246149SsjgLD_X?=-X
150246149SsjgLD_x?=-x
151246149SsjgLD_r?=-r
152246149Ssjg
153246149Ssjg# Non BSD machines will be using bmake.
154246149Ssjg.if ${TARGET_OSNAME} == "SunOS"
155246149SsjgLD_shared=-assert pure-text
156246149Ssjg.if ${OBJECT_FMT} == "ELF" || ${MACHINE} == "solaris"
157246149Ssjg# Solaris
158246149SsjgLD_shared=-h lib${LIB}.so.${SHLIB_MAJOR} -G
159246149Ssjg.endif
160246149Ssjg.elif ${TARGET_OSNAME} == "HP-UX"
161246149SsjgLD_shared=-b
162246149SsjgLD_so=sl
163246149SsjgDLLIB=
164246149Ssjg# HPsUX lorder does not grok anything but .o
165246149SsjgLD_sobjs=`${LORDER} ${OBJS} | ${TSORT} | sed 's,\.o,.so,'`
166246149SsjgLD_pobjs=`${LORDER} ${OBJS} | ${TSORT} | sed 's,\.o,.po,'`
167246149Ssjg.elif ${TARGET_OSNAME} == "OSF1"
168246149SsjgLD_shared= -msym -shared -expect_unresolved '*'
169246149SsjgLD_solib= -all lib${LIB}_pic.a
170246149SsjgDLLIB=
171246149Ssjg# lorder does not grok anything but .o
172246149SsjgLD_sobjs=`${LORDER} ${OBJS} | ${TSORT} | sed 's,\.o,.so,'`
173246149SsjgLD_pobjs=`${LORDER} ${OBJS} | ${TSORT} | sed 's,\.o,.po,'`
174246149SsjgAR_cq= -cqs
175246149Ssjg.elif ${TARGET_OSNAME} == "FreeBSD"
176246149SsjgLD_solib= lib${LIB}_pic.a
177246149Ssjg.elif ${TARGET_OSNAME} == "Linux"
178246149Ssjg# this is ambiguous of course
179246149SsjgLD_shared=-shared -h lib${LIB}.so.${SHLIB_MAJOR}
180246149SsjgLD_solib= --whole-archive lib${LIB}_pic.a
181246149Ssjg# Linux uses GNU ld, which is a multi-pass linker
182246149Ssjg# so we don't need to use lorder or tsort
183246149SsjgLD_objs = ${OBJS}
184246149SsjgLD_pobjs = ${POBJS}
185246149SsjgLD_sobjs = ${SOBJS}
186246149Ssjg.elif ${TARGET_OSNAME} == "Darwin"
187246149SsjgSHLIB_LD = ${CC}
188246149SsjgSHLIB_INSTALL_VERSION ?= ${SHLIB_MAJOR}
189246149SsjgSHLIB_COMPATABILITY_VERSION ?= ${SHLIB_MAJOR}.${SHLIB_MINOR:U0}
190246149SsjgSHLIB_COMPATABILITY ?= \
191246149Ssjg	-compatibility_version ${SHLIB_COMPATABILITY_VERSION} \
192246149Ssjg	-current_version ${SHLIB_FULLVERSION}
193246149SsjgLD_shared = -dynamiclib \
194246149Ssjg	-flat_namespace -undefined suppress \
195246149Ssjg	-install_name ${LIBDIR}/lib${LIB}.${SHLIB_INSTALL_VERSION}.${LD_solink} \
196246149Ssjg	${SHLIB_COMPATABILITY}
197246149SsjgSHLIB_LINKS =
198246149Ssjg.for v in ${SHLIB_COMPATABILITY_VERSION} ${SHLIB_INSTALL_VERSION}
199246149Ssjg.if "$v" != "${SHLIB_FULLVERSION}"
200246149SsjgSHLIB_LINKS += lib${LIB}.$v.${LD_solink}
201246149Ssjg.endif
202246149Ssjg.endfor
203246149Ssjg.if ${MK_LINKLIB} != "no"
204246149SsjgSHLIB_LINKS += lib${LIB}.${LD_solink}
205246149Ssjg.endif
206246149Ssjg
207246149SsjgLD_so = ${SHLIB_FULLVERSION}.dylib
208246149SsjgLD_sobjs = ${SOBJS:O:u}
209246149SsjgLD_solib = ${LD_sobjs}
210246149SsjgSOLIB = ${LD_sobjs}
211246149SsjgLD_solink = dylib
212246149Ssjg.if ${MACHINE_ARCH} == "i386"
213246149SsjgPICFLAG ?= -fPIC
214246149Ssjg.else
215246149SsjgPICFLAG ?= -fPIC -fno-common
216246149Ssjg.endif
217246149SsjgRANLIB = :
218246149Ssjg.endif
219246149Ssjg
220246149SsjgSHLIB_LD ?= ${LD}
221246149Ssjg
222246149Ssjg.if !empty(SHLIB_MAJOR)
223246149Ssjg.if ${NEED_SOLINKS} && empty(SHLIB_LINKS)
224246149Ssjg.if ${MK_LINKLIB} != "no"
225246149SsjgSHLIB_LINKS = lib${LIB}.${LD_solink}
226246149Ssjg.endif
227246149Ssjg.if "${SHLIB_FULLVERSION}" != "${SHLIB_MAJOR}"
228246149SsjgSHLIB_LINKS += lib${LIB}.${LD_solink}.${SHLIB_MAJOR}
229246149Ssjg.endif
230246149Ssjg.endif
231246149Ssjg.endif
232246149Ssjg
233246149SsjgLIBTOOL?=libtool
234246149SsjgLD_shared ?= -Bshareable -Bforcearchive
235246149SsjgLD_so ?= so.${SHLIB_FULLVERSION}
236246149SsjgLD_solink ?= so
237246149Ssjg.if empty(LORDER)
238246149SsjgLD_objs ?= ${OBJS}
239246149SsjgLD_pobjs ?= ${POBJS}
240246149SsjgLD_sobjs ?= ${SOBJS}
241246149Ssjg.else
242246149SsjgLD_objs ?= `${LORDER} ${OBJS} | ${TSORT}`
243246149SsjgLD_sobjs ?= `${LORDER} ${SOBJS} | ${TSORT}`
244246149SsjgLD_pobjs ?= `${LORDER} ${POBJS} | ${TSORT}`
245246149Ssjg.endif
246246149SsjgLD_solib ?= ${LD_sobjs}
247246149SsjgAR_cq ?= cq
248246149Ssjg.if exists(/netbsd) && exists(${DESTDIR}/usr/lib/libdl.so)
249246149SsjgDLLIB ?= -ldl
250246149Ssjg.endif
251246149Ssjg
252246149Ssjg# some libs have lots of objects, and scanning all .o, .po and .So meta files
253246149Ssjg# is a waste of time, this tells meta.autodep.mk to just pick one 
254246149Ssjg# (typically .So)
255246149Ssjg# yes, 42 is a random number.
256246149Ssjg.if ${MK_META_MODE} == "yes" && ${SRCS:Uno:[\#]} > 42
257246149SsjgOPTIMIZE_OBJECT_META_FILES ?= yes
258246149Ssjg.endif
259246149Ssjg
260246149Ssjg
261246149Ssjg.if ${MK_LIBTOOL} == "yes"
262246149Ssjg# because libtool is so facist about naming the object files,
263246149Ssjg# we cannot (yet) build profiled libs
264246149SsjgMK_PROFILE=no
265246149Ssjg_LIBS=lib${LIB}.a
266246149Ssjg.if exists(${.CURDIR}/shlib_version)
267246149SsjgSHLIB_AGE != . ${.CURDIR}/shlib_version ; echo $$age
268246149Ssjg.endif
269246149Ssjg.else
270246149Ssjg# for the normal .a we do not want to strip symbols
271246149Ssjg.c.o:
272246149Ssjg	${COMPILE.c} ${.IMPSRC}
273246149Ssjg
274246149Ssjg# for the normal .a we do not want to strip symbols
275246149Ssjg.cc.o .C.o:
276246149Ssjg	${COMPILE.cc} ${.IMPSRC}
277246149Ssjg
278246149Ssjg.S.o .s.o:
279246149Ssjg	@echo ${COMPILE.S} ${CFLAGS:M-[ID]*} ${AINC} ${.IMPSRC}
280246149Ssjg	@${COMPILE.S} ${CFLAGS:M-[ID]*} ${AINC} ${.IMPSRC} 
281246149Ssjg
282246149Ssjg.if (${LD_X} == "")
283246149Ssjg.c.po:
284253883Ssjg	${COMPILE.c} ${CC_PG} ${PROFFLAGS} ${.IMPSRC} -o ${.TARGET}
285246149Ssjg
286246149Ssjg.cc.po .C.po:
287246149Ssjg	${COMPILE.cc} -pg ${.IMPSRC} -o ${.TARGET}
288246149Ssjg
289246149Ssjg.S.so .s.so:
290246149Ssjg	${COMPILE.S} ${PICFLAG} ${CC_PIC} ${CFLAGS:M-[ID]*} ${AINC} ${.IMPSRC} -o ${.TARGET}
291246149Ssjg.else
292246149Ssjg.c.po:
293253883Ssjg	@echo ${COMPILE.c} ${CC_PG} ${PROFFLAGS} ${.IMPSRC} -o ${.TARGET}
294253883Ssjg	@${COMPILE.c} ${CC_PG} ${PROFFLAGS} ${.IMPSRC} -o ${.TARGET}.o
295246149Ssjg	@${LD} ${LD_X} ${LD_r} ${.TARGET}.o -o ${.TARGET}
296246149Ssjg	@rm -f ${.TARGET}.o
297246149Ssjg
298246149Ssjg.cc.po .C.po:
299253883Ssjg	@echo ${COMPILE.cc} ${CXX_PG} ${PROFFLAGS} ${.IMPSRC} -o ${.TARGET}
300253883Ssjg	@${COMPILE.cc} ${CXX_PG} ${.IMPSRC} -o ${.TARGET}.o
301246149Ssjg	@${LD} ${LD_X} ${LD_r} ${.TARGET}.o -o ${.TARGET}
302246149Ssjg	@rm -f ${.TARGET}.o
303246149Ssjg
304246149Ssjg.S.so .s.so:
305246149Ssjg	@echo ${COMPILE.S} ${PICFLAG} ${CC_PIC} ${CFLAGS:M-[ID]*} ${AINC} ${.IMPSRC} -o ${.TARGET}
306246149Ssjg	@${COMPILE.S} ${PICFLAG} ${CC_PIC} ${CFLAGS:M-[ID]*} ${AINC} ${.IMPSRC} -o ${.TARGET}.o
307246149Ssjg	@${LD} ${LD_x} ${LD_r} ${.TARGET}.o -o ${.TARGET}
308246149Ssjg	@rm -f ${.TARGET}.o
309246149Ssjg.endif
310246149Ssjg
311246149Ssjg.if (${LD_x} == "")
312246149Ssjg.c.so:
313246149Ssjg	${COMPILE.c} ${PICFLAG} ${CC_PIC} ${.IMPSRC} -o ${.TARGET}
314246149Ssjg
315246149Ssjg.cc.so .C.so:
316246149Ssjg	${COMPILE.cc} ${PICFLAG} ${CC_PIC} ${.IMPSRC} -o ${.TARGET}
317246149Ssjg
318246149Ssjg.S.po .s.po:
319253883Ssjg	${COMPILE.S} ${PROFFLAGS} ${CFLAGS:M-[ID]*} ${AINC} ${.IMPSRC} -o ${.TARGET}
320246149Ssjg.else
321246149Ssjg
322246149Ssjg.c.so:
323246149Ssjg	@echo ${COMPILE.c} ${PICFLAG} ${CC_PIC} ${.IMPSRC} -o ${.TARGET}
324246149Ssjg	@${COMPILE.c} ${PICFLAG} ${CC_PIC} ${.IMPSRC} -o ${.TARGET}.o
325246149Ssjg	@${LD} ${LD_x} ${LD_r} ${.TARGET}.o -o ${.TARGET}
326246149Ssjg	@rm -f ${.TARGET}.o
327246149Ssjg
328246149Ssjg.cc.so .C.so:
329246149Ssjg	@echo ${COMPILE.cc} ${PICFLAG} ${CC_PIC} ${.IMPSRC} -o ${.TARGET}
330246149Ssjg	@${COMPILE.cc} ${PICFLAG} ${CC_PIC} ${.IMPSRC} -o ${.TARGET}.o
331246149Ssjg	@${LD} ${LD_x} ${LD_r} ${.TARGET}.o -o ${.TARGET}
332246149Ssjg	@rm -f ${.TARGET}.o
333246149Ssjg
334246149Ssjg.S.po .s.po:
335253883Ssjg	@echo ${COMPILE.S} ${PROFFLAGS} ${CFLAGS:M-[ID]*} ${AINC} ${.IMPSRC} -o ${.TARGET}
336253883Ssjg	@${COMPILE.S} ${PROFFLAGS} ${CFLAGS:M-[ID]*} ${AINC} ${.IMPSRC} -o ${.TARGET}.o
337246149Ssjg	@${LD} ${LD_X} ${LD_r} ${.TARGET}.o -o ${.TARGET}
338246149Ssjg	@rm -f ${.TARGET}.o
339246149Ssjg
340246149Ssjg.endif
341246149Ssjg.endif
342246149Ssjg
343246149Ssjg.c.ln:
344246149Ssjg	${LINT} ${LINTFLAGS} ${CFLAGS:M-[IDU]*} -i ${.IMPSRC}
345246149Ssjg
346246149Ssjg.if ${MK_LIBTOOL} != "yes"
347246149Ssjg
348246149Ssjg.if !defined(PICFLAG)
349246149SsjgPICFLAG=-fpic
350246149Ssjg.endif
351246149Ssjg
352246149Ssjg_LIBS=
353246149Ssjg
354246149Ssjg.if ${MK_ARCHIVE} != "no"
355246149Ssjg_LIBS += lib${LIB}.a
356246149Ssjg.endif
357246149Ssjg
358246149Ssjg.if ${MK_PROFILE} != "no"
359246149Ssjg_LIBS+=lib${LIB}_p.a
360246149SsjgPOBJS+=${OBJS:.o=.po}
361246149Ssjg.endif
362246149Ssjg
363246149Ssjg.if ${MK_PIC} != "no"
364246149Ssjg.if ${MK_PICLIB} == "no"
365246149SsjgSOLIB ?= lib${LIB}.a
366246149Ssjg.else
367246149SsjgSOLIB=lib${LIB}_pic.a
368246149Ssjg_LIBS+=${SOLIB}
369246149Ssjg.endif
370246149Ssjg.if !empty(SHLIB_FULLVERSION)
371246149Ssjg_LIBS+=lib${LIB}.${LD_so}
372246149Ssjg.endif
373246149Ssjg.endif
374246149Ssjg
375246149Ssjg.if ${MK_LINT} != "no"
376246149Ssjg_LIBS+=llib-l${LIB}.ln
377246149Ssjg.endif
378246149Ssjg
379246149Ssjg# here is where you can define what LIB* are
380246149Ssjg.-include <libnames.mk>
381246149Ssjg.if ${MK_DPADD_MK} == "yes"
382246149Ssjg# lots of cool magic, but might not suit everyone.
383246149Ssjg.include <dpadd.mk>
384246149Ssjg.endif
385246149Ssjg
386246149Ssjg.if !defined(_SKIP_BUILD)
387246149Ssjgall: prebuild .WAIT ${_LIBS} 
388246149Ssjg# a hook for things that must be done early
389246149Ssjgprebuild:
390246149Ssjg.if !defined(.PARSEDIR)
391246149Ssjg# no-op is the best we can do if not bmake.
392246149Ssjg.WAIT:
393246149Ssjg.endif
394246149Ssjg.endif
395246149Ssjgall: _SUBDIRUSE
396246149Ssjg
397246149Ssjg.for s in ${SRCS:N*.h:M*/*}
398246149Ssjg${.o .so .po .lo:L:@o@${s:T:R}$o@}: $s
399246149Ssjg.endfor
400246149Ssjg
401246149SsjgOBJS+=	${SRCS:T:N*.h:R:S/$/.o/g}
402246149Ssjg.NOPATH:	${OBJS}
403246149Ssjg
404246149Ssjg.if ${MK_LIBTOOL} == "yes"
405246149Ssjg.if ${MK_PIC} == "no"
406246149SsjgLT_STATIC=-static
407246149Ssjg.else
408246149SsjgLT_STATIC=
409246149Ssjg.endif
410246149SsjgSHLIB_AGE?=0
411246149Ssjg
412246149Ssjg# .lo's are created as a side effect
413246149Ssjg.s.o .S.o .c.o:
414246149Ssjg	${LIBTOOL} --mode=compile ${CC} ${LT_STATIC} ${CFLAGS} ${CPPFLAGS} ${IMPFLAGS} -c ${.IMPSRC}
415246149Ssjg
416246149Ssjg# can't really do profiled libs with libtool - its too facist about
417246149Ssjg# naming the output...
418246149Ssjglib${LIB}.a:: ${OBJS}
419246149Ssjg	@rm -f ${.TARGET}
420246149Ssjg	${LIBTOOL} --mode=link ${CC} ${LT_STATIC} -o ${.TARGET:.a=.la} ${OBJS:.o=.lo} -rpath ${SHLIBDIR}:/usr/lib -version-info ${SHLIB_MAJOR}:${SHLIB_MINOR}:${SHLIB_AGE}
421246149Ssjg	@ln .libs/${.TARGET} .
422246149Ssjg
423246149Ssjglib${LIB}.${LD_so}:: lib${LIB}.a
424246149Ssjg	@[ -s ${.TARGET}.${SHLIB_AGE} ] || { ln -s .libs/lib${LIB}.${LD_so}* . 2>/dev/null; : }
425246149Ssjg	@[ -s ${.TARGET} ] || ln -s ${.TARGET}.${SHLIB_AGE} ${.TARGET}
426246149Ssjg
427246149Ssjg.else  # MK_LIBTOOL=yes
428246149Ssjg
429246149Ssjglib${LIB}.a:: ${OBJS}
430246149Ssjg	@echo building standard ${LIB} library
431246149Ssjg	@rm -f ${.TARGET}
432246149Ssjg	@${AR} ${AR_cq} ${.TARGET} ${LD_objs}
433246149Ssjg	${RANLIB} ${.TARGET}
434246149Ssjg
435246149SsjgPOBJS+=	${OBJS:.o=.po}
436246149Ssjg.NOPATH:	${POBJS}
437246149Ssjglib${LIB}_p.a:: ${POBJS}
438246149Ssjg	@echo building profiled ${LIB} library
439246149Ssjg	@rm -f ${.TARGET}
440246149Ssjg	@${AR} ${AR_cq} ${.TARGET} ${LD_pobjs}
441246149Ssjg	${RANLIB} ${.TARGET}
442246149Ssjg
443246149SsjgSOBJS+=	${OBJS:.o=.so}
444246149Ssjg.NOPATH:	${SOBJS}
445246149Ssjglib${LIB}_pic.a:: ${SOBJS}
446246149Ssjg	@echo building shared object ${LIB} library
447246149Ssjg	@rm -f ${.TARGET}
448246149Ssjg	@${AR} ${AR_cq} ${.TARGET} ${LD_sobjs}
449246149Ssjg	${RANLIB} ${.TARGET}
450246149Ssjg
451246149Ssjg#SHLIB_LDADD?= ${LDADD}
452246149Ssjg
453246149Ssjg# bound to be non-portable...
454246149Ssjg# this is known to work for NetBSD 1.6 and FreeBSD 4.2
455246149Ssjglib${LIB}.${LD_so}: ${SOLIB} ${DPADD}
456246149Ssjg	@echo building shared ${LIB} library \(version ${SHLIB_FULLVERSION}\)
457246149Ssjg	@rm -f ${.TARGET}
458246149Ssjg.if ${TARGET_OSNAME} == "NetBSD" || ${TARGET_OSNAME} == "FreeBSD"
459246149Ssjg.if ${OBJECT_FMT} == "ELF"
460246149Ssjg	${SHLIB_LD} -x -shared ${SHLIB_SHFLAGS} -o ${.TARGET} \
461246149Ssjg	    ${SHLIB_LDSTARTFILE} \
462246149Ssjg	    --whole-archive ${SOLIB} --no-whole-archive ${SHLIB_LDADD} \
463246149Ssjg	    ${SHLIB_LDENDFILE}
464246149Ssjg.else
465246149Ssjg	${SHLIB_LD} ${LD_x} ${LD_shared} \
466246149Ssjg	    -o ${.TARGET} ${SOLIB} ${SHLIB_LDADD}
467246149Ssjg.endif
468246149Ssjg.else
469246149Ssjg	${SHLIB_LD} -o ${.TARGET} ${LD_shared} ${LD_solib} ${DLLIB} ${SHLIB_LDADD}
470246149Ssjg.endif
471246149Ssjg.endif
472246149Ssjg.if !empty(SHLIB_LINKS)
473246149Ssjg	rm -f ${SHLIB_LINKS}; ${SHLIB_LINKS:O:u:@x@ln -s ${.TARGET} $x;@}
474246149Ssjg.endif
475246149Ssjg
476246149SsjgLOBJS+=	${LSRCS:.c=.ln} ${SRCS:M*.c:.c=.ln}
477246149Ssjg.NOPATH:	${LOBJS}
478246149SsjgLLIBS?=	-lc
479246149Ssjgllib-l${LIB}.ln: ${LOBJS}
480246149Ssjg	@echo building llib-l${LIB}.ln
481246149Ssjg	@rm -f llib-l${LIB}.ln
482246149Ssjg	@${LINT} -C${LIB} ${LOBJS} ${LLIBS}
483246149Ssjg
484246149Ssjg.if !target(clean)
485246149Ssjgcleanlib: .PHONY
486246149Ssjg	rm -f a.out [Ee]rrs mklog core *.core ${CLEANFILES}
487246149Ssjg	rm -f lib${LIB}.a ${OBJS}
488246149Ssjg	rm -f lib${LIB}_p.a ${POBJS}
489246149Ssjg	rm -f lib${LIB}_pic.a lib${LIB}.so.*.* ${SOBJS}
490246149Ssjg	rm -f llib-l${LIB}.ln ${LOBJS}
491246149Ssjg.if !empty(SHLIB_LINKS)
492246149Ssjg	rm -f ${SHLIB_LINKS}
493246149Ssjg.endif
494246149Ssjg
495246149Ssjgclean: _SUBDIRUSE cleanlib
496246149Ssjgcleandir: _SUBDIRUSE cleanlib
497246149Ssjg.else
498246149Ssjgcleandir: _SUBDIRUSE clean
499246149Ssjg.endif
500246149Ssjg
501246149Ssjg.if defined(SRCS) && (!defined(MKDEP) || ${MKDEP} != autodep)
502246149Ssjgafterdepend: .depend
503246149Ssjg	@(TMP=/tmp/_depend$$$$; \
504246149Ssjg	    sed -e 's/^\([^\.]*\).o[ ]*:/\1.o \1.po \1.so \1.ln:/' \
505246149Ssjg	      < .depend > $$TMP; \
506246149Ssjg	    mv $$TMP .depend)
507246149Ssjg.endif
508246149Ssjg
509246149Ssjg.if !target(install)
510246149Ssjg.if !target(beforeinstall)
511246149Ssjgbeforeinstall:
512246149Ssjg.endif
513246149Ssjg
514246149Ssjg.if !empty(LIBOWN)
515246149SsjgLIB_INSTALL_OWN ?= -o ${LIBOWN} -g ${LIBGRP}
516246149Ssjg.endif
517246149Ssjg
518246149Ssjg.include <links.mk>
519246149Ssjg
520246149Ssjg.if !target(realinstall)
521246149Ssjgrealinstall: libinstall
522246149Ssjg.endif
523246149Ssjg.if !target(libinstall)
524246149Ssjglibinstall:
525246149Ssjg	[ -d ${DESTDIR}/${LIBDIR} ] || \
526246149Ssjg	${INSTALL} -d ${LIB_INSTALL_OWN} -m 775 ${DESTDIR}${LIBDIR}
527246149Ssjg.if ${MK_ARCHIVE} != "no"
528246149Ssjg	${INSTALL} ${COPY} ${LIB_INSTALL_OWN} -m 600 lib${LIB}.a \
529246149Ssjg	    ${DESTDIR}${LIBDIR}
530246149Ssjg	${RANLIB} ${DESTDIR}${LIBDIR}/lib${LIB}.a
531246149Ssjg	chmod ${LIBMODE} ${DESTDIR}${LIBDIR}/lib${LIB}.a
532246149Ssjg.endif
533246149Ssjg.if ${MK_PROFILE} != "no"
534246149Ssjg	${INSTALL} ${COPY} ${LIB_INSTALL_OWN} -m 600 \
535246149Ssjg	    lib${LIB}_p.a ${DESTDIR}${LIBDIR}
536246149Ssjg	${RANLIB} ${DESTDIR}${LIBDIR}/lib${LIB}_p.a
537246149Ssjg	chmod ${LIBMODE} ${DESTDIR}${LIBDIR}/lib${LIB}_p.a
538246149Ssjg.endif
539246149Ssjg.if ${MK_PIC} != "no"
540246149Ssjg.if ${MK_PICLIB} != "no"
541246149Ssjg	${INSTALL} ${COPY} ${LIB_INSTALL_OWN} -m 600 \
542246149Ssjg	    lib${LIB}_pic.a ${DESTDIR}${LIBDIR}
543246149Ssjg	${RANLIB} ${DESTDIR}${LIBDIR}/lib${LIB}_pic.a
544246149Ssjg	chmod ${LIBMODE} ${DESTDIR}${LIBDIR}/lib${LIB}_pic.a
545246149Ssjg.endif
546246149Ssjg.if !empty(SHLIB_MAJOR)
547246149Ssjg	${INSTALL} ${COPY} ${LIB_INSTALL_OWN} -m ${LIBMODE} \
548246149Ssjg	    lib${LIB}.${LD_so} ${DESTDIR}${LIBDIR}
549246149Ssjg.if !empty(SHLIB_LINKS)
550246149Ssjg	(cd ${DESTDIR}${LIBDIR} && { rm -f ${SHLIB_LINKS}; ${SHLIB_LINKS:O:u:@x@ln -s lib${LIB}.${LD_so} $x;@} })
551246149Ssjg.endif
552246149Ssjg.endif
553246149Ssjg.endif
554246149Ssjg.if ${MK_LINT} != "no" && ${MK_LINKLIB} != "no" && !empty(LOBJS)
555246149Ssjg	${INSTALL} ${COPY} ${LIB_INSTALL_OWN} -m ${LIBMODE} \
556246149Ssjg	    llib-l${LIB}.ln ${DESTDIR}${LINTLIBDIR}
557246149Ssjg.endif
558246149Ssjg.if defined(LINKS) && !empty(LINKS)
559246149Ssjg	@set ${LINKS}; ${_LINKS_SCRIPT}
560246149Ssjg.endif
561246149Ssjg.endif
562246149Ssjg
563246149Ssjginstall: maninstall _SUBDIRUSE
564246149Ssjgmaninstall: afterinstall
565246149Ssjgafterinstall: realinstall
566246149Ssjgrealinstall: beforeinstall
567246149Ssjg.endif
568246149Ssjg
569246149Ssjg.if ${MK_MAN} != "no"
570246149Ssjg.include <man.mk>
571246149Ssjg.endif
572246149Ssjg
573246149Ssjg.if ${MK_NLS} != "no"
574246149Ssjg.include <nls.mk>
575246149Ssjg.endif
576246149Ssjg
577246149Ssjg.include <obj.mk>
578246149Ssjg.include <inc.mk>
579246149Ssjg.include <dep.mk>
580246149Ssjg.include <subdir.mk>
581246149Ssjg.endif
582246149Ssjg
583246149Ssjg# during building we usually need/want to install libs somewhere central
584246149Ssjg# note that we do NOT ch{own,grp} as that would likely fail at this point.
585246149Ssjg# otherwise it is the same as realinstall
586246149Ssjg# Note that we don't need this when using dpadd.mk
587246149Ssjg.libinstall:	${_LIBS}
588246149Ssjg	test -d ${DESTDIR}${LIBDIR} || ${INSTALL} -d -m775 ${DESTDIR}${LIBDIR}
589246149Ssjg.for _lib in ${_LIBS:M*.a}
590246149Ssjg	${INSTALL} ${COPY} -m 644 ${_lib} ${DESTDIR}${LIBDIR}
591246149Ssjg	${RANLIB} ${DESTDIR}${LIBDIR}/${_lib}
592246149Ssjg.endfor
593246149Ssjg.for _lib in ${_LIBS:M*.${LD_solink}*:O:u}
594246149Ssjg	${INSTALL} ${COPY} -m ${LIBMODE} ${_lib} ${DESTDIR}${LIBDIR}
595246149Ssjg.if !empty(SHLIB_LINKS)
596246149Ssjg	(cd ${DESTDIR}${LIBDIR} && { ${SHLIB_LINKS:O:u:@x@ln -sf ${_lib} $x;@}; })
597246149Ssjg.endif
598246149Ssjg.endfor
599246149Ssjg	@touch ${.TARGET}
600246149Ssjg
601246149Ssjg.include <final.mk>
602246149Ssjg.endif
603