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