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