xref: /freebsd/share/mk/bsd.lib.mk (revision ebacd8013fe5f7fdf9f6a5b286f6680dd2891036)
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
266# lld >= 16 turned on --no-undefined-version by default, but we have several
267# symbols in our version maps that may or may not exist, depending on
268# compile-time defines.
269.if ${LINKER_TYPE} == "lld" && ${LINKER_VERSION} >= 160000
270LDFLAGS+=	-Wl,--undefined-version
271.endif
272.endif
273
274.if defined(LIB) && !empty(LIB) || defined(SHLIB_NAME)
275OBJS+=		${SRCS:N*.h:${OBJS_SRCS_FILTER:ts:}:S/$/.o/}
276BCOBJS+=	${SRCS:N*.[hsS]:N*.asm:${OBJS_SRCS_FILTER:ts:}:S/$/.bco/g}
277LLOBJS+=	${SRCS:N*.[hsS]:N*.asm:${OBJS_SRCS_FILTER:ts:}:S/$/.llo/g}
278CLEANFILES+=	${OBJS} ${BCOBJS} ${LLOBJS} ${STATICOBJS}
279.endif
280
281.if defined(LIB) && !empty(LIB)
282.if defined(STATIC_LDSCRIPT)
283_STATICLIB_SUFFIX=	_real
284.endif
285_LIBS=		lib${LIB_PRIVATE}${LIB}${_STATICLIB_SUFFIX}.a
286
287lib${LIB_PRIVATE}${LIB}${_STATICLIB_SUFFIX}.a: ${OBJS} ${STATICOBJS}
288	@${ECHO} building static ${LIB} library
289	@rm -f ${.TARGET}
290	${AR} ${ARFLAGS} ${.TARGET} ${OBJS} ${STATICOBJS} ${ARADD}
291.endif
292
293.if !defined(INTERNALLIB)
294
295.if ${MK_PROFILE} != "no" && defined(LIB) && !empty(LIB)
296_LIBS+=		lib${LIB_PRIVATE}${LIB}_p.a
297POBJS+=		${OBJS:.o=.po} ${STATICOBJS:.o=.po}
298DEPENDOBJS+=	${POBJS}
299CLEANFILES+=	${POBJS}
300
301lib${LIB_PRIVATE}${LIB}_p.a: ${POBJS}
302	@${ECHO} building profiled ${LIB} library
303	@rm -f ${.TARGET}
304	${AR} ${ARFLAGS} ${.TARGET} ${POBJS} ${ARADD}
305.endif
306
307.if defined(LLVM_LINK)
308lib${LIB_PRIVATE}${LIB}.bc: ${BCOBJS}
309	${LLVM_LINK} -o ${.TARGET} ${BCOBJS}
310
311lib${LIB_PRIVATE}${LIB}.ll: ${LLOBJS}
312	${LLVM_LINK} -S -o ${.TARGET} ${LLOBJS}
313
314CLEANFILES+=	lib${LIB_PRIVATE}${LIB}.bc lib${LIB_PRIVATE}${LIB}.ll
315.endif
316
317.if defined(SHLIB_NAME) || \
318    defined(INSTALL_PIC_ARCHIVE) && defined(LIB) && !empty(LIB)
319SOBJS+=		${OBJS:.o=.pico}
320DEPENDOBJS+=	${SOBJS}
321CLEANFILES+=	${SOBJS}
322.endif
323
324.if defined(SHLIB_NAME)
325_LIBS+=		${SHLIB_NAME}
326
327SOLINKOPTS+=	-shared -Wl,-x
328.if defined(LD_FATAL_WARNINGS) && ${LD_FATAL_WARNINGS} == "no"
329SOLINKOPTS+=	-Wl,--no-fatal-warnings
330.else
331SOLINKOPTS+=	-Wl,--fatal-warnings
332.endif
333SOLINKOPTS+=	-Wl,--warn-shared-textrel
334
335.if target(beforelinking)
336beforelinking: ${SOBJS}
337${SHLIB_NAME_FULL}: beforelinking
338.endif
339
340.if defined(SHLIB_LINK)
341.if defined(SHLIB_LDSCRIPT) && !empty(SHLIB_LDSCRIPT) && exists(${.CURDIR}/${SHLIB_LDSCRIPT})
342${SHLIB_LINK:R}.ld: ${.CURDIR}/${SHLIB_LDSCRIPT}
343	sed -e 's,@@SHLIB@@,${_SHLIBDIR}/${SHLIB_NAME},g' \
344	    -e 's,@@LIBDIR@@,${_LIBDIR},g' \
345	    ${.ALLSRC} > ${.TARGET}
346
347${SHLIB_NAME_FULL}: ${SHLIB_LINK:R}.ld
348CLEANFILES+=	${SHLIB_LINK:R}.ld
349.endif
350CLEANFILES+=	${SHLIB_LINK}
351.endif
352
353${SHLIB_NAME_FULL}: ${SOBJS}
354	@${ECHO} building shared library ${SHLIB_NAME}
355	@rm -f ${SHLIB_NAME} ${SHLIB_LINK}
356.if defined(SHLIB_LINK) && !commands(${SHLIB_LINK:R}.ld) && ${MK_DEBUG_FILES} == "no"
357	# Note: This uses ln instead of ${INSTALL_LIBSYMLINK} since we are in OBJDIR
358	@${LN:Uln} -fs ${SHLIB_NAME} ${SHLIB_LINK}
359.endif
360	${_LD:N${CCACHE_BIN}} ${LDFLAGS} ${SSP_CFLAGS} ${SOLINKOPTS} \
361	    -o ${.TARGET} -Wl,-soname,${SONAME} ${SOBJS} ${LDADD}
362.if ${MK_CTF} != "no"
363	${CTFMERGE} ${CTFFLAGS} -o ${.TARGET} ${SOBJS}
364.endif
365
366.if ${MK_DEBUG_FILES} != "no"
367CLEANFILES+=	${SHLIB_NAME_FULL} ${SHLIB_NAME}.debug
368${SHLIB_NAME}: ${SHLIB_NAME_FULL} ${SHLIB_NAME}.debug
369	${OBJCOPY} --strip-debug --add-gnu-debuglink=${SHLIB_NAME}.debug \
370	    ${SHLIB_NAME_FULL} ${.TARGET}
371.if defined(SHLIB_LINK) && !commands(${SHLIB_LINK:R}.ld)
372	# Note: This uses ln instead of ${INSTALL_LIBSYMLINK} since we are in OBJDIR
373	@${LN:Uln} -fs ${SHLIB_NAME} ${SHLIB_LINK}
374.endif
375
376${SHLIB_NAME}.debug: ${SHLIB_NAME_FULL}
377	${OBJCOPY} --only-keep-debug ${SHLIB_NAME_FULL} ${.TARGET}
378.endif
379.endif #defined(SHLIB_NAME)
380
381.if defined(INSTALL_PIC_ARCHIVE) && defined(LIB) && !empty(LIB) && ${MK_TOOLCHAIN} != "no"
382_LIBS+=		lib${LIB_PRIVATE}${LIB}_pic.a
383
384lib${LIB_PRIVATE}${LIB}_pic.a: ${SOBJS}
385	@${ECHO} building special pic ${LIB} library
386	@rm -f ${.TARGET}
387	${AR} ${ARFLAGS} ${.TARGET} ${SOBJS} ${ARADD}
388.endif
389
390.if defined(BUILD_NOSSP_PIC_ARCHIVE) && defined(LIB) && !empty(LIB)
391NOSSPSOBJS+=	${OBJS:.o=.nossppico}
392DEPENDOBJS+=	${NOSSPSOBJS}
393CLEANFILES+=	${NOSSPSOBJS}
394_LIBS+=		lib${LIB_PRIVATE}${LIB}_nossp_pic.a
395
396lib${LIB_PRIVATE}${LIB}_nossp_pic.a: ${NOSSPSOBJS}
397	@${ECHO} building special nossp pic ${LIB} library
398	@rm -f ${.TARGET}
399	${AR} ${ARFLAGS} ${.TARGET} ${NOSSPSOBJS} ${ARADD}
400.endif
401
402.endif # !defined(INTERNALLIB)
403
404.if defined(INTERNALLIB) && ${MK_PIE} != "no" && defined(LIB) && !empty(LIB)
405PIEOBJS+=	${OBJS:.o=.pieo}
406DEPENDOBJS+=	${PIEOBJS}
407CLEANFILES+=	${PIEOBJS}
408
409_LIBS+=		lib${LIB_PRIVATE}${LIB}_pie.a
410
411lib${LIB_PRIVATE}${LIB}_pie.a: ${PIEOBJS}
412	@${ECHO} building pie ${LIB} library
413	@rm -f ${.TARGET}
414	${AR} ${ARFLAGS} ${.TARGET} ${PIEOBJS} ${ARADD}
415.endif
416
417.if defined(_SKIP_BUILD)
418all:
419.else
420.if defined(_LIBS) && !empty(_LIBS)
421all: ${_LIBS}
422.endif
423
424.if ${MK_MAN} != "no" && !defined(LIBRARIES_ONLY)
425all: all-man
426.endif
427.endif
428
429CLEANFILES+=	${_LIBS}
430
431_EXTRADEPEND:
432.if !defined(NO_EXTRADEPEND) && defined(SHLIB_NAME)
433.if defined(DPADD) && !empty(DPADD)
434	echo ${SHLIB_NAME_FULL}: ${DPADD} >> ${DEPENDFILE}
435.endif
436.endif
437
438.if !target(install)
439
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} -C -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} -C -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 -C -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) && ${MK_TOOLCHAIN} != "no"
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}
564.include <bsd.links.mk>
565
566.if ${MK_MAN} != "no" && !defined(LIBRARIES_ONLY)
567realinstall: maninstall
568.ORDER: beforeinstall maninstall
569.endif
570
571.endif
572
573.if ${MK_MAN} != "no" && !defined(LIBRARIES_ONLY)
574.include <bsd.man.mk>
575.endif
576
577.if defined(LIB) && !empty(LIB)
578OBJS_DEPEND_GUESS+= ${SRCS:M*.h}
579.for _S in ${SRCS:N*.[hly]}
580OBJS_DEPEND_GUESS.${_S:${OBJS_SRCS_FILTER:ts:}}.po+=	${_S}
581.endfor
582.endif
583.if defined(SHLIB_NAME) || \
584    defined(INSTALL_PIC_ARCHIVE) && defined(LIB) && !empty(LIB)
585.for _S in ${SRCS:N*.[hly]}
586OBJS_DEPEND_GUESS.${_S:${OBJS_SRCS_FILTER:ts:}}.pico+=	${_S}
587.endfor
588.endif
589.if defined(BUILD_NOSSP_PIC_ARCHIVE) && defined(LIB) && !empty(LIB)
590.for _S in ${SRCS:N*.[hly]}
591OBJS_DEPEND_GUESS.${_S:${OBJS_SRCS_FILTER:ts:}}.nossppico+=	${_S}
592.endfor
593.endif
594
595.if defined(HAS_TESTS)
596MAKE+=			MK_MAKE_CHECK_USE_SANDBOX=yes
597SUBDIR_TARGETS+=	check
598TESTS_LD_LIBRARY_PATH+=	${.OBJDIR}
599.endif
600
601.include <bsd.dep.mk>
602.include <bsd.clang-analyze.mk>
603.include <bsd.obj.mk>
604.include <bsd.sys.mk>
605