bsd.lib.mk revision 1.410 1 # $NetBSD: bsd.lib.mk,v 1.410 2024/11/01 23:06:17 christos Exp $
2 # @(#)bsd.lib.mk 8.3 (Berkeley) 4/22/94
3
4 .include <bsd.init.mk>
5 .include <bsd.shlib.mk>
6 .include <bsd.gcc.mk>
7 .include <bsd.sanitizer.mk>
8
9 # Pull in <bsd.sys.mk> here so we can override its .c.o rule
10 .include <bsd.sys.mk>
11
12 LIBISMODULE?= no
13 LIBISPRIVATE?= no
14 LIBISCXX?= no
15
16 .if ${LIBISMODULE} != "no"
17 _LIB_PREFIX?= # empty
18 MKDEBUGLIB:= no
19 MKPROFILE:= no
20 MKPICINSTALL:= no
21 MAKESTATICLIB?= no
22 MAKELINKLIB?= yes
23 _LINTINSTALL?= no
24 .else
25 _LIB_PREFIX?= lib
26 .endif
27
28 .if ${LIBISPRIVATE} != "no"
29 MKDEBUGLIB:= no
30 MKPROFILE:= no
31 MKPICINSTALL:= no
32 . if defined(NOSTATICLIB) && ${MKPICLIB} != "no"
33 MAKESTATICLIB?= no
34 . elif ${LIBISPRIVATE} != "pic"
35 MKPIC:= no
36 . endif
37 MAKELINKLIB?= no
38 _LINTINSTALL?= no
39 .endif
40
41 _LINTINSTALL?= ${MKLINT}
42 LINKINSTALL?= ${MAKELINKLIB}
43 MAKELINKLIB?= ${MKLINKLIB}
44 MAKESTATICLIB?= ${MKSTATICLIB}
45
46 ##### Basic targets
47 .PHONY: checkver libinstall
48 realinstall: checkver libinstall
49
50 ##### LIB specific flags.
51 # XXX: This is needed for programs that link with .a libraries
52 # Perhaps a more correct solution is to always generate _pic.a
53 # files or always have a shared library.
54 # Another fix is to provide rcrt0.o like OpenBSD does and
55 # do relocations for static PIE.
56 .if defined(MKPIE) && (${MKPIE} != "no") && !defined(NOPIE)
57 CFLAGS+= ${PIE_CFLAGS}
58 AFLAGS+= ${PIE_AFLAGS}
59 .endif
60 # The -fPIC is needed for libraries that include other libares
61 # The order matters here, PIC needs to be last
62 .if ${LIBISPRIVATE} == "pic"
63 CFLAGS+= -fPIC
64 AFLAGS+= -fPIC
65 .endif
66
67 PGFLAGS+= -pg
68 .if ${MKPIC} != "no"
69 PGFLAGS+= -fPIC
70 .endif
71
72 ##### Libraries that this may depend upon.
73 .if defined(LIBDPLIBS) && ${MKPIC} != "no" # {
74 .for _lib _dir in ${LIBDPLIBS}
75 .if !defined(LIBDO.${_lib})
76 LIBDO.${_lib}!= cd "${_dir}" && ${PRINTOBJDIR}
77 .MAKEOVERRIDES+=LIBDO.${_lib}
78 .endif
79 .if ${LIBDO.${_lib}} == "_external"
80 LDADD+= -l${_lib}
81 .else
82 LDADD+= -L${LIBDO.${_lib}} -l${_lib}
83 .if exists(${LIBDO.${_lib}}/lib${_lib}_pic.a)
84 DPADD+= ${LIBDO.${_lib}}/lib${_lib}_pic.a
85 .elif exists(${LIBDO.${_lib}}/lib${_lib}.so)
86 DPADD+= ${LIBDO.${_lib}}/lib${_lib}.so
87 .else
88 DPADD+= ${LIBDO.${_lib}}/lib${_lib}.a
89 .endif
90 .endif
91 .endfor
92 .endif # }
93
94 ##### Build and install rules
95 MKDEP_SUFFIXES?= .o .po .pico .go .ln .d
96
97 .if !defined(SHLIB_MAJOR) && exists(${SHLIB_VERSION_FILE}) # {
98 SHLIB_MAJOR != . ${SHLIB_VERSION_FILE} ; echo $$major
99 SHLIB_MINOR != . ${SHLIB_VERSION_FILE} ; echo $$minor
100 SHLIB_TEENY != . ${SHLIB_VERSION_FILE} ; echo $$teeny
101
102 DPADD+= ${SHLIB_VERSION_FILE}
103
104 # Check for higher installed library versions.
105 .if !defined(NOCHECKVER) && !defined(NOCHECKVER_${LIB}) && \
106 exists(${NETBSDSRCDIR}/lib/checkver)
107 checkver:
108 @(cd "${.CURDIR}" && \
109 HOST_SH=${HOST_SH:Q} AWK=${TOOL_AWK:Q} \
110 ${HOST_SH} ${NETBSDSRCDIR}/lib/checkver -v ${SHLIB_VERSION_FILE} \
111 -d ${_DEST.OBJ} ${LIB})
112 .endif
113 .endif # }
114
115 .if !target(checkver)
116 checkver:
117 .endif
118
119 print-shlib-major:
120 .if defined(SHLIB_MAJOR) && ${MKPIC} != "no"
121 @echo ${SHLIB_MAJOR}
122 .else
123 @false
124 .endif
125
126 print-shlib-minor:
127 .if defined(SHLIB_MINOR) && ${MKPIC} != "no"
128 @echo ${SHLIB_MINOR}
129 .else
130 @false
131 .endif
132
133 print-shlib-teeny:
134 .if defined(SHLIB_TEENY) && ${MKPIC} != "no"
135 @echo ${SHLIB_TEENY}
136 .else
137 @false
138 .endif
139
140 .if ${LIBISPRIVATE} == "no"
141 .if defined(SHLIB_MAJOR) && !empty(SHLIB_MAJOR) # {
142 .if defined(SHLIB_MINOR) && !empty(SHLIB_MINOR)
143 .if defined(SHLIB_TEENY) && !empty(SHLIB_TEENY)
144 SHLIB_FULLVERSION=${SHLIB_MAJOR}.${SHLIB_MINOR}.${SHLIB_TEENY}
145 .else
146 SHLIB_FULLVERSION=${SHLIB_MAJOR}.${SHLIB_MINOR}
147 .endif
148 .else
149 SHLIB_FULLVERSION=${SHLIB_MAJOR}
150 .endif
151 .endif # }
152 .endif
153
154 # add additional suffixes not exported.
155 # .po is used for profiling object files.
156 # .pico is used for PIC object files.
157 .SUFFIXES: .out .a .ln .pico .po .go .o .s .S .c .cc .cpp .cxx .C .m .F .f .r .y .l .cl .p .h
158 .SUFFIXES: .sh .m4 .m
159
160
161 # Set PICFLAGS to cc flags for producing position-independent code,
162 # if not already set.
163
164 # Data-driven table using make variables to control how shared libraries
165 # are built for different platforms and object formats.
166 # SHLIB_MAJOR, SHLIB_MINOR, SHLIB_TEENY: Major, minor, and teeny version
167 # numbers of shared library
168 # SHLIB_SOVERSION: version number to be compiled into a shared library
169 # via -soname. Usually ${SHLIB_MAJOR} on ELF.
170 # NetBSD/pmax used to use ${SHLIB_MAJOR}[.${SHLIB_MINOR}
171 # [.${SHLIB_TEENY}]]
172 # SHLIB_SHFLAGS: Flags to tell ${LD} to emit shared library.
173 # with ELF, also set shared-lib version for ld.so.
174 # SHLIB_LDSTARTFILE: support .o file, call C++ file-level constructors
175 # SHLIB_LDENDFILE: support .o file, call C++ file-level destructors
176
177 PICFLAGS ?= -fPIC
178
179 .if ${MKPICLIB} != "no"
180 CSHLIBFLAGS+= ${PICFLAGS} ${SANITIZERFLAGS} ${LIBCSANITIZERFLAGS}
181 .endif
182
183 .if defined(CSHLIBFLAGS) && !empty(CSHLIBFLAGS)
184 MKSHLIBOBJS= yes
185 .else
186 MKSHLIBOBJS= no
187 .endif
188
189 # Avoid adding "-g" if we already have a "-g*" option.
190 .if (${MKDEBUG:Uno} != "no" && !defined(NODEBUG)) && \
191 (!defined(CFLAGS) || empty(CFLAGS:M-g*)) && \
192 (!defined(CXXFLAGS) || empty(CXXFLAGS:M-g*))
193 # We only add -g to the shared library objects
194 # because we don't currently split .a archives.
195 CSHLIBFLAGS+= -g
196 .if ${LIBISPRIVATE} != "no"
197 CFLAGS+= -g
198 .endif
199 .endif
200
201 # Platform-independent linker flags for ELF shared libraries
202 SHLIB_SOVERSION= ${SHLIB_MAJOR}
203 SHLIB_SHFLAGS= -Wl,-soname,${_LIB}.so.${SHLIB_SOVERSION}
204 SHLIB_SHFLAGS+= ${SANITIZERFLAGS}
205 .if !defined(SHLIB_WARNTEXTREL) || ${SHLIB_WARNTEXTREL} != "no"
206 SHLIB_SHFLAGS+= -Wl,--warn-shared-textrel
207 .endif
208 .if !defined(SHLIB_MKMAP) || ${SHLIB_MKMAP} != "no"
209 SHLIB_SHFLAGS+= -Wl,-Map=${_LIB}.so.${SHLIB_SOVERSION}.map
210 .endif
211 CLEANFILES+= ${_LIB}.so.${SHLIB_SOVERSION}.map
212 SHLIB_LDSTARTFILE?= ${_GCC_CRTI} ${_GCC_CRTBEGINS}
213 SHLIB_LDENDFILE?= ${_GCC_CRTENDS} ${_GCC_CRTN}
214
215 CFLAGS+= ${COPTS}
216 OBJCFLAGS+= ${OBJCOPTS}
217 AFLAGS+= ${COPTS}
218 FFLAGS+= ${FOPTS}
219
220 .if defined(CTFCONVERT)
221 .if defined(CFLAGS) && !empty(CFLAGS:M*-g*)
222 CTFFLAGS+= -g
223 .if defined(HAVE_GCC)
224 #CFLAGS+= -gdwarf-2
225 .endif
226 .endif
227 .endif
228
229 LIBSTRIPAOBJS= yes
230 .if !defined(CFLAGS) || empty(CFLAGS:M*-g*)
231 LIBSTRIPCOBJS= yes
232 .endif
233 .if !defined(OBJCFLAGS) || empty(OBJCFLAGS:M*-g*)
234 LIBSTRIPOBJCOBJS= yes
235 .endif
236 .if !defined(FFLAGS) || empty(FFLAGS:M*-g*)
237 LIBSTRIPFOBJS= yes
238 .endif
239 .if !defined(CSHLIBFLAGS) || empty(CSHLIBFLAGS:M*-g*)
240 LIBSTRIPSHLIBOBJS= yes
241 .endif
242
243 .c.o:
244 ${_MKTARGET_COMPILE}
245 ${COMPILE.c} ${COPTS.${.IMPSRC:T}} ${CPUFLAGS.${.IMPSRC:T}} ${CPPFLAGS.${.IMPSRC:T}} ${.IMPSRC} ${OBJECT_TARGET}
246 ${CTFCONVERT_RUN}
247 .if defined(LIBSTRIPCOBJS)
248 ${OBJCOPY} ${OBJCOPYLIBFLAGS} ${.TARGET}
249 .endif
250
251 .c.po:
252 ${_MKTARGET_COMPILE}
253 ${COMPILE.c} ${PROFFLAGS} ${COPTS.${.IMPSRC:T}} ${CPUFLAGS.${.IMPSRC:T}} ${CPPFLAGS.${.IMPSRC:T}} ${PGFLAGS} ${.IMPSRC} ${OBJECT_TARGET}
254 ${CTFCONVERT_RUN}
255 .if defined(LIBSTRIPCOBJS)
256 ${OBJCOPY} ${OBJCOPYLIBFLAGS} ${.TARGET}
257 .endif
258
259 .c.go:
260 ${_MKTARGET_COMPILE}
261 ${COMPILE.c} ${DEBUGFLAGS} ${COPTS.${.IMPSRC:T}} ${CPUFLAGS.${.IMPSRC:T}} ${CPPFLAGS.${.IMPSRC:T}} -g ${.IMPSRC} -o ${.TARGET}
262
263 .c.pico:
264 ${_MKTARGET_COMPILE}
265 ${COMPILE.c} ${COPTS.${.IMPSRC:T}} ${CPUFLAGS.${.IMPSRC:T}} ${CPPFLAGS.${.IMPSRC:T}} ${CSHLIBFLAGS} ${.IMPSRC} -o ${.TARGET}
266 .if defined(LIBSTRIPSHLIBOBJS)
267 ${OBJCOPY} ${OBJCOPYLIBFLAGS} ${.TARGET}
268 .endif
269
270 .cc.o .cpp.o .cxx.o .C.o:
271 ${_MKTARGET_COMPILE}
272 ${COMPILE.cc} ${COPTS.${.IMPSRC:T}} ${CPUFLAGS.${.IMPSRC:T}} ${CPPFLAGS.${.IMPSRC:T}} ${.IMPSRC} -o ${.TARGET}
273 .if defined(LIBSTRIPCOBJS)
274 ${OBJCOPY} ${OBJCOPYLIBFLAGS} ${.TARGET}
275 .endif
276
277 .cc.po .cpp.po .cxx.po .C.po:
278 ${_MKTARGET_COMPILE}
279 ${COMPILE.cc} ${PROFFLAGS} ${COPTS.${.IMPSRC:T}} ${CPUFLAGS.${.IMPSRC:T}} ${CPPFLAGS.${.IMPSRC:T}} ${PGFLAGS} ${.IMPSRC} -o ${.TARGET}
280 .if defined(LIBSTRIPCOBJS)
281 ${OBJCOPY} ${OBJCOPYLIBFLAGS} ${.TARGET}
282 .endif
283
284 .cc.go .cpp.go .cxx.go .C.go:
285 ${_MKTARGET_COMPILE}
286 ${COMPILE.cc} ${DEBUGFLAGS} ${COPTS.${.IMPSRC:T}} ${CPUFLAGS.${.IMPSRC:T}} ${CPPFLAGS.${.IMPSRC:T}} -g ${.IMPSRC} -o ${.TARGET}
287
288 .cc.pico .cpp.pico .cxx.pico .C.pico:
289 ${_MKTARGET_COMPILE}
290 ${COMPILE.cc} ${COPTS.${.IMPSRC:T}} ${CPUFLAGS.${.IMPSRC:T}} ${CPPFLAGS.${.IMPSRC:T}} ${CSHLIBFLAGS} ${.IMPSRC} -o ${.TARGET}
291 .if defined(LIBSTRIPSHLIBOBJS)
292 ${OBJCOPY} ${OBJCOPYLIBFLAGS} ${.TARGET}
293 .endif
294
295 .f.o:
296 ${_MKTARGET_COMPILE}
297 ${COMPILE.f} ${.IMPSRC} ${OBJECT_TARGET}
298 ${CTFCONVERT_RUN}
299 .if defined(LIBSTRIPFOBJS)
300 ${OBJCOPY} ${OBJCOPYLIBFLAGS} ${.TARGET}
301 .endif
302
303 .f.po:
304 ${_MKTARGET_COMPILE}
305 ${COMPILE.f} ${PROFFLAGS} ${PGFLAGS} ${.IMPSRC} ${OBJECT_TARGET}
306 ${CTFCONVERT_RUN}
307 .if defined(LIBSTRIPFOBJS)
308 ${OBJCOPY} ${OBJCOPYLIBFLAGS} ${.TARGET}
309 .endif
310
311 .f.go:
312 ${_MKTARGET_COMPILE}
313 ${COMPILE.f} ${DEBUGFLAGS} -g ${.IMPSRC} -o ${.TARGET}
314
315 .f.pico:
316 ${_MKTARGET_COMPILE}
317 ${COMPILE.f} ${PICFLAGS} ${.IMPSRC} -o ${.TARGET}
318 .if defined(LIBSTRIPFOBJS)
319 ${OBJCOPY} ${OBJCOPYLIBFLAGS} ${.TARGET}
320 .endif
321
322 .f.ln:
323 ${_MKTARGET_COMPILE}
324 @echo Skipping lint for Fortran libraries.
325
326 .m.o:
327 ${_MKTARGET_COMPILE}
328 ${COMPILE.m} ${OBJCOPTS.${.IMPSRC:T}} ${.IMPSRC} ${OBJECT_TARGET}
329 ${CTFCONVERT_RUN}
330 .if defined(LIBSTRIPOBJCOBJS)
331 ${OBJCOPY} ${OBJCOPYLIBFLAGS} ${.TARGET}
332 .endif
333
334 .m.po:
335 ${_MKTARGET_COMPILE}
336 ${COMPILE.m} ${PROFFLAGS} ${PGFLAGS} ${OBJCOPTS.${.IMPSRC:T}} ${.IMPSRC} ${OBJECT_TARGET}
337 ${CTFCONVERT_RUN}
338 .if defined(LIBSTRIPOBJCOBJS)
339 ${OBJCOPY} ${OBJCOPYLIBFLAGS} ${.TARGET}
340 .endif
341
342 .m.go:
343 ${_MKTARGET_COMPILE}
344 ${COMPILE.m} ${DEBUGFLAGS} -g ${OBJCOPTS.${.IMPSRC:T}} ${.IMPSRC} -o ${.TARGET}
345 .if defined(LIBSTRIPOBJCOBJS)
346 ${OBJCOPY} ${OBJCOPYLIBFLAGS} ${.TARGET}
347 .endif
348
349 .m.pico:
350 ${_MKTARGET_COMPILE}
351 ${COMPILE.m} ${CSHLIBFLAGS} ${OBJCOPTS.${.IMPSRC:T}} ${.IMPSRC} -o ${.TARGET}
352 .if defined(LIBSTRIPOBJCOBJS)
353 ${OBJCOPY} ${OBJCOPYLIBFLAGS} ${.TARGET}
354 .endif
355
356 .s.o:
357 ${_MKTARGET_COMPILE}
358 ${COMPILE.s} ${COPTS.${.IMPSRC:T}} ${CPUFLAGS.${.IMPSRC:T}} ${CPPFLAGS.${.IMPSRC:T}} ${.IMPSRC} ${OBJECT_TARGET}
359 ${CTFCONVERT_RUN}
360 .if defined(LIBSTRIPAOBJS)
361 ${OBJCOPY} ${OBJCOPYLIBFLAGS} ${.TARGET}
362 .endif
363
364 .S.o:
365 ${_MKTARGET_COMPILE}
366 ${COMPILE.S} ${COPTS.${.IMPSRC:T}} ${CPUFLAGS.${.IMPSRC:T}} ${CPPFLAGS.${.IMPSRC:T}} ${.IMPSRC} ${OBJECT_TARGET}
367 ${CTFCONVERT_RUN}
368 .if defined(LIBSTRIPAOBJS)
369 ${OBJCOPY} ${OBJCOPYLIBFLAGS} ${.TARGET}
370 .endif
371
372 .s.po:
373 ${_MKTARGET_COMPILE}
374 ${COMPILE.s} ${PROFFLAGS} ${COPTS.${.IMPSRC:T}} ${CPUFLAGS.${.IMPSRC:T}} ${CPPFLAGS.${.IMPSRC:T}} ${.IMPSRC} ${OBJECT_TARGET}
375 ${CTFCONVERT_RUN}
376 .if defined(LIBSTRIPAOBJS)
377 ${OBJCOPY} ${OBJCOPYLIBFLAGS} ${.TARGET}
378 .endif
379
380 .S.po:
381 ${_MKTARGET_COMPILE}
382 ${COMPILE.S} ${PROFFLAGS} ${COPTS.${.IMPSRC:T}} ${CPUFLAGS.${.IMPSRC:T}} ${CPPFLAGS.${.IMPSRC:T}} ${.IMPSRC} ${OBJECT_TARGET}
383 ${CTFCONVERT_RUN}
384 .if defined(LIBSTRIPAOBJS)
385 ${OBJCOPY} ${OBJCOPYLIBFLAGS} ${.TARGET}
386 .endif
387
388 .s.go:
389 ${_MKTARGET_COMPILE}
390 ${COMPILE.s} ${DEBUGFLAGS} ${COPTS.${.IMPSRC:T}} ${CPUFLAGS.${.IMPSRC:T}} ${CPPFLAGS.${.IMPSRC:T}} ${.IMPSRC} -o ${.TARGET}
391
392 .S.go:
393 ${_MKTARGET_COMPILE}
394 ${COMPILE.S} ${DEBUGFLAGS} ${COPTS.${.IMPSRC:T}} ${CPUFLAGS.${.IMPSRC:T}} ${CPPFLAGS.${.IMPSRC:T}} ${.IMPSRC} -o ${.TARGET}
395
396 .s.pico:
397 ${_MKTARGET_COMPILE}
398 ${COMPILE.s} ${PICFLAGS} ${COPTS.${.IMPSRC:T}} ${CPUFLAGS.${.IMPSRC:T}} ${CPPFLAGS.${.IMPSRC:T}} ${.IMPSRC} -o ${.TARGET}
399 .if defined(LIBSTRIPAOBJS)
400 ${OBJCOPY} ${OBJCOPYLIBFLAGS} ${.TARGET}
401 .endif
402
403 .S.pico:
404 ${_MKTARGET_COMPILE}
405 ${COMPILE.S} ${PICFLAGS} ${COPTS.${.IMPSRC:T}} ${CPUFLAGS.${.IMPSRC:T}} ${CPPFLAGS.${.IMPSRC:T}} ${.IMPSRC} -o ${.TARGET}
406 .if defined(LIBSTRIPAOBJS)
407 ${OBJCOPY} ${OBJCOPYLIBFLAGS} ${.TARGET}
408 .endif
409
410 # Declare a few variables to make our life easier later.
411 _LIB:=${_LIB_PREFIX}${LIB}
412 _LIB.a:=${_LIB}.a
413 _LIB_p.a:=${_LIB}_p.a
414 _LIB_g.a:=${_LIB}_g.a
415 _LIB_pic.a:=${_LIB}_pic.a
416 _LIB.ln:=llib-l${LIB}.ln
417
418 .if ${MKPIC} != "no" && defined(SHLIB_FULLVERSION)
419 _LIB.so:=${_LIB}.so
420 _LIB.so.major:=${_LIB}.so.${SHLIB_MAJOR}
421 _LIB.so.full:=${_LIB}.so.${SHLIB_FULLVERSION}
422 _LIB.so.link:=${_LIB}.so.${SHLIB_FULLVERSION}.link
423 .if ${MKDEBUG:Uno} != "no" && !defined(NODEBUG)
424 _LIB.so.debug:=${_LIB.so.full}.debug
425 .endif
426 .endif
427
428 _DEST.LIB:=${DESTDIR}${LIBDIR}
429 _DEST.OBJ:=${DESTDIR}${_LIBSODIR}
430 _DEST.LINT:=${DESTDIR}${LINTLIBDIR}
431 _DEST.DEBUG:=${DESTDIR}${DEBUGDIR}${LIBDIR}
432 _DEST.ODEBUG:=${DESTDIR}${DEBUGDIR}${_LIBSODIR}
433
434 .if ${MKPIC} == "no" || (defined(LDSTATIC) && ${LDSTATIC} != "") \
435 || ${MAKELINKLIB} != "no" || ${MAKESTATICLIB} != "no"
436 _BUILDSTATICLIB=yes
437 .else
438 _BUILDSTATICLIB=no
439 .endif
440
441 .if defined(LIB) # {
442 .if ${_BUILDSTATICLIB} != "no"
443 _LIBS=${_LIB.a}
444 .else
445 _LIBS=
446 .endif
447
448 OBJS+=${SRCS:N*.h:N*.sh:R:S/$/.o/g}
449
450 STOBJS+=${OBJS}
451
452 LOBJS+=${LSRCS:.c=.ln} ${SRCS:M*.c:.c=.ln}
453
454 .if ${LIBISPRIVATE} != "no"
455 # No installation is required
456 libinstall::
457 .endif
458
459 .if ${MKDEBUGLIB} != "no"
460 _LIBS+=${_LIB_g.a}
461 GOBJS+=${OBJS:.o=.go}
462 DEBUGFLAGS?=-DDEBUG
463 .endif
464
465 .if ${MKPROFILE} != "no"
466 _LIBS+=${_LIB_p.a}
467 POBJS+=${OBJS:.o=.po}
468 PROFFLAGS?=-DGPROF -DPROF
469 .endif
470
471 .if ${MKPIC} != "no" # {
472 .if ${MKPICLIB} == "no"
473 .if ${MKSHLIBOBJS} != "no"
474 # make _pic.a, which isn't really pic,
475 # since it's needed for making shared lib.
476 # but don't install it.
477 SOLIB=${_LIB_pic.a}
478 SOBJS+=${OBJS:.o=.pico}
479 .else
480 SOLIB=${_LIB.a}
481 .endif
482 .else
483 SOLIB=${_LIB_pic.a}
484 _LIBS+=${SOLIB}
485 SOBJS+=${OBJS:.o=.pico}
486 .endif
487 .if defined(SHLIB_FULLVERSION)
488 _LIBS+=${_LIB.so.full}
489 .endif
490 .endif # }
491
492 .if ${MKLINT} != "no" && !empty(LOBJS)
493 _LIBS+=${_LIB.ln}
494 .endif
495
496 ALLOBJS=
497 .if ${_BUILDSTATICLIB} != "no"
498 ALLOBJS+=${STOBJS}
499 .endif
500 ALLOBJS+=${POBJS} ${SOBJS}
501 .if ${MKLINT} != "no" && !empty(LOBJS)
502 ALLOBJS+=${LOBJS}
503 .endif
504 .else # !defined(LIB) # } {
505 LOBJS=
506 SOBJS=
507 .endif # !defined(LIB) # }
508
509 _YLSRCS= ${SRCS:M*.[ly]:C/\..$/.c/} ${YHEADER:D${SRCS:M*.y:.y=.h}}
510
511 .NOPATH: ${ALLOBJS} ${_LIBS} ${_YLSRCS}
512
513 realall: ${SRCS} ${ALLOBJS:O} ${_LIBS} ${_LIB.so.debug}
514
515 .if ${MKARZERO} == "yes"
516 _ARFL=crsD
517 _ARRANFL=sD
518 _INSTRANLIB=
519 .else
520 _ARFL=crs
521 _ARRANFL=s
522 _INSTRANLIB=${empty(PRESERVE):?-a "${RANLIB} -t":}
523 .endif
524
525 # If you change this, please consider reflecting the change in
526 # the override in sys/rump/Makefile.rump.
527 .if !target(__archivebuild)
528 __archivebuild: .USE
529 ${_MKTARGET_BUILD}
530 @rm -f ${.TARGET}
531 ${AR} ${_ARFL} ${.TARGET} $$(NM=${NM} ${LORDER} ${.ALLSRC:M*o} | ${TSORT})
532 .endif
533
534 .if !target(__archiveinstall)
535 __archiveinstall: .USE
536 ${_MKTARGET_INSTALL}
537 ${INSTALL_FILE} -o ${LIBOWN} -g ${LIBGRP} -m ${LIBMODE} \
538 ${_INSTRANLIB} ${.ALLSRC} ${.TARGET}
539 .endif
540
541 __archivesymlinkpic: .USE
542 ${_MKTARGET_INSTALL}
543 ${INSTALL_SYMLINK} ${.ALLSRC} ${.TARGET}
544
545 .if !target(__buildstdlib)
546 __buildstdlib: .USE
547 @echo building standard ${.TARGET:T:S/.o//:S/lib//} library
548 @rm -f ${.TARGET}
549 @${LINK.c:S/-nostdinc//} -nostdlib ${LDFLAGS} -Wno-unused-command-line-argument -r -o ${.TARGET} $$(NM=${NM} ${LORDER} ${.ALLSRC:M*o} | ${TSORT})
550 .endif
551
552 .if !target(__buildproflib)
553 __buildproflib: .USE
554 @echo building profiled ${.TARGET:T:S/.o//:S/lib//} library
555 ${_MKTARGET_BUILD}
556 @rm -f ${.TARGET}
557 @${LINK.c:S/-nostdinc//} -nostdlib ${LDFLAGS} -r -o ${.TARGET} $$(NM=${NM} ${LORDER} ${.ALLSRC:M*po} | ${TSORT})
558 .endif
559
560 DPSRCS+= ${_YLSRCS}
561 CLEANFILES+= ${_YLSRCS}
562
563 ${STOBJS} ${POBJS} ${GOBJS} ${SOBJS} ${LOBJS}: ${DPSRCS}
564
565 ${_LIB.a}:: ${STOBJS} __archivebuild
566
567 ${_LIB_p.a}:: ${POBJS} __archivebuild
568
569 ${_LIB_pic.a}:: ${SOBJS} __archivebuild
570
571 ${_LIB_g.a}:: ${GOBJS} __archivebuild
572
573
574 _LIBLDOPTS=
575 .if ${SHLIBDIR} != "/usr/lib"
576 _LIBLDOPTS+= -Wl,-rpath,${SHLIBDIR} \
577 -L=${SHLIBDIR}
578 .elif ${SHLIBINSTALLDIR} != "/usr/lib"
579 _LIBLDOPTS+= -Wl,-rpath-link,${DESTDIR}${SHLIBINSTALLDIR} \
580 -L=${SHLIBINSTALLDIR}
581 .endif
582 .if ${MKSTRIPSYM} != "no"
583 _LIBLDOPTS+= -Wl,-x
584 .else
585 _LIBLDOPTS+= -Wl,-X
586 .endif
587
588 # gcc -shared now adds -lc automatically. For libraries other than libc and
589 # libgcc* we add as a dependency the installed shared libc. For libc and
590 # libgcc* we avoid adding libc as a dependency by using -nostdlib. Note that
591 # -Xl,-nostdlib is not enough because we want to tell the compiler-driver not
592 # to add standard libraries, not the linker.
593 .if !defined(LIB)
594 .if !empty(LIBC_SO)
595 DPLIBC ?= ${DESTDIR}${LIBC_SO}
596 .endif
597 .else
598 .if ${LIB} != "c" && ${LIB:Mgcc*} == ""
599 .if !empty(LIBC_SO)
600 DPLIBC ?= ${DESTDIR}${LIBC_SO}
601 .endif
602 .else
603 LDLIBC ?= -nodefaultlibs
604 .if ${HAVE_LIBGCC} == "yes" && ${LIB} == "c"
605 LDADD+= -lgcc
606 .endif
607 .endif
608 .endif
609
610 .if ${LIBISCXX} != "no"
611 LIBCC:= ${CXX}
612 . if ${MKLIBCXX} == "yes"
613 LIBDPLIBS+= c++ ${.CURDIR}/../../../../../external/bsd/libc++/lib
614 . else
615 LIBDPLIBS+= stdc++ ${.CURDIR}/../../../../../external/gpl3/${EXTERNAL_GCC_SUBDIR}/lib/libstdc++-v3
616 . endif
617 .else
618 LIBCC:= ${CC}
619 .endif
620
621 # VERSION_MAP
622 #
623 # Path to an ld version script to use when linking the library.
624 # Resolved from .PATH like a target prerequisite.
625 #
626 # Implemented by adding -Wl,--version-script=${${VERSION_MAP}:P}
627 # to LDFLAGS, and by adding ${VERSION_MAP} to DPADD to make it a
628 # target prerequisite so :P works.
629 #
630 .if !empty(VERSION_MAP)
631 DPADD+= ${VERSION_MAP}
632 LDFLAGS+= -Wl,--version-script=${${VERSION_MAP}:P}
633 .endif
634
635 _LDADD.${_LIB}= ${LDADD} ${LDADD.${_LIB}}
636 _LDFLAGS.${_LIB}= ${LDFLAGS} ${LDFLAGS.${_LIB}}
637
638 _MAINLIBDEPS= ${SOLIB} ${DPADD} ${DPLIBC} \
639 ${SHLIB_LDSTARTFILE} ${SHLIB_LDENDFILE}
640
641 .if defined(_LIB.so.debug)
642 ${_LIB.so.debug}: ${_LIB.so.link}
643 ${_MKTARGET_CREATE}
644 ( ${OBJCOPY} --only-keep-debug --compress-debug-sections \
645 ${_LIB.so.link} ${_LIB.so.debug} \
646 ) || (rm -f ${.TARGET}; false)
647 ${_LIB.so.full}: ${_LIB.so.link} ${_LIB.so.debug}
648 ${_MKTARGET_CREATE}
649 ( ${OBJCOPY} --strip-debug -p -R .gnu_debuglink \
650 --add-gnu-debuglink=${_LIB.so.debug} \
651 ${_LIB.so.link} ${_LIB.so.full}.tmp && \
652 ${MV} ${_LIB.so.full}.tmp ${_LIB.so.full} \
653 ) || (rm -f ${.TARGET}; false)
654 ${_LIB.so.link}: ${_MAINLIBDEPS}
655 .else # aka no MKDEBUG
656 ${_LIB.so.full}: ${_MAINLIBDEPS}
657 .endif
658 ${_MKTARGET_BUILD}
659 rm -f ${.TARGET}
660 ${LIBCC} ${LDLIBC} -shared ${SHLIB_SHFLAGS} \
661 ${_LDFLAGS.${_LIB}} -o ${.TARGET}.tmp ${_LIBLDOPTS} \
662 -Wl,--whole-archive ${SOLIB} \
663 -Wl,--no-whole-archive ${_LDADD.${_LIB}}
664 .if ${MKSTRIPIDENT} != "no"
665 ${OBJCOPY} -R .ident ${.TARGET}.tmp
666 .endif
667 ${MV} ${.TARGET}.tmp ${.TARGET}
668 # We don't use INSTALL_SYMLINK here because this is just
669 # happening inside the build directory/objdir. XXX Why does
670 # this spend so much effort on libraries that aren't live??? XXX
671 # XXX Also creates dead symlinks until the .full rule runs
672 # above and creates the main link
673 .if defined(SHLIB_FULLVERSION) && defined(SHLIB_MAJOR) && \
674 "${SHLIB_FULLVERSION}" != "${SHLIB_MAJOR}"
675 ${HOST_LN} -sf ${_LIB.so.full} ${_LIB.so.major}.tmp
676 ${MV} ${_LIB.so.major}.tmp ${_LIB.so.major}
677 .endif
678 ${HOST_LN} -sf ${_LIB.so.full} ${_LIB.so}.tmp
679 ${MV} ${_LIB.so}.tmp ${_LIB.so}
680
681 # If there's a file listing expected symbols, fail if the diff from it
682 # to the actual symbols is nonempty, and show the diff in that case.
683 .if exists(${.CURDIR}/${LIB}.${LIBC_MACHINE_ARCH:U${MACHINE_ARCH}}.expsym)
684 LIB_EXPSYM?= ${LIB}.${LIBC_MACHINE_ARCH:U${MACHINE_ARCH}}.expsym
685 .elif exists(${.CURDIR}/${LIB}.${LIBC_MACHINE_CPU:U${MACHINE_CPU}}.expsym)
686 LIB_EXPSYM?= ${LIB}.${LIBC_MACHINE_CPU:U${MACHINE_CPU}}.expsym
687 .elif exists(${.CURDIR}/${LIB}.expsym)
688 LIB_EXPSYM?= ${LIB}.expsym
689 .endif
690
691 .if !empty(LIB_EXPSYM) && ${MKPIC} != "no"
692 realall: ${_LIB.so.full}.diffsym
693 ${_LIB.so.full}.diffsym: ${LIB_EXPSYM} ${_LIB.so.full}.actsym
694 ${_MKTARGET_CREATE}
695 if diff -u ${.ALLSRC} >${.TARGET}.tmp; then \
696 ${MV} ${.TARGET}.tmp ${.TARGET}; \
697 else \
698 ret=$$?; \
699 cat ${.TARGET}.tmp; \
700 echo ${_LIB.so.full}: error: \
701 actual symbols differ from expected symbols >&2; \
702 exit $$ret; \
703 fi
704 ${_LIB.so.full}.actsym: ${_LIB.so.full}
705 ${_MKTARGET_CREATE}
706 ${NM} --dynamic --extern-only --defined-only --with-symbol-versions \
707 ${.ALLSRC} \
708 | cut -d' ' -f3 | LANG=C sort -u >${.TARGET}.tmp
709 ${MV} ${.TARGET}.tmp ${.TARGET}
710 CLEANFILES+= ${_LIB.so.full}.actsym
711 CLEANFILES+= ${_LIB.so.full}.actsym.tmp
712 CLEANFILES+= ${_LIB.so.full}.diffsym
713 CLEANFILES+= ${_LIB.so.full}.diffsym.tmp
714 update-symbols: .PHONY
715 update-symbols: ${_LIB.so.full}.actsym
716 cp ${.ALLSRC} ${defined(NETBSDSRCDIR_RW):?${.CURDIR:C,^${NETBSDSRCDIR}/,${NETBSDSRCDIR_RW}/,}:${.CURDIR}}/${LIB_EXPSYM}
717 .endif
718
719 .if !empty(LOBJS) # {
720 LLIBS?= -lc
721 ${_LIB.ln}: ${LOBJS}
722 ${_MKTARGET_COMPILE}
723 rm -f ${.TARGET}
724 .if defined(DESTDIR)
725 ${LINT} -C${LIB} ${.ALLSRC} -L${DESTDIR}/usr/libdata ${LLIBS}
726 .else
727 ${LINT} -C${LIB} ${.ALLSRC} ${LLIBS}
728 .endif
729 .endif # }
730
731 # Only intended to be invoked manually, not as part of dependall.
732 lint: ${LOBJS}
733 .if defined(LOBJS) && !empty(LOBJS)
734 ${LINT} ${LINTFLAGS} -Cmanual-lint ${LOBJS}
735 .endif
736
737
738 # If the number of entries in CLEANFILES is too large, then the
739 # commands in bsd.clean.mk encounter errors like "exec(/bin/sh)
740 # failed (Argument list too long)". Avoid that by splitting the
741 # files to clean into several lists using different variable names.
742 # __cleanuse is an internal target in bsd.clean.mk; the way we
743 # use it here mimics the way it's used by the clean target in
744 # bsd.clean.mk.
745 #
746 clean: libclean1 libclean2 libclean3 libclean4 libclean5
747 libclean1: .PHONY .MADE __cleanuse LIBCLEANFILES1
748 libclean2: .PHONY .MADE __cleanuse LIBCLEANFILES2
749 libclean3: .PHONY .MADE __cleanuse LIBCLEANFILES3
750 libclean4: .PHONY .MADE __cleanuse LIBCLEANFILES4
751 libclean5: .PHONY .MADE __cleanuse LIBCLEANFILES5
752 CLEANFILES+= a.out [Ee]rrs mklog core *.core
753 LIBCLEANFILES1+= ${_LIB.a} ${STOBJS} ${STOBJS:=.tmp}
754 LIBCLEANFILES2+= ${_LIB_p.a} ${POBJS} ${POBJS:=.tmp}
755 LIBCLEANFILES3+= ${_LIB_g.a} ${GOBJS} ${GOBJS:=.tmp}
756 LIBCLEANFILES4+= ${_LIB_pic.a}
757 .if ${MKPIC} != "no" && defined(SHLIB_FULLVERSION)
758 LIBCLEANFILES4+= ${_LIB.so}.* ${_LIB.so} ${_LIB.so.debug}
759 .endif
760 LIBCLEANFILES4+= ${SOBJS} ${SOBJS:=.tmp}
761 LIBCLEANFILES5+= ${_LIB.ln} ${LOBJS} llib-lmanual-lint.ln
762
763 .if !target(libinstall) # {
764 # Make sure it gets defined, in case MKPIC==no && MKLINKLIB==no
765 libinstall::
766
767 .if ${MAKELINKLIB} != "no" && ${MAKESTATICLIB} != "no" && ${LINKINSTALL} != "no"
768 libinstall:: ${_DEST.LIB}/${_LIB.a}
769 .PRECIOUS: ${_DEST.LIB}/${_LIB.a}
770
771 .if ${MKUPDATE} == "no"
772 .if !defined(BUILD) && !make(all) && !make(${_LIB.a})
773 ${_DEST.LIB}/${_LIB.a}! .MADE
774 .endif
775 ${_DEST.LIB}/${_LIB.a}! ${_LIB.a} __archiveinstall
776 .else
777 .if !defined(BUILD) && !make(all) && !make(${_LIB.a})
778 ${_DEST.LIB}/${_LIB.a}: .MADE
779 .endif
780 ${_DEST.LIB}/${_LIB.a}: ${_LIB.a} __archiveinstall
781 .endif
782 .endif
783
784 .if ${MKPROFILE} != "no"
785 libinstall:: ${_DEST.LIB}/${_LIB_p.a}
786 .PRECIOUS: ${_DEST.LIB}/${_LIB_p.a}
787
788 .if ${MKUPDATE} == "no"
789 .if !defined(BUILD) && !make(all) && !make(${_LIB_p.a})
790 ${_DEST.LIB}/${_LIB_p.a}! .MADE
791 .endif
792 ${_DEST.LIB}/${_LIB_p.a}! ${_LIB_p.a} __archiveinstall
793 .else
794 .if !defined(BUILD) && !make(all) && !make(${_LIB_p.a})
795 ${_DEST.LIB}/${_LIB_p.a}: .MADE
796 .endif
797 ${_DEST.LIB}/${_LIB_p.a}: ${_LIB_p.a} __archiveinstall
798 .endif
799 .endif
800
801 .if ${MKDEBUGLIB} != "no"
802 libinstall:: ${_DEST.LIB}/${_LIB_g.a}
803 .PRECIOUS: ${_DEST.LIB}/${_LIB_g.a}
804
805 .if ${MKUPDATE} == "no"
806 .if !defined(BUILD) && !make(all) && !make(${_LIB_g.a})
807 ${_DEST.LIB}/${_LIB_g.a}! .MADE
808 .endif
809 ${_DEST.LIB}/${_LIB_g.a}! ${_LIB_g.a} __archiveinstall
810 .else
811 .if !defined(BUILD) && !make(all) && !make(${LIB_g.a})
812 ${_DEST.LIB}/${_LIB_g.a}: .MADE
813 .endif
814 ${_DEST.LIB}/${_LIB_g.a}: ${_LIB_g.a} __archiveinstall
815 .endif
816 .endif
817
818 .if ${MKPIC} != "no" && ${MKPICINSTALL} != "no"
819 libinstall:: ${_DEST.LIB}/${_LIB_pic.a}
820 .PRECIOUS: ${_DEST.LIB}/${_LIB_pic.a}
821
822 .if ${MKUPDATE} == "no"
823 .if !defined(BUILD) && !make(all) && !make(${_LIB_pic.a})
824 ${_DEST.LIB}/${_LIB_pic.a}! .MADE
825 .endif
826 .if ${MKPICLIB} == "no"
827 ${_DEST.LIB}/${_LIB_pic.a}! ${_LIB.a} __archivesymlinkpic
828 .else
829 ${_DEST.LIB}/${_LIB_pic.a}! ${_LIB_pic.a} __archiveinstall
830 .endif
831 .else
832 .if !defined(BUILD) && !make(all) && !make(${_LIB_pic.a})
833 ${_DEST.LIB}/${_LIB_pic.a}: .MADE
834 .endif
835 .if ${MKPICLIB} == "no"
836 ${_DEST.LIB}/${_LIB_pic.a}: ${_LIB.a} __archivesymlinkpic
837 .else
838 ${_DEST.LIB}/${_LIB_pic.a}: ${_LIB_pic.a} __archiveinstall
839 .endif
840 .endif
841 .endif
842
843 .if ${MKPIC} != "no" && defined(SHLIB_FULLVERSION)
844
845 libinstall:: ${_DEST.OBJ}/${_LIB.so.full}
846 .PRECIOUS: ${_DEST.OBJ}/${_LIB.so.full}
847
848 .if ${MKUPDATE} == "no"
849 .if !defined(BUILD) && !make(all) && !make(${_LIB.so.full})
850 ${_DEST.OBJ}/${_LIB.so.full}! .MADE
851 .endif
852 ${_DEST.OBJ}/${_LIB.so.full}! ${_LIB.so.full}
853 .else
854 .if !defined(BUILD) && !make(all) && !make(${_LIB.so.full})
855 ${_DEST.OBJ}/${_LIB.so.full}: .MADE
856 .endif
857 ${_DEST.OBJ}/${_LIB.so.full}: ${_LIB.so.full}
858 .endif
859 ${_MKTARGET_INSTALL}
860 ${INSTALL_FILE} -o ${LIBOWN} -g ${LIBGRP} -m ${LIBMODE} \
861 ${.ALLSRC} ${.TARGET}
862 .if ${_LIBSODIR} != ${LIBDIR}
863 ${INSTALL_SYMLINK} -l r ${_DEST.OBJ}/${_LIB.so.full} \
864 ${_DEST.LIB}/${_LIB.so.full}
865 .endif
866 .if defined(SHLIB_FULLVERSION) && defined(SHLIB_MAJOR) && \
867 "${SHLIB_FULLVERSION}" != "${SHLIB_MAJOR}"
868 ${INSTALL_SYMLINK} ${_LIB.so.full} ${_DEST.OBJ}/${_LIB.so.major}
869 .if ${_LIBSODIR} != ${LIBDIR}
870 ${INSTALL_SYMLINK} -l r ${_DEST.OBJ}/${_LIB.so.full} \
871 ${_DEST.LIB}/${_LIB.so.major}
872 .endif
873 .endif
874 .if ${MAKELINKLIB} != "no" && ${LINKINSTALL} != "no"
875 ${INSTALL_SYMLINK} ${_LIB.so.full} ${_DEST.OBJ}/${_LIB.so}
876 .if ${_LIBSODIR} != ${LIBDIR}
877 ${INSTALL_SYMLINK} -l r ${_DEST.OBJ}/${_LIB.so.full} \
878 ${_DEST.LIB}/${_LIB.so}
879 .endif
880 .endif
881 .endif
882
883 .if defined(_LIB.so.debug)
884 libinstall:: ${_DEST.DEBUG}/${_LIB.so.debug}
885 .PRECIOUS: ${_DEST.DEBUG}/${_LIB.so.debug}
886
887 ${_DEST.DEBUG}/${_LIB.so.debug}: ${_LIB.so.debug}
888 ${_MKTARGET_INSTALL}
889 ${INSTALL_FILE} -o ${DEBUGOWN} -g ${DEBUGGRP} -m ${DEBUGMODE} \
890 ${.ALLSRC} ${.TARGET}
891 .if ${_LIBSODIR} != ${LIBDIR}
892 ${INSTALL_SYMLINK} -l r ${_DEST.DEBUG}/${_LIB.so.debug} \
893 ${_DEST.ODEBUG}/${_LIB.so.debug}
894 .endif
895 .endif
896
897 .if ${_LINTINSTALL} != "no" && !empty(LOBJS)
898 libinstall:: ${_DEST.LINT}/${_LIB.ln}
899 .PRECIOUS: ${_DEST.LINT}/${_LIB.ln}
900
901 .if ${MKUPDATE} == "no"
902 .if !defined(BUILD) && !make(all) && !make(${_LIB.ln})
903 ${_DEST.LINT}/${_LIB.ln}! .MADE
904 .endif
905 ${_DEST.LINT}/${_LIB.ln}! ${_LIB.ln}
906 .else
907 .if !defined(BUILD) && !make(all) && !make(${_LIB.ln})
908 ${_DEST.LINT}/${_LIB.ln}: .MADE
909 .endif
910 ${_DEST.LINT}/${_LIB.ln}: ${_LIB.ln}
911 .endif
912 ${_MKTARGET_INSTALL}
913 ${INSTALL_FILE} -o ${LIBOWN} -g ${LIBGRP} -m ${LIBMODE} \
914 ${.ALLSRC} ${_DEST.LINT}
915 .endif
916 .endif # !target(libinstall) # }
917
918 ##### Pull in related .mk logic
919 LINKSOWN?= ${LIBOWN}
920 LINKSGRP?= ${LIBGRP}
921 LINKSMODE?= ${LIBMODE}
922 .include <bsd.man.mk>
923 .include <bsd.nls.mk>
924 .include <bsd.files.mk>
925 .include <bsd.inc.mk>
926 .include <bsd.links.mk>
927 .include <bsd.dep.mk>
928 .include <bsd.clang-analyze.mk>
929 .include <bsd.clean.mk>
930
931 ${TARGETS}: # ensure existence
932