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