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