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