1# $Id: lib.mk,v 1.49 2013/07/18 05:46:24 sjg Exp $
2
3.if !target(__${.PARSEFILE}__)
4__${.PARSEFILE}__:
5
6.include <init.mk>
7
8.if ${OBJECT_FMT} == "ELF"
9NEED_SOLINKS?= yes
10.endif
11
12.if exists(${.CURDIR}/shlib_version)
13SHLIB_MAJOR != . ${.CURDIR}/shlib_version ; echo $$major
14SHLIB_MINOR != . ${.CURDIR}/shlib_version ; echo $$minor
15.endif
16
17print-shlib-major:
18.if defined(SHLIB_MAJOR) && ${MK_PIC} != "no"
19	@echo ${SHLIB_MAJOR}
20.else
21	@false
22.endif
23
24print-shlib-minor:
25.if defined(SHLIB_MINOR) && ${MK_PIC} != "no"
26	@echo ${SHLIB_MINOR}
27.else
28	@false
29.endif
30
31print-shlib-teeny:
32.if defined(SHLIB_TEENY) && ${MK_PIC} != "no"
33	@echo ${SHLIB_TEENY}
34.else
35	@false
36.endif
37
38SHLIB_FULLVERSION ?= ${${SHLIB_MAJOR} ${SHLIB_MINOR} ${SHLIB_TEENY}:L:ts.}
39SHLIB_FULLVERSION := ${SHLIB_FULLVERSION}
40
41# add additional suffixes not exported.
42# .po is used for profiling object files.
43# .so is used for PIC object files.
44.SUFFIXES: .out .a .ln .so .po .o .s .S .c .cc .C .m .F .f .r .y .l .cl .p .h
45.SUFFIXES: .sh .m4 .m
46
47CFLAGS+=	${COPTS}
48
49# Derrived from NetBSD-1.6
50
51# Set PICFLAGS to cc flags for producing position-independent code,
52# if not already set.  Includes -DPIC, if required.
53
54# Data-driven table using make variables to control how shared libraries
55# are built for different platforms and object formats.
56# OBJECT_FMT:		currently either "ELF" or "a.out", from <bsd.own.mk>
57# SHLIB_SOVERSION:	version number to be compiled into a shared library
58#			via -soname. Usualy ${SHLIB_MAJOR} on ELF.
59#			NetBSD/pmax used to use ${SHLIB_MAJOR}[.${SHLIB_MINOR}
60#			[.${SHLIB_TEENY}]]
61# SHLIB_SHFLAGS:	Flags to tell ${LD} to emit shared library.
62#			with ELF, also set shared-lib version for ld.so.
63# SHLIB_LDSTARTFILE:	support .o file, call C++ file-level constructors
64# SHLIB_LDENDFILE:	support .o file, call C++ file-level destructors
65# FPICFLAGS:		flags for ${FC} to compile .[fF] files to .so objects.
66# CPPICFLAGS:		flags for ${CPP} to preprocess .[sS] files for ${AS}
67# CPICFLAGS:		flags for ${CC} to compile .[cC] files to .so objects.
68# CAPICFLAGS		flags for {$CC} to compiling .[Ss] files
69#		 	(usually just ${CPPPICFLAGS} ${CPICFLAGS})
70# APICFLAGS:		flags for ${AS} to assemble .[sS] to .so objects.
71
72.if ${TARGET_OSNAME} == "NetBSD"
73.if ${MACHINE_ARCH} == "alpha"
74		# Alpha-specific shared library flags
75FPICFLAGS ?= -fPIC
76CPICFLAGS ?= -fPIC -DPIC
77CPPPICFLAGS?= -DPIC 
78CAPICFLAGS?= ${CPPPICFLAGS} ${CPICFLAGS}
79APICFLAGS ?=
80.elif ${MACHINE_ARCH} == "mipsel" || ${MACHINE_ARCH} == "mipseb"
81		# mips-specific shared library flags
82
83# On mips, all libs are compiled with ABIcalls, not just sharedlibs.
84MKPICLIB= no
85
86# so turn shlib PIC flags on for ${AS}.
87AINC+=-DABICALLS
88AFLAGS+= -fPIC
89AS+=	-KPIC
90
91.elif ${MACHINE_ARCH} == "vax" && ${OBJECT_FMT} == "ELF"
92# On the VAX, all object are PIC by default, not just sharedlibs.
93MKPICLIB= no
94
95.elif (${MACHINE_ARCH} == "sparc" || ${MACHINE_ARCH} == "sparc64") && \
96       ${OBJECT_FMT} == "ELF"
97# If you use -fPIC you need to define BIGPIC to turn on 32-bit 
98# relocations in asm code
99FPICFLAGS ?= -fPIC
100CPICFLAGS ?= -fPIC -DPIC
101CPPPICFLAGS?= -DPIC -DBIGPIC
102CAPICFLAGS?= ${CPPPICFLAGS} ${CPICFLAGS}
103APICFLAGS ?= -KPIC
104
105.else
106
107# Platform-independent flags for NetBSD a.out shared libraries
108SHLIB_SOVERSION=${SHLIB_FULLVERSION}
109SHLIB_SHFLAGS=
110FPICFLAGS ?= -fPIC
111CPICFLAGS?= -fPIC -DPIC
112CPPPICFLAGS?= -DPIC 
113CAPICFLAGS?= ${CPPPICFLAGS} ${CPICFLAGS}
114APICFLAGS?= -k
115
116.endif
117
118# Platform-independent linker flags for ELF shared libraries
119.if ${OBJECT_FMT} == "ELF"
120SHLIB_SOVERSION=	${SHLIB_MAJOR}
121SHLIB_SHFLAGS=		-soname lib${LIB}.so.${SHLIB_SOVERSION}
122SHLIB_LDSTARTFILE?=	/usr/lib/crtbeginS.o
123SHLIB_LDENDFILE?=	/usr/lib/crtendS.o
124.endif
125
126# for compatability with the following
127CC_PIC?= ${CPICFLAGS}
128LD_shared=${SHLIB_SHFLAGS}
129
130.endif # NetBSD
131
132.if ${TARGET_OSNAME} == "FreeBSD"
133.if ${OBJECT_FMT} == "ELF"
134SHLIB_SOVERSION=	${SHLIB_MAJOR}
135SHLIB_SHFLAGS=		-soname lib${LIB}.so.${SHLIB_SOVERSION}
136.else
137SHLIB_SHFLAGS=		-assert pure-text
138.endif
139SHLIB_LDSTARTFILE=
140SHLIB_LDENDFILE=
141CC_PIC?= -fpic
142LD_shared=${SHLIB_SHFLAGS}
143
144.endif # FreeBSD
145
146MKPICLIB?= yes
147
148# sys.mk can override these
149LD_X?=-X
150LD_x?=-x
151LD_r?=-r
152
153# Non BSD machines will be using bmake.
154.if ${TARGET_OSNAME} == "SunOS"
155LD_shared=-assert pure-text
156.if ${OBJECT_FMT} == "ELF" || ${MACHINE} == "solaris"
157# Solaris
158LD_shared=-h lib${LIB}.so.${SHLIB_MAJOR} -G
159.endif
160.elif ${TARGET_OSNAME} == "HP-UX"
161LD_shared=-b
162LD_so=sl
163DLLIB=
164# HPsUX lorder does not grok anything but .o
165LD_sobjs=`${LORDER} ${OBJS} | ${TSORT} | sed 's,\.o,.so,'`
166LD_pobjs=`${LORDER} ${OBJS} | ${TSORT} | sed 's,\.o,.po,'`
167.elif ${TARGET_OSNAME} == "OSF1"
168LD_shared= -msym -shared -expect_unresolved '*'
169LD_solib= -all lib${LIB}_pic.a
170DLLIB=
171# lorder does not grok anything but .o
172LD_sobjs=`${LORDER} ${OBJS} | ${TSORT} | sed 's,\.o,.so,'`
173LD_pobjs=`${LORDER} ${OBJS} | ${TSORT} | sed 's,\.o,.po,'`
174AR_cq= -cqs
175.elif ${TARGET_OSNAME} == "FreeBSD"
176LD_solib= lib${LIB}_pic.a
177.elif ${TARGET_OSNAME} == "Linux"
178# this is ambiguous of course
179LD_shared=-shared -h lib${LIB}.so.${SHLIB_MAJOR}
180LD_solib= --whole-archive lib${LIB}_pic.a
181# Linux uses GNU ld, which is a multi-pass linker
182# so we don't need to use lorder or tsort
183LD_objs = ${OBJS}
184LD_pobjs = ${POBJS}
185LD_sobjs = ${SOBJS}
186.elif ${TARGET_OSNAME} == "Darwin"
187SHLIB_LD = ${CC}
188SHLIB_INSTALL_VERSION ?= ${SHLIB_MAJOR}
189SHLIB_COMPATABILITY_VERSION ?= ${SHLIB_MAJOR}.${SHLIB_MINOR:U0}
190SHLIB_COMPATABILITY ?= \
191	-compatibility_version ${SHLIB_COMPATABILITY_VERSION} \
192	-current_version ${SHLIB_FULLVERSION}
193LD_shared = -dynamiclib \
194	-flat_namespace -undefined suppress \
195	-install_name ${LIBDIR}/lib${LIB}.${SHLIB_INSTALL_VERSION}.${LD_solink} \
196	${SHLIB_COMPATABILITY}
197SHLIB_LINKS =
198.for v in ${SHLIB_COMPATABILITY_VERSION} ${SHLIB_INSTALL_VERSION}
199.if "$v" != "${SHLIB_FULLVERSION}"
200SHLIB_LINKS += lib${LIB}.$v.${LD_solink}
201.endif
202.endfor
203.if ${MK_LINKLIB} != "no"
204SHLIB_LINKS += lib${LIB}.${LD_solink}
205.endif
206
207LD_so = ${SHLIB_FULLVERSION}.dylib
208LD_sobjs = ${SOBJS:O:u}
209LD_solib = ${LD_sobjs}
210SOLIB = ${LD_sobjs}
211LD_solink = dylib
212.if ${MACHINE_ARCH} == "i386"
213PICFLAG ?= -fPIC
214.else
215PICFLAG ?= -fPIC -fno-common
216.endif
217RANLIB = :
218.endif
219
220SHLIB_LD ?= ${LD}
221
222.if !empty(SHLIB_MAJOR)
223.if ${NEED_SOLINKS} && empty(SHLIB_LINKS)
224.if ${MK_LINKLIB} != "no"
225SHLIB_LINKS = lib${LIB}.${LD_solink}
226.endif
227.if "${SHLIB_FULLVERSION}" != "${SHLIB_MAJOR}"
228SHLIB_LINKS += lib${LIB}.${LD_solink}.${SHLIB_MAJOR}
229.endif
230.endif
231.endif
232
233LIBTOOL?=libtool
234LD_shared ?= -Bshareable -Bforcearchive
235LD_so ?= so.${SHLIB_FULLVERSION}
236LD_solink ?= so
237.if empty(LORDER)
238LD_objs ?= ${OBJS}
239LD_pobjs ?= ${POBJS}
240LD_sobjs ?= ${SOBJS}
241.else
242LD_objs ?= `${LORDER} ${OBJS} | ${TSORT}`
243LD_sobjs ?= `${LORDER} ${SOBJS} | ${TSORT}`
244LD_pobjs ?= `${LORDER} ${POBJS} | ${TSORT}`
245.endif
246LD_solib ?= ${LD_sobjs}
247AR_cq ?= cq
248.if exists(/netbsd) && exists(${DESTDIR}/usr/lib/libdl.so)
249DLLIB ?= -ldl
250.endif
251
252# some libs have lots of objects, and scanning all .o, .po and .So meta files
253# is a waste of time, this tells meta.autodep.mk to just pick one 
254# (typically .So)
255# yes, 42 is a random number.
256.if ${MK_META_MODE} == "yes" && ${SRCS:Uno:[\#]} > 42
257OPTIMIZE_OBJECT_META_FILES ?= yes
258.endif
259
260
261.if ${MK_LIBTOOL} == "yes"
262# because libtool is so facist about naming the object files,
263# we cannot (yet) build profiled libs
264MK_PROFILE=no
265_LIBS=lib${LIB}.a
266.if exists(${.CURDIR}/shlib_version)
267SHLIB_AGE != . ${.CURDIR}/shlib_version ; echo $$age
268.endif
269.else
270# for the normal .a we do not want to strip symbols
271.c.o:
272	${COMPILE.c} ${.IMPSRC}
273
274# for the normal .a we do not want to strip symbols
275.cc.o .C.o:
276	${COMPILE.cc} ${.IMPSRC}
277
278.S.o .s.o:
279	@echo ${COMPILE.S} ${CFLAGS:M-[ID]*} ${AINC} ${.IMPSRC}
280	@${COMPILE.S} ${CFLAGS:M-[ID]*} ${AINC} ${.IMPSRC} 
281
282.if (${LD_X} == "")
283.c.po:
284	${COMPILE.c} ${CC_PG} ${PROFFLAGS} ${.IMPSRC} -o ${.TARGET}
285
286.cc.po .C.po:
287	${COMPILE.cc} -pg ${.IMPSRC} -o ${.TARGET}
288
289.S.so .s.so:
290	${COMPILE.S} ${PICFLAG} ${CC_PIC} ${CFLAGS:M-[ID]*} ${AINC} ${.IMPSRC} -o ${.TARGET}
291.else
292.c.po:
293	@echo ${COMPILE.c} ${CC_PG} ${PROFFLAGS} ${.IMPSRC} -o ${.TARGET}
294	@${COMPILE.c} ${CC_PG} ${PROFFLAGS} ${.IMPSRC} -o ${.TARGET}.o
295	@${LD} ${LD_X} ${LD_r} ${.TARGET}.o -o ${.TARGET}
296	@rm -f ${.TARGET}.o
297
298.cc.po .C.po:
299	@echo ${COMPILE.cc} ${CXX_PG} ${PROFFLAGS} ${.IMPSRC} -o ${.TARGET}
300	@${COMPILE.cc} ${CXX_PG} ${.IMPSRC} -o ${.TARGET}.o
301	@${LD} ${LD_X} ${LD_r} ${.TARGET}.o -o ${.TARGET}
302	@rm -f ${.TARGET}.o
303
304.S.so .s.so:
305	@echo ${COMPILE.S} ${PICFLAG} ${CC_PIC} ${CFLAGS:M-[ID]*} ${AINC} ${.IMPSRC} -o ${.TARGET}
306	@${COMPILE.S} ${PICFLAG} ${CC_PIC} ${CFLAGS:M-[ID]*} ${AINC} ${.IMPSRC} -o ${.TARGET}.o
307	@${LD} ${LD_x} ${LD_r} ${.TARGET}.o -o ${.TARGET}
308	@rm -f ${.TARGET}.o
309.endif
310
311.if (${LD_x} == "")
312.c.so:
313	${COMPILE.c} ${PICFLAG} ${CC_PIC} ${.IMPSRC} -o ${.TARGET}
314
315.cc.so .C.so:
316	${COMPILE.cc} ${PICFLAG} ${CC_PIC} ${.IMPSRC} -o ${.TARGET}
317
318.S.po .s.po:
319	${COMPILE.S} ${PROFFLAGS} ${CFLAGS:M-[ID]*} ${AINC} ${.IMPSRC} -o ${.TARGET}
320.else
321
322.c.so:
323	@echo ${COMPILE.c} ${PICFLAG} ${CC_PIC} ${.IMPSRC} -o ${.TARGET}
324	@${COMPILE.c} ${PICFLAG} ${CC_PIC} ${.IMPSRC} -o ${.TARGET}.o
325	@${LD} ${LD_x} ${LD_r} ${.TARGET}.o -o ${.TARGET}
326	@rm -f ${.TARGET}.o
327
328.cc.so .C.so:
329	@echo ${COMPILE.cc} ${PICFLAG} ${CC_PIC} ${.IMPSRC} -o ${.TARGET}
330	@${COMPILE.cc} ${PICFLAG} ${CC_PIC} ${.IMPSRC} -o ${.TARGET}.o
331	@${LD} ${LD_x} ${LD_r} ${.TARGET}.o -o ${.TARGET}
332	@rm -f ${.TARGET}.o
333
334.S.po .s.po:
335	@echo ${COMPILE.S} ${PROFFLAGS} ${CFLAGS:M-[ID]*} ${AINC} ${.IMPSRC} -o ${.TARGET}
336	@${COMPILE.S} ${PROFFLAGS} ${CFLAGS:M-[ID]*} ${AINC} ${.IMPSRC} -o ${.TARGET}.o
337	@${LD} ${LD_X} ${LD_r} ${.TARGET}.o -o ${.TARGET}
338	@rm -f ${.TARGET}.o
339
340.endif
341.endif
342
343.c.ln:
344	${LINT} ${LINTFLAGS} ${CFLAGS:M-[IDU]*} -i ${.IMPSRC}
345
346.if ${MK_LIBTOOL} != "yes"
347
348.if !defined(PICFLAG)
349PICFLAG=-fpic
350.endif
351
352_LIBS=
353
354.if ${MK_ARCHIVE} != "no"
355_LIBS += lib${LIB}.a
356.endif
357
358.if ${MK_PROFILE} != "no"
359_LIBS+=lib${LIB}_p.a
360POBJS+=${OBJS:.o=.po}
361.endif
362
363.if ${MK_PIC} != "no"
364.if ${MK_PICLIB} == "no"
365SOLIB ?= lib${LIB}.a
366.else
367SOLIB=lib${LIB}_pic.a
368_LIBS+=${SOLIB}
369.endif
370.if !empty(SHLIB_FULLVERSION)
371_LIBS+=lib${LIB}.${LD_so}
372.endif
373.endif
374
375.if ${MK_LINT} != "no"
376_LIBS+=llib-l${LIB}.ln
377.endif
378
379# here is where you can define what LIB* are
380.-include <libnames.mk>
381.if ${MK_DPADD_MK} == "yes"
382# lots of cool magic, but might not suit everyone.
383.include <dpadd.mk>
384.endif
385
386.if !defined(_SKIP_BUILD)
387all: prebuild .WAIT ${_LIBS} 
388# a hook for things that must be done early
389prebuild:
390.if !defined(.PARSEDIR)
391# no-op is the best we can do if not bmake.
392.WAIT:
393.endif
394.endif
395all: _SUBDIRUSE
396
397.for s in ${SRCS:N*.h:M*/*}
398${.o .so .po .lo:L:@o@${s:T:R}$o@}: $s
399.endfor
400
401OBJS+=	${SRCS:T:N*.h:R:S/$/.o/g}
402.NOPATH:	${OBJS}
403
404.if ${MK_LIBTOOL} == "yes"
405.if ${MK_PIC} == "no"
406LT_STATIC=-static
407.else
408LT_STATIC=
409.endif
410SHLIB_AGE?=0
411
412# .lo's are created as a side effect
413.s.o .S.o .c.o:
414	${LIBTOOL} --mode=compile ${CC} ${LT_STATIC} ${CFLAGS} ${CPPFLAGS} ${IMPFLAGS} -c ${.IMPSRC}
415
416# can't really do profiled libs with libtool - its too facist about
417# naming the output...
418lib${LIB}.a:: ${OBJS}
419	@rm -f ${.TARGET}
420	${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}
421	@ln .libs/${.TARGET} .
422
423lib${LIB}.${LD_so}:: lib${LIB}.a
424	@[ -s ${.TARGET}.${SHLIB_AGE} ] || { ln -s .libs/lib${LIB}.${LD_so}* . 2>/dev/null; : }
425	@[ -s ${.TARGET} ] || ln -s ${.TARGET}.${SHLIB_AGE} ${.TARGET}
426
427.else  # MK_LIBTOOL=yes
428
429lib${LIB}.a:: ${OBJS}
430	@echo building standard ${LIB} library
431	@rm -f ${.TARGET}
432	@${AR} ${AR_cq} ${.TARGET} ${LD_objs}
433	${RANLIB} ${.TARGET}
434
435POBJS+=	${OBJS:.o=.po}
436.NOPATH:	${POBJS}
437lib${LIB}_p.a:: ${POBJS}
438	@echo building profiled ${LIB} library
439	@rm -f ${.TARGET}
440	@${AR} ${AR_cq} ${.TARGET} ${LD_pobjs}
441	${RANLIB} ${.TARGET}
442
443SOBJS+=	${OBJS:.o=.so}
444.NOPATH:	${SOBJS}
445lib${LIB}_pic.a:: ${SOBJS}
446	@echo building shared object ${LIB} library
447	@rm -f ${.TARGET}
448	@${AR} ${AR_cq} ${.TARGET} ${LD_sobjs}
449	${RANLIB} ${.TARGET}
450
451#SHLIB_LDADD?= ${LDADD}
452
453# bound to be non-portable...
454# this is known to work for NetBSD 1.6 and FreeBSD 4.2
455lib${LIB}.${LD_so}: ${SOLIB} ${DPADD}
456	@echo building shared ${LIB} library \(version ${SHLIB_FULLVERSION}\)
457	@rm -f ${.TARGET}
458.if ${TARGET_OSNAME} == "NetBSD" || ${TARGET_OSNAME} == "FreeBSD"
459.if ${OBJECT_FMT} == "ELF"
460	${SHLIB_LD} -x -shared ${SHLIB_SHFLAGS} -o ${.TARGET} \
461	    ${SHLIB_LDSTARTFILE} \
462	    --whole-archive ${SOLIB} --no-whole-archive ${SHLIB_LDADD} \
463	    ${SHLIB_LDENDFILE}
464.else
465	${SHLIB_LD} ${LD_x} ${LD_shared} \
466	    -o ${.TARGET} ${SOLIB} ${SHLIB_LDADD}
467.endif
468.else
469	${SHLIB_LD} -o ${.TARGET} ${LD_shared} ${LD_solib} ${DLLIB} ${SHLIB_LDADD}
470.endif
471.endif
472.if !empty(SHLIB_LINKS)
473	rm -f ${SHLIB_LINKS}; ${SHLIB_LINKS:O:u:@x@ln -s ${.TARGET} $x;@}
474.endif
475
476LOBJS+=	${LSRCS:.c=.ln} ${SRCS:M*.c:.c=.ln}
477.NOPATH:	${LOBJS}
478LLIBS?=	-lc
479llib-l${LIB}.ln: ${LOBJS}
480	@echo building llib-l${LIB}.ln
481	@rm -f llib-l${LIB}.ln
482	@${LINT} -C${LIB} ${LOBJS} ${LLIBS}
483
484.if !target(clean)
485cleanlib: .PHONY
486	rm -f a.out [Ee]rrs mklog core *.core ${CLEANFILES}
487	rm -f lib${LIB}.a ${OBJS}
488	rm -f lib${LIB}_p.a ${POBJS}
489	rm -f lib${LIB}_pic.a lib${LIB}.so.*.* ${SOBJS}
490	rm -f llib-l${LIB}.ln ${LOBJS}
491.if !empty(SHLIB_LINKS)
492	rm -f ${SHLIB_LINKS}
493.endif
494
495clean: _SUBDIRUSE cleanlib
496cleandir: _SUBDIRUSE cleanlib
497.else
498cleandir: _SUBDIRUSE clean
499.endif
500
501.if defined(SRCS) && (!defined(MKDEP) || ${MKDEP} != autodep)
502afterdepend: .depend
503	@(TMP=/tmp/_depend$$$$; \
504	    sed -e 's/^\([^\.]*\).o[ ]*:/\1.o \1.po \1.so \1.ln:/' \
505	      < .depend > $$TMP; \
506	    mv $$TMP .depend)
507.endif
508
509.if !target(install)
510.if !target(beforeinstall)
511beforeinstall:
512.endif
513
514.if !empty(LIBOWN)
515LIB_INSTALL_OWN ?= -o ${LIBOWN} -g ${LIBGRP}
516.endif
517
518.include <links.mk>
519
520.if !target(realinstall)
521realinstall: libinstall
522.endif
523.if !target(libinstall)
524libinstall:
525	[ -d ${DESTDIR}/${LIBDIR} ] || \
526	${INSTALL} -d ${LIB_INSTALL_OWN} -m 775 ${DESTDIR}${LIBDIR}
527.if ${MK_ARCHIVE} != "no"
528	${INSTALL} ${COPY} ${LIB_INSTALL_OWN} -m 600 lib${LIB}.a \
529	    ${DESTDIR}${LIBDIR}
530	${RANLIB} ${DESTDIR}${LIBDIR}/lib${LIB}.a
531	chmod ${LIBMODE} ${DESTDIR}${LIBDIR}/lib${LIB}.a
532.endif
533.if ${MK_PROFILE} != "no"
534	${INSTALL} ${COPY} ${LIB_INSTALL_OWN} -m 600 \
535	    lib${LIB}_p.a ${DESTDIR}${LIBDIR}
536	${RANLIB} ${DESTDIR}${LIBDIR}/lib${LIB}_p.a
537	chmod ${LIBMODE} ${DESTDIR}${LIBDIR}/lib${LIB}_p.a
538.endif
539.if ${MK_PIC} != "no"
540.if ${MK_PICLIB} != "no"
541	${INSTALL} ${COPY} ${LIB_INSTALL_OWN} -m 600 \
542	    lib${LIB}_pic.a ${DESTDIR}${LIBDIR}
543	${RANLIB} ${DESTDIR}${LIBDIR}/lib${LIB}_pic.a
544	chmod ${LIBMODE} ${DESTDIR}${LIBDIR}/lib${LIB}_pic.a
545.endif
546.if !empty(SHLIB_MAJOR)
547	${INSTALL} ${COPY} ${LIB_INSTALL_OWN} -m ${LIBMODE} \
548	    lib${LIB}.${LD_so} ${DESTDIR}${LIBDIR}
549.if !empty(SHLIB_LINKS)
550	(cd ${DESTDIR}${LIBDIR} && { rm -f ${SHLIB_LINKS}; ${SHLIB_LINKS:O:u:@x@ln -s lib${LIB}.${LD_so} $x;@} })
551.endif
552.endif
553.endif
554.if ${MK_LINT} != "no" && ${MK_LINKLIB} != "no" && !empty(LOBJS)
555	${INSTALL} ${COPY} ${LIB_INSTALL_OWN} -m ${LIBMODE} \
556	    llib-l${LIB}.ln ${DESTDIR}${LINTLIBDIR}
557.endif
558.if defined(LINKS) && !empty(LINKS)
559	@set ${LINKS}; ${_LINKS_SCRIPT}
560.endif
561.endif
562
563install: maninstall _SUBDIRUSE
564maninstall: afterinstall
565afterinstall: realinstall
566realinstall: beforeinstall
567.endif
568
569.if ${MK_MAN} != "no"
570.include <man.mk>
571.endif
572
573.if ${MK_NLS} != "no"
574.include <nls.mk>
575.endif
576
577.include <obj.mk>
578.include <inc.mk>
579.include <dep.mk>
580.include <subdir.mk>
581.endif
582
583# during building we usually need/want to install libs somewhere central
584# note that we do NOT ch{own,grp} as that would likely fail at this point.
585# otherwise it is the same as realinstall
586# Note that we don't need this when using dpadd.mk
587.libinstall:	${_LIBS}
588	test -d ${DESTDIR}${LIBDIR} || ${INSTALL} -d -m775 ${DESTDIR}${LIBDIR}
589.for _lib in ${_LIBS:M*.a}
590	${INSTALL} ${COPY} -m 644 ${_lib} ${DESTDIR}${LIBDIR}
591	${RANLIB} ${DESTDIR}${LIBDIR}/${_lib}
592.endfor
593.for _lib in ${_LIBS:M*.${LD_solink}*:O:u}
594	${INSTALL} ${COPY} -m ${LIBMODE} ${_lib} ${DESTDIR}${LIBDIR}
595.if !empty(SHLIB_LINKS)
596	(cd ${DESTDIR}${LIBDIR} && { ${SHLIB_LINKS:O:u:@x@ln -sf ${_lib} $x;@}; })
597.endif
598.endfor
599	@touch ${.TARGET}
600
601.include <final.mk>
602.endif
603