xref: /freebsd/contrib/bmake/mk/lib.mk (revision bdd1243d)
1# $Id: lib.mk,v 1.74 2023/04/20 23:45:56 sjg Exp $
2
3.if !target(__${.PARSEFILE}__)
4__${.PARSEFILE}__: .NOTMAIN
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,-soname,lib${LIB}.so.${SHLIB_MAJOR}
174LD_solib= -Wl,--whole-archive lib${LIB}_pic.a -Wl,--no-whole-archive
175.if ${COMPILER_TYPE} == "gcc"
176# Linux uses GNU ld, which is a multi-pass linker
177# so we don't need to use lorder or tsort
178LD_objs = ${OBJS}
179LD_pobjs = ${POBJS}
180LD_sobjs = ${SOBJS}
181.endif
182.elif ${TARGET_OSNAME} == "Darwin"
183SHLIB_LD = ${CC}
184SHLIB_INSTALL_VERSION ?= ${SHLIB_MAJOR}
185SHLIB_COMPATABILITY_VERSION ?= ${SHLIB_MAJOR}.${SHLIB_MINOR:U0}
186SHLIB_COMPATABILITY ?= \
187	-compatibility_version ${SHLIB_COMPATABILITY_VERSION} \
188	-current_version ${SHLIB_FULLVERSION}
189LD_shared = -dynamiclib \
190	-flat_namespace -undefined suppress \
191	-install_name ${LIBDIR}/lib${LIB}.${SHLIB_INSTALL_VERSION}.${LD_solink} \
192	${SHLIB_COMPATABILITY}
193SHLIB_LINKS =
194.for v in ${SHLIB_COMPATABILITY_VERSION} ${SHLIB_INSTALL_VERSION}
195.if "$v" != "${SHLIB_FULLVERSION}"
196SHLIB_LINKS += lib${LIB}.$v.${LD_solink}
197.endif
198.endfor
199.if ${MK_LINKLIB} != "no"
200SHLIB_LINKS += lib${LIB}.${LD_solink}
201.endif
202
203LD_so = ${SHLIB_FULLVERSION}.dylib
204LD_sobjs = ${SOBJS:O:u}
205LD_solib = ${LD_sobjs}
206SOLIB = ${LD_sobjs}
207LD_solink = dylib
208.if ${MACHINE_ARCH} == "i386"
209PICFLAG ?= -fPIC
210.else
211PICFLAG ?= -fPIC -fno-common
212.endif
213RANLIB = :
214.endif
215
216SHLIB_LD ?= ${LD}
217
218.if !empty(SHLIB_MAJOR)
219.if ${NEED_SOLINKS} && empty(SHLIB_LINKS)
220.if ${MK_LINKLIB} != "no"
221SHLIB_LINKS = lib${LIB}.${LD_solink}
222.endif
223.if "${SHLIB_FULLVERSION}" != "${SHLIB_MAJOR}"
224SHLIB_LINKS += lib${LIB}.${LD_solink}.${SHLIB_MAJOR}
225.endif
226.endif
227.endif
228
229LIBTOOL?=libtool
230LD_shared ?= -Bshareable -Bforcearchive
231LD_so ?= so.${SHLIB_FULLVERSION}
232LD_solink ?= so
233.if empty(LORDER)
234LD_objs ?= ${OBJS}
235LD_pobjs ?= ${POBJS}
236LD_sobjs ?= ${SOBJS}
237.else
238LD_objs ?= `${LORDER} ${OBJS} | ${TSORT}`
239LD_sobjs ?= `${LORDER} ${SOBJS} | ${TSORT}`
240LD_pobjs ?= `${LORDER} ${POBJS} | ${TSORT}`
241.endif
242LD_solib ?= ${LD_sobjs}
243AR_cq ?= cq
244.if exists(/netbsd) && exists(${DESTDIR}/usr/lib/libdl.so)
245DLLIB ?= -ldl
246.endif
247
248# some libs have lots of objects, and scanning all .o, .po and ${PICO} meta files
249# is a waste of time, this tells meta.autodep.mk to just pick one
250# (typically ${PICO})
251# yes, 42 is a random number.
252.if ${MK_DIRDEPS_BUILD} == "yes" && ${SRCS:Uno:[\#]} > 42
253OPTIMIZE_OBJECT_META_FILES ?= yes
254.endif
255
256
257.if ${MK_LIBTOOL} == "yes"
258# because libtool is so fascist about naming the object files,
259# we cannot (yet) build profiled libs
260MK_PROFILE=no
261_LIBS=lib${LIB}.a
262.if exists(${.CURDIR}/shlib_version)
263SHLIB_AGE != . ${.CURDIR}/shlib_version ; echo $$age
264.endif
265.else
266# for the normal .a we do not want to strip symbols
267.c.o:
268	${COMPILE.c} ${.IMPSRC}
269
270# for the normal .a we do not want to strip symbols
271${CXX_SUFFIXES:%=%.o}:
272	${COMPILE.cc} ${.IMPSRC}
273
274.S.o .s.o:
275	${COMPILE.S} ${CFLAGS:M-[ID]*} ${AINC} ${.IMPSRC}
276
277.if (${LD_X} == "")
278.c.po:
279	${COMPILE.c} ${CC_PG} ${PROFFLAGS} ${.IMPSRC} -o ${.TARGET}
280
281${CXX_SUFFIXES:%=%.po}:
282	${COMPILE.cc} -pg ${.IMPSRC} -o ${.TARGET}
283
284.S${PICO} .s${PICO}:
285	${COMPILE.S} ${PICFLAG} ${CC_PIC} ${CFLAGS:M-[ID]*} ${AINC} ${.IMPSRC} -o ${.TARGET}
286.else
287.c.po:
288	${COMPILE.c} ${CC_PG} ${PROFFLAGS} ${.IMPSRC} -o ${.TARGET}.o
289	@${LD} ${LD_X} ${LD_r} ${.TARGET}.o -o ${.TARGET}
290	@rm -f ${.TARGET}.o
291
292${CXX_SUFFIXES:%=%.po}:
293	${COMPILE.cc} ${CXX_PG} ${.IMPSRC} -o ${.TARGET}.o
294	${LD} ${LD_X} ${LD_r} ${.TARGET}.o -o ${.TARGET}
295	@rm -f ${.TARGET}.o
296
297.S${PICO} .s${PICO}:
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	${COMPILE.c} ${PICFLAG} ${CC_PIC} ${.IMPSRC} -o ${.TARGET}.o
316	${LD} ${LD_x} ${LD_r} ${.TARGET}.o -o ${.TARGET}
317	@rm -f ${.TARGET}.o
318
319${CXX_SUFFIXES:%=%${PICO}}:
320	${COMPILE.cc} ${PICFLAG} ${CC_PIC} ${.IMPSRC} -o ${.TARGET}.o
321	${LD} ${LD_x} ${LD_r} ${.TARGET}.o -o ${.TARGET}
322	@rm -f ${.TARGET}.o
323
324.S.po .s.po:
325	${COMPILE.S} ${PROFFLAGS} ${CFLAGS:M-[ID]*} ${AINC} ${.IMPSRC} -o ${.TARGET}.o
326	${LD} ${LD_X} ${LD_r} ${.TARGET}.o -o ${.TARGET}
327	@rm -f ${.TARGET}.o
328
329.endif
330.endif
331
332.c.ln:
333	${LINT} ${LINTFLAGS} ${CFLAGS:M-[IDU]*} -i ${.IMPSRC}
334
335.if ${MK_LIBTOOL} != "yes"
336
337.if !defined(PICFLAG)
338PICFLAG=-fpic
339.endif
340
341_LIBS=
342
343.if ${MK_ARCHIVE} != "no"
344_LIBS += lib${LIB}.a
345.endif
346
347.if ${MK_PROFILE} != "no"
348_LIBS+=lib${LIB}_p.a
349POBJS+=${OBJS:.o=.po}
350.endif
351
352.if ${MK_PIC} != "no"
353.if ${MK_PICLIB} == "no"
354SOLIB ?= lib${LIB}.a
355.else
356SOLIB=lib${LIB}_pic.a
357_LIBS+=${SOLIB}
358.endif
359.if !empty(SHLIB_FULLVERSION)
360_LIBS+=lib${LIB}.${LD_so}
361.endif
362.endif
363
364.if ${MK_LINT} != "no"
365_LIBS+=llib-l${LIB}.ln
366.endif
367
368# here is where you can define what LIB* are
369.-include <libnames.mk>
370.if ${MK_DPADD_MK} == "yes"
371# lots of cool magic, but might not suit everyone.
372.include <dpadd.mk>
373.endif
374
375.if empty(LIB)
376_LIBS=
377.elif ${MK_LDORDER_MK} != "no"
378# Record any libs that we need to be linked with
379_LIBS+= ${libLDORDER_INC}
380
381.include <ldorder.mk>
382.endif
383
384.if !defined(_SKIP_BUILD)
385realbuild: ${_LIBS}
386.endif
387
388all: _SUBDIRUSE
389
390.for s in ${SRCS:N*.h:M*/*}
391${.o ${PICO} .po .lo:L:@o@${s:T:R}$o@}: $s
392.endfor
393
394OBJS+=	${SRCS:T:N*.h:R:S/$/.o/g}
395.NOPATH:	${OBJS}
396
397.if ${MK_LIBTOOL} == "yes"
398.if ${MK_PIC} == "no"
399LT_STATIC=-static
400.else
401LT_STATIC=
402.endif
403SHLIB_AGE?=0
404
405# .lo's are created as a side effect
406.s.o .S.o .c.o:
407	${LIBTOOL} --mode=compile ${CC} ${LT_STATIC} ${CFLAGS} ${CPPFLAGS} ${IMPFLAGS} -c ${.IMPSRC}
408
409# can't really do profiled libs with libtool - its too fascist about
410# naming the output...
411lib${LIB}.a: ${OBJS}
412	@rm -f ${.TARGET}
413	${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}
414	@ln .libs/${.TARGET} .
415
416lib${LIB}.${LD_so}: lib${LIB}.a
417	@[ -s ${.TARGET}.${SHLIB_AGE} ] || { ln -s .libs/lib${LIB}.${LD_so}* . 2>/dev/null; : }
418	@[ -s ${.TARGET} ] || ln -s ${.TARGET}.${SHLIB_AGE} ${.TARGET}
419
420.else  # MK_LIBTOOL=yes
421
422lib${LIB}.a: ${OBJS}
423	@${META_NOECHO} building standard ${LIB} library
424	@rm -f ${.TARGET}
425	@${AR} ${AR_cq} ${.TARGET} ${LD_objs}
426	${RANLIB} ${.TARGET}
427
428POBJS+=	${OBJS:.o=.po}
429.NOPATH:	${POBJS}
430lib${LIB}_p.a: ${POBJS}
431	@${META_NOECHO} building profiled ${LIB} library
432	@rm -f ${.TARGET}
433	@${AR} ${AR_cq} ${.TARGET} ${LD_pobjs}
434	${RANLIB} ${.TARGET}
435
436SOBJS+=	${OBJS:.o=${PICO}}
437.NOPATH:	${SOBJS}
438lib${LIB}_pic.a: ${SOBJS}
439	@${META_NOECHO} building shared object ${LIB} library
440	@rm -f ${.TARGET}
441	@${AR} ${AR_cq} ${.TARGET} ${LD_sobjs}
442	${RANLIB} ${.TARGET}
443
444#SHLIB_LDADD?= ${LDADD}
445
446# bound to be non-portable...
447# this is known to work for NetBSD 1.6 and FreeBSD 4.2
448lib${LIB}.${LD_so}: ${SOLIB} ${DPADD}
449	@${META_NOECHO} building shared ${LIB} library \(version ${SHLIB_FULLVERSION}\)
450	@rm -f ${.TARGET}
451.if ${TARGET_OSNAME:NFreeBSD:NNetBSD} == ""
452.if ${OBJECT_FMT} == "ELF"
453	${SHLIB_LD} -x -shared ${SHLIB_SHFLAGS} ${LDFLAGS} -o ${.TARGET} \
454	    ${SHLIB_LDSTARTFILE} \
455	    --whole-archive ${SOLIB} --no-whole-archive \
456	    ${LDADD} ${SHLIB_LDADD} ${SHLIB_LDENDFILE}
457.else
458	${SHLIB_LD} ${LD_x} ${LD_shared} ${LDFLAGS} \
459	    -o ${.TARGET} ${SOLIB} ${LDADD} ${SHLIB_LDADD}
460.endif
461.else
462	${SHLIB_LD} ${LDFLAGS} -o ${.TARGET} \
463	    ${LD_shared} ${LD_solib} ${DLLIB} ${LDADD} ${SHLIB_LDADD}
464.endif
465.endif
466.if !empty(SHLIB_LINKS)
467	rm -f ${SHLIB_LINKS}; ${SHLIB_LINKS:O:u:@x@ln -s ${.TARGET} $x;@}
468.endif
469
470LOBJS+=	${LSRCS:.c=.ln} ${SRCS:M*.c:.c=.ln}
471.NOPATH:	${LOBJS}
472LLIBS?=	-lc
473llib-l${LIB}.ln: ${LOBJS}
474	@${META_NOECHO} building llib-l${LIB}.ln
475	@rm -f llib-l${LIB}.ln
476	@${LINT} -C${LIB} ${LOBJS} ${LLIBS}
477
478.if !target(clean)
479cleanlib: .PHONY
480	rm -f a.out [Ee]rrs mklog core *.core ${CLEANFILES}
481	rm -f lib${LIB}.a ${OBJS}
482	rm -f lib${LIB}_p.a ${POBJS}
483	rm -f lib${LIB}_pic.a lib${LIB}.so.*.* ${SOBJS}
484	rm -f llib-l${LIB}.ln ${LOBJS}
485.if !empty(SHLIB_LINKS)
486	rm -f ${SHLIB_LINKS}
487.endif
488
489clean: _SUBDIRUSE cleanlib
490cleandir: _SUBDIRUSE cleanlib
491.else
492cleandir: _SUBDIRUSE clean
493.endif
494
495.if defined(SRCS) && (!defined(MKDEP) || ${MKDEP} != autodep)
496afterdepend: .depend
497	@(TMP=/tmp/_depend$$$$; \
498	    sed -e 's/^\([^\.]*\).o[ ]*:/\1.o \1.po \1${PICO} \1.ln:/' \
499	      < .depend > $$TMP; \
500	    mv $$TMP .depend)
501.endif
502
503.if !target(install)
504.if !target(beforeinstall)
505beforeinstall:
506.endif
507
508.if !empty(LIBOWN)
509LIB_INSTALL_OWN ?= -o ${LIBOWN} -g ${LIBGRP}
510.endif
511
512.include <links.mk>
513
514.if !target(libinstall) && !empty(LIB)
515realinstall: 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 644 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 644 \
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_LDORDER_MK} != "no"
532	${INSTALL} ${COPY} ${LIB_INSTALL_OWN} -m 644 \
533		lib${LIB}.ldorder.inc ${DESTDIR}${LIBDIR}
534.endif
535.if ${MK_PIC} != "no"
536.if ${MK_PICLIB} != "no"
537	${INSTALL} ${COPY} ${LIB_INSTALL_OWN} -m 644 \
538	    lib${LIB}_pic.a ${DESTDIR}${LIBDIR}
539	${RANLIB} ${DESTDIR}${LIBDIR}/lib${LIB}_pic.a
540	chmod ${LIBMODE} ${DESTDIR}${LIBDIR}/lib${LIB}_pic.a
541.endif
542.if !empty(SHLIB_MAJOR)
543	${INSTALL} ${COPY} ${LIB_INSTALL_OWN} -m ${LIBMODE} \
544	    lib${LIB}.${LD_so} ${DESTDIR}${LIBDIR}
545.if !empty(SHLIB_LINKS)
546	(cd ${DESTDIR}${LIBDIR} && { rm -f ${SHLIB_LINKS}; ${SHLIB_LINKS:O:u:@x@ln -s lib${LIB}.${LD_so} $x;@} })
547.endif
548.endif
549.endif
550.if ${MK_LINT} != "no" && ${MK_LINKLIB} != "no" && !empty(LOBJS)
551	${INSTALL} ${COPY} ${LIB_INSTALL_OWN} -m ${LIBMODE} \
552	    llib-l${LIB}.ln ${DESTDIR}${LINTLIBDIR}
553.endif
554.if defined(LINKS) && !empty(LINKS)
555	@set ${LINKS}; ${_LINKS_SCRIPT}
556.endif
557.endif
558
559.if ${MK_MAN} != "no"
560install: maninstall _SUBDIRUSE
561maninstall: afterinstall
562.endif
563afterinstall: realinstall
564libinstall: beforeinstall
565realinstall: beforeinstall
566.endif
567
568.if defined(FILES) || defined(FILESGROUPS)
569.include <files.mk>
570.endif
571
572.if ${MK_MAN} != "no"
573.include <man.mk>
574.endif
575
576.if ${MK_NLS} != "no"
577.include <nls.mk>
578.endif
579
580.include <obj.mk>
581.include <inc.mk>
582.include <dep.mk>
583.include <subdir.mk>
584.endif
585
586# during building we usually need/want to install libs somewhere central
587# note that we do NOT ch{own,grp} as that would likely fail at this point.
588# otherwise it is the same as realinstall
589# Note that we don't need this when using dpadd.mk
590.libinstall:	${_LIBS}
591	test -d ${DESTDIR}${LIBDIR} || ${INSTALL} -d -m775 ${DESTDIR}${LIBDIR}
592.for _lib in ${_LIBS:M*.a}
593	${INSTALL} ${COPY} -m 644 ${_lib} ${DESTDIR}${LIBDIR}
594	${RANLIB} ${DESTDIR}${LIBDIR}/${_lib}
595.endfor
596.for _lib in ${_LIBS:M*.${LD_solink}*:O:u}
597	${INSTALL} ${COPY} -m ${LIBMODE} ${_lib} ${DESTDIR}${LIBDIR}
598.if !empty(SHLIB_LINKS)
599	(cd ${DESTDIR}${LIBDIR} && { ${SHLIB_LINKS:O:u:@x@ln -sf ${_lib} $x;@}; })
600.endif
601.endfor
602	@touch ${.TARGET}
603
604.if !empty(LIB)
605STAGE_LIBDIR?= ${STAGE_OBJTOP}${LIBDIR}
606stage_libs: ${_LIBS}
607.endif
608
609.include <final.mk>
610.endif
611