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