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