xref: /freebsd/contrib/bmake/mk/lib.mk (revision 5ca8e32633c4ffbbcd6762e5888b6a4ba0708c6c)
1# $Id: lib.mk,v 1.84 2024/02/19 00:06:19 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
398OBJS_SRCS = ${SRCS:${OBJS_SRCS_FILTER}}
399
400.for s in ${OBJS_SRCS:M*/*}
401${.o ${PICO} .po .lo:L:@o@${s:T:R}$o@}: $s
402.endfor
403
404OBJS+=	${OBJS_SRCS:T:R:S/$/.o/g}
405.NOPATH:	${OBJS}
406
407.if ${MK_LIBTOOL} == "yes"
408.if ${MK_PIC} == "no"
409LT_STATIC=-static
410.else
411LT_STATIC=
412.endif
413SHLIB_AGE?=0
414
415# .lo's are created as a side effect
416.s.o .S.o .c.o:
417	${LIBTOOL} --mode=compile ${CC} ${LT_STATIC} ${CFLAGS} ${CPPFLAGS} ${IMPFLAGS} -c ${.IMPSRC}
418
419# can't really do profiled libs with libtool - its too fascist about
420# naming the output...
421lib${LIB}.a: ${OBJS}
422	@rm -f ${.TARGET}
423	${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}
424	@ln .libs/${.TARGET} .
425
426lib${LIB}.${LD_so}: lib${LIB}.a
427	@[ -s ${.TARGET}.${SHLIB_AGE} ] || { ln -s .libs/lib${LIB}.${LD_so}* . 2>/dev/null; : }
428	@[ -s ${.TARGET} ] || ln -s ${.TARGET}.${SHLIB_AGE} ${.TARGET}
429
430.else  # MK_LIBTOOL=yes
431
432lib${LIB}.a: ${OBJS}
433	@${META_NOECHO} building standard ${LIB} library
434	@rm -f ${.TARGET}
435	@${AR} ${AR_cq} ${.TARGET} ${LD_objs}
436	${RANLIB} ${.TARGET}
437
438POBJS+=	${OBJS:.o=.po}
439.NOPATH:	${POBJS}
440lib${LIB}_p.a: ${POBJS}
441	@${META_NOECHO} building profiled ${LIB} library
442	@rm -f ${.TARGET}
443	@${AR} ${AR_cq} ${.TARGET} ${LD_pobjs}
444	${RANLIB} ${.TARGET}
445
446SOBJS+=	${OBJS:.o=${PICO}}
447.NOPATH:	${SOBJS}
448lib${LIB}_pic.a: ${SOBJS}
449	@${META_NOECHO} building shared object ${LIB} library
450	@rm -f ${.TARGET}
451	@${AR} ${AR_cq} ${.TARGET} ${LD_sobjs}
452	${RANLIB} ${.TARGET}
453
454# bound to be non-portable...
455# this is known to work for NetBSD 1.6 and FreeBSD 4.2
456lib${LIB}.${LD_so}: ${SOLIB} ${DPADD}
457	@${META_NOECHO} building shared ${LIB} library \(version ${SHLIB_FULLVERSION}\)
458	@rm -f ${.TARGET}
459.if ${TARGET_OSNAME:NFreeBSD:NNetBSD} == ""
460.if ${OBJECT_FMT} == "ELF"
461	${SHLIB_LD} -shared -Wl,-x ${SHLIB_SHFLAGS} ${LDFLAGS} -o ${.TARGET} \
462	    -Wl,--whole-archive ${SOLIB} -Wl,--no-whole-archive \
463	    ${LDADD} ${SHLIB_LDADD}
464.else
465	${SHLIB_LD} ${LD_x} ${LD_shared} ${LDFLAGS} \
466	    -o ${.TARGET} ${SOLIB} ${LDADD} ${SHLIB_LDADD}
467.endif
468.else
469	${SHLIB_LD} ${LDFLAGS} -o ${.TARGET} \
470	    ${LD_shared} ${LD_solib} ${DLLIB} ${LDADD} ${SHLIB_LDADD}
471.endif
472.endif
473.if !empty(SHLIB_LINKS)
474	rm -f ${SHLIB_LINKS}; ${SHLIB_LINKS:O:u:@x@ln -s ${.TARGET} $x;@}
475.endif
476
477LOBJS+=	${LSRCS:.c=.ln} ${SRCS:M*.c:.c=.ln}
478.NOPATH:	${LOBJS}
479LLIBS?=	-lc
480llib-l${LIB}.ln: ${LOBJS}
481	@${META_NOECHO} building llib-l${LIB}.ln
482	@rm -f llib-l${LIB}.ln
483	@${LINT} -C${LIB} ${LOBJS} ${LLIBS}
484
485.if !target(clean)
486cleanlib: .PHONY
487	rm -f a.out [Ee]rrs mklog core *.core ${CLEANFILES}
488	rm -f lib${LIB}.a ${OBJS}
489	rm -f lib${LIB}_p.a ${POBJS}
490	rm -f lib${LIB}_pic.a lib${LIB}*${LD_solink} lib${LIB}*${LD_solink}.* ${SOBJS}
491	rm -f llib-l${LIB}.ln ${LOBJS}
492.if !empty(SHLIB_LINKS)
493	rm -f ${SHLIB_LINKS}
494.endif
495
496clean: _SUBDIRUSE cleanlib
497cleandir: _SUBDIRUSE cleanlib
498.else
499cleandir: _SUBDIRUSE clean
500.endif
501
502.if defined(SRCS) && (!defined(MKDEP) || ${MKDEP} != autodep)
503afterdepend: .depend
504	@(TMP=/tmp/_depend$$$$; \
505	    sed -e 's/^\([^\.]*\).o[ ]*:/\1.o \1.po \1${PICO} \1.ln:/' \
506	      < .depend > $$TMP; \
507	    mv $$TMP .depend)
508.endif
509
510.if !target(install)
511.if !target(beforeinstall)
512beforeinstall:
513.endif
514
515.if !empty(LIBOWN)
516LIB_INSTALL_OWN ?= -o ${LIBOWN} -g ${LIBGRP}
517.endif
518
519.include <links.mk>
520
521.if !target(libinstall) && !empty(LIB)
522realinstall: libinstall
523libinstall:
524	[ -d ${DESTDIR}/${LIBDIR} ] || \
525	${INSTALL} -d ${LIB_INSTALL_OWN} -m 775 ${DESTDIR}${LIBDIR}
526.if ${MK_ARCHIVE} != "no"
527	${INSTALL} ${COPY} ${LIB_INSTALL_OWN} -m 644 lib${LIB}.a \
528	    ${DESTDIR}${LIBDIR}
529	${RANLIB} ${DESTDIR}${LIBDIR}/lib${LIB}.a
530	chmod ${LIBMODE} ${DESTDIR}${LIBDIR}/lib${LIB}.a
531.endif
532.if ${MK_PROFILE} != "no"
533	${INSTALL} ${COPY} ${LIB_INSTALL_OWN} -m 644 \
534	    lib${LIB}_p.a ${DESTDIR}${LIBDIR}
535	${RANLIB} ${DESTDIR}${LIBDIR}/lib${LIB}_p.a
536	chmod ${LIBMODE} ${DESTDIR}${LIBDIR}/lib${LIB}_p.a
537.endif
538.if ${MK_LDORDER_MK} != "no"
539	${INSTALL} ${COPY} ${LIB_INSTALL_OWN} -m 644 \
540		lib${LIB}.ldorder.inc ${DESTDIR}${LIBDIR}
541.endif
542.if ${MK_PIC} != "no"
543.if ${MK_PICLIB} != "no"
544	${INSTALL} ${COPY} ${LIB_INSTALL_OWN} -m 644 \
545	    lib${LIB}_pic.a ${DESTDIR}${LIBDIR}
546	${RANLIB} ${DESTDIR}${LIBDIR}/lib${LIB}_pic.a
547	chmod ${LIBMODE} ${DESTDIR}${LIBDIR}/lib${LIB}_pic.a
548.endif
549.if !empty(SHLIB_MAJOR)
550	${INSTALL} ${COPY} ${LIB_INSTALL_OWN} -m ${LIBMODE} \
551	    lib${LIB}.${LD_so} ${DESTDIR}${LIBDIR}
552.if !empty(SHLIB_LINKS)
553	(cd ${DESTDIR}${LIBDIR} && { rm -f ${SHLIB_LINKS}; ${SHLIB_LINKS:O:u:@x@ln -s lib${LIB}.${LD_so} $x;@} })
554.endif
555.endif
556.endif
557.if ${MK_LINT} != "no" && ${MK_LINKLIB} != "no" && !empty(LOBJS)
558	${INSTALL} ${COPY} ${LIB_INSTALL_OWN} -m ${LIBMODE} \
559	    llib-l${LIB}.ln ${DESTDIR}${LINTLIBDIR}
560.endif
561.if defined(LINKS) && !empty(LINKS)
562	@set ${LINKS}; ${_LINKS_SCRIPT}
563.endif
564.endif
565
566.if ${MK_MAN} != "no"
567install: maninstall _SUBDIRUSE
568maninstall: afterinstall
569.endif
570afterinstall: realinstall
571libinstall: beforeinstall
572realinstall: beforeinstall
573.endif
574
575.if defined(FILES) || defined(FILESGROUPS)
576.include <files.mk>
577.endif
578
579.if ${MK_MAN} != "no"
580.include <man.mk>
581.endif
582
583.if ${MK_NLS} != "no"
584.include <nls.mk>
585.endif
586
587.include <obj.mk>
588.include <inc.mk>
589.include <dep.mk>
590.include <subdir.mk>
591.endif
592
593# during building we usually need/want to install libs somewhere central
594# note that we do NOT ch{own,grp} as that would likely fail at this point.
595# otherwise it is the same as realinstall
596# Note that we don't need this when using dpadd.mk
597.libinstall:	${_LIBS}
598	test -d ${DESTDIR}${LIBDIR} || ${INSTALL} -d -m775 ${DESTDIR}${LIBDIR}
599.for _lib in ${_LIBS:M*.a}
600	${INSTALL} ${COPY} -m 644 ${_lib} ${DESTDIR}${LIBDIR}
601	${RANLIB} ${DESTDIR}${LIBDIR}/${_lib}
602.endfor
603.for _lib in ${_LIBS:M*.${LD_solink}*:O:u}
604	${INSTALL} ${COPY} -m ${LIBMODE} ${_lib} ${DESTDIR}${LIBDIR}
605.if !empty(SHLIB_LINKS)
606	(cd ${DESTDIR}${LIBDIR} && { ${SHLIB_LINKS:O:u:@x@ln -sf ${_lib} $x;@}; })
607.endif
608.endfor
609	@touch ${.TARGET}
610
611.if !empty(LIB)
612STAGE_LIBDIR?= ${STAGE_OBJTOP}${LIBDIR}
613stage_libs: ${_LIBS}
614
615__libtoken ?= __lib${LIB:C,[^a-zA-Z0-9_],_,g}__
616__libtoken := ${__libtoken}
617COPTS += -D${__libtoken}
618.endif
619
620.include <final.mk>
621.endif
622