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