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