xref: /freebsd/contrib/bmake/mk/lib.mk (revision 1edb7116)
1# $Id: lib.mk,v 1.81 2023/10/03 18:18:57 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# we simplify life by letting the toolchain do most of the work
66# _CCLINK is set by init.mk based on whether we are doing C++ or not
67SHLIB_LD ?= ${_CCLINK}
68
69.if ${TARGET_OSNAME} == "NetBSD"
70.if ${MACHINE_ARCH} == "alpha"
71		# Alpha-specific shared library flags
72FPICFLAGS ?= -fPIC
73CPICFLAGS ?= -fPIC -DPIC
74CPPPICFLAGS?= -DPIC
75CAPICFLAGS?= ${CPPPICFLAGS} ${CPICFLAGS}
76APICFLAGS ?=
77.elif ${MACHINE_ARCH} == "mipsel" || ${MACHINE_ARCH} == "mipseb"
78		# mips-specific shared library flags
79
80# On mips, all libs are compiled with ABIcalls, not just sharedlibs.
81MKPICLIB= no
82
83# so turn shlib PIC flags on for ${AS}.
84AINC+=-DABICALLS
85AFLAGS+= -fPIC
86AS+=	-KPIC
87
88.elif ${MACHINE_ARCH} == "vax" && ${OBJECT_FMT} == "ELF"
89# On the VAX, all object are PIC by default, not just sharedlibs.
90MKPICLIB= no
91
92.elif (${MACHINE_ARCH} == "sparc" || ${MACHINE_ARCH} == "sparc64") && \
93       ${OBJECT_FMT} == "ELF"
94# If you use -fPIC you need to define BIGPIC to turn on 32-bit
95# relocations in asm code
96FPICFLAGS ?= -fPIC
97CPICFLAGS ?= -fPIC -DPIC
98CPPPICFLAGS?= -DPIC -DBIGPIC
99CAPICFLAGS?= ${CPPPICFLAGS} ${CPICFLAGS}
100APICFLAGS ?= -KPIC
101
102.else
103
104# Platform-independent flags for NetBSD a.out shared libraries
105SHLIB_SOVERSION=${SHLIB_FULLVERSION}
106SHLIB_SHFLAGS=
107FPICFLAGS ?= -fPIC
108CPICFLAGS?= -fPIC -DPIC
109CPPPICFLAGS?= -DPIC
110CAPICFLAGS?= ${CPPPICFLAGS} ${CPICFLAGS}
111APICFLAGS?= -k
112
113.endif
114
115# Platform-independent linker flags for ELF shared libraries
116.if ${OBJECT_FMT} == "ELF"
117SHLIB_SOVERSION=	${SHLIB_MAJOR}
118SHLIB_SHFLAGS=		-Wl,-soname,lib${LIB}.so.${SHLIB_SOVERSION}
119SHLIB_LDSTARTFILE?=	/usr/lib/crtbeginS.o
120SHLIB_LDENDFILE?=	/usr/lib/crtendS.o
121.endif
122
123# for compatibility with the following
124CC_PIC?= ${CPICFLAGS}
125LD_shared=${SHLIB_SHFLAGS}
126
127.endif # NetBSD
128
129.if ${TARGET_OSNAME} == "FreeBSD"
130.if ${OBJECT_FMT} == "ELF"
131SHLIB_SOVERSION=	${SHLIB_MAJOR}
132SHLIB_SHFLAGS=		-Wl,-soname,lib${LIB}.so.${SHLIB_SOVERSION}
133.else
134SHLIB_SHFLAGS=		-assert pure-text
135.endif
136SHLIB_LDSTARTFILE=
137SHLIB_LDENDFILE=
138CC_PIC?= -fpic
139LD_shared=${SHLIB_SHFLAGS}
140
141.endif # FreeBSD
142
143MKPICLIB?= yes
144
145# sys.mk can override these
146LD_X?=-X
147LD_x?=-x
148LD_r?=-r
149
150# Non BSD machines will be using bmake.
151.if ${TARGET_OSNAME} == "SunOS"
152LD_shared=-assert pure-text
153.if ${OBJECT_FMT} == "ELF" || ${MACHINE} == "solaris"
154# Solaris
155LD_shared=-h lib${LIB}.so.${SHLIB_MAJOR} -G
156.endif
157.elif ${TARGET_OSNAME} == "HP-UX"
158LD_shared=-b
159LD_so=sl
160DLLIB=
161# HPsUX lorder does not grok anything but .o
162LD_sobjs=`${LORDER} ${OBJS} | ${TSORT} | sed 's,\.o,${PICO},'`
163LD_pobjs=`${LORDER} ${OBJS} | ${TSORT} | sed 's,\.o,.po,'`
164.elif ${TARGET_OSNAME} == "OSF1"
165LD_shared= -msym -shared -expect_unresolved '*'
166LD_solib= -all lib${LIB}_pic.a
167DLLIB=
168# lorder does not grok anything but .o
169LD_sobjs=`${LORDER} ${OBJS} | ${TSORT} | sed 's,\.o,${PICO},'`
170LD_pobjs=`${LORDER} ${OBJS} | ${TSORT} | sed 's,\.o,.po,'`
171AR_cq= -cqs
172.elif ${TARGET_OSNAME} == "FreeBSD"
173LD_solib= lib${LIB}_pic.a
174.elif ${TARGET_OSNAME} == "Linux"
175# this is ambiguous of course
176LD_shared=-shared -Wl,-soname,lib${LIB}.so.${SHLIB_MAJOR}
177LD_solib= -Wl,--whole-archive lib${LIB}_pic.a -Wl,--no-whole-archive
178.if ${COMPILER_TYPE} == "gcc"
179# Linux uses GNU ld, which is a multi-pass linker
180# so we don't need to use lorder or tsort
181LD_objs = ${OBJS}
182LD_pobjs = ${POBJS}
183LD_sobjs = ${SOBJS}
184.endif
185.elif ${TARGET_OSNAME} == "Darwin"
186SHLIB_INSTALL_VERSION ?= ${SHLIB_MAJOR}
187SHLIB_COMPATABILITY_VERSION ?= ${SHLIB_MAJOR}.${SHLIB_MINOR:U0}
188SHLIB_COMPATABILITY ?= \
189	-compatibility_version ${SHLIB_COMPATABILITY_VERSION} \
190	-current_version ${SHLIB_FULLVERSION}
191LD_shared = -dynamiclib \
192	-flat_namespace -undefined suppress \
193	-install_name ${LIBDIR}/lib${LIB}.${SHLIB_INSTALL_VERSION}.${LD_solink} \
194	${SHLIB_COMPATABILITY}
195SHLIB_LINKS =
196.for v in ${SHLIB_COMPATABILITY_VERSION} ${SHLIB_INSTALL_VERSION}
197.if "$v" != "${SHLIB_FULLVERSION}"
198SHLIB_LINKS += lib${LIB}.$v.${LD_solink}
199.endif
200.endfor
201.if ${MK_LINKLIB} != "no"
202SHLIB_LINKS += lib${LIB}.${LD_solink}
203.endif
204
205LD_so = ${SHLIB_FULLVERSION}.dylib
206LD_sobjs = ${SOBJS:O:u}
207LD_solib = ${LD_sobjs}
208SOLIB = ${LD_sobjs}
209LD_solink = dylib
210.if ${MACHINE_ARCH} == "i386"
211PICFLAG ?= -fPIC
212.else
213PICFLAG ?= -fPIC -fno-common
214.endif
215RANLIB = :
216.endif
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# 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:NFreeBSD:NNetBSD} == ""
450.if ${OBJECT_FMT} == "ELF"
451	${SHLIB_LD} -shared -Wl,-x ${SHLIB_SHFLAGS} ${LDFLAGS} -o ${.TARGET} \
452	    -Wl,--whole-archive ${SOLIB} -Wl,--no-whole-archive \
453	    ${LDADD} ${SHLIB_LDADD}
454.else
455	${SHLIB_LD} ${LD_x} ${LD_shared} ${LDFLAGS} \
456	    -o ${.TARGET} ${SOLIB} ${LDADD} ${SHLIB_LDADD}
457.endif
458.else
459	${SHLIB_LD} ${LDFLAGS} -o ${.TARGET} \
460	    ${LD_shared} ${LD_solib} ${DLLIB} ${LDADD} ${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}*${LD_solink} lib${LIB}*${LD_solink}.* ${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
605__libtoken ?= __lib${LIB:C,[^a-zA-Z0-9_],_,g}__
606__libtoken := ${__libtoken}
607COPTS += -D${__libtoken}
608.endif
609
610.include <final.mk>
611.endif
612