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