include: reduce default stack size
[minix.git] / share / mk / bsd.lib.mk
blob622b7a916749d1d46b06d4ec4c9a5e7b7550641a
1 # $NetBSD: bsd.lib.mk,v 1.324 2012/08/23 21:21:16 joerg Exp $
2 # @(#)bsd.lib.mk 8.3 (Berkeley) 4/22/94
4 .include <bsd.init.mk>
5 .include <bsd.shlib.mk>
6 .include <bsd.gcc.mk>
7 # Pull in <bsd.sys.mk> here so we can override its .c.o rule
8 .include <bsd.sys.mk>
10 LIBISMODULE?= no
11 LIBISPRIVATE?= no
12 LIBISCXX?= no
14 _LIB_PREFIX= lib
16 .if ${LIBISMODULE} != "no"
17 _LIB_PREFIX= # empty
18 MKDEBUGLIB:= no
19 MKLINT:= no
20 MKPICINSTALL:= no
21 MKPROFILE:= no
22 MKSTATICLIB:= no
23 .endif
25 .if ${LIBISPRIVATE} != "no"
26 MKDEBUGLIB:= no
27 MKLINT:= no
28 MKPICINSTALL:= no
29 . if defined(NOSTATICLIB) && ${MKPICLIB} != "no"
30 MKSTATICLIB:= no
31 . else
32 MKPIC:= no
33 . endif
34 MKPROFILE:= no
35 .endif
37 ##### Basic targets
38 .PHONY: checkver libinstall
39 realinstall: checkver libinstall
41 ##### LIB specific flags.
42 # XXX: This is needed for programs that link with .a libraries
43 # Perhaps a more correct solution is to always generate _pic.a
44 # files or always have a shared library.
45 .if defined(MKPIE) && (${MKPIE} != "no")
46 CFLAGS+= ${PIE_CFLAGS}
47 AFLAGS+= ${PIE_AFLAGS}
48 .endif
50 ##### Libraries that this may depend upon.
51 .if defined(LIBDPLIBS) && ${MKPIC} != "no" # {
52 .for _lib _dir in ${LIBDPLIBS}
53 .if !defined(LIBDO.${_lib})
54 LIBDO.${_lib}!= cd "${_dir}" && ${PRINTOBJDIR}
55 .MAKEOVERRIDES+=LIBDO.${_lib}
56 .endif
57 LDADD+= -L${LIBDO.${_lib}} -l${_lib}
58 DPADD+= ${LIBDO.${_lib}}/lib${_lib}.so
59 .endfor
60 .endif # }
62 ##### Build and install rules
63 MKDEP_SUFFIXES?= .o .po .pico .go .ln
65 .if !defined(SHLIB_MAJOR) && exists(${SHLIB_VERSION_FILE}) # {
66 SHLIB_MAJOR != . ${SHLIB_VERSION_FILE} ; echo $$major
67 SHLIB_MINOR != . ${SHLIB_VERSION_FILE} ; echo $$minor
68 SHLIB_TEENY != . ${SHLIB_VERSION_FILE} ; echo $$teeny
70 DPADD+= ${SHLIB_VERSION_FILE}
72 # Check for higher installed library versions.
73 .if !defined(NOCHECKVER) && !defined(NOCHECKVER_${LIB}) && \
74 exists(${NETBSDSRCDIR}/lib/checkver)
75 checkver:
76 @(cd "${.CURDIR}" && \
77 HOST_SH=${HOST_SH:Q} AWK=${TOOL_AWK:Q} \
78 ${HOST_SH} ${NETBSDSRCDIR}/lib/checkver -v ${SHLIB_VERSION_FILE} \
79 -d ${DESTDIR}${_LIBSODIR} ${LIB})
80 .endif
81 .endif # }
83 .if !target(checkver)
84 checkver:
85 .endif
87 print-shlib-major:
88 .if defined(SHLIB_MAJOR) && ${MKPIC} != "no"
89 @echo ${SHLIB_MAJOR}
90 .else
91 @false
92 .endif
94 print-shlib-minor:
95 .if defined(SHLIB_MINOR) && ${MKPIC} != "no"
96 @echo ${SHLIB_MINOR}
97 .else
98 @false
99 .endif
101 print-shlib-teeny:
102 .if defined(SHLIB_TEENY) && ${MKPIC} != "no"
103 @echo ${SHLIB_TEENY}
104 .else
105 @false
106 .endif
108 .if defined(SHLIB_MAJOR) && !empty(SHLIB_MAJOR) # {
109 .if defined(SHLIB_MINOR) && !empty(SHLIB_MINOR)
110 .if defined(SHLIB_TEENY) && !empty(SHLIB_TEENY)
111 SHLIB_FULLVERSION=${SHLIB_MAJOR}.${SHLIB_MINOR}.${SHLIB_TEENY}
112 .else
113 SHLIB_FULLVERSION=${SHLIB_MAJOR}.${SHLIB_MINOR}
114 .endif
115 .else
116 SHLIB_FULLVERSION=${SHLIB_MAJOR}
117 .endif
118 .endif # }
120 # add additional suffixes not exported.
121 # .po is used for profiling object files.
122 # .pico is used for PIC object files.
123 .SUFFIXES: .out .a .ln .pico .po .go .o .s .S .c .cc .cpp .cxx .C .m .F .f .r .y .l .cl .p .h
124 .SUFFIXES: .sh .m4 .m
127 # Set PICFLAGS to cc flags for producing position-independent code,
128 # if not already set. Includes -DPIC, if required.
130 # Data-driven table using make variables to control how shared libraries
131 # are built for different platforms and object formats.
132 # SHLIB_MAJOR, SHLIB_MINOR, SHLIB_TEENY: Major, minor, and teeny version
133 # numbers of shared library
134 # SHLIB_SOVERSION: version number to be compiled into a shared library
135 # via -soname. Usualy ${SHLIB_MAJOR} on ELF.
136 # NetBSD/pmax used to use ${SHLIB_MAJOR}[.${SHLIB_MINOR}
137 # [.${SHLIB_TEENY}]]
138 # SHLIB_SHFLAGS: Flags to tell ${LD} to emit shared library.
139 # with ELF, also set shared-lib version for ld.so.
140 # SHLIB_LDSTARTFILE: support .o file, call C++ file-level constructors
141 # SHLIB_LDENDFILE: support .o file, call C++ file-level destructors
142 # FPICFLAGS: flags for ${FC} to compile .[fF] files to .pico objects.
143 # CPPPICFLAGS: flags for ${CPP} to preprocess .[sS] files for ${AS}
144 # CPICFLAGS: flags for ${CC} to compile .[cC] files to pic objects.
145 # CSHLIBFLAGS: flags for ${CC} to compile .[cC] files to .pico objects.
146 # (usually includes ${CPICFLAGS})
147 # CAPICFLAGS: flags for ${CC} to compiling .[Ss] files
148 # (usually just ${CPPPICFLAGS} ${CPICFLAGS})
149 # APICFLAGS: flags for ${AS} to assemble .[sS] to .pico objects.
151 .if ${MACHINE_ARCH} == "alpha" # {
153 FPICFLAGS ?= -fPIC
154 CPICFLAGS ?= -fPIC -DPIC
155 CPPPICFLAGS?= -DPIC
156 CAPICFLAGS?= ${CPPPICFLAGS} ${CPICFLAGS}
157 APICFLAGS ?=
159 .elif (${MACHINE_ARCH} == "sparc" || ${MACHINE_ARCH} == "sparc64") # } {
161 # If you use -fPIC you need to define BIGPIC to turn on 32-bit
162 # relocations in asm code
163 FPICFLAGS ?= -fPIC
164 CPICFLAGS ?= -fPIC -DPIC
165 CPPPICFLAGS?= -DPIC -DBIGPIC
166 CAPICFLAGS?= ${CPPPICFLAGS} ${CPICFLAGS}
167 APICFLAGS ?= -KPIC
169 .else # } {
171 # Platform-independent flags for NetBSD shared libraries
172 SHLIB_SOVERSION=${SHLIB_FULLVERSION}
173 SHLIB_SHFLAGS=
174 FPICFLAGS ?= -fPIC
175 CPICFLAGS?= -fPIC -DPIC
176 CPPPICFLAGS?= -DPIC
177 CAPICFLAGS?= ${CPPPICFLAGS} ${CPICFLAGS}
178 APICFLAGS?= -k
180 .endif # }
182 .if ${MKPICLIB} != "no"
183 CSHLIBFLAGS+= ${CPICFLAGS}
184 .endif
186 .if defined(CSHLIBFLAGS) && !empty(CSHLIBFLAGS)
187 MKSHLIBOBJS= yes
188 .else
189 MKSHLIBOBJS= no
190 .endif
192 # Platform-independent linker flags for ELF shared libraries
193 SHLIB_SOVERSION= ${SHLIB_MAJOR}
194 SHLIB_SHFLAGS= -Wl,-soname,${_LIB_PREFIX}${LIB}.so.${SHLIB_SOVERSION}
195 SHLIB_SHFLAGS+= -Wl,--warn-shared-textrel
196 SHLIB_LDSTARTFILE?= ${_GCC_CRTI} ${_GCC_CRTBEGINS}
197 SHLIB_LDENDFILE?= ${_GCC_CRTENDS} ${_GCC_CRTN}
199 CFLAGS+= ${COPTS}
200 OBJCFLAGS+= ${OBJCOPTS}
201 AFLAGS+= ${COPTS}
202 FFLAGS+= ${FOPTS}
204 .if defined(CTFCONVERT)
205 .if defined(CFLAGS) && !empty(CFLAGS:M*-g*)
206 CTFFLAGS+= -g
207 .endif
208 .endif
210 .c.o:
211 ${_MKTARGET_COMPILE}
212 ${COMPILE.c} ${COPTS.${.IMPSRC:T}} ${CPUFLAGS.${.IMPSRC:T}} ${CPPFLAGS.${.IMPSRC:T}} ${.IMPSRC} -o ${.TARGET}
213 .if defined(CTFCONVERT)
214 ${CTFCONVERT} ${CTFFLAGS} ${.TARGET}
215 .endif
216 .if !defined(CFLAGS) || empty(CFLAGS:M*-g*)
217 ${OBJCOPY} ${OBJCOPYLIBFLAGS} ${.TARGET}
218 .endif
220 .c.po:
221 ${_MKTARGET_COMPILE}
222 ${COMPILE.c} ${PROFFLAGS} ${COPTS.${.IMPSRC:T}} ${CPUFLAGS.${.IMPSRC:T}} ${CPPFLAGS.${.IMPSRC:T}} -pg ${.IMPSRC} -o ${.TARGET}
223 .if defined(CTFCONVERT)
224 ${CTFCONVERT} ${CTFFLAGS} ${.TARGET}
225 .endif
226 .if !defined(CFLAGS) || empty(CFLAGS:M*-g*)
227 ${OBJCOPY} ${OBJCOPYLIBFLAGS} ${.TARGET}
228 .endif
230 .c.go:
231 ${_MKTARGET_COMPILE}
232 ${COMPILE.c} ${DEBUGFLAGS} ${COPTS.${.IMPSRC:T}} ${CPUFLAGS.${.IMPSRC:T}} ${CPPFLAGS.${.IMPSRC:T}} -g ${.IMPSRC} -o ${.TARGET}
234 .c.pico:
235 ${_MKTARGET_COMPILE}
236 ${COMPILE.c} ${COPTS.${.IMPSRC:T}} ${CPUFLAGS.${.IMPSRC:T}} ${CPPFLAGS.${.IMPSRC:T}} ${CSHLIBFLAGS} ${.IMPSRC} -o ${.TARGET}
237 .if !defined(CFLAGS) || empty(CFLAGS:M*-g*)
238 ${OBJCOPY} ${OBJCOPYLIBFLAGS} ${.TARGET}
239 .endif
241 .cc.o .cpp.o .cxx.o .C.o:
242 ${_MKTARGET_COMPILE}
243 ${COMPILE.cc} ${COPTS.${.IMPSRC:T}} ${CPUFLAGS.${.IMPSRC:T}} ${CPPFLAGS.${.IMPSRC:T}} ${.IMPSRC} -o ${.TARGET}
244 .if !defined(CFLAGS) || empty(CFLAGS:M*-g*)
245 ${OBJCOPY} ${OBJCOPYLIBFLAGS} ${.TARGET}
246 .endif
248 .cc.po .cpp.po .cxx.po .C.po:
249 ${_MKTARGET_COMPILE}
250 ${COMPILE.cc} ${PROFFLAGS} ${COPTS.${.IMPSRC:T}} ${CPUFLAGS.${.IMPSRC:T}} ${CPPFLAGS.${.IMPSRC:T}} -pg ${.IMPSRC} -o ${.TARGET}
251 .if !defined(CFLAGS) || empty(CFLAGS:M*-g*)
252 ${OBJCOPY} ${OBJCOPYLIBFLAGS} ${.TARGET}
253 .endif
255 .cc.go .cpp.go .cxx.go .C.go:
256 ${_MKTARGET_COMPILE}
257 ${COMPILE.cc} ${DEBUGFLAGS} ${COPTS.${.IMPSRC:T}} ${CPUFLAGS.${.IMPSRC:T}} ${CPPFLAGS.${.IMPSRC:T}} -g ${.IMPSRC} -o ${.TARGET}
259 .cc.pico .cpp.pico .cxx.pico .C.pico:
260 ${_MKTARGET_COMPILE}
261 ${COMPILE.cc} ${COPTS.${.IMPSRC:T}} ${CPUFLAGS.${.IMPSRC:T}} ${CPPFLAGS.${.IMPSRC:T}} ${CSHLIBFLAGS} ${.IMPSRC} -o ${.TARGET}
262 .if !defined(CFLAGS) || empty(CFLAGS:M*-g*)
263 ${OBJCOPY} ${OBJCOPYLIBFLAGS} ${.TARGET}
264 .endif
266 .f.o:
267 ${_MKTARGET_COMPILE}
268 ${COMPILE.f} ${.IMPSRC} -o ${.TARGET}
269 .if defined(CTFCONVERT)
270 ${CTFCONVERT} ${CTFFLAGS} ${.TARGET}
271 .endif
272 .if !defined(FOPTS) || empty(FOPTS:M*-g*)
273 ${OBJCOPY} ${OBJCOPYLIBFLAGS} ${.TARGET}
274 .endif
276 .f.po:
277 ${_MKTARGET_COMPILE}
278 ${COMPILE.f} ${PROFFLAGS} -pg ${.IMPSRC} -o ${.TARGET}
279 .if defined(CTFCONVERT)
280 ${CTFCONVERT} ${CTFFLAGS} ${.TARGET}
281 .endif
282 .if !defined(FOPTS) || empty(FOPTS:M*-g*)
283 ${OBJCOPY} ${OBJCOPYLIBFLAGS} ${.TARGET}
284 .endif
286 .f.go:
287 ${_MKTARGET_COMPILE}
288 ${COMPILE.f} ${DEBUGFLAGS} -g ${.IMPSRC} -o ${.TARGET}
290 .f.pico:
291 ${_MKTARGET_COMPILE}
292 ${COMPILE.f} ${FPICFLAGS} ${.IMPSRC} -o ${.TARGET}
293 .if !defined(FOPTS) || empty(FOPTS:M*-g*)
294 ${OBJCOPY} ${OBJCOPYLIBFLAGS} ${.TARGET}
295 .endif
297 .f.ln:
298 ${_MKTARGET_COMPILE}
299 @echo Skipping lint for Fortran libraries.
301 .m.o:
302 ${_MKTARGET_COMPILE}
303 ${COMPILE.m} ${OBJCOPTS.${.IMPSRC:T}} ${.IMPSRC} -o ${.TARGET}
304 .if defined(CTFCONVERT)
305 ${CTFCONVERT} ${CTFFLAGS} ${.TARGET}
306 .endif
307 .if !defined(OBJCFLAGS) || empty(OBJCFLAGS:M*-g*)
308 ${OBJCOPY} ${OBJCOPYLIBFLAGS} ${.TARGET}
309 .endif
311 .m.po:
312 ${_MKTARGET_COMPILE}
313 ${COMPILE.m} ${PROFFLAGS} -pg ${OBJCOPTS.${.IMPSRC:T}} ${.IMPSRC} -o ${.TARGET}
314 .if defined(CTFCONVERT)
315 ${CTFCONVERT} ${CTFFLAGS} ${.TARGET}
316 .endif
317 .if !defined(OBJCFLAGS) || empty(OBJCFLAGS:M*-g*)
318 ${OBJCOPY} ${OBJCOPYLIBFLAGS} ${.TARGET}
319 .endif
321 .m.go:
322 ${_MKTARGET_COMPILE}
323 ${COMPILE.m} ${DEBUGFLAGS} -g ${OBJCOPTS.${.IMPSRC:T}} ${.IMPSRC} -o ${.TARGET}
324 .if !defined(OBJCFLAGS) || empty(OBJCFLAGS:M*-g*)
325 ${OBJCOPY} ${OBJCOPYLIBFLAGS} ${.TARGET}
326 .endif
328 .m.pico:
329 ${_MKTARGET_COMPILE}
330 ${COMPILE.m} ${CSHLIBFLAGS} ${OBJCOPTS.${.IMPSRC:T}} ${.IMPSRC} -o ${.TARGET}
331 .if !defined(OBJCFLAGS) || empty(OBJCFLAGS:M*-g*)
332 ${OBJCOPY} ${OBJCOPYLIBFLAGS} ${.TARGET}
333 .endif
335 .s.o:
336 ${_MKTARGET_COMPILE}
337 ${COMPILE.s} ${COPTS.${.IMPSRC:T}} ${CPUFLAGS.${.IMPSRC:T}} ${CPPFLAGS.${.IMPSRC:T}} ${.IMPSRC} -o ${.TARGET}
338 .if defined(CTFCONVERT)
339 ${CTFCONVERT} ${CTFFLAGS} ${.TARGET}
340 .endif
341 ${OBJCOPY} ${OBJCOPYLIBFLAGS} ${.TARGET}
343 .S.o:
344 ${_MKTARGET_COMPILE}
345 ${COMPILE.S} ${COPTS.${.IMPSRC:T}} ${CPUFLAGS.${.IMPSRC:T}} ${CPPFLAGS.${.IMPSRC:T}} ${.IMPSRC} -o ${.TARGET}
346 .if defined(CTFCONVERT)
347 ${CTFCONVERT} ${CTFFLAGS} ${.TARGET}
348 .endif
349 ${OBJCOPY} ${OBJCOPYLIBFLAGS} ${.TARGET}
351 .s.po:
352 ${_MKTARGET_COMPILE}
353 ${COMPILE.s} ${PROFFLAGS} ${COPTS.${.IMPSRC:T}} ${CPUFLAGS.${.IMPSRC:T}} ${CPPFLAGS.${.IMPSRC:T}} ${.IMPSRC} -o ${.TARGET}
354 .if defined(CTFCONVERT)
355 ${CTFCONVERT} ${CTFFLAGS} ${.TARGET}
356 .endif
357 ${OBJCOPY} ${OBJCOPYLIBFLAGS} ${.TARGET}
359 .S.po:
360 ${_MKTARGET_COMPILE}
361 ${COMPILE.S} ${PROFFLAGS} ${COPTS.${.IMPSRC:T}} ${CPUFLAGS.${.IMPSRC:T}} ${CPPFLAGS.${.IMPSRC:T}} ${.IMPSRC} -o ${.TARGET}
362 .if defined(CTFCONVERT)
363 ${CTFCONVERT} ${CTFFLAGS} ${.TARGET}
364 .endif
365 ${OBJCOPY} ${OBJCOPYLIBFLAGS} ${.TARGET}
367 .s.go:
368 ${_MKTARGET_COMPILE}
369 ${COMPILE.s} ${DEBUGFLAGS} ${COPTS.${.IMPSRC:T}} ${CPUFLAGS.${.IMPSRC:T}} ${CPPFLAGS.${.IMPSRC:T}} ${.IMPSRC} -o ${.TARGET}
371 .S.go:
372 ${_MKTARGET_COMPILE}
373 ${COMPILE.S} ${DEBUGFLAGS} ${COPTS.${.IMPSRC:T}} ${CPUFLAGS.${.IMPSRC:T}} ${CPPFLAGS.${.IMPSRC:T}} ${.IMPSRC} -o ${.TARGET}
375 .s.pico:
376 ${_MKTARGET_COMPILE}
377 ${COMPILE.s} ${CAPICFLAGS} ${COPTS.${.IMPSRC:T}} ${CPUFLAGS.${.IMPSRC:T}} ${CPPFLAGS.${.IMPSRC:T}} ${.IMPSRC} -o ${.TARGET}
378 ${OBJCOPY} ${OBJCOPYLIBFLAGS} ${.TARGET}
380 .S.pico:
381 ${_MKTARGET_COMPILE}
382 ${COMPILE.S} ${CAPICFLAGS} ${COPTS.${.IMPSRC:T}} ${CPUFLAGS.${.IMPSRC:T}} ${CPPFLAGS.${.IMPSRC:T}} ${.IMPSRC} -o ${.TARGET}
383 ${OBJCOPY} ${OBJCOPYLIBFLAGS} ${.TARGET}
385 .if defined(LIB) # {
386 .if (${MKPIC} == "no" || (defined(LDSTATIC) && ${LDSTATIC} != "") \
387 || ${MKLINKLIB} != "no") && ${MKSTATICLIB} != "no"
388 _LIBS=lib${LIB}.a
389 .else
390 _LIBS=
391 .endif
393 .if ${LIBISPRIVATE} != "no" \
394 && (defined(USE_COMBINE) && ${USE_COMBINE} == "yes" \
395 && !defined(NOCOMBINE)) # {
396 .for f in ${SRCS:N*.h:N*.sh:C/\.[yl]$/.c/g}
397 COMBINEFLAGS.${LIB}.$f := ${CPPFLAGS.$f:D1} ${CPUFLAGS.$f:D2} ${COPTS.$f:D3} ${OBJCOPTS.$f:D4} ${CXXFLAGS.$f:D5}
398 .if empty(COMBINEFLAGS.${LIB}.${f}) && !defined(NOCOMBINE.$f)
399 COMBINESRCS+= ${f}
400 NODPSRCS+= ${f}
401 .else
402 OBJS+= ${f:R:S/$/.o/}
403 .endif
404 .endfor
406 .if !empty(COMBINESRCS)
407 OBJS+= lib${LIB}_combine.o
408 lib${LIB}_combine.o: ${COMBINESRCS}
409 ${_MKTARGET_COMPILE}
410 ${COMPILE.c} -MD --combine ${.ALLSRC} -o ${.TARGET}
411 .if !defined(CFLAGS) || empty(CFLAGS:M*-g*)
412 ${OBJCOPY} -x ${.TARGET}
413 .endif
415 CLEANFILES+= lib${LIB}_combine.d
417 .if exists("lib${LIB}_combine.d")
418 .include "lib${LIB}_combine.d"
419 .endif
420 .endif # empty(XSRCS.${LIB})
421 .else # } {
422 OBJS+=${SRCS:N*.h:N*.sh:R:S/$/.o/g}
423 .endif # }
425 STOBJS+=${OBJS}
427 LOBJS+=${LSRCS:.c=.ln} ${SRCS:M*.c:.c=.ln}
429 .if ${LIBISPRIVATE} != "no"
430 # No installation is required
431 libinstall::
432 .endif
434 .if ${MKDEBUGLIB} != "no"
435 _LIBS+=lib${LIB}_g.a
436 GOBJS+=${OBJS:.o=.go}
437 DEBUGFLAGS?=-DDEBUG
438 .endif
440 .if ${MKPROFILE} != "no"
441 _LIBS+=lib${LIB}_p.a
442 POBJS+=${OBJS:.o=.po}
443 PROFFLAGS?=-DGPROF -DPROF
444 .endif
446 .if ${MKPIC} != "no" # {
447 .if ${MKPICLIB} == "no"
448 .if ${MKSHLIBOBJS} != "no"
449 # make _pic.a, which isn't really pic,
450 # since it's needed for making shared lib.
451 # but don't install it.
452 SOLIB=lib${LIB}_pic.a
453 SOBJS+=${OBJS:.o=.pico}
454 .else
455 SOLIB=lib${LIB}.a
456 .endif
457 .else
458 SOLIB=lib${LIB}_pic.a
459 _LIBS+=${SOLIB}
460 SOBJS+=${OBJS:.o=.pico}
461 .endif
462 .if defined(SHLIB_FULLVERSION)
463 _LIB.so:=lib${LIB}.so.${SHLIB_FULLVERSION}
464 .if ${MKDEBUG} != "no"
465 _LIB.debug:=${_LIB.so}.debug
466 .endif
467 _LIBS+=lib${LIB}.so.${SHLIB_FULLVERSION}
468 .endif
469 .endif # }
471 .if ${MKLINT} != "no" && !empty(LOBJS)
472 _LIBS+=llib-l${LIB}.ln
473 .endif
475 ALLOBJS=
476 .if (${MKPIC} == "no" || (defined(LDSTATIC) && ${LDSTATIC} != "") \
477 || ${MKLINKLIB} != "no") && ${MKSTATICLIB} != "no"
478 ALLOBJS+=${STOBJS}
479 .endif
480 ALLOBJS+=${POBJS} ${SOBJS}
481 .if ${MKLINT} != "no" && !empty(LOBJS)
482 ALLOBJS+=${LOBJS}
483 .endif
484 .else # !defined(LIB) # } {
485 LOBJS=
486 SOBJS=
487 .endif # !defined(LIB) # }
489 _YLSRCS= ${SRCS:M*.[ly]:C/\..$/.c/} ${YHEADER:D${SRCS:M*.y:.y=.h}}
491 .NOPATH: ${ALLOBJS} ${_LIBS} ${_YLSRCS}
493 realall: ${SRCS} ${ALLOBJS:O} ${_LIBS} ${_LIB.debug}
495 MKARZERO?=no
497 .if ${MKARZERO} == "yes"
498 _ARFL=crsD
499 _ARRANFL=sD
500 _INSTRANLIB=
501 .else
502 _ARFL=crs
503 _ARRANFL=s
504 _INSTRANLIB=${empty(PRESERVE):?-a "${RANLIB} -t":}
505 .endif
507 # If you change this, please consider reflecting the change in
508 # the override in sys/rump/Makefile.rump.
509 .if !target(__archivebuild)
510 __archivebuild: .USE
511 ${_MKTARGET_BUILD}
512 rm -f ${.TARGET}
513 ${AR} ${_ARFL} ${.TARGET} `NM=${NM} ${LORDER} ${.ALLSRC:M*o} | ${TSORT}`
514 .endif
516 .if !target(__archiveinstall)
517 __archiveinstall: .USE
518 ${_MKTARGET_INSTALL}
519 ${INSTALL_FILE} -o ${LIBOWN} -g ${LIBGRP} -m ${LIBMODE} \
520 ${_INSTRANLIB} ${.ALLSRC} ${.TARGET}
521 .endif
523 __archivesymlinkpic: .USE
524 ${_MKTARGET_INSTALL}
525 ${INSTALL_SYMLINK} ${.ALLSRC} ${.TARGET}
527 DPSRCS+= ${_YLSRCS}
528 CLEANFILES+= ${_YLSRCS}
530 ${STOBJS} ${POBJS} ${GOBJS} ${SOBJS} ${LOBJS}: ${DPSRCS}
532 lib${LIB}.a:: ${STOBJS} __archivebuild
534 lib${LIB}_p.a:: ${POBJS} __archivebuild
536 lib${LIB}_pic.a:: ${SOBJS} __archivebuild
538 lib${LIB}_g.a:: ${GOBJS} __archivebuild
541 _LIBLDOPTS=
542 .if ${SHLIBDIR} != "/usr/lib"
543 _LIBLDOPTS+= -Wl,-rpath,${SHLIBDIR} \
544 -L=${SHLIBDIR}
545 .elif ${SHLIBINSTALLDIR} != "/usr/lib"
546 _LIBLDOPTS+= -Wl,-rpath-link,${DESTDIR}${SHLIBINSTALLDIR} \
547 -L=${SHLIBINSTALLDIR}
548 .endif
550 # gcc -shared now adds -lc automatically. For libraries other than libc and
551 # libgcc* we add as a dependency the installed shared libc. For libc and
552 # libgcc* we avoid adding libc as a dependency by using -nostdlib. Note that
553 # -Xl,-nostdlib is not enough because we want to tell the compiler-driver not
554 # to add standard libraries, not the linker.
555 .if !defined(LIB)
556 .if !empty(LIBC_SO)
557 DPLIBC ?= ${DESTDIR}${LIBC_SO}
558 .endif
559 .else
560 .if ${LIB} != "c" && ${LIB:Mgcc*} == ""
561 .if !empty(LIBC_SO)
562 DPLIBC ?= ${DESTDIR}${LIBC_SO}
563 .endif
564 .else
565 LDLIBC ?= -nodefaultlibs
566 .if ${LIB} == "c"
567 LDADD+= ${${ACTIVE_CC} == "gcc":?-lgcc:}
568 LDADD+= ${${ACTIVE_CC} == "clang":?-L/usr/pkg/compiler-rt/lib -lCompilerRT-Generic:}
569 .endif
570 .endif
571 .endif
573 .if ${LIBISCXX} != "no"
574 LIBCC:= ${CXX}
575 .else
576 LIBCC:= ${CC}
577 .endif
579 _LDADD.lib${LIB}= ${LDADD} ${LDADD.lib${LIB}}
580 _LDFLAGS.lib${LIB}= ${LDFLAGS} ${LDFLAGS.lib${LIB}}
582 lib${LIB}.so.${SHLIB_FULLVERSION}: ${SOLIB} ${DPADD} ${DPLIBC} \
583 ${SHLIB_LDSTARTFILE} ${SHLIB_LDENDFILE}
584 ${_MKTARGET_BUILD}
585 rm -f lib${LIB}.so.${SHLIB_FULLVERSION}
586 ${LIBCC} ${LDLIBC} -Wl,-x -shared ${SHLIB_SHFLAGS} ${_LDFLAGS.lib${LIB}} \
587 -o ${.TARGET} ${_LIBLDOPTS} \
588 -Wl,--whole-archive ${SOLIB} -Wl,--no-whole-archive ${_LDADD.lib${LIB}}
589 # We don't use INSTALL_SYMLINK here because this is just
590 # happening inside the build directory/objdir. XXX Why does
591 # this spend so much effort on libraries that aren't live??? XXX
592 .if defined(SHLIB_FULLVERSION) && defined(SHLIB_MAJOR) && \
593 "${SHLIB_FULLVERSION}" != "${SHLIB_MAJOR}"
594 ${HOST_LN} -sf lib${LIB}.so.${SHLIB_FULLVERSION} lib${LIB}.so.${SHLIB_MAJOR}.tmp
595 mv -f lib${LIB}.so.${SHLIB_MAJOR}.tmp lib${LIB}.so.${SHLIB_MAJOR}
596 .endif
597 ${HOST_LN} -sf lib${LIB}.so.${SHLIB_FULLVERSION} lib${LIB}.so.tmp
598 mv -f lib${LIB}.so.tmp lib${LIB}.so
599 .if ${MKSTRIPIDENT} != "no"
600 ${OBJCOPY} -R .ident ${.TARGET}
601 .endif
603 .if defined(_LIB.debug)
604 ${_LIB.debug}: ${_LIB.so}
605 ${_MKTARGET_CREATE}
606 ( ${OBJCOPY} --only-keep-debug ${_LIB.so} ${_LIB.debug} \
607 && ${OBJCOPY} --strip-debug -p -R .gnu_debuglink \
608 --add-gnu-debuglink=${_LIB.debug} ${_LIB.so} \
609 ) || (rm -f ${_LIB.debug}; false)
610 .endif
612 .if !empty(LOBJS) # {
613 LLIBS?= -lc
614 llib-l${LIB}.ln: ${LOBJS}
615 ${_MKTARGET_COMPILE}
616 rm -f llib-l${LIB}.ln
617 .if defined(DESTDIR)
618 ${LINT} -C${LIB} ${.ALLSRC} -L${DESTDIR}/usr/libdata ${LLIBS}
619 .else
620 ${LINT} -C${LIB} ${.ALLSRC} ${LLIBS}
621 .endif
622 .endif # }
624 lint: ${LOBJS}
625 .if defined(LOBJS) && !empty(LOBJS)
626 ${LINT} ${LINTFLAGS} ${LOBJS}
627 .endif
629 # If the number of entries in CLEANFILES is too large, then the
630 # commands in bsd.clean.mk encounter errors like "exec(/bin/sh)
631 # failed (Argument list too long)". Avoid that by splitting the
632 # files to clean into several lists using different variable names.
633 # __cleanuse is an internal target in bsd.clean.mk; the way we
634 # use it here mimics the way it's used by the clean target in
635 # bsd.clean.mk.
637 clean: libclean1 libclean2 libclean3 libclean4 libclean5
638 libclean1: .PHONY .MADE __cleanuse LIBCLEANFILES1
639 libclean2: .PHONY .MADE __cleanuse LIBCLEANFILES2
640 libclean3: .PHONY .MADE __cleanuse LIBCLEANFILES3
641 libclean4: .PHONY .MADE __cleanuse LIBCLEANFILES4
642 libclean5: .PHONY .MADE __cleanuse LIBCLEANFILES5
643 CLEANFILES+= a.out [Ee]rrs mklog core *.core
644 LIBCLEANFILES1+= lib${LIB}.a ${STOBJS} ${STOBJS:=.tmp}
645 LIBCLEANFILES2+= lib${LIB}_p.a ${POBJS} ${POBJS:=.tmp}
646 LIBCLEANFILES3+= lib${LIB}_g.a ${GOBJS} ${GOBJS:=.tmp}
647 LIBCLEANFILES4+= lib${LIB}_pic.a lib${LIB}.so.* lib${LIB}.so ${_LIB.debug}
648 LIBCLEANFILES4+= ${SOBJS} ${SOBJS:=.tmp}
649 LIBCLEANFILES5+= llib-l${LIB}.ln ${LOBJS}
651 .if !target(libinstall) # {
652 # Make sure it gets defined, in case MKPIC==no && MKLINKLIB==no
653 libinstall::
655 .if ${MKLINKLIB} != "no" && ${MKSTATICLIB} != "no"
656 libinstall:: ${DESTDIR}${LIBDIR}/lib${LIB}.a
657 .PRECIOUS: ${DESTDIR}${LIBDIR}/lib${LIB}.a
659 .if ${MKUPDATE} == "no"
660 .if !defined(BUILD) && !make(all) && !make(lib${LIB}.a)
661 ${DESTDIR}${LIBDIR}/lib${LIB}.a! .MADE
662 .endif
663 ${DESTDIR}${LIBDIR}/lib${LIB}.a! lib${LIB}.a __archiveinstall
664 .else
665 .if !defined(BUILD) && !make(all) && !make(lib${LIB}.a)
666 ${DESTDIR}${LIBDIR}/lib${LIB}.a: .MADE
667 .endif
668 ${DESTDIR}${LIBDIR}/lib${LIB}.a: lib${LIB}.a __archiveinstall
669 .endif
670 .endif
672 .if ${MKPROFILE} != "no"
673 libinstall:: ${DESTDIR}${LIBDIR}/lib${LIB}_p.a
674 .PRECIOUS: ${DESTDIR}${LIBDIR}/lib${LIB}_p.a
676 .if ${MKUPDATE} == "no"
677 .if !defined(BUILD) && !make(all) && !make(lib${LIB}_p.a)
678 ${DESTDIR}${LIBDIR}/lib${LIB}_p.a! .MADE
679 .endif
680 ${DESTDIR}${LIBDIR}/lib${LIB}_p.a! lib${LIB}_p.a __archiveinstall
681 .else
682 .if !defined(BUILD) && !make(all) && !make(lib${LIB}_p.a)
683 ${DESTDIR}${LIBDIR}/lib${LIB}_p.a: .MADE
684 .endif
685 ${DESTDIR}${LIBDIR}/lib${LIB}_p.a: lib${LIB}_p.a __archiveinstall
686 .endif
687 .endif
689 .if ${MKDEBUGLIB} != "no"
690 libinstall:: ${DESTDIR}${LIBDIR}/lib${LIB}_g.a
691 .PRECIOUS: ${DESTDIR}${LIBDIR}/lib${LIB}_g.a
693 .if ${MKUPDATE} == "no"
694 .if !defined(BUILD) && !make(all) && !make(lib${LIB}_g.a)
695 ${DESTDIR}${LIBDIR}/lib${LIB}_g.a! .MADE
696 .endif
697 ${DESTDIR}${LIBDIR}/lib${LIB}_g.a! lib${LIB}_g.a __archiveinstall
698 .else
699 .if !defined(BUILD) && !make(all) && !make(lib${LIB}_g.a)
700 ${DESTDIR}${LIBDIR}/lib${LIB}_g.a: .MADE
701 .endif
702 ${DESTDIR}${LIBDIR}/lib${LIB}_g.a: lib${LIB}_g.a __archiveinstall
703 .endif
704 .endif
706 .if ${MKPIC} != "no" && ${MKPICINSTALL} != "no"
707 libinstall:: ${DESTDIR}${LIBDIR}/lib${LIB}_pic.a
708 .PRECIOUS: ${DESTDIR}${LIBDIR}/lib${LIB}_pic.a
710 .if ${MKUPDATE} == "no"
711 .if !defined(BUILD) && !make(all) && !make(lib${LIB}_pic.a)
712 ${DESTDIR}${LIBDIR}/lib${LIB}_pic.a! .MADE
713 .endif
714 .if ${MKPICLIB} == "no"
715 ${DESTDIR}${LIBDIR}/lib${LIB}_pic.a! lib${LIB}.a __archivesymlinkpic
716 .else
717 ${DESTDIR}${LIBDIR}/lib${LIB}_pic.a! lib${LIB}_pic.a __archiveinstall
718 .endif
719 .else
720 .if !defined(BUILD) && !make(all) && !make(lib${LIB}_pic.a)
721 ${DESTDIR}${LIBDIR}/lib${LIB}_pic.a: .MADE
722 .endif
723 .if ${MKPICLIB} == "no"
724 ${DESTDIR}${LIBDIR}/lib${LIB}_pic.a: lib${LIB}.a __archivesymlinkpic
725 .else
726 ${DESTDIR}${LIBDIR}/lib${LIB}_pic.a: lib${LIB}_pic.a __archiveinstall
727 .endif
728 .endif
729 .endif
731 .if ${MKPIC} != "no" && defined(SHLIB_FULLVERSION)
732 _LIB_SO_TGT= ${DESTDIR}${_LIBSODIR}/${_LIB_PREFIX}${LIB}.so
733 _LIB_SO_TGTLIBDIR= ${DESTDIR}${LIBDIR}/${_LIB_PREFIX}${LIB}.so
735 libinstall:: ${_LIB_SO_TGT}.${SHLIB_FULLVERSION}
736 .PRECIOUS: ${_LIB_SO_TGT}.${SHLIB_FULLVERSION}
738 .if ${MKUPDATE} == "no"
739 .if !defined(BUILD) && !make(all) && !make(lib${LIB}.so.${SHLIB_FULLVERSION})
740 ${_LIB_SO_TGT}.${SHLIB_FULLVERSION}! .MADE
741 .endif
742 ${_LIB_SO_TGT}.${SHLIB_FULLVERSION}! lib${LIB}.so.${SHLIB_FULLVERSION}
743 .else
744 .if !defined(BUILD) && !make(all) && !make(lib${LIB}.so.${SHLIB_FULLVERSION})
745 ${_LIB_SO_TGT}.${SHLIB_FULLVERSION}: .MADE
746 .endif
747 ${_LIB_SO_TGT}.${SHLIB_FULLVERSION}: lib${LIB}.so.${SHLIB_FULLVERSION}
748 .endif
749 ${_MKTARGET_INSTALL}
750 ${INSTALL_FILE} -o ${LIBOWN} -g ${LIBGRP} -m ${LIBMODE} \
751 ${.ALLSRC} ${.TARGET}
752 .if ${_LIBSODIR} != ${LIBDIR}
753 ${INSTALL_SYMLINK} -l r \
754 ${_LIB_SO_TGT}.${SHLIB_FULLVERSION} \
755 ${_LIB_SO_TGTLIBDIR}.${SHLIB_FULLVERSION}
756 .endif
757 .if defined(SHLIB_FULLVERSION) && defined(SHLIB_MAJOR) && \
758 "${SHLIB_FULLVERSION}" != "${SHLIB_MAJOR}"
759 ${INSTALL_SYMLINK} \
760 ${_LIB_PREFIX}${LIB}.so.${SHLIB_FULLVERSION} \
761 ${_LIB_SO_TGT}.${SHLIB_MAJOR}
762 .if ${_LIBSODIR} != ${LIBDIR}
763 ${INSTALL_SYMLINK} -l r \
764 ${_LIB_SO_TGT}.${SHLIB_FULLVERSION} \
765 ${_LIB_SO_TGTLIBDIR}.${SHLIB_MAJOR}
766 .endif
767 .endif
768 .if ${MKLINKLIB} != "no"
769 ${INSTALL_SYMLINK} \
770 ${_LIB_PREFIX}${LIB}.so.${SHLIB_FULLVERSION} \
771 ${_LIB_SO_TGT}
772 .if ${_LIBSODIR} != ${LIBDIR}
773 ${INSTALL_SYMLINK} -l r \
774 ${_LIB_SO_TGT}.${SHLIB_FULLVERSION} \
775 ${_LIB_SO_TGTLIBDIR}
776 .endif
777 .endif
778 .endif
780 .if defined(_LIB.debug)
781 libinstall:: ${DESTDIR}${DEBUGDIR}${LIBDIR}/${_LIB.debug}
782 .PRECIOUS: ${DESTDIR}${DEBUGDIR}${LIBDIR}/${_LIB.debug}
784 ${DESTDIR}${DEBUGDIR}${LIBDIR}/${_LIB.debug}: ${_LIB.debug}
785 ${_MKTARGET_INSTALL}
786 ${INSTALL_FILE} -o ${DEBUGOWN} -g ${DEBUGGRP} -m ${DEBUGMODE} \
787 ${.ALLSRC} ${.TARGET}
788 .endif
790 .if ${MKLINT} != "no" && !empty(LOBJS)
791 libinstall:: ${DESTDIR}${LINTLIBDIR}/llib-l${LIB}.ln
792 .PRECIOUS: ${DESTDIR}${LINTLIBDIR}/llib-l${LIB}.ln
794 .if ${MKUPDATE} == "no"
795 .if !defined(BUILD) && !make(all) && !make(llib-l${LIB}.ln)
796 ${DESTDIR}${LINTLIBDIR}/llib-l${LIB}.ln! .MADE
797 .endif
798 ${DESTDIR}${LINTLIBDIR}/llib-l${LIB}.ln! llib-l${LIB}.ln
799 .else
800 .if !defined(BUILD) && !make(all) && !make(llib-l${LIB}.ln)
801 ${DESTDIR}${LINTLIBDIR}/llib-l${LIB}.ln: .MADE
802 .endif
803 ${DESTDIR}${LINTLIBDIR}/llib-l${LIB}.ln: llib-l${LIB}.ln
804 .endif
805 ${_MKTARGET_INSTALL}
806 ${INSTALL_FILE} -o ${LIBOWN} -g ${LIBGRP} -m ${LIBMODE} \
807 ${.ALLSRC} ${DESTDIR}${LINTLIBDIR}
808 .endif
809 .endif # !target(libinstall) # }
811 ##### Pull in related .mk logic
812 LINKSOWN?= ${LIBOWN}
813 LINKSGRP?= ${LIBGRP}
814 LINKSMODE?= ${LIBMODE}
815 .include <bsd.man.mk>
816 .include <bsd.nls.mk>
817 .include <bsd.files.mk>
818 .include <bsd.inc.mk>
819 .include <bsd.links.mk>
820 .include <bsd.dep.mk>
821 .include <bsd.clang-analyze.mk>
822 .include <bsd.clean.mk>
824 ${TARGETS}: # ensure existence