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