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