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