xref: /freebsd/share/mk/bsd.lib.mk (revision af23369a6deaaeb612ab266eb88b8bb8d560c322)
1#	from: @(#)bsd.lib.mk	5.26 (Berkeley) 5/2/91
2# $FreeBSD$
3#
4
5.include <bsd.init.mk>
6.include <bsd.compiler.mk>
7.include <bsd.linker.mk>
8
9__<bsd.lib.mk>__:
10
11.if defined(LIB_CXX) || defined(SHLIB_CXX)
12_LD=	${CXX}
13.else
14_LD=	${CC}
15.endif
16.if defined(LIB_CXX)
17LIB=	${LIB_CXX}
18.endif
19.if defined(SHLIB_CXX)
20SHLIB=	${SHLIB_CXX}
21.endif
22
23LIB_PRIVATE=	${PRIVATELIB:Dprivate}
24# Set up the variables controlling shared libraries.  After this section,
25# SHLIB_NAME will be defined only if we are to create a shared library.
26# SHLIB_LINK will be defined only if we are to create a link to it.
27# INSTALL_PIC_ARCHIVE will be defined only if we are to create a PIC archive.
28# BUILD_NOSSP_PIC_ARCHIVE will be defined only if we are to create a PIC archive.
29.if defined(NO_PIC)
30.undef SHLIB_NAME
31.undef INSTALL_PIC_ARCHIVE
32.undef BUILD_NOSSP_PIC_ARCHIVE
33.else
34.if !defined(SHLIB) && defined(LIB)
35SHLIB=		${LIB}
36.endif
37.if !defined(SHLIB_NAME) && defined(SHLIB) && defined(SHLIB_MAJOR)
38SHLIB_NAME=	lib${LIB_PRIVATE}${SHLIB}.so.${SHLIB_MAJOR}
39.endif
40.if defined(SHLIB_NAME) && !empty(SHLIB_NAME:M*.so.*)
41SHLIB_LINK?=	${SHLIB_NAME:R}
42.endif
43SONAME?=	${SHLIB_NAME}
44.endif
45
46.if defined(CRUNCH_CFLAGS)
47CFLAGS+=	${CRUNCH_CFLAGS}
48.endif
49
50.if ${MK_ASSERT_DEBUG} == "no"
51CFLAGS+= -DNDEBUG
52# XXX: shouldn't we ensure that !asserts marks potentially unused variables as
53# __unused instead of disabling -Werror globally?
54MK_WERROR=	no
55.endif
56
57.if defined(DEBUG_FLAGS)
58CFLAGS+= ${DEBUG_FLAGS}
59
60.if ${MK_CTF} != "no" && ${DEBUG_FLAGS:M-g} != ""
61CTFFLAGS+= -g
62.endif
63.else
64STRIP?=	-s
65.endif
66
67.if ${SHLIBDIR:M*lib32*}
68TAGS+=	lib32
69.endif
70
71.if defined(NO_ROOT)
72.if !defined(TAGS) || ! ${TAGS:Mpackage=*}
73TAGS+=		package=${PACKAGE:Uutilities}
74.endif
75TAG_ARGS=	-T ${TAGS:[*]:S/ /,/g}
76.endif
77
78# ELF hardening knobs
79.if ${MK_BIND_NOW} != "no"
80LDFLAGS+= -Wl,-znow
81.endif
82.if ${LINKER_TYPE} != "mac"
83.if ${MK_RELRO} == "no"
84LDFLAGS+= -Wl,-znorelro
85.else
86LDFLAGS+= -Wl,-zrelro
87.endif
88.endif
89.if ${MK_RETPOLINE} != "no"
90.if ${COMPILER_FEATURES:Mretpoline} && ${LINKER_FEATURES:Mretpoline}
91CFLAGS+= -mretpoline
92CXXFLAGS+= -mretpoline
93LDFLAGS+= -Wl,-zretpolineplt
94.else
95.warning Retpoline requested but not supported by compiler or linker
96.endif
97.endif
98
99# Initialize stack variables on function entry
100.if ${MK_INIT_ALL_ZERO} == "yes"
101.if ${COMPILER_FEATURES:Minit-all}
102CFLAGS+= -ftrivial-auto-var-init=zero \
103    -enable-trivial-auto-var-init-zero-knowing-it-will-be-removed-from-clang
104CXXFLAGS+= -ftrivial-auto-var-init=zero \
105    -enable-trivial-auto-var-init-zero-knowing-it-will-be-removed-from-clang
106.else
107.warning InitAll (zeros) requested but not support by compiler
108.endif
109.elif ${MK_INIT_ALL_PATTERN} == "yes"
110.if ${COMPILER_FEATURES:Minit-all}
111CFLAGS+= -ftrivial-auto-var-init=pattern
112CXXFLAGS+= -ftrivial-auto-var-init=pattern
113.else
114.warning InitAll (pattern) requested but not support by compiler
115.endif
116.endif
117
118# bsd.sanitizer.mk is not installed, so don't require it (e.g. for ports).
119.sinclude "bsd.sanitizer.mk"
120
121.if ${MK_DEBUG_FILES} != "no" && empty(DEBUG_FLAGS:M-g) && \
122    empty(DEBUG_FLAGS:M-gdwarf*)
123.if !${COMPILER_FEATURES:Mcompressed-debug}
124CFLAGS+= ${DEBUG_FILES_CFLAGS:N-gz*}
125CXXFLAGS+= ${DEBUG_FILES_CFLAGS:N-gz*}
126.else
127CFLAGS+= ${DEBUG_FILES_CFLAGS}
128CXXFLAGS+= ${DEBUG_FILES_CFLAGS}
129.endif
130CTFFLAGS+= -g
131.endif
132
133.if ${MACHINE_CPUARCH} == "riscv" && ${LINKER_FEATURES:Mriscv-relaxations} == ""
134CFLAGS += -mno-relax
135.endif
136
137.include <bsd.libnames.mk>
138
139# prefer .s to a .c, add .po, remove stuff not used in the BSD libraries
140# .pico used for PIC object files
141# .nossppico used for NOSSP PIC object files
142# .pieo used for PIE object files
143.SUFFIXES: .out .o .bc .ll .po .pico .nossppico .pieo .S .asm .s .c .cc .cpp .cxx .C .f .y .l .ln
144
145.if !defined(PICFLAG)
146PICFLAG=-fpic
147PIEFLAG=-fpie
148.endif
149
150PO_FLAG=-pg
151
152.c.po:
153	${CC} ${PO_FLAG} ${STATIC_CFLAGS} ${PO_CFLAGS} -c ${.IMPSRC} -o ${.TARGET}
154	${CTFCONVERT_CMD}
155
156.c.pico:
157	${CC} ${PICFLAG} -DPIC ${SHARED_CFLAGS} ${CFLAGS} -c ${.IMPSRC} -o ${.TARGET}
158	${CTFCONVERT_CMD}
159
160.c.nossppico:
161	${CC} ${PICFLAG} -DPIC ${SHARED_CFLAGS:C/^-fstack-protector.*$//:C/^-fsanitize.*$//} ${CFLAGS:C/^-fstack-protector.*$//:C/^-fsanitize.*$//} -c ${.IMPSRC} -o ${.TARGET}
162	${CTFCONVERT_CMD}
163
164.c.pieo:
165	${CC} ${PIEFLAG} -DPIC ${SHARED_CFLAGS} ${CFLAGS} -c ${.IMPSRC} -o ${.TARGET}
166	${CTFCONVERT_CMD}
167
168.cc.po .C.po .cpp.po .cxx.po:
169	${CXX} ${PO_FLAG} ${STATIC_CXXFLAGS} ${PO_CXXFLAGS} -c ${.IMPSRC} -o ${.TARGET}
170
171.cc.pico .C.pico .cpp.pico .cxx.pico:
172	${CXX} ${PICFLAG} -DPIC ${SHARED_CXXFLAGS} ${CXXFLAGS} -c ${.IMPSRC} -o ${.TARGET}
173
174.cc.nossppico .C.nossppico .cpp.nossppico .cxx.nossppico:
175	${CXX} ${PICFLAG} -DPIC ${SHARED_CXXFLAGS:C/^-fstack-protector.*$//:C/^-fsanitize.*$//} ${CXXFLAGS:C/^-fstack-protector.*$//:C/^-fsanitize.*$//} -c ${.IMPSRC} -o ${.TARGET}
176
177.cc.pieo .C.pieo .cpp.pieo .cxx.pieo:
178	${CXX} ${PIEFLAG} ${SHARED_CXXFLAGS} ${CXXFLAGS} -c ${.IMPSRC} -o ${.TARGET}
179
180.f.po:
181	${FC} -pg ${FFLAGS} -o ${.TARGET} -c ${.IMPSRC}
182	${CTFCONVERT_CMD}
183
184.f.pico:
185	${FC} ${PICFLAG} -DPIC ${FFLAGS} -o ${.TARGET} -c ${.IMPSRC}
186	${CTFCONVERT_CMD}
187
188.f.nossppico:
189	${FC} ${PICFLAG} -DPIC ${FFLAGS:C/^-fstack-protector.*$//} -o ${.TARGET} -c ${.IMPSRC}
190	${CTFCONVERT_CMD}
191
192.s.po .s.pico .s.nossppico .s.pieo:
193	${AS} ${AFLAGS} -o ${.TARGET} ${.IMPSRC}
194	${CTFCONVERT_CMD}
195
196.asm.po:
197	${CC:N${CCACHE_BIN}} -x assembler-with-cpp -DPROF ${PO_CFLAGS} \
198	    ${ACFLAGS} -c ${.IMPSRC} -o ${.TARGET}
199	${CTFCONVERT_CMD}
200
201.asm.pico:
202	${CC:N${CCACHE_BIN}} -x assembler-with-cpp ${PICFLAG} -DPIC \
203	    ${CFLAGS} ${ACFLAGS} -c ${.IMPSRC} -o ${.TARGET}
204	${CTFCONVERT_CMD}
205
206.asm.nossppico:
207	${CC:N${CCACHE_BIN}} -x assembler-with-cpp ${PICFLAG} -DPIC \
208	    ${CFLAGS:C/^-fstack-protector.*$//} ${ACFLAGS} -c ${.IMPSRC} -o ${.TARGET}
209	${CTFCONVERT_CMD}
210
211.asm.pieo:
212	${CC:N${CCACHE_BIN}} -x assembler-with-cpp ${PIEFLAG} -DPIC \
213	    ${CFLAGS} ${ACFLAGS} -c ${.IMPSRC} -o ${.TARGET}
214	${CTFCONVERT_CMD}
215
216.S.po:
217	${CC:N${CCACHE_BIN}} -DPROF ${PO_CFLAGS} ${ACFLAGS} -c ${.IMPSRC} \
218	    -o ${.TARGET}
219	${CTFCONVERT_CMD}
220
221.S.pico:
222	${CC:N${CCACHE_BIN}} ${PICFLAG} -DPIC ${CFLAGS} ${ACFLAGS} \
223	    -c ${.IMPSRC} -o ${.TARGET}
224	${CTFCONVERT_CMD}
225
226.S.nossppico:
227	${CC:N${CCACHE_BIN}} ${PICFLAG} -DPIC ${CFLAGS:C/^-fstack-protector.*$//} ${ACFLAGS} \
228	    -c ${.IMPSRC} -o ${.TARGET}
229	${CTFCONVERT_CMD}
230
231.S.pieo:
232	${CC:N${CCACHE_BIN}} ${PIEFLAG} -DPIC ${CFLAGS} ${ACFLAGS} \
233	    -c ${.IMPSRC} -o ${.TARGET}
234	${CTFCONVERT_CMD}
235
236_LIBDIR:=${LIBDIR}
237_SHLIBDIR:=${SHLIBDIR}
238
239.if defined(SHLIB_NAME)
240.if ${MK_DEBUG_FILES} != "no"
241SHLIB_NAME_FULL=${SHLIB_NAME}.full
242# Use ${DEBUGDIR} for base system debug files, else .debug subdirectory
243.if ${_SHLIBDIR} == "/boot" ||\
244    ${SHLIBDIR:C%/lib(/.*)?$%/lib%} == "/lib" ||\
245    ${SHLIBDIR:C%/usr/(tests/)?lib(32|exec)?(/.*)?%/usr/lib%} == "/usr/lib"
246DEBUGFILEDIR=${DEBUGDIR}${_SHLIBDIR}
247.else
248DEBUGFILEDIR=${_SHLIBDIR}/.debug
249.endif
250.if !exists(${DESTDIR}${DEBUGFILEDIR})
251DEBUGMKDIR=
252.endif
253.else
254SHLIB_NAME_FULL=${SHLIB_NAME}
255.endif
256.endif
257
258.include <bsd.symver.mk>
259
260# Allow libraries to specify their own version map or have it
261# automatically generated (see bsd.symver.mk above).
262.if !empty(VERSION_MAP)
263${SHLIB_NAME_FULL}:	${VERSION_MAP}
264LDFLAGS+=	-Wl,--version-script=${VERSION_MAP}
265.endif
266
267.if defined(LIB) && !empty(LIB) || defined(SHLIB_NAME)
268OBJS+=		${SRCS:N*.h:${OBJS_SRCS_FILTER:ts:}:S/$/.o/}
269BCOBJS+=	${SRCS:N*.[hsS]:N*.asm:${OBJS_SRCS_FILTER:ts:}:S/$/.bco/g}
270LLOBJS+=	${SRCS:N*.[hsS]:N*.asm:${OBJS_SRCS_FILTER:ts:}:S/$/.llo/g}
271CLEANFILES+=	${OBJS} ${BCOBJS} ${LLOBJS} ${STATICOBJS}
272.endif
273
274.if defined(LIB) && !empty(LIB)
275.if defined(STATIC_LDSCRIPT)
276_STATICLIB_SUFFIX=	_real
277.endif
278_LIBS=		lib${LIB_PRIVATE}${LIB}${_STATICLIB_SUFFIX}.a
279
280lib${LIB_PRIVATE}${LIB}${_STATICLIB_SUFFIX}.a: ${OBJS} ${STATICOBJS}
281	@${ECHO} building static ${LIB} library
282	@rm -f ${.TARGET}
283	${AR} ${ARFLAGS} ${.TARGET} ${OBJS} ${STATICOBJS} ${ARADD}
284.endif
285
286.if !defined(INTERNALLIB)
287
288.if ${MK_PROFILE} != "no" && defined(LIB) && !empty(LIB)
289_LIBS+=		lib${LIB_PRIVATE}${LIB}_p.a
290POBJS+=		${OBJS:.o=.po} ${STATICOBJS:.o=.po}
291DEPENDOBJS+=	${POBJS}
292CLEANFILES+=	${POBJS}
293
294lib${LIB_PRIVATE}${LIB}_p.a: ${POBJS}
295	@${ECHO} building profiled ${LIB} library
296	@rm -f ${.TARGET}
297	${AR} ${ARFLAGS} ${.TARGET} ${POBJS} ${ARADD}
298.endif
299
300.if defined(LLVM_LINK)
301lib${LIB_PRIVATE}${LIB}.bc: ${BCOBJS}
302	${LLVM_LINK} -o ${.TARGET} ${BCOBJS}
303
304lib${LIB_PRIVATE}${LIB}.ll: ${LLOBJS}
305	${LLVM_LINK} -S -o ${.TARGET} ${LLOBJS}
306
307CLEANFILES+=	lib${LIB_PRIVATE}${LIB}.bc lib${LIB_PRIVATE}${LIB}.ll
308.endif
309
310.if defined(SHLIB_NAME) || \
311    defined(INSTALL_PIC_ARCHIVE) && defined(LIB) && !empty(LIB)
312SOBJS+=		${OBJS:.o=.pico}
313DEPENDOBJS+=	${SOBJS}
314CLEANFILES+=	${SOBJS}
315.endif
316
317.if defined(SHLIB_NAME)
318_LIBS+=		${SHLIB_NAME}
319
320SOLINKOPTS+=	-shared -Wl,-x
321.if defined(LD_FATAL_WARNINGS) && ${LD_FATAL_WARNINGS} == "no"
322SOLINKOPTS+=	-Wl,--no-fatal-warnings
323.else
324SOLINKOPTS+=	-Wl,--fatal-warnings
325.endif
326SOLINKOPTS+=	-Wl,--warn-shared-textrel
327
328.if target(beforelinking)
329beforelinking: ${SOBJS}
330${SHLIB_NAME_FULL}: beforelinking
331.endif
332
333.if defined(SHLIB_LINK)
334.if defined(SHLIB_LDSCRIPT) && !empty(SHLIB_LDSCRIPT) && exists(${.CURDIR}/${SHLIB_LDSCRIPT})
335${SHLIB_LINK:R}.ld: ${.CURDIR}/${SHLIB_LDSCRIPT}
336	sed -e 's,@@SHLIB@@,${_SHLIBDIR}/${SHLIB_NAME},g' \
337	    -e 's,@@LIBDIR@@,${_LIBDIR},g' \
338	    ${.ALLSRC} > ${.TARGET}
339
340${SHLIB_NAME_FULL}: ${SHLIB_LINK:R}.ld
341CLEANFILES+=	${SHLIB_LINK:R}.ld
342.endif
343CLEANFILES+=	${SHLIB_LINK}
344.endif
345
346${SHLIB_NAME_FULL}: ${SOBJS}
347	@${ECHO} building shared library ${SHLIB_NAME}
348	@rm -f ${SHLIB_NAME} ${SHLIB_LINK}
349.if defined(SHLIB_LINK) && !commands(${SHLIB_LINK:R}.ld) && ${MK_DEBUG_FILES} == "no"
350	# Note: This uses ln instead of ${INSTALL_LIBSYMLINK} since we are in OBJDIR
351	@${LN:Uln} -fs ${SHLIB_NAME} ${SHLIB_LINK}
352.endif
353	${_LD:N${CCACHE_BIN}} ${LDFLAGS} ${SSP_CFLAGS} ${SOLINKOPTS} \
354	    -o ${.TARGET} -Wl,-soname,${SONAME} ${SOBJS} ${LDADD}
355.if ${MK_CTF} != "no"
356	${CTFMERGE} ${CTFFLAGS} -o ${.TARGET} ${SOBJS}
357.endif
358
359.if ${MK_DEBUG_FILES} != "no"
360CLEANFILES+=	${SHLIB_NAME_FULL} ${SHLIB_NAME}.debug
361${SHLIB_NAME}: ${SHLIB_NAME_FULL} ${SHLIB_NAME}.debug
362	${OBJCOPY} --strip-debug --add-gnu-debuglink=${SHLIB_NAME}.debug \
363	    ${SHLIB_NAME_FULL} ${.TARGET}
364.if defined(SHLIB_LINK) && !commands(${SHLIB_LINK:R}.ld)
365	# Note: This uses ln instead of ${INSTALL_LIBSYMLINK} since we are in OBJDIR
366	@${LN:Uln} -fs ${SHLIB_NAME} ${SHLIB_LINK}
367.endif
368
369${SHLIB_NAME}.debug: ${SHLIB_NAME_FULL}
370	${OBJCOPY} --only-keep-debug ${SHLIB_NAME_FULL} ${.TARGET}
371.endif
372.endif #defined(SHLIB_NAME)
373
374.if defined(INSTALL_PIC_ARCHIVE) && defined(LIB) && !empty(LIB) && ${MK_TOOLCHAIN} != "no"
375_LIBS+=		lib${LIB_PRIVATE}${LIB}_pic.a
376
377lib${LIB_PRIVATE}${LIB}_pic.a: ${SOBJS}
378	@${ECHO} building special pic ${LIB} library
379	@rm -f ${.TARGET}
380	${AR} ${ARFLAGS} ${.TARGET} ${SOBJS} ${ARADD}
381.endif
382
383.if defined(BUILD_NOSSP_PIC_ARCHIVE) && defined(LIB) && !empty(LIB)
384NOSSPSOBJS+=	${OBJS:.o=.nossppico}
385DEPENDOBJS+=	${NOSSPSOBJS}
386CLEANFILES+=	${NOSSPSOBJS}
387_LIBS+=		lib${LIB_PRIVATE}${LIB}_nossp_pic.a
388
389lib${LIB_PRIVATE}${LIB}_nossp_pic.a: ${NOSSPSOBJS}
390	@${ECHO} building special nossp pic ${LIB} library
391	@rm -f ${.TARGET}
392	${AR} ${ARFLAGS} ${.TARGET} ${NOSSPSOBJS} ${ARADD}
393.endif
394
395.endif # !defined(INTERNALLIB)
396
397.if defined(INTERNALLIB) && ${MK_PIE} != "no" && defined(LIB) && !empty(LIB)
398PIEOBJS+=	${OBJS:.o=.pieo}
399DEPENDOBJS+=	${PIEOBJS}
400CLEANFILES+=	${PIEOBJS}
401
402_LIBS+=		lib${LIB_PRIVATE}${LIB}_pie.a
403
404lib${LIB_PRIVATE}${LIB}_pie.a: ${PIEOBJS}
405	@${ECHO} building pie ${LIB} library
406	@rm -f ${.TARGET}
407	${AR} ${ARFLAGS} ${.TARGET} ${PIEOBJS} ${ARADD}
408.endif
409
410.if defined(_SKIP_BUILD)
411all:
412.else
413.if defined(_LIBS) && !empty(_LIBS)
414all: ${_LIBS}
415.endif
416
417.if ${MK_MAN} != "no" && !defined(LIBRARIES_ONLY)
418all: all-man
419.endif
420.endif
421
422CLEANFILES+=	${_LIBS}
423
424_EXTRADEPEND:
425.if !defined(NO_EXTRADEPEND) && defined(SHLIB_NAME)
426.if defined(DPADD) && !empty(DPADD)
427	echo ${SHLIB_NAME_FULL}: ${DPADD} >> ${DEPENDFILE}
428.endif
429.endif
430
431.if !target(install)
432
433.if defined(PRECIOUSLIB)
434.if !defined(NO_FSCHG)
435SHLINSTALLFLAGS+= -fschg
436.endif
437.endif
438# Install libraries with -S to avoid risk of modifying in-use libraries when
439# installing to a running system.  It is safe to avoid this for NO_ROOT builds
440# that are only creating an image.
441#
442# XXX: Since Makefile.inc1 ends up building lib/libc both as part of
443# _startup_libs and as part of _generic_libs it ends up getting installed a
444# second time during the parallel build, and although the .WAIT in lib/Makefile
445# stops that mattering for lib, other directories like secure/lib are built in
446# parallel at the top level and are unaffected by that, so can sometimes race
447# with the libc.so.7 reinstall and see a missing or corrupt file. Ideally the
448# build system would be fixed to not build/install libc to WORLDTMP the second
449# time round, but for now using -S ensures the install is atomic and thus we
450# never see a broken intermediate state, so use it even for NO_ROOT builds.
451.if !defined(NO_SAFE_LIBINSTALL) #&& !defined(NO_ROOT)
452SHLINSTALLFLAGS+= -S
453SHLINSTALLSYMLINKFLAGS+= -S
454.endif
455
456_INSTALLFLAGS:=	${INSTALLFLAGS}
457.for ie in ${INSTALLFLAGS_EDIT}
458_INSTALLFLAGS:=	${_INSTALLFLAGS${ie}}
459.endfor
460_SHLINSTALLFLAGS:=	${SHLINSTALLFLAGS}
461_SHLINSTALLSYMLINKFLAGS:= ${SHLINSTALLSYMLINKFLAGS}
462.for ie in ${INSTALLFLAGS_EDIT}
463_SHLINSTALLFLAGS:=	${_SHLINSTALLFLAGS${ie}}
464.endfor
465
466.if defined(PCFILES)
467.for pcfile in ${PCFILES}
468installpcfiles: installpcfiles-${pcfile}
469
470installpcfiles-${pcfile}: ${pcfile}
471	${INSTALL} ${TAG_ARGS:D${TAG_ARGS},dev} -o ${LIBOWN} -g ${LIBGRP} -m ${LIBMODE} \
472	    ${_INSTALLFLAGS} \
473	    ${.ALLSRC} ${DESTDIR}${LIBDATADIR}/pkgconfig/
474.endfor
475.endif
476installpcfiles: .PHONY
477
478.if !defined(INTERNALLIB)
479realinstall: _libinstall installpcfiles
480.ORDER: beforeinstall _libinstall
481_libinstall:
482.if defined(LIB) && !empty(LIB) && ${MK_INSTALLLIB} != "no"
483	${INSTALL} ${TAG_ARGS:D${TAG_ARGS},dev} -C -o ${LIBOWN} -g ${LIBGRP} -m ${LIBMODE} \
484	    ${_INSTALLFLAGS} lib${LIB_PRIVATE}${LIB}${_STATICLIB_SUFFIX}.a ${DESTDIR}${_LIBDIR}/
485.if ${MK_PROFILE} != "no"
486	${INSTALL} ${TAG_ARGS:D${TAG_ARGS},dev} -C -o ${LIBOWN} -g ${LIBGRP} -m ${LIBMODE} \
487	    ${_INSTALLFLAGS} lib${LIB_PRIVATE}${LIB}_p.a ${DESTDIR}${_LIBDIR}/
488.endif
489.endif
490.if defined(SHLIB_NAME)
491	${INSTALL} ${TAG_ARGS} ${STRIP} -o ${LIBOWN} -g ${LIBGRP} -m ${LIBMODE} \
492	    ${_INSTALLFLAGS} ${_SHLINSTALLFLAGS} \
493	    ${SHLIB_NAME} ${DESTDIR}${_SHLIBDIR}/
494.if ${MK_DEBUG_FILES} != "no"
495.if defined(DEBUGMKDIR)
496	${INSTALL} ${TAG_ARGS:D${TAG_ARGS},dbg} -d ${DESTDIR}${DEBUGFILEDIR}/
497.endif
498	${INSTALL} ${TAG_ARGS:D${TAG_ARGS},dbg} -o ${LIBOWN} -g ${LIBGRP} -m ${DEBUGMODE} \
499	    ${_INSTALLFLAGS} \
500	    ${SHLIB_NAME}.debug ${DESTDIR}${DEBUGFILEDIR}/
501.endif
502.if defined(SHLIB_LINK)
503.if commands(${SHLIB_LINK:R}.ld)
504	${INSTALL} ${TAG_ARGS:D${TAG_ARGS},dev} -S -C -o ${LIBOWN} -g ${LIBGRP} -m ${LIBMODE} \
505	    ${_INSTALLFLAGS} ${SHLIB_LINK:R}.ld \
506	    ${DESTDIR}${_LIBDIR}/${SHLIB_LINK}
507.for _SHLIB_LINK_LINK in ${SHLIB_LDSCRIPT_LINKS}
508	${INSTALL_LIBSYMLINK} ${_SHLINSTALLSYMLINKFLAGS} ${TAG_ARGS} ${SHLIB_LINK} \
509	    ${DESTDIR}${_LIBDIR}/${_SHLIB_LINK_LINK}
510.endfor
511.else
512.if ${_SHLIBDIR} == ${_LIBDIR}
513.if ${SHLIB_LINK:Mlib*}
514	${INSTALL_RSYMLINK} ${_SHLINSTALLSYMLINKFLAGS} ${TAG_ARGS:D${TAG_ARGS},dev} \
515	    ${SHLIB_NAME} ${DESTDIR}${_LIBDIR}/${SHLIB_LINK}
516.else
517	${INSTALL_RSYMLINK} ${_SHLINSTALLSYMLINKFLAGS} ${TAG_ARGS} ${DESTDIR}${_SHLIBDIR}/${SHLIB_NAME} \
518	    ${DESTDIR}${_LIBDIR}/${SHLIB_LINK}
519.endif
520.else
521.if ${SHLIB_LINK:Mlib*}
522	${INSTALL_RSYMLINK} ${_SHLINSTALLSYMLINKFLAGS} ${TAG_ARGS:D${TAG_ARGS},dev} \
523	    ${DESTDIR}${_SHLIBDIR}/${SHLIB_NAME} ${DESTDIR}${_LIBDIR}/${SHLIB_LINK}
524.else
525	${INSTALL_RSYMLINK} ${_SHLINSTALLSYMLINKFLAGS} ${TAG_ARGS} \
526	    ${DESTDIR}${_SHLIBDIR}/${SHLIB_NAME} ${DESTDIR}${_LIBDIR}/${SHLIB_LINK}
527.endif
528.if exists(${DESTDIR}${_LIBDIR}/${SHLIB_NAME})
529	-chflags noschg ${DESTDIR}${_LIBDIR}/${SHLIB_NAME}
530	rm -f ${DESTDIR}${_LIBDIR}/${SHLIB_NAME}
531.endif
532.endif # _SHLIBDIR == _LIBDIR
533.endif # SHLIB_LDSCRIPT
534.endif # SHLIB_LINK
535.endif # SHIB_NAME
536.if defined(INSTALL_PIC_ARCHIVE) && defined(LIB) && !empty(LIB) && ${MK_TOOLCHAIN} != "no"
537	${INSTALL} ${TAG_ARGS:D${TAG_ARGS},dev} -o ${LIBOWN} -g ${LIBGRP} -m ${LIBMODE} \
538	    ${_INSTALLFLAGS} lib${LIB}_pic.a ${DESTDIR}${_LIBDIR}/
539.endif
540.endif # !defined(INTERNALLIB)
541
542.if !defined(LIBRARIES_ONLY)
543.include <bsd.nls.mk>
544.include <bsd.confs.mk>
545.include <bsd.files.mk>
546#No need to install header for INTERNALLIB
547.if !defined(INTERNALLIB)
548.include <bsd.incs.mk>
549.endif
550.endif
551
552LINKOWN?=	${LIBOWN}
553LINKGRP?=	${LIBGRP}
554LINKMODE?=	${LIBMODE}
555SYMLINKOWN?=	${LIBOWN}
556SYMLINKGRP?=	${LIBGRP}
557.include <bsd.links.mk>
558
559.if ${MK_MAN} != "no" && !defined(LIBRARIES_ONLY)
560realinstall: maninstall
561.ORDER: beforeinstall maninstall
562.endif
563
564.endif
565
566.if ${MK_MAN} != "no" && !defined(LIBRARIES_ONLY)
567.include <bsd.man.mk>
568.endif
569
570.if defined(LIB) && !empty(LIB)
571OBJS_DEPEND_GUESS+= ${SRCS:M*.h}
572.for _S in ${SRCS:N*.[hly]}
573OBJS_DEPEND_GUESS.${_S:${OBJS_SRCS_FILTER:ts:}}.po+=	${_S}
574.endfor
575.endif
576.if defined(SHLIB_NAME) || \
577    defined(INSTALL_PIC_ARCHIVE) && defined(LIB) && !empty(LIB)
578.for _S in ${SRCS:N*.[hly]}
579OBJS_DEPEND_GUESS.${_S:${OBJS_SRCS_FILTER:ts:}}.pico+=	${_S}
580.endfor
581.endif
582.if defined(BUILD_NOSSP_PIC_ARCHIVE) && defined(LIB) && !empty(LIB)
583.for _S in ${SRCS:N*.[hly]}
584OBJS_DEPEND_GUESS.${_S:${OBJS_SRCS_FILTER:ts:}}.nossppico+=	${_S}
585.endfor
586.endif
587
588.if defined(HAS_TESTS)
589MAKE+=			MK_MAKE_CHECK_USE_SANDBOX=yes
590SUBDIR_TARGETS+=	check
591TESTS_LD_LIBRARY_PATH+=	${.OBJDIR}
592.endif
593
594.include <bsd.dep.mk>
595.include <bsd.clang-analyze.mk>
596.include <bsd.obj.mk>
597.include <bsd.sys.mk>
598