xref: /freebsd/share/mk/bsd.lib.mk (revision 19261079b74319502c6ffa1249920079f0f69a72)
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_LIBS=		lib${LIB_PRIVATE}${LIB}.a
275
276lib${LIB_PRIVATE}${LIB}.a: ${OBJS} ${STATICOBJS}
277	@${ECHO} building static ${LIB} library
278	@rm -f ${.TARGET}
279	${AR} ${ARFLAGS} ${.TARGET} ${OBJS} ${STATICOBJS} ${ARADD}
280.endif
281
282.if !defined(INTERNALLIB)
283
284.if ${MK_PROFILE} != "no" && defined(LIB) && !empty(LIB)
285_LIBS+=		lib${LIB_PRIVATE}${LIB}_p.a
286POBJS+=		${OBJS:.o=.po} ${STATICOBJS:.o=.po}
287DEPENDOBJS+=	${POBJS}
288CLEANFILES+=	${POBJS}
289
290lib${LIB_PRIVATE}${LIB}_p.a: ${POBJS}
291	@${ECHO} building profiled ${LIB} library
292	@rm -f ${.TARGET}
293	${AR} ${ARFLAGS} ${.TARGET} ${POBJS} ${ARADD}
294.endif
295
296.if defined(LLVM_LINK)
297lib${LIB_PRIVATE}${LIB}.bc: ${BCOBJS}
298	${LLVM_LINK} -o ${.TARGET} ${BCOBJS}
299
300lib${LIB_PRIVATE}${LIB}.ll: ${LLOBJS}
301	${LLVM_LINK} -S -o ${.TARGET} ${LLOBJS}
302
303CLEANFILES+=	lib${LIB_PRIVATE}${LIB}.bc lib${LIB_PRIVATE}${LIB}.ll
304.endif
305
306.if defined(SHLIB_NAME) || \
307    defined(INSTALL_PIC_ARCHIVE) && defined(LIB) && !empty(LIB)
308SOBJS+=		${OBJS:.o=.pico}
309DEPENDOBJS+=	${SOBJS}
310CLEANFILES+=	${SOBJS}
311.endif
312
313.if defined(SHLIB_NAME)
314_LIBS+=		${SHLIB_NAME}
315
316SOLINKOPTS+=	-shared -Wl,-x
317.if defined(LD_FATAL_WARNINGS) && ${LD_FATAL_WARNINGS} == "no"
318SOLINKOPTS+=	-Wl,--no-fatal-warnings
319.else
320SOLINKOPTS+=	-Wl,--fatal-warnings
321.endif
322SOLINKOPTS+=	-Wl,--warn-shared-textrel
323
324.if target(beforelinking)
325beforelinking: ${SOBJS}
326${SHLIB_NAME_FULL}: beforelinking
327.endif
328
329.if defined(SHLIB_LINK)
330.if defined(SHLIB_LDSCRIPT) && !empty(SHLIB_LDSCRIPT) && exists(${.CURDIR}/${SHLIB_LDSCRIPT})
331${SHLIB_LINK:R}.ld: ${.CURDIR}/${SHLIB_LDSCRIPT}
332	sed -e 's,@@SHLIB@@,${_SHLIBDIR}/${SHLIB_NAME},g' \
333	    -e 's,@@LIBDIR@@,${_LIBDIR},g' \
334	    ${.ALLSRC} > ${.TARGET}
335
336${SHLIB_NAME_FULL}: ${SHLIB_LINK:R}.ld
337CLEANFILES+=	${SHLIB_LINK:R}.ld
338.endif
339CLEANFILES+=	${SHLIB_LINK}
340.endif
341
342${SHLIB_NAME_FULL}: ${SOBJS}
343	@${ECHO} building shared library ${SHLIB_NAME}
344	@rm -f ${SHLIB_NAME} ${SHLIB_LINK}
345.if defined(SHLIB_LINK) && !commands(${SHLIB_LINK:R}.ld) && ${MK_DEBUG_FILES} == "no"
346	# Note: This uses ln instead of ${INSTALL_LIBSYMLINK} since we are in OBJDIR
347	@${LN:Uln} -fs ${SHLIB_NAME} ${SHLIB_LINK}
348.endif
349	${_LD:N${CCACHE_BIN}} ${LDFLAGS} ${SSP_CFLAGS} ${SOLINKOPTS} \
350	    -o ${.TARGET} -Wl,-soname,${SONAME} ${SOBJS} ${LDADD}
351.if ${MK_CTF} != "no"
352	${CTFMERGE} ${CTFFLAGS} -o ${.TARGET} ${SOBJS}
353.endif
354
355.if ${MK_DEBUG_FILES} != "no"
356CLEANFILES+=	${SHLIB_NAME_FULL} ${SHLIB_NAME}.debug
357${SHLIB_NAME}: ${SHLIB_NAME_FULL} ${SHLIB_NAME}.debug
358	${OBJCOPY} --strip-debug --add-gnu-debuglink=${SHLIB_NAME}.debug \
359	    ${SHLIB_NAME_FULL} ${.TARGET}
360.if defined(SHLIB_LINK) && !commands(${SHLIB_LINK:R}.ld)
361	# Note: This uses ln instead of ${INSTALL_LIBSYMLINK} since we are in OBJDIR
362	@${LN:Uln} -fs ${SHLIB_NAME} ${SHLIB_LINK}
363.endif
364
365${SHLIB_NAME}.debug: ${SHLIB_NAME_FULL}
366	${OBJCOPY} --only-keep-debug ${SHLIB_NAME_FULL} ${.TARGET}
367.endif
368.endif #defined(SHLIB_NAME)
369
370.if defined(INSTALL_PIC_ARCHIVE) && defined(LIB) && !empty(LIB) && ${MK_TOOLCHAIN} != "no"
371_LIBS+=		lib${LIB_PRIVATE}${LIB}_pic.a
372
373lib${LIB_PRIVATE}${LIB}_pic.a: ${SOBJS}
374	@${ECHO} building special pic ${LIB} library
375	@rm -f ${.TARGET}
376	${AR} ${ARFLAGS} ${.TARGET} ${SOBJS} ${ARADD}
377.endif
378
379.if defined(BUILD_NOSSP_PIC_ARCHIVE) && defined(LIB) && !empty(LIB)
380NOSSPSOBJS+=	${OBJS:.o=.nossppico}
381DEPENDOBJS+=	${NOSSPSOBJS}
382CLEANFILES+=	${NOSSPSOBJS}
383_LIBS+=		lib${LIB_PRIVATE}${LIB}_nossp_pic.a
384
385lib${LIB_PRIVATE}${LIB}_nossp_pic.a: ${NOSSPSOBJS}
386	@${ECHO} building special nossp pic ${LIB} library
387	@rm -f ${.TARGET}
388	${AR} ${ARFLAGS} ${.TARGET} ${NOSSPSOBJS} ${ARADD}
389.endif
390
391.endif # !defined(INTERNALLIB)
392
393.if defined(INTERNALLIB) && ${MK_PIE} != "no"
394PIEOBJS+=	${OBJS:.o=.pieo}
395DEPENDOBJS+=	${PIEOBJS}
396CLEANFILES+=	${PIEOBJS}
397
398_LIBS+=		lib${LIB_PRIVATE}${LIB}_pie.a
399
400lib${LIB_PRIVATE}${LIB}_pie.a: ${PIEOBJS}
401	@${ECHO} building pie ${LIB} library
402	@rm -f ${.TARGET}
403	${AR} ${ARFLAGS} ${.TARGET} ${PIEOBJS} ${ARADD}
404.endif
405
406.if defined(_SKIP_BUILD)
407all:
408.else
409.if defined(_LIBS) && !empty(_LIBS)
410all: ${_LIBS}
411.endif
412
413.if ${MK_MAN} != "no" && !defined(LIBRARIES_ONLY)
414all: all-man
415.endif
416.endif
417
418CLEANFILES+=	${_LIBS}
419
420_EXTRADEPEND:
421.if !defined(NO_EXTRADEPEND) && defined(SHLIB_NAME)
422.if defined(DPADD) && !empty(DPADD)
423	echo ${SHLIB_NAME_FULL}: ${DPADD} >> ${DEPENDFILE}
424.endif
425.endif
426
427.if !target(install)
428
429.if defined(PRECIOUSLIB)
430.if !defined(NO_FSCHG)
431SHLINSTALLFLAGS+= -fschg
432.endif
433.endif
434# Install libraries with -S to avoid risk of modifying in-use libraries when
435# installing to a running system.  It is safe to avoid this for NO_ROOT builds
436# that are only creating an image.
437#
438# XXX: Since Makefile.inc1 ends up building lib/libc both as part of
439# _startup_libs and as part of _generic_libs it ends up getting installed a
440# second time during the parallel build, and although the .WAIT in lib/Makefile
441# stops that mattering for lib, other directories like secure/lib are built in
442# parallel at the top level and are unaffected by that, so can sometimes race
443# with the libc.so.7 reinstall and see a missing or corrupt file. Ideally the
444# build system would be fixed to not build/install libc to WORLDTMP the second
445# time round, but for now using -S ensures the install is atomic and thus we
446# never see a broken intermediate state, so use it even for NO_ROOT builds.
447.if !defined(NO_SAFE_LIBINSTALL) #&& !defined(NO_ROOT)
448SHLINSTALLFLAGS+= -S
449SHLINSTALLSYMLINKFLAGS+= -S
450.endif
451
452_INSTALLFLAGS:=	${INSTALLFLAGS}
453.for ie in ${INSTALLFLAGS_EDIT}
454_INSTALLFLAGS:=	${_INSTALLFLAGS${ie}}
455.endfor
456_SHLINSTALLFLAGS:=	${SHLINSTALLFLAGS}
457_SHLINSTALLSYMLINKFLAGS:= ${SHLINSTALLSYMLINKFLAGS}
458.for ie in ${INSTALLFLAGS_EDIT}
459_SHLINSTALLFLAGS:=	${_SHLINSTALLFLAGS${ie}}
460.endfor
461
462.if defined(PCFILES)
463.for pcfile in ${PCFILES}
464installpcfiles: installpcfiles-${pcfile}
465
466installpcfiles-${pcfile}: ${pcfile}
467	${INSTALL} ${TAG_ARGS:D${TAG_ARGS},dev} -o ${LIBOWN} -g ${LIBGRP} -m ${LIBMODE} \
468	    ${_INSTALLFLAGS} \
469	    ${.ALLSRC} ${DESTDIR}${LIBDATADIR}/pkgconfig
470.endfor
471.endif
472installpcfiles: .PHONY
473
474.if !defined(INTERNALLIB)
475realinstall: _libinstall installpcfiles
476.ORDER: beforeinstall _libinstall
477_libinstall:
478.if defined(LIB) && !empty(LIB) && ${MK_INSTALLLIB} != "no"
479	${INSTALL} ${TAG_ARGS:D${TAG_ARGS},dev} -C -o ${LIBOWN} -g ${LIBGRP} -m ${LIBMODE} \
480	    ${_INSTALLFLAGS} lib${LIB_PRIVATE}${LIB}.a ${DESTDIR}${_LIBDIR}/
481.endif
482.if ${MK_PROFILE} != "no" && defined(LIB) && !empty(LIB)
483	${INSTALL} ${TAG_ARGS:D${TAG_ARGS},dev} -C -o ${LIBOWN} -g ${LIBGRP} -m ${LIBMODE} \
484	    ${_INSTALLFLAGS} lib${LIB_PRIVATE}${LIB}_p.a ${DESTDIR}${_LIBDIR}/
485.endif
486.if defined(SHLIB_NAME)
487	${INSTALL} ${TAG_ARGS} ${STRIP} -o ${LIBOWN} -g ${LIBGRP} -m ${LIBMODE} \
488	    ${_INSTALLFLAGS} ${_SHLINSTALLFLAGS} \
489	    ${SHLIB_NAME} ${DESTDIR}${_SHLIBDIR}/
490.if ${MK_DEBUG_FILES} != "no"
491.if defined(DEBUGMKDIR)
492	${INSTALL} ${TAG_ARGS:D${TAG_ARGS},dbg} -d ${DESTDIR}${DEBUGFILEDIR}/
493.endif
494	${INSTALL} ${TAG_ARGS:D${TAG_ARGS},dbg} -o ${LIBOWN} -g ${LIBGRP} -m ${DEBUGMODE} \
495	    ${_INSTALLFLAGS} \
496	    ${SHLIB_NAME}.debug ${DESTDIR}${DEBUGFILEDIR}/
497.endif
498.if defined(SHLIB_LINK)
499.if commands(${SHLIB_LINK:R}.ld)
500	${INSTALL} ${TAG_ARGS:D${TAG_ARGS},dev} -S -C -o ${LIBOWN} -g ${LIBGRP} -m ${LIBMODE} \
501	    ${_INSTALLFLAGS} ${SHLIB_LINK:R}.ld \
502	    ${DESTDIR}${_LIBDIR}/${SHLIB_LINK}
503.for _SHLIB_LINK_LINK in ${SHLIB_LDSCRIPT_LINKS}
504	${INSTALL_LIBSYMLINK} ${_SHLINSTALLSYMLINKFLAGS} ${TAG_ARGS} ${SHLIB_LINK} \
505	    ${DESTDIR}${_LIBDIR}/${_SHLIB_LINK_LINK}
506.endfor
507.else
508.if ${_SHLIBDIR} == ${_LIBDIR}
509.if ${SHLIB_LINK:Mlib*}
510	${INSTALL_RSYMLINK} ${_SHLINSTALLSYMLINKFLAGS} ${TAG_ARGS:D${TAG_ARGS},dev} \
511	    ${SHLIB_NAME} ${DESTDIR}${_LIBDIR}/${SHLIB_LINK}
512.else
513	${INSTALL_RSYMLINK} ${_SHLINSTALLSYMLINKFLAGS} ${TAG_ARGS} ${DESTDIR}${_SHLIBDIR}/${SHLIB_NAME} \
514	    ${DESTDIR}${_LIBDIR}/${SHLIB_LINK}
515.endif
516.else
517.if ${SHLIB_LINK:Mlib*}
518	${INSTALL_RSYMLINK} ${_SHLINSTALLSYMLINKFLAGS} ${TAG_ARGS:D${TAG_ARGS},dev} \
519	    ${DESTDIR}${_SHLIBDIR}/${SHLIB_NAME} ${DESTDIR}${_LIBDIR}/${SHLIB_LINK}
520.else
521	${INSTALL_RSYMLINK} ${_SHLINSTALLSYMLINKFLAGS} ${TAG_ARGS} \
522	    ${DESTDIR}${_SHLIBDIR}/${SHLIB_NAME} ${DESTDIR}${_LIBDIR}/${SHLIB_LINK}
523.endif
524.if exists(${DESTDIR}${_LIBDIR}/${SHLIB_NAME})
525	-chflags noschg ${DESTDIR}${_LIBDIR}/${SHLIB_NAME}
526	rm -f ${DESTDIR}${_LIBDIR}/${SHLIB_NAME}
527.endif
528.endif # _SHLIBDIR == _LIBDIR
529.endif # SHLIB_LDSCRIPT
530.endif # SHLIB_LINK
531.endif # SHIB_NAME
532.if defined(INSTALL_PIC_ARCHIVE) && defined(LIB) && !empty(LIB) && ${MK_TOOLCHAIN} != "no"
533	${INSTALL} ${TAG_ARGS:D${TAG_ARGS},dev} -o ${LIBOWN} -g ${LIBGRP} -m ${LIBMODE} \
534	    ${_INSTALLFLAGS} lib${LIB}_pic.a ${DESTDIR}${_LIBDIR}/
535.endif
536.endif # !defined(INTERNALLIB)
537
538.if !defined(LIBRARIES_ONLY)
539.include <bsd.nls.mk>
540.include <bsd.confs.mk>
541.include <bsd.files.mk>
542#No need to install header for INTERNALLIB
543.if !defined(INTERNALLIB)
544.include <bsd.incs.mk>
545.endif
546.endif
547
548LINKOWN?=	${LIBOWN}
549LINKGRP?=	${LIBGRP}
550LINKMODE?=	${LIBMODE}
551SYMLINKOWN?=	${LIBOWN}
552SYMLINKGRP?=	${LIBGRP}
553.include <bsd.links.mk>
554
555.if ${MK_MAN} != "no" && !defined(LIBRARIES_ONLY)
556realinstall: maninstall
557.ORDER: beforeinstall maninstall
558.endif
559
560.endif
561
562.if ${MK_MAN} != "no" && !defined(LIBRARIES_ONLY)
563.include <bsd.man.mk>
564.endif
565
566.if defined(LIB) && !empty(LIB)
567OBJS_DEPEND_GUESS+= ${SRCS:M*.h}
568.for _S in ${SRCS:N*.[hly]}
569OBJS_DEPEND_GUESS.${_S:${OBJS_SRCS_FILTER:ts:}}.po+=	${_S}
570.endfor
571.endif
572.if defined(SHLIB_NAME) || \
573    defined(INSTALL_PIC_ARCHIVE) && defined(LIB) && !empty(LIB)
574.for _S in ${SRCS:N*.[hly]}
575OBJS_DEPEND_GUESS.${_S:${OBJS_SRCS_FILTER:ts:}}.pico+=	${_S}
576.endfor
577.endif
578.if defined(BUILD_NOSSP_PIC_ARCHIVE) && defined(LIB) && !empty(LIB)
579.for _S in ${SRCS:N*.[hly]}
580OBJS_DEPEND_GUESS.${_S:${OBJS_SRCS_FILTER:ts:}}.nossppico+=	${_S}
581.endfor
582.endif
583
584.if defined(HAS_TESTS)
585MAKE+=			MK_MAKE_CHECK_USE_SANDBOX=yes
586SUBDIR_TARGETS+=	check
587TESTS_LD_LIBRARY_PATH+=	${.OBJDIR}
588.endif
589
590.include <bsd.dep.mk>
591.include <bsd.clang-analyze.mk>
592.include <bsd.obj.mk>
593.include <bsd.sys.mk>
594