lib.mk revision 246149
1246149Ssjg# $Id: lib.mk,v 1.48 2012/11/12 04:08:18 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
149246149SsjgCC_PG?=-pg
150246149SsjgCC_PIC?=-DPIC
151246149Ssjg
152246149SsjgLD_X?=-X
153246149SsjgLD_x?=-x
154246149SsjgLD_r?=-r
155246149Ssjg
156246149Ssjg# Non BSD machines will be using bmake.
157246149Ssjg.if ${TARGET_OSNAME} == "SunOS"
158246149SsjgLD_shared=-assert pure-text
159246149Ssjg.if ${OBJECT_FMT} == "ELF" || ${MACHINE} == "solaris"
160246149Ssjg# Solaris
161246149SsjgLD_shared=-h lib${LIB}.so.${SHLIB_MAJOR} -G
162246149Ssjg.endif
163246149Ssjg.elif ${TARGET_OSNAME} == "HP-UX"
164246149SsjgLD_shared=-b
165246149SsjgLD_so=sl
166246149SsjgDLLIB=
167246149Ssjg# HPsUX lorder does not grok anything but .o
168246149SsjgLD_sobjs=`${LORDER} ${OBJS} | ${TSORT} | sed 's,\.o,.so,'`
169246149SsjgLD_pobjs=`${LORDER} ${OBJS} | ${TSORT} | sed 's,\.o,.po,'`
170246149Ssjg.elif ${TARGET_OSNAME} == "OSF1"
171246149SsjgLD_shared= -msym -shared -expect_unresolved '*'
172246149SsjgLD_solib= -all lib${LIB}_pic.a
173246149SsjgDLLIB=
174246149Ssjg# lorder does not grok anything but .o
175246149SsjgLD_sobjs=`${LORDER} ${OBJS} | ${TSORT} | sed 's,\.o,.so,'`
176246149SsjgLD_pobjs=`${LORDER} ${OBJS} | ${TSORT} | sed 's,\.o,.po,'`
177246149SsjgAR_cq= -cqs
178246149Ssjg.elif ${TARGET_OSNAME} == "FreeBSD"
179246149SsjgLD_solib= lib${LIB}_pic.a
180246149Ssjg.elif ${TARGET_OSNAME} == "Linux"
181246149Ssjg# this is ambiguous of course
182246149SsjgLD_shared=-shared -h lib${LIB}.so.${SHLIB_MAJOR}
183246149SsjgLD_solib= --whole-archive lib${LIB}_pic.a
184246149Ssjg# Linux uses GNU ld, which is a multi-pass linker
185246149Ssjg# so we don't need to use lorder or tsort
186246149SsjgLD_objs = ${OBJS}
187246149SsjgLD_pobjs = ${POBJS}
188246149SsjgLD_sobjs = ${SOBJS}
189246149Ssjg.elif ${TARGET_OSNAME} == "Darwin"
190246149SsjgSHLIB_LD = ${CC}
191246149SsjgSHLIB_INSTALL_VERSION ?= ${SHLIB_MAJOR}
192246149SsjgSHLIB_COMPATABILITY_VERSION ?= ${SHLIB_MAJOR}.${SHLIB_MINOR:U0}
193246149SsjgSHLIB_COMPATABILITY ?= \
194246149Ssjg	-compatibility_version ${SHLIB_COMPATABILITY_VERSION} \
195246149Ssjg	-current_version ${SHLIB_FULLVERSION}
196246149SsjgLD_shared = -dynamiclib \
197246149Ssjg	-flat_namespace -undefined suppress \
198246149Ssjg	-install_name ${LIBDIR}/lib${LIB}.${SHLIB_INSTALL_VERSION}.${LD_solink} \
199246149Ssjg	${SHLIB_COMPATABILITY}
200246149SsjgSHLIB_LINKS =
201246149Ssjg.for v in ${SHLIB_COMPATABILITY_VERSION} ${SHLIB_INSTALL_VERSION}
202246149Ssjg.if "$v" != "${SHLIB_FULLVERSION}"
203246149SsjgSHLIB_LINKS += lib${LIB}.$v.${LD_solink}
204246149Ssjg.endif
205246149Ssjg.endfor
206246149Ssjg.if ${MK_LINKLIB} != "no"
207246149SsjgSHLIB_LINKS += lib${LIB}.${LD_solink}
208246149Ssjg.endif
209246149Ssjg
210246149SsjgLD_so = ${SHLIB_FULLVERSION}.dylib
211246149SsjgLD_sobjs = ${SOBJS:O:u}
212246149SsjgLD_solib = ${LD_sobjs}
213246149SsjgSOLIB = ${LD_sobjs}
214246149SsjgLD_solink = dylib
215246149Ssjg.if ${MACHINE_ARCH} == "i386"
216246149SsjgPICFLAG ?= -fPIC
217246149Ssjg.else
218246149SsjgPICFLAG ?= -fPIC -fno-common
219246149Ssjg.endif
220246149SsjgRANLIB = :
221246149Ssjg.endif
222246149Ssjg
223246149SsjgSHLIB_LD ?= ${LD}
224246149Ssjg
225246149Ssjg.if !empty(SHLIB_MAJOR)
226246149Ssjg.if ${NEED_SOLINKS} && empty(SHLIB_LINKS)
227246149Ssjg.if ${MK_LINKLIB} != "no"
228246149SsjgSHLIB_LINKS = lib${LIB}.${LD_solink}
229246149Ssjg.endif
230246149Ssjg.if "${SHLIB_FULLVERSION}" != "${SHLIB_MAJOR}"
231246149SsjgSHLIB_LINKS += lib${LIB}.${LD_solink}.${SHLIB_MAJOR}
232246149Ssjg.endif
233246149Ssjg.endif
234246149Ssjg.endif
235246149Ssjg
236246149SsjgLIBTOOL?=libtool
237246149SsjgLD_shared ?= -Bshareable -Bforcearchive
238246149SsjgLD_so ?= so.${SHLIB_FULLVERSION}
239246149SsjgLD_solink ?= so
240246149Ssjg.if empty(LORDER)
241246149SsjgLD_objs ?= ${OBJS}
242246149SsjgLD_pobjs ?= ${POBJS}
243246149SsjgLD_sobjs ?= ${SOBJS}
244246149Ssjg.else
245246149SsjgLD_objs ?= `${LORDER} ${OBJS} | ${TSORT}`
246246149SsjgLD_sobjs ?= `${LORDER} ${SOBJS} | ${TSORT}`
247246149SsjgLD_pobjs ?= `${LORDER} ${POBJS} | ${TSORT}`
248246149Ssjg.endif
249246149SsjgLD_solib ?= ${LD_sobjs}
250246149SsjgAR_cq ?= cq
251246149Ssjg.if exists(/netbsd) && exists(${DESTDIR}/usr/lib/libdl.so)
252246149SsjgDLLIB ?= -ldl
253246149Ssjg.endif
254246149Ssjg
255246149Ssjg# some libs have lots of objects, and scanning all .o, .po and .So meta files
256246149Ssjg# is a waste of time, this tells meta.autodep.mk to just pick one 
257246149Ssjg# (typically .So)
258246149Ssjg# yes, 42 is a random number.
259246149Ssjg.if ${MK_META_MODE} == "yes" && ${SRCS:Uno:[\#]} > 42
260246149SsjgOPTIMIZE_OBJECT_META_FILES ?= yes
261246149Ssjg.endif
262246149Ssjg
263246149Ssjg
264246149Ssjg.if ${MK_LIBTOOL} == "yes"
265246149Ssjg# because libtool is so facist about naming the object files,
266246149Ssjg# we cannot (yet) build profiled libs
267246149SsjgMK_PROFILE=no
268246149Ssjg_LIBS=lib${LIB}.a
269246149Ssjg.if exists(${.CURDIR}/shlib_version)
270246149SsjgSHLIB_AGE != . ${.CURDIR}/shlib_version ; echo $$age
271246149Ssjg.endif
272246149Ssjg.else
273246149Ssjg# for the normal .a we do not want to strip symbols
274246149Ssjg.c.o:
275246149Ssjg	${COMPILE.c} ${.IMPSRC}
276246149Ssjg
277246149Ssjg# for the normal .a we do not want to strip symbols
278246149Ssjg.cc.o .C.o:
279246149Ssjg	${COMPILE.cc} ${.IMPSRC}
280246149Ssjg
281246149Ssjg.S.o .s.o:
282246149Ssjg	@echo ${COMPILE.S} ${CFLAGS:M-[ID]*} ${AINC} ${.IMPSRC}
283246149Ssjg	@${COMPILE.S} ${CFLAGS:M-[ID]*} ${AINC} ${.IMPSRC} 
284246149Ssjg
285246149Ssjg.if (${LD_X} == "")
286246149Ssjg.c.po:
287246149Ssjg	${COMPILE.c} ${CC_PG} ${.IMPSRC} -o ${.TARGET}
288246149Ssjg
289246149Ssjg.cc.po .C.po:
290246149Ssjg	${COMPILE.cc} -pg ${.IMPSRC} -o ${.TARGET}
291246149Ssjg
292246149Ssjg.S.so .s.so:
293246149Ssjg	${COMPILE.S} ${PICFLAG} ${CC_PIC} ${CFLAGS:M-[ID]*} ${AINC} ${.IMPSRC} -o ${.TARGET}
294246149Ssjg.else
295246149Ssjg.c.po:
296246149Ssjg	@echo ${COMPILE.c} ${CC_PG} ${.IMPSRC} -o ${.TARGET}
297246149Ssjg	@${COMPILE.c} ${CC_PG} ${.IMPSRC} -o ${.TARGET}.o
298246149Ssjg	@${LD} ${LD_X} ${LD_r} ${.TARGET}.o -o ${.TARGET}
299246149Ssjg	@rm -f ${.TARGET}.o
300246149Ssjg
301246149Ssjg.cc.po .C.po:
302246149Ssjg	@echo ${COMPILE.cc} -pg ${.IMPSRC} -o ${.TARGET}
303246149Ssjg	@${COMPILE.cc} -pg ${.IMPSRC} -o ${.TARGET}.o
304246149Ssjg	@${LD} ${LD_X} ${LD_r} ${.TARGET}.o -o ${.TARGET}
305246149Ssjg	@rm -f ${.TARGET}.o
306246149Ssjg
307246149Ssjg.S.so .s.so:
308246149Ssjg	@echo ${COMPILE.S} ${PICFLAG} ${CC_PIC} ${CFLAGS:M-[ID]*} ${AINC} ${.IMPSRC} -o ${.TARGET}
309246149Ssjg	@${COMPILE.S} ${PICFLAG} ${CC_PIC} ${CFLAGS:M-[ID]*} ${AINC} ${.IMPSRC} -o ${.TARGET}.o
310246149Ssjg	@${LD} ${LD_x} ${LD_r} ${.TARGET}.o -o ${.TARGET}
311246149Ssjg	@rm -f ${.TARGET}.o
312246149Ssjg.endif
313246149Ssjg
314246149Ssjg.if (${LD_x} == "")
315246149Ssjg.c.so:
316246149Ssjg	${COMPILE.c} ${PICFLAG} ${CC_PIC} ${.IMPSRC} -o ${.TARGET}
317246149Ssjg
318246149Ssjg.cc.so .C.so:
319246149Ssjg	${COMPILE.cc} ${PICFLAG} ${CC_PIC} ${.IMPSRC} -o ${.TARGET}
320246149Ssjg
321246149Ssjg.S.po .s.po:
322246149Ssjg	${COMPILE.S} -DGPROF -DPROF ${CFLAGS:M-[ID]*} ${AINC} ${.IMPSRC} -o ${.TARGET}
323246149Ssjg.else
324246149Ssjg
325246149Ssjg.c.so:
326246149Ssjg	@echo ${COMPILE.c} ${PICFLAG} ${CC_PIC} ${.IMPSRC} -o ${.TARGET}
327246149Ssjg	@${COMPILE.c} ${PICFLAG} ${CC_PIC} ${.IMPSRC} -o ${.TARGET}.o
328246149Ssjg	@${LD} ${LD_x} ${LD_r} ${.TARGET}.o -o ${.TARGET}
329246149Ssjg	@rm -f ${.TARGET}.o
330246149Ssjg
331246149Ssjg.cc.so .C.so:
332246149Ssjg	@echo ${COMPILE.cc} ${PICFLAG} ${CC_PIC} ${.IMPSRC} -o ${.TARGET}
333246149Ssjg	@${COMPILE.cc} ${PICFLAG} ${CC_PIC} ${.IMPSRC} -o ${.TARGET}.o
334246149Ssjg	@${LD} ${LD_x} ${LD_r} ${.TARGET}.o -o ${.TARGET}
335246149Ssjg	@rm -f ${.TARGET}.o
336246149Ssjg
337246149Ssjg.S.po .s.po:
338246149Ssjg	@echo ${COMPILE.S} -DGPROF -DPROF ${CFLAGS:M-[ID]*} ${AINC} ${.IMPSRC} -o ${.TARGET}
339246149Ssjg	@${COMPILE.S} -DGPROF -DPROF ${CFLAGS:M-[ID]*} ${AINC} ${.IMPSRC} -o ${.TARGET}.o
340246149Ssjg	@${LD} ${LD_X} ${LD_r} ${.TARGET}.o -o ${.TARGET}
341246149Ssjg	@rm -f ${.TARGET}.o
342246149Ssjg
343246149Ssjg.endif
344246149Ssjg.endif
345246149Ssjg
346246149Ssjg.c.ln:
347246149Ssjg	${LINT} ${LINTFLAGS} ${CFLAGS:M-[IDU]*} -i ${.IMPSRC}
348246149Ssjg
349246149Ssjg.if ${MK_LIBTOOL} != "yes"
350246149Ssjg
351246149Ssjg.if !defined(PICFLAG)
352246149SsjgPICFLAG=-fpic
353246149Ssjg.endif
354246149Ssjg
355246149Ssjg_LIBS=
356246149Ssjg
357246149Ssjg.if ${MK_ARCHIVE} != "no"
358246149Ssjg_LIBS += lib${LIB}.a
359246149Ssjg.endif
360246149Ssjg
361246149Ssjg.if ${MK_PROFILE} != "no"
362246149Ssjg_LIBS+=lib${LIB}_p.a
363246149SsjgPOBJS+=${OBJS:.o=.po}
364246149Ssjg.endif
365246149Ssjg
366246149Ssjg.if ${MK_PIC} != "no"
367246149Ssjg.if ${MK_PICLIB} == "no"
368246149SsjgSOLIB ?= lib${LIB}.a
369246149Ssjg.else
370246149SsjgSOLIB=lib${LIB}_pic.a
371246149Ssjg_LIBS+=${SOLIB}
372246149Ssjg.endif
373246149Ssjg.if !empty(SHLIB_FULLVERSION)
374246149Ssjg_LIBS+=lib${LIB}.${LD_so}
375246149Ssjg.endif
376246149Ssjg.endif
377246149Ssjg
378246149Ssjg.if ${MK_LINT} != "no"
379246149Ssjg_LIBS+=llib-l${LIB}.ln
380246149Ssjg.endif
381246149Ssjg
382246149Ssjg# here is where you can define what LIB* are
383246149Ssjg.-include <libnames.mk>
384246149Ssjg.if ${MK_DPADD_MK} == "yes"
385246149Ssjg# lots of cool magic, but might not suit everyone.
386246149Ssjg.include <dpadd.mk>
387246149Ssjg.endif
388246149Ssjg
389246149Ssjg.if !defined(_SKIP_BUILD)
390246149Ssjgall: prebuild .WAIT ${_LIBS} 
391246149Ssjg# a hook for things that must be done early
392246149Ssjgprebuild:
393246149Ssjg.if !defined(.PARSEDIR)
394246149Ssjg# no-op is the best we can do if not bmake.
395246149Ssjg.WAIT:
396246149Ssjg.endif
397246149Ssjg.endif
398246149Ssjgall: _SUBDIRUSE
399246149Ssjg
400246149Ssjg.for s in ${SRCS:N*.h:M*/*}
401246149Ssjg${.o .so .po .lo:L:@o@${s:T:R}$o@}: $s
402246149Ssjg.endfor
403246149Ssjg
404246149SsjgOBJS+=	${SRCS:T:N*.h:R:S/$/.o/g}
405246149Ssjg.NOPATH:	${OBJS}
406246149Ssjg
407246149Ssjg.if ${MK_LIBTOOL} == "yes"
408246149Ssjg.if ${MK_PIC} == "no"
409246149SsjgLT_STATIC=-static
410246149Ssjg.else
411246149SsjgLT_STATIC=
412246149Ssjg.endif
413246149SsjgSHLIB_AGE?=0
414246149Ssjg
415246149Ssjg# .lo's are created as a side effect
416246149Ssjg.s.o .S.o .c.o:
417246149Ssjg	${LIBTOOL} --mode=compile ${CC} ${LT_STATIC} ${CFLAGS} ${CPPFLAGS} ${IMPFLAGS} -c ${.IMPSRC}
418246149Ssjg
419246149Ssjg# can't really do profiled libs with libtool - its too facist about
420246149Ssjg# naming the output...
421246149Ssjglib${LIB}.a:: ${OBJS}
422246149Ssjg	@rm -f ${.TARGET}
423246149Ssjg	${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}
424246149Ssjg	@ln .libs/${.TARGET} .
425246149Ssjg
426246149Ssjglib${LIB}.${LD_so}:: lib${LIB}.a
427246149Ssjg	@[ -s ${.TARGET}.${SHLIB_AGE} ] || { ln -s .libs/lib${LIB}.${LD_so}* . 2>/dev/null; : }
428246149Ssjg	@[ -s ${.TARGET} ] || ln -s ${.TARGET}.${SHLIB_AGE} ${.TARGET}
429246149Ssjg
430246149Ssjg.else  # MK_LIBTOOL=yes
431246149Ssjg
432246149Ssjglib${LIB}.a:: ${OBJS}
433246149Ssjg	@echo building standard ${LIB} library
434246149Ssjg	@rm -f ${.TARGET}
435246149Ssjg	@${AR} ${AR_cq} ${.TARGET} ${LD_objs}
436246149Ssjg	${RANLIB} ${.TARGET}
437246149Ssjg
438246149SsjgPOBJS+=	${OBJS:.o=.po}
439246149Ssjg.NOPATH:	${POBJS}
440246149Ssjglib${LIB}_p.a:: ${POBJS}
441246149Ssjg	@echo building profiled ${LIB} library
442246149Ssjg	@rm -f ${.TARGET}
443246149Ssjg	@${AR} ${AR_cq} ${.TARGET} ${LD_pobjs}
444246149Ssjg	${RANLIB} ${.TARGET}
445246149Ssjg
446246149SsjgSOBJS+=	${OBJS:.o=.so}
447246149Ssjg.NOPATH:	${SOBJS}
448246149Ssjglib${LIB}_pic.a:: ${SOBJS}
449246149Ssjg	@echo building shared object ${LIB} library
450246149Ssjg	@rm -f ${.TARGET}
451246149Ssjg	@${AR} ${AR_cq} ${.TARGET} ${LD_sobjs}
452246149Ssjg	${RANLIB} ${.TARGET}
453246149Ssjg
454246149Ssjg#SHLIB_LDADD?= ${LDADD}
455246149Ssjg
456246149Ssjg# bound to be non-portable...
457246149Ssjg# this is known to work for NetBSD 1.6 and FreeBSD 4.2
458246149Ssjglib${LIB}.${LD_so}: ${SOLIB} ${DPADD}
459246149Ssjg	@echo building shared ${LIB} library \(version ${SHLIB_FULLVERSION}\)
460246149Ssjg	@rm -f ${.TARGET}
461246149Ssjg.if ${TARGET_OSNAME} == "NetBSD" || ${TARGET_OSNAME} == "FreeBSD"
462246149Ssjg.if ${OBJECT_FMT} == "ELF"
463246149Ssjg	${SHLIB_LD} -x -shared ${SHLIB_SHFLAGS} -o ${.TARGET} \
464246149Ssjg	    ${SHLIB_LDSTARTFILE} \
465246149Ssjg	    --whole-archive ${SOLIB} --no-whole-archive ${SHLIB_LDADD} \
466246149Ssjg	    ${SHLIB_LDENDFILE}
467246149Ssjg.else
468246149Ssjg	${SHLIB_LD} ${LD_x} ${LD_shared} \
469246149Ssjg	    -o ${.TARGET} ${SOLIB} ${SHLIB_LDADD}
470246149Ssjg.endif
471246149Ssjg.else
472246149Ssjg	${SHLIB_LD} -o ${.TARGET} ${LD_shared} ${LD_solib} ${DLLIB} ${SHLIB_LDADD}
473246149Ssjg.endif
474246149Ssjg.endif
475246149Ssjg.if !empty(SHLIB_LINKS)
476246149Ssjg	rm -f ${SHLIB_LINKS}; ${SHLIB_LINKS:O:u:@x@ln -s ${.TARGET} $x;@}
477246149Ssjg.endif
478246149Ssjg
479246149SsjgLOBJS+=	${LSRCS:.c=.ln} ${SRCS:M*.c:.c=.ln}
480246149Ssjg.NOPATH:	${LOBJS}
481246149SsjgLLIBS?=	-lc
482246149Ssjgllib-l${LIB}.ln: ${LOBJS}
483246149Ssjg	@echo building llib-l${LIB}.ln
484246149Ssjg	@rm -f llib-l${LIB}.ln
485246149Ssjg	@${LINT} -C${LIB} ${LOBJS} ${LLIBS}
486246149Ssjg
487246149Ssjg.if !target(clean)
488246149Ssjgcleanlib: .PHONY
489246149Ssjg	rm -f a.out [Ee]rrs mklog core *.core ${CLEANFILES}
490246149Ssjg	rm -f lib${LIB}.a ${OBJS}
491246149Ssjg	rm -f lib${LIB}_p.a ${POBJS}
492246149Ssjg	rm -f lib${LIB}_pic.a lib${LIB}.so.*.* ${SOBJS}
493246149Ssjg	rm -f llib-l${LIB}.ln ${LOBJS}
494246149Ssjg.if !empty(SHLIB_LINKS)
495246149Ssjg	rm -f ${SHLIB_LINKS}
496246149Ssjg.endif
497246149Ssjg
498246149Ssjgclean: _SUBDIRUSE cleanlib
499246149Ssjgcleandir: _SUBDIRUSE cleanlib
500246149Ssjg.else
501246149Ssjgcleandir: _SUBDIRUSE clean
502246149Ssjg.endif
503246149Ssjg
504246149Ssjg.if defined(SRCS) && (!defined(MKDEP) || ${MKDEP} != autodep)
505246149Ssjgafterdepend: .depend
506246149Ssjg	@(TMP=/tmp/_depend$$$$; \
507246149Ssjg	    sed -e 's/^\([^\.]*\).o[ ]*:/\1.o \1.po \1.so \1.ln:/' \
508246149Ssjg	      < .depend > $$TMP; \
509246149Ssjg	    mv $$TMP .depend)
510246149Ssjg.endif
511246149Ssjg
512246149Ssjg.if !target(install)
513246149Ssjg.if !target(beforeinstall)
514246149Ssjgbeforeinstall:
515246149Ssjg.endif
516246149Ssjg
517246149Ssjg.if !empty(LIBOWN)
518246149SsjgLIB_INSTALL_OWN ?= -o ${LIBOWN} -g ${LIBGRP}
519246149Ssjg.endif
520246149Ssjg
521246149Ssjg.include <links.mk>
522246149Ssjg
523246149Ssjg.if !target(realinstall)
524246149Ssjgrealinstall: libinstall
525246149Ssjg.endif
526246149Ssjg.if !target(libinstall)
527246149Ssjglibinstall:
528246149Ssjg	[ -d ${DESTDIR}/${LIBDIR} ] || \
529246149Ssjg	${INSTALL} -d ${LIB_INSTALL_OWN} -m 775 ${DESTDIR}${LIBDIR}
530246149Ssjg.if ${MK_ARCHIVE} != "no"
531246149Ssjg	${INSTALL} ${COPY} ${LIB_INSTALL_OWN} -m 600 lib${LIB}.a \
532246149Ssjg	    ${DESTDIR}${LIBDIR}
533246149Ssjg	${RANLIB} ${DESTDIR}${LIBDIR}/lib${LIB}.a
534246149Ssjg	chmod ${LIBMODE} ${DESTDIR}${LIBDIR}/lib${LIB}.a
535246149Ssjg.endif
536246149Ssjg.if ${MK_PROFILE} != "no"
537246149Ssjg	${INSTALL} ${COPY} ${LIB_INSTALL_OWN} -m 600 \
538246149Ssjg	    lib${LIB}_p.a ${DESTDIR}${LIBDIR}
539246149Ssjg	${RANLIB} ${DESTDIR}${LIBDIR}/lib${LIB}_p.a
540246149Ssjg	chmod ${LIBMODE} ${DESTDIR}${LIBDIR}/lib${LIB}_p.a
541246149Ssjg.endif
542246149Ssjg.if ${MK_PIC} != "no"
543246149Ssjg.if ${MK_PICLIB} != "no"
544246149Ssjg	${INSTALL} ${COPY} ${LIB_INSTALL_OWN} -m 600 \
545246149Ssjg	    lib${LIB}_pic.a ${DESTDIR}${LIBDIR}
546246149Ssjg	${RANLIB} ${DESTDIR}${LIBDIR}/lib${LIB}_pic.a
547246149Ssjg	chmod ${LIBMODE} ${DESTDIR}${LIBDIR}/lib${LIB}_pic.a
548246149Ssjg.endif
549246149Ssjg.if !empty(SHLIB_MAJOR)
550246149Ssjg	${INSTALL} ${COPY} ${LIB_INSTALL_OWN} -m ${LIBMODE} \
551246149Ssjg	    lib${LIB}.${LD_so} ${DESTDIR}${LIBDIR}
552246149Ssjg.if !empty(SHLIB_LINKS)
553246149Ssjg	(cd ${DESTDIR}${LIBDIR} && { rm -f ${SHLIB_LINKS}; ${SHLIB_LINKS:O:u:@x@ln -s lib${LIB}.${LD_so} $x;@} })
554246149Ssjg.endif
555246149Ssjg.endif
556246149Ssjg.endif
557246149Ssjg.if ${MK_LINT} != "no" && ${MK_LINKLIB} != "no" && !empty(LOBJS)
558246149Ssjg	${INSTALL} ${COPY} ${LIB_INSTALL_OWN} -m ${LIBMODE} \
559246149Ssjg	    llib-l${LIB}.ln ${DESTDIR}${LINTLIBDIR}
560246149Ssjg.endif
561246149Ssjg.if defined(LINKS) && !empty(LINKS)
562246149Ssjg	@set ${LINKS}; ${_LINKS_SCRIPT}
563246149Ssjg.endif
564246149Ssjg.endif
565246149Ssjg
566246149Ssjginstall: maninstall _SUBDIRUSE
567246149Ssjgmaninstall: afterinstall
568246149Ssjgafterinstall: realinstall
569246149Ssjgrealinstall: beforeinstall
570246149Ssjg.endif
571246149Ssjg
572246149Ssjg.if ${MK_MAN} != "no"
573246149Ssjg.include <man.mk>
574246149Ssjg.endif
575246149Ssjg
576246149Ssjg.if ${MK_NLS} != "no"
577246149Ssjg.include <nls.mk>
578246149Ssjg.endif
579246149Ssjg
580246149Ssjg.include <obj.mk>
581246149Ssjg.include <inc.mk>
582246149Ssjg.include <dep.mk>
583246149Ssjg.include <subdir.mk>
584246149Ssjg.endif
585246149Ssjg
586246149Ssjg# during building we usually need/want to install libs somewhere central
587246149Ssjg# note that we do NOT ch{own,grp} as that would likely fail at this point.
588246149Ssjg# otherwise it is the same as realinstall
589246149Ssjg# Note that we don't need this when using dpadd.mk
590246149Ssjg.libinstall:	${_LIBS}
591246149Ssjg	test -d ${DESTDIR}${LIBDIR} || ${INSTALL} -d -m775 ${DESTDIR}${LIBDIR}
592246149Ssjg.for _lib in ${_LIBS:M*.a}
593246149Ssjg	${INSTALL} ${COPY} -m 644 ${_lib} ${DESTDIR}${LIBDIR}
594246149Ssjg	${RANLIB} ${DESTDIR}${LIBDIR}/${_lib}
595246149Ssjg.endfor
596246149Ssjg.for _lib in ${_LIBS:M*.${LD_solink}*:O:u}
597246149Ssjg	${INSTALL} ${COPY} -m ${LIBMODE} ${_lib} ${DESTDIR}${LIBDIR}
598246149Ssjg.if !empty(SHLIB_LINKS)
599246149Ssjg	(cd ${DESTDIR}${LIBDIR} && { ${SHLIB_LINKS:O:u:@x@ln -sf ${_lib} $x;@}; })
600246149Ssjg.endif
601246149Ssjg.endfor
602246149Ssjg	@touch ${.TARGET}
603246149Ssjg
604246149Ssjg.include <final.mk>
605246149Ssjg.endif
606