merge libminlib with libc
[minix3.git] / share / mk / bsd.lib.mk
blob08e3ec2aeee6ced341172623a34be193bd83ab33
1 # $NetBSD: bsd.lib.mk,v 1.342 2013/10/18 16:06:52 christos 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 .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
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 .if ${LIBDO.${_lib}} == "_external"
58 LDADD+= -l${_lib}
59 .else
60 LDADD+= -L${LIBDO.${_lib}} -l${_lib}
61 DPADD+= ${LIBDO.${_lib}}/lib${_lib}.so # Don't use _LIB_PREFIX
62 .endif
63 .endfor
64 .endif # }
66 ##### Build and install rules
67 MKDEP_SUFFIXES?= .o .po .pico .go .ln
69 .if !defined(SHLIB_MAJOR) && exists(${SHLIB_VERSION_FILE}) # {
70 SHLIB_MAJOR != . ${SHLIB_VERSION_FILE} ; echo $$major
71 SHLIB_MINOR != . ${SHLIB_VERSION_FILE} ; echo $$minor
72 SHLIB_TEENY != . ${SHLIB_VERSION_FILE} ; echo $$teeny
74 DPADD+= ${SHLIB_VERSION_FILE}
76 # Check for higher installed library versions.
77 .if !defined(NOCHECKVER) && !defined(NOCHECKVER_${LIB}) && \
78 exists(${NETBSDSRCDIR}/lib/checkver)
79 checkver:
80 @(cd "${.CURDIR}" && \
81 HOST_SH=${HOST_SH:Q} AWK=${TOOL_AWK:Q} \
82 ${HOST_SH} ${NETBSDSRCDIR}/lib/checkver -v ${SHLIB_VERSION_FILE} \
83 -d ${_DEST.OBJ} ${LIB})
84 .endif
85 .endif # }
87 .if !target(checkver)
88 checkver:
89 .endif
91 print-shlib-major:
92 .if defined(SHLIB_MAJOR) && ${MKPIC} != "no"
93 @echo ${SHLIB_MAJOR}
94 .else
95 @false
96 .endif
98 print-shlib-minor:
99 .if defined(SHLIB_MINOR) && ${MKPIC} != "no"
100 @echo ${SHLIB_MINOR}
101 .else
102 @false
103 .endif
105 print-shlib-teeny:
106 .if defined(SHLIB_TEENY) && ${MKPIC} != "no"
107 @echo ${SHLIB_TEENY}
108 .else
109 @false
110 .endif
112 .if defined(SHLIB_MAJOR) && !empty(SHLIB_MAJOR) # {
113 .if defined(SHLIB_MINOR) && !empty(SHLIB_MINOR)
114 .if defined(SHLIB_TEENY) && !empty(SHLIB_TEENY)
115 SHLIB_FULLVERSION=${SHLIB_MAJOR}.${SHLIB_MINOR}.${SHLIB_TEENY}
116 .else
117 SHLIB_FULLVERSION=${SHLIB_MAJOR}.${SHLIB_MINOR}
118 .endif
119 .else
120 SHLIB_FULLVERSION=${SHLIB_MAJOR}
121 .endif
122 .endif # }
124 # add additional suffixes not exported.
125 # .po is used for profiling object files.
126 # .pico is used for PIC object files.
127 .SUFFIXES: .out .a .ln .pico .po .go .o .s .S .c .cc .cpp .cxx .C .m .F .f .r .y .l .cl .p .h
128 .SUFFIXES: .sh .m4 .m
131 # Set PICFLAGS to cc flags for producing position-independent code,
132 # if not already set.
134 # Data-driven table using make variables to control how shared libraries
135 # are built for different platforms and object formats.
136 # SHLIB_MAJOR, SHLIB_MINOR, SHLIB_TEENY: Major, minor, and teeny version
137 # numbers of shared library
138 # SHLIB_SOVERSION: version number to be compiled into a shared library
139 # via -soname. Usualy ${SHLIB_MAJOR} on ELF.
140 # NetBSD/pmax used to use ${SHLIB_MAJOR}[.${SHLIB_MINOR}
141 # [.${SHLIB_TEENY}]]
142 # SHLIB_SHFLAGS: Flags to tell ${LD} to emit shared library.
143 # with ELF, also set shared-lib version for ld.so.
144 # SHLIB_LDSTARTFILE: support .o file, call C++ file-level constructors
145 # SHLIB_LDENDFILE: support .o file, call C++ file-level destructors
147 PICFLAGS ?= -fPIC
149 .if ${MKPICLIB} != "no"
150 CSHLIBFLAGS+= ${PICFLAGS}
151 .endif
153 .if defined(CSHLIBFLAGS) && !empty(CSHLIBFLAGS)
154 MKSHLIBOBJS= yes
155 .else
156 MKSHLIBOBJS= no
157 .endif
159 .if (defined(MKDEBUG) && (${MKDEBUG} != "no")) || \
160 (defined(CFLAGS) && !empty(CFLAGS:M*-g*))
161 # We only add -g to the shared library objects
162 # because we don't currently split .a archives.
163 CSHLIBFLAGS+= -g
164 .if ${LIBISPRIVATE} == "yes"
165 CFLAGS+= -g
166 .endif
167 .endif
169 # Platform-independent linker flags for ELF shared libraries
170 SHLIB_SOVERSION= ${SHLIB_MAJOR}
171 SHLIB_SHFLAGS= -Wl,-soname,${_LIB}.so.${SHLIB_SOVERSION}
172 SHLIB_SHFLAGS+= -Wl,--warn-shared-textrel
173 .if !defined(SHLIB_MKMAP) || ${SHLIB_MKMAP} != "no"
174 SHLIB_SHFLAGS+= -Wl,-Map=${_LIB}.so.${SHLIB_SOVERSION}.map
175 .endif
176 CLEANFILES+= ${_LIB}.so.${SHLIB_SOVERSION}.map
177 SHLIB_LDSTARTFILE?= ${_GCC_CRTI} ${_GCC_CRTBEGINS}
178 SHLIB_LDENDFILE?= ${_GCC_CRTENDS} ${_GCC_CRTN}
180 CFLAGS+= ${COPTS}
181 OBJCFLAGS+= ${OBJCOPTS}
182 AFLAGS+= ${COPTS}
183 FFLAGS+= ${FOPTS}
185 .if defined(CTFCONVERT)
186 .if defined(CFLAGS) && !empty(CFLAGS:M*-g*)
187 CTFFLAGS+= -g
188 .endif
189 .endif
191 LIBSTRIPAOBJS= yes
192 .if !defined(CFLAGS) || empty(CFLAGS:M*-g*)
193 LIBSTRIPCOBJS= yes
194 .endif
195 .if !defined(OBJCFLAGS) || empty(OBJCFLAGS:M*-g*)
196 LIBSTRIPOBJCOBJS= yes
197 .endif
198 .if !defined(FFLAGS) || empty(FFLAGS:M*-g*)
199 LIBSTRIPFOBJS= yes
200 .endif
201 .if !defined(CSHLIBFLAGS) || empty(CSHLIBFLAGS:M*-g*)
202 LIBSTRIPSHLIBOBJS= yes
203 .endif
205 .if defined(__MINIX) && ${USE_BITCODE:Uno} == "yes"
206 SHLIB_SHFLAGS+= -L ${DESTDIR}/usr/lib
207 SHLIB_SHFLAGS+= -Wl,-plugin=${GOLD_PLUGIN} \
208 -Wl,-plugin-opt=-disable-opt
210 .S.bc: ${.TARGET:.bc=.o}
211 rm -f ${.TARGET}
212 ln ${.TARGET:.bc=.o} ${.TARGET}
213 .c.bc:
214 ${_MKTARGET_COMPILE}
215 ${COMPILE.c} ${COPTS.${.IMPSRC:T}} ${CPUFLAGS.${.IMPSRC:T}} ${CPPFLAGS.${.IMPSRC:T}} ${.IMPSRC} -o ${.TARGET} -flto
217 .cc.bc .cxx.bc .cpp.bc:
218 ${_MKTARGET_COMPILE}
219 ${COMPILE.cc} ${COPTS.${.IMPSRC:T}} ${CPUFLAGS.${.IMPSRC:T}} ${CPPFLAGS.${.IMPSRC:T}} ${.IMPSRC} -o ${.TARGET} -flto
220 .endif # defined(__MINIX) && ${USE_BITCODE:Uno} == "yes"
221 .c.o:
222 ${_MKTARGET_COMPILE}
223 ${COMPILE.c} ${COPTS.${.IMPSRC:T}} ${CPUFLAGS.${.IMPSRC:T}} ${CPPFLAGS.${.IMPSRC:T}} ${.IMPSRC} -o ${.TARGET}
224 .if defined(CTFCONVERT)
225 ${CTFCONVERT} ${CTFFLAGS} ${.TARGET}
226 .endif
227 .if defined(LIBSTRIPCOBJS)
228 ${OBJCOPY} ${OBJCOPYLIBFLAGS} ${.TARGET}
229 .endif
231 .c.po:
232 ${_MKTARGET_COMPILE}
233 ${COMPILE.c} ${PROFFLAGS} ${COPTS.${.IMPSRC:T}} ${CPUFLAGS.${.IMPSRC:T}} ${CPPFLAGS.${.IMPSRC:T}} -pg ${.IMPSRC} -o ${.TARGET}
234 .if defined(CTFCONVERT)
235 ${CTFCONVERT} ${CTFFLAGS} ${.TARGET}
236 .endif
237 .if defined(LIBSTRIPCOBJS)
238 ${OBJCOPY} ${OBJCOPYLIBFLAGS} ${.TARGET}
239 .endif
241 .c.go:
242 ${_MKTARGET_COMPILE}
243 ${COMPILE.c} ${DEBUGFLAGS} ${COPTS.${.IMPSRC:T}} ${CPUFLAGS.${.IMPSRC:T}} ${CPPFLAGS.${.IMPSRC:T}} -g ${.IMPSRC} -o ${.TARGET}
245 .c.pico:
246 ${_MKTARGET_COMPILE}
247 ${COMPILE.c} ${COPTS.${.IMPSRC:T}} ${CPUFLAGS.${.IMPSRC:T}} ${CPPFLAGS.${.IMPSRC:T}} ${CSHLIBFLAGS} ${.IMPSRC} -o ${.TARGET}
248 .if defined(LIBSTRIPSHLIBOBJS)
249 ${OBJCOPY} ${OBJCOPYLIBFLAGS} ${.TARGET}
250 .endif
252 .cc.o .cpp.o .cxx.o .C.o:
253 ${_MKTARGET_COMPILE}
254 ${COMPILE.cc} ${COPTS.${.IMPSRC:T}} ${CPUFLAGS.${.IMPSRC:T}} ${CPPFLAGS.${.IMPSRC:T}} ${.IMPSRC} -o ${.TARGET}
255 .if defined(LIBSTRIPCOBJS)
256 ${OBJCOPY} ${OBJCOPYLIBFLAGS} ${.TARGET}
257 .endif
259 .cc.po .cpp.po .cxx.po .C.po:
260 ${_MKTARGET_COMPILE}
261 ${COMPILE.cc} ${PROFFLAGS} ${COPTS.${.IMPSRC:T}} ${CPUFLAGS.${.IMPSRC:T}} ${CPPFLAGS.${.IMPSRC:T}} -pg ${.IMPSRC} -o ${.TARGET}
262 .if defined(LIBSTRIPCOBJS)
263 ${OBJCOPY} ${OBJCOPYLIBFLAGS} ${.TARGET}
264 .endif
266 .cc.go .cpp.go .cxx.go .C.go:
267 ${_MKTARGET_COMPILE}
268 ${COMPILE.cc} ${DEBUGFLAGS} ${COPTS.${.IMPSRC:T}} ${CPUFLAGS.${.IMPSRC:T}} ${CPPFLAGS.${.IMPSRC:T}} -g ${.IMPSRC} -o ${.TARGET}
270 .cc.pico .cpp.pico .cxx.pico .C.pico:
271 ${_MKTARGET_COMPILE}
272 ${COMPILE.cc} ${COPTS.${.IMPSRC:T}} ${CPUFLAGS.${.IMPSRC:T}} ${CPPFLAGS.${.IMPSRC:T}} ${CSHLIBFLAGS} ${.IMPSRC} -o ${.TARGET}
273 .if defined(LIBSTRIPSHLIBOBJS)
274 ${OBJCOPY} ${OBJCOPYLIBFLAGS} ${.TARGET}
275 .endif
277 .f.o:
278 ${_MKTARGET_COMPILE}
279 ${COMPILE.f} ${.IMPSRC} -o ${.TARGET}
280 .if defined(CTFCONVERT)
281 ${CTFCONVERT} ${CTFFLAGS} ${.TARGET}
282 .endif
283 .if defined(LIBSTRIPFOBJS)
284 ${OBJCOPY} ${OBJCOPYLIBFLAGS} ${.TARGET}
285 .endif
287 .f.po:
288 ${_MKTARGET_COMPILE}
289 ${COMPILE.f} ${PROFFLAGS} -pg ${.IMPSRC} -o ${.TARGET}
290 .if defined(CTFCONVERT)
291 ${CTFCONVERT} ${CTFFLAGS} ${.TARGET}
292 .endif
293 .if defined(LIBSTRIPFOBJS)
294 ${OBJCOPY} ${OBJCOPYLIBFLAGS} ${.TARGET}
295 .endif
297 .f.go:
298 ${_MKTARGET_COMPILE}
299 ${COMPILE.f} ${DEBUGFLAGS} -g ${.IMPSRC} -o ${.TARGET}
301 .f.pico:
302 ${_MKTARGET_COMPILE}
303 ${COMPILE.f} ${PICFLAGS} ${.IMPSRC} -o ${.TARGET}
304 .if defined(LIBSTRIPFOBJS)
305 ${OBJCOPY} ${OBJCOPYLIBFLAGS} ${.TARGET}
306 .endif
308 .f.ln:
309 ${_MKTARGET_COMPILE}
310 @echo Skipping lint for Fortran libraries.
312 .m.o:
313 ${_MKTARGET_COMPILE}
314 ${COMPILE.m} ${OBJCOPTS.${.IMPSRC:T}} ${.IMPSRC} -o ${.TARGET}
315 .if defined(CTFCONVERT)
316 ${CTFCONVERT} ${CTFFLAGS} ${.TARGET}
317 .endif
318 .if defined(LIBSTRIPOBJCOBJS)
319 ${OBJCOPY} ${OBJCOPYLIBFLAGS} ${.TARGET}
320 .endif
322 .m.po:
323 ${_MKTARGET_COMPILE}
324 ${COMPILE.m} ${PROFFLAGS} -pg ${OBJCOPTS.${.IMPSRC:T}} ${.IMPSRC} -o ${.TARGET}
325 .if defined(CTFCONVERT)
326 ${CTFCONVERT} ${CTFFLAGS} ${.TARGET}
327 .endif
328 .if defined(LIBSTRIPOBJCOBJS)
329 ${OBJCOPY} ${OBJCOPYLIBFLAGS} ${.TARGET}
330 .endif
332 .m.go:
333 ${_MKTARGET_COMPILE}
334 ${COMPILE.m} ${DEBUGFLAGS} -g ${OBJCOPTS.${.IMPSRC:T}} ${.IMPSRC} -o ${.TARGET}
335 .if defined(LIBSTRIPOBJCOBJS)
336 ${OBJCOPY} ${OBJCOPYLIBFLAGS} ${.TARGET}
337 .endif
339 .m.pico:
340 ${_MKTARGET_COMPILE}
341 ${COMPILE.m} ${CSHLIBFLAGS} ${OBJCOPTS.${.IMPSRC:T}} ${.IMPSRC} -o ${.TARGET}
342 .if defined(LIBSTRIPOBJCOBJS)
343 ${OBJCOPY} ${OBJCOPYLIBFLAGS} ${.TARGET}
344 .endif
346 .s.o:
347 ${_MKTARGET_COMPILE}
348 ${COMPILE.s} ${COPTS.${.IMPSRC:T}} ${CPUFLAGS.${.IMPSRC:T}} ${CPPFLAGS.${.IMPSRC:T}} ${.IMPSRC} -o ${.TARGET}
349 .if defined(CTFCONVERT)
350 ${CTFCONVERT} ${CTFFLAGS} ${.TARGET}
351 .endif
352 .if defined(LIBSTRIPAOBJS)
353 ${OBJCOPY} ${OBJCOPYLIBFLAGS} ${.TARGET}
354 .endif
356 .S.o:
357 ${_MKTARGET_COMPILE}
358 ${COMPILE.S} ${COPTS.${.IMPSRC:T}} ${CPUFLAGS.${.IMPSRC:T}} ${CPPFLAGS.${.IMPSRC:T}} ${.IMPSRC} -o ${.TARGET}
359 .if defined(CTFCONVERT)
360 ${CTFCONVERT} ${CTFFLAGS} ${.TARGET}
361 .endif
362 .if defined(LIBSTRIPAOBJS)
363 ${OBJCOPY} ${OBJCOPYLIBFLAGS} ${.TARGET}
364 .endif
366 .s.po:
367 ${_MKTARGET_COMPILE}
368 ${COMPILE.s} ${PROFFLAGS} ${COPTS.${.IMPSRC:T}} ${CPUFLAGS.${.IMPSRC:T}} ${CPPFLAGS.${.IMPSRC:T}} ${.IMPSRC} -o ${.TARGET}
369 .if defined(CTFCONVERT)
370 ${CTFCONVERT} ${CTFFLAGS} ${.TARGET}
371 .endif
372 .if defined(LIBSTRIPAOBJS)
373 ${OBJCOPY} ${OBJCOPYLIBFLAGS} ${.TARGET}
374 .endif
376 .S.po:
377 ${_MKTARGET_COMPILE}
378 ${COMPILE.S} ${PROFFLAGS} ${COPTS.${.IMPSRC:T}} ${CPUFLAGS.${.IMPSRC:T}} ${CPPFLAGS.${.IMPSRC:T}} ${.IMPSRC} -o ${.TARGET}
379 .if defined(CTFCONVERT)
380 ${CTFCONVERT} ${CTFFLAGS} ${.TARGET}
381 .endif
382 .if defined(LIBSTRIPAOBJS)
383 ${OBJCOPY} ${OBJCOPYLIBFLAGS} ${.TARGET}
384 .endif
386 .s.go:
387 ${_MKTARGET_COMPILE}
388 ${COMPILE.s} ${DEBUGFLAGS} ${COPTS.${.IMPSRC:T}} ${CPUFLAGS.${.IMPSRC:T}} ${CPPFLAGS.${.IMPSRC:T}} ${.IMPSRC} -o ${.TARGET}
390 .S.go:
391 ${_MKTARGET_COMPILE}
392 ${COMPILE.S} ${DEBUGFLAGS} ${COPTS.${.IMPSRC:T}} ${CPUFLAGS.${.IMPSRC:T}} ${CPPFLAGS.${.IMPSRC:T}} ${.IMPSRC} -o ${.TARGET}
394 .s.pico:
395 ${_MKTARGET_COMPILE}
396 ${COMPILE.s} ${PICFLAGS} ${COPTS.${.IMPSRC:T}} ${CPUFLAGS.${.IMPSRC:T}} ${CPPFLAGS.${.IMPSRC:T}} ${.IMPSRC} -o ${.TARGET}
397 .if defined(LIBSTRIPAOBJS)
398 ${OBJCOPY} ${OBJCOPYLIBFLAGS} ${.TARGET}
399 .endif
401 .S.pico:
402 ${_MKTARGET_COMPILE}
403 ${COMPILE.S} ${PICFLAGS} ${COPTS.${.IMPSRC:T}} ${CPUFLAGS.${.IMPSRC:T}} ${CPPFLAGS.${.IMPSRC:T}} ${.IMPSRC} -o ${.TARGET}
404 .if defined(LIBSTRIPAOBJS)
405 ${OBJCOPY} ${OBJCOPYLIBFLAGS} ${.TARGET}
406 .endif
408 # Declare a few variables to make our life easier later.
409 _LIB:=${_LIB_PREFIX}${LIB}
410 _LIB.a:=${_LIB}.a
411 _LIB_p.a:=${_LIB}_p.a
412 _LIB_g.a:=${_LIB}_g.a
413 _LIB_pic.a:=${_LIB}_pic.a
414 _LIB.ln:=llib-l${LIB}.ln
415 .if defined(__MINIX) && ${USE_BITCODE:Uno} == "yes"
416 _LIB_bc.a:=${_LIB}_bc.a
417 .endif # defined(__MINIX)
419 .if ${MKPIC} != "no" && defined(SHLIB_FULLVERSION)
420 _LIB.so:=${_LIB}.so
421 _LIB.so.major:=${_LIB}.so.${SHLIB_MAJOR}
422 _LIB.so.full:=${_LIB}.so.${SHLIB_FULLVERSION}
423 .if ${MKDEBUG} != "no"
424 _LIB.so.debug:=${_LIB.so.full}.debug
425 .endif
426 .endif
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}
434 .if defined(LIB) # {
435 .if (${MKPIC} == "no" || (defined(LDSTATIC) && ${LDSTATIC} != "") \
436 || ${MKLINKLIB} != "no") && ${MKSTATICLIB} != "no"
437 _LIBS=${_LIB.a}
438 .else
439 _LIBS=
440 .endif
442 .if ${LIBISPRIVATE} != "no" \
443 && (defined(USE_COMBINE) && ${USE_COMBINE} == "yes" \
444 && !defined(NOCOMBINE)) # {
445 .for f in ${SRCS:N*.h:N*.sh:C/\.[yl]$/.c/g}
446 COMBINEFLAGS.${LIB}.$f := ${CPPFLAGS.$f:D1} ${CPUFLAGS.$f:D2} ${COPTS.$f:D3} ${OBJCOPTS.$f:D4} ${CXXFLAGS.$f:D5}
447 .if empty(COMBINEFLAGS.${LIB}.${f}) && !defined(NOCOMBINE.$f)
448 COMBINESRCS+= ${f}
449 NODPSRCS+= ${f}
450 .else
451 OBJS+= ${f:R:S/$/.o/}
452 .endif
453 .endfor
455 .if !empty(COMBINESRCS)
456 OBJS+= ${_LIB}_combine.o
457 ${_LIB}_combine.o: ${COMBINESRCS}
458 ${_MKTARGET_COMPILE}
459 ${COMPILE.c} -MD --combine ${.ALLSRC} -o ${.TARGET}
460 .if defined(LIBSTRIPOBJS)
461 ${OBJCOPY} -x ${.TARGET}
462 .endif
464 CLEANFILES+= ${_LIB}_combine.d
466 .if exists("${_LIB}_combine.d")
467 .include "${_LIB}_combine.d"
468 .endif
469 .endif # empty(XSRCS.${LIB})
470 .else # } {
471 OBJS+=${SRCS:N*.h:N*.sh:R:S/$/.o/g}
472 .endif # }
474 STOBJS+=${OBJS}
476 LOBJS+=${LSRCS:.c=.ln} ${SRCS:M*.c:.c=.ln}
478 .if ${LIBISPRIVATE} != "no"
479 # No installation is required
480 libinstall::
481 .endif
483 .if ${MKDEBUGLIB} != "no"
484 _LIBS+=${_LIB_g.a}
485 GOBJS+=${OBJS:.o=.go}
486 DEBUGFLAGS?=-DDEBUG
487 .endif
489 .if ${MKPROFILE} != "no"
490 _LIBS+=${_LIB_p.a}
491 POBJS+=${OBJS:.o=.po}
492 PROFFLAGS?=-DGPROF -DPROF
493 .endif
495 .if ${MKPIC} != "no" # {
496 .if ${MKPICLIB} == "no"
497 .if ${MKSHLIBOBJS} != "no"
498 # make _pic.a, which isn't really pic,
499 # since it's needed for making shared lib.
500 # but don't install it.
501 SOLIB=${_LIB_pic.a}
502 SOBJS+=${OBJS:.o=.pico}
503 .else
504 SOLIB=${_LIB.a}
505 .endif
506 .else
507 SOLIB=${_LIB_pic.a}
508 _LIBS+=${SOLIB}
509 SOBJS+=${OBJS:.o=.pico}
510 .endif
511 .if defined(SHLIB_FULLVERSION)
512 _LIBS+=${_LIB.so.full}
513 .endif
514 .endif # }
516 .if ${MKLINT} != "no" && !empty(LOBJS)
517 _LIBS+=${_LIB.ln}
518 .endif
520 ALLOBJS=
521 .if (${MKPIC} == "no" || (defined(LDSTATIC) && ${LDSTATIC} != "") \
522 || ${MKLINKLIB} != "no") && ${MKSTATICLIB} != "no"
523 ALLOBJS+=${STOBJS}
524 .endif
525 ALLOBJS+=${POBJS} ${SOBJS}
526 .if ${MKLINT} != "no" && !empty(LOBJS)
527 ALLOBJS+=${LOBJS}
528 .endif
529 .else # !defined(LIB) # } {
530 LOBJS=
531 SOBJS=
532 .endif # !defined(LIB) # }
534 _YLSRCS= ${SRCS:M*.[ly]:C/\..$/.c/} ${YHEADER:D${SRCS:M*.y:.y=.h}}
536 .if ${USE_BITCODE:Uno} == "yes"
537 _LIBS+=${_LIB_bc.a}
538 .endif # ${USE_BITCODE:Uno} == "yes"
540 .NOPATH: ${ALLOBJS} ${_LIBS} ${_YLSRCS}
542 realall: ${SRCS} ${ALLOBJS:O} ${_LIBS} ${_LIB.so.debug}
544 MKARZERO?=no
546 .if ${MKARZERO} == "yes"
547 _ARFL=crsD
548 _ARRANFL=sD
549 _INSTRANLIB=
550 .else
551 _ARFL=crs
552 _ARRANFL=s
553 .if ${USE_BITCODE:Uno} == "yes"
554 _INSTRANLIB=${empty(PRESERVE):?-a "${AR} --plugin ${GOLD_PLUGIN} -s":}
555 .else
556 _INSTRANLIB=${empty(PRESERVE):?-a "${RANLIB} -t":}
557 .endif # ${USE_BITCODE:Uno} == "yes"
558 .endif
560 # If you change this, please consider reflecting the change in
561 # the override in sys/rump/Makefile.rump.
562 .if !target(__archivebuild)
563 __archivebuild: .USE
564 ${_MKTARGET_BUILD}
565 rm -f ${.TARGET}
566 ${AR} ${_ARFL} ${.TARGET} `NM=${NM} ${LORDER} ${.ALLSRC:M*o} | ${TSORT}`
567 .endif
569 .if !target(__archiveinstall)
570 __archiveinstall: .USE
571 ${_MKTARGET_INSTALL}
572 ${INSTALL_FILE} -o ${LIBOWN} -g ${LIBGRP} -m ${LIBMODE} \
573 ${_INSTRANLIB} ${.ALLSRC} ${.TARGET}
574 .endif
576 __archivesymlinkpic: .USE
577 ${_MKTARGET_INSTALL}
578 ${INSTALL_SYMLINK} ${.ALLSRC} ${.TARGET}
580 DPSRCS+= ${_YLSRCS}
581 CLEANFILES+= ${_YLSRCS}
583 ${STOBJS} ${POBJS} ${GOBJS} ${SOBJS} ${LOBJS}: ${DPSRCS}
585 .if ${USE_BITCODE:Uno} == "yes"
587 .if !target(__archivebuildbc)
588 __archivebuildbc: .USE
589 ${_MKTARGET_BUILD}
590 rm -f ${.TARGET}
591 ${AR} ${_ARFL} --plugin ${GOLD_PLUGIN} ${.TARGET} ${.ALLSRC:M*bc}
592 .endif
594 # LSC: Ignore libunwind in the bitcode archive, otherwise final linking chokes
595 # on libunwind hidden assembly symbols.
596 BCOBJS+=${OBJS:Nlibunwind.*:.o=.bc}
597 ALLOBJS+=${BCOBJS}
598 ${_LIB_bc.a}:: ${BCOBJS} __archivebuildbc
600 .endif # ${USE_BITCODE:Uno} == "yes"
602 ${_LIB.a}:: ${STOBJS} __archivebuild
604 ${_LIB_p.a}:: ${POBJS} __archivebuild
606 ${_LIB_pic.a}:: ${SOBJS} __archivebuild
608 ${_LIB_g.a}:: ${GOBJS} __archivebuild
611 _LIBLDOPTS=
612 .if ${SHLIBDIR} != "/usr/lib"
613 _LIBLDOPTS+= -Wl,-rpath,${SHLIBDIR} \
614 -L=${SHLIBDIR}
615 .elif ${SHLIBINSTALLDIR} != "/usr/lib"
616 _LIBLDOPTS+= -Wl,-rpath-link,${DESTDIR}${SHLIBINSTALLDIR} \
617 -L=${SHLIBINSTALLDIR}
618 .endif
620 # gcc -shared now adds -lc automatically. For libraries other than libc and
621 # libgcc* we add as a dependency the installed shared libc. For libc and
622 # libgcc* we avoid adding libc as a dependency by using -nostdlib. Note that
623 # -Xl,-nostdlib is not enough because we want to tell the compiler-driver not
624 # to add standard libraries, not the linker.
625 .if !defined(LIB)
626 .if !empty(LIBC_SO)
627 DPLIBC ?= ${DESTDIR}${LIBC_SO}
628 .endif
629 .else
630 .if ${LIB} != "c" && ${LIB:Mgcc*} == "" \
631 && ${LIB} != "sys" && ${LIB} != "minc" && ${LIB} != "mthread" # Minix-specific libs
632 .if !empty(LIBC_SO)
633 DPLIBC ?= ${DESTDIR}${LIBC_SO}
634 .endif
635 .else
636 LDLIBC ?= -nodefaultlibs
637 .if ${HAVE_LIBGCC} == "yes" && (${LIB} == "c" || ${LIB} == "minc")
638 .if !defined(__MINIX)
639 LDADD+= -lgcc
640 .else
641 LDADD+= ${${ACTIVE_CC} == "gcc":? -lgcc:}
642 .if ${MACHINE_ARCH} == "earm"
643 LDADD+= ${${ACTIVE_CC} == "gcc":? -lgcc_eh:}
644 .endif # ${MACHINE_ARCH} == "earm"
645 .endif # !defined(__MINIX)
646 .endif
647 .endif
648 .endif
650 .if ${LIBISCXX} != "no"
651 LIBCC:= ${CXX}
652 . if ${MKLIBCXX} == "yes"
653 LIBDPLIBS+= c++ ${.CURDIR}/../../../../../external/bsd/libc++/lib
654 . elif defined(HAVE_GCC) && ${HAVE_GCC} == 4
655 LIBDPLIBS+= stdc++ ${.CURDIR}/../../../../../gnu/lib/libstdc++-v3_4
656 . else
657 LIBDPLIBS+= stdc++ ${.CURDIR}/../../../../../external/gpl3/gcc/lib/libstdc++-v3
658 . endif
659 .else
660 LIBCC:= ${CC}
661 .endif
663 _LDADD.${_LIB}= ${LDADD} ${LDADD.${_LIB}}
664 _LDFLAGS.${_LIB}= ${LDFLAGS} ${LDFLAGS.${_LIB}}
666 ${_LIB.so.full}: ${SOLIB} ${DPADD} ${DPLIBC} \
667 ${SHLIB_LDSTARTFILE} ${SHLIB_LDENDFILE}
668 ${_MKTARGET_BUILD}
669 rm -f ${.TARGET}
670 ${LIBCC} ${LDLIBC} -Wl,-x -shared ${SHLIB_SHFLAGS} \
671 ${_LDFLAGS.${_LIB}} -o ${.TARGET} ${_LIBLDOPTS} \
672 -Wl,--whole-archive ${SOLIB} \
673 -Wl,--no-whole-archive ${_LDADD.${_LIB}}
674 # We don't use INSTALL_SYMLINK here because this is just
675 # happening inside the build directory/objdir. XXX Why does
676 # this spend so much effort on libraries that aren't live??? XXX
677 .if defined(SHLIB_FULLVERSION) && defined(SHLIB_MAJOR) && \
678 "${SHLIB_FULLVERSION}" != "${SHLIB_MAJOR}"
679 ${HOST_LN} -sf ${_LIB.so.full} ${_LIB.so.major}.tmp
680 mv -f ${_LIB.so.major}.tmp ${_LIB.so.major}
681 .endif
682 ${HOST_LN} -sf ${_LIB.so.full} ${_LIB.so}.tmp
683 mv -f ${_LIB.so}.tmp ${_LIB.so}
684 .if ${MKSTRIPIDENT} != "no"
685 ${OBJCOPY} -R .ident ${.TARGET}
686 .endif
688 .if defined(_LIB.so.debug)
689 ${_LIB.so.debug}: ${_LIB.so.full}
690 ${_MKTARGET_CREATE}
691 ( ${OBJCOPY} --only-keep-debug ${_LIB.so.full} ${_LIB.so.debug} \
692 && ${OBJCOPY} --strip-debug -p -R .gnu_debuglink \
693 --add-gnu-debuglink=${_LIB.so.debug} ${_LIB.so.full} \
694 ) || (rm -f ${.TARGET}; false)
695 .endif
697 .if !empty(LOBJS) # {
698 LLIBS?= -lc
699 ${_LIB.ln}: ${LOBJS}
700 ${_MKTARGET_COMPILE}
701 rm -f ${.TARGET}
702 .if defined(DESTDIR)
703 ${LINT} -C${LIB} ${.ALLSRC} -L${DESTDIR}/usr/libdata ${LLIBS}
704 .else
705 ${LINT} -C${LIB} ${.ALLSRC} ${LLIBS}
706 .endif
707 .endif # }
709 lint: ${LOBJS}
710 .if defined(LOBJS) && !empty(LOBJS)
711 ${LINT} ${LINTFLAGS} ${LOBJS}
712 .endif
715 # If the number of entries in CLEANFILES is too large, then the
716 # commands in bsd.clean.mk encounter errors like "exec(/bin/sh)
717 # failed (Argument list too long)". Avoid that by splitting the
718 # files to clean into several lists using different variable names.
719 # __cleanuse is an internal target in bsd.clean.mk; the way we
720 # use it here mimics the way it's used by the clean target in
721 # bsd.clean.mk.
723 clean: libclean1 libclean2 libclean3 libclean4 libclean5
724 libclean1: .PHONY .MADE __cleanuse LIBCLEANFILES1
725 libclean2: .PHONY .MADE __cleanuse LIBCLEANFILES2
726 libclean3: .PHONY .MADE __cleanuse LIBCLEANFILES3
727 libclean4: .PHONY .MADE __cleanuse LIBCLEANFILES4
728 libclean5: .PHONY .MADE __cleanuse LIBCLEANFILES5
729 .if defined(__MINIX)
730 # MINIX: core conflicts with core/ in lib/liblwip
731 CLEANFILES+= a.out [Ee]rrs mklog *.core
732 .else
733 CLEANFILES+= a.out [Ee]rrs mklog core *.core
734 .endif # defined(__MINIX)
735 LIBCLEANFILES1+= ${_LIB.a} ${STOBJS} ${STOBJS:=.tmp}
736 LIBCLEANFILES2+= ${_LIB_p.a} ${POBJS} ${POBJS:=.tmp}
737 LIBCLEANFILES3+= ${_LIB_g.a} ${GOBJS} ${GOBJS:=.tmp}
738 LIBCLEANFILES4+= ${_LIB_pic.a}
739 .if ${MKPIC} != "no" && defined(SHLIB_FULLVERSION)
740 LIBCLEANFILES4+= ${_LIB.so}.* ${_LIB.so} ${_LIB.so.debug}
741 .endif
742 LIBCLEANFILES4+= ${SOBJS} ${SOBJS:=.tmp}
743 LIBCLEANFILES5+= ${_LIB.ln} ${LOBJS}
745 .if defined(__MINIX)
746 clean: libclean6
747 libclean6: .PHONY .MADE __cleanuse LIBCLEANFILES6
748 LIBCLEANFILES6+= ${_LIB_bc.a} ${BCOBJS} ${BCOBJS:=.tmp}
749 .endif
751 .if !target(libinstall) # {
752 # Make sure it gets defined, in case MKPIC==no && MKLINKLIB==no
753 libinstall::
755 .if ${USE_BITCODE:Uno} == "yes"
756 libinstall:: ${_DEST.LIB}/bc/${_LIB.a}
757 .PRECIOUS: ${_DEST.LIB}/bc/${_LIB.a}
759 .if ${MKUPDATE} == "no"
760 .if !defined(BUILD) && !make(all) && !make(${_LIB_bc.a})
761 ${_DEST.LIB}/bc/${_LIB.a}! .MADE
762 .endif
763 ${_DEST.LIB}/bc/${_LIB.a}! ${_LIB_bc.a} __archiveinstall
764 .else
765 .if !defined(BUILD) && !make(all) && !make(${_LIB_bc.a})
766 ${_DEST.LIB}/bc/${_LIB.a}: .MADE
767 .endif
768 ${_DEST.LIB}/bc/${_LIB.a}: ${_LIB_bc.a} __archiveinstall
769 .endif
770 .endif # ${USE_BITCODE:Uno} == "yes"
772 .if ${MKLINKLIB} != "no" && ${MKSTATICLIB} != "no"
773 libinstall:: ${_DEST.LIB}/${_LIB.a}
774 .PRECIOUS: ${_DEST.LIB}/${_LIB.a}
776 .if ${MKUPDATE} == "no"
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 .else
782 .if !defined(BUILD) && !make(all) && !make(${_LIB.a})
783 ${_DEST.LIB}/${_LIB.a}: .MADE
784 .endif
785 ${_DEST.LIB}/${_LIB.a}: ${_LIB.a} __archiveinstall
786 .endif
787 .endif
789 .if ${MKPROFILE} != "no"
790 libinstall:: ${_DEST.LIB}/${_LIB_p.a}
791 .PRECIOUS: ${_DEST.LIB}/${_LIB_p.a}
793 .if ${MKUPDATE} == "no"
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 .else
799 .if !defined(BUILD) && !make(all) && !make(${_LIB_p.a})
800 ${_DEST.LIB}/${_LIB_p.a}: .MADE
801 .endif
802 ${_DEST.LIB}/${_LIB_p.a}: ${_LIB_p.a} __archiveinstall
803 .endif
804 .endif
806 .if ${MKDEBUGLIB} != "no"
807 libinstall:: ${_DEST.LIB}/${_LIB_g.a}
808 .PRECIOUS: ${_DEST.LIB}/${_LIB_g.a}
810 .if ${MKUPDATE} == "no"
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 .else
816 .if !defined(BUILD) && !make(all) && !make(${LIB_g.a})
817 ${_DEST.LIB}/${_LIB_g.a}: .MADE
818 .endif
819 ${_DEST.LIB}/${_LIB_g.a}: ${_LIB_g.a} __archiveinstall
820 .endif
821 .endif
823 .if ${MKPIC} != "no" && ${MKPICINSTALL} != "no"
824 libinstall:: ${_DEST.LIB}/${_LIB_pic.a}
825 .PRECIOUS: ${_DEST.LIB}/${_LIB_pic.a}
827 .if ${MKUPDATE} == "no"
828 .if !defined(BUILD) && !make(all) && !make(${_LIB_pic.a})
829 ${_DEST.LIB}/${_LIB_pic.a}! .MADE
830 .endif
831 .if ${MKPICLIB} == "no"
832 ${_DEST.LIB}/${_LIB_pic.a}! ${_LIB.a} __archivesymlinkpic
833 .else
834 ${_DEST.LIB}/${_LIB_pic.a}! ${_LIB_pic.a} __archiveinstall
835 .endif
836 .else
837 .if !defined(BUILD) && !make(all) && !make(${_LIB_pic.a})
838 ${_DEST.LIB}/${_LIB_pic.a}: .MADE
839 .endif
840 .if ${MKPICLIB} == "no"
841 ${_DEST.LIB}/${_LIB_pic.a}: ${_LIB.a} __archivesymlinkpic
842 .else
843 ${_DEST.LIB}/${_LIB_pic.a}: ${_LIB_pic.a} __archiveinstall
844 .endif
845 .endif
846 .endif
848 .if ${MKPIC} != "no" && defined(SHLIB_FULLVERSION)
850 libinstall:: ${_DEST.OBJ}/${_LIB.so.full}
851 .PRECIOUS: ${_DEST.OBJ}/${_LIB.so.full}
853 .if ${MKUPDATE} == "no"
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 .else
859 .if !defined(BUILD) && !make(all) && !make(${_LIB.so.full})
860 ${_DEST.OBJ}/${_LIB.so.full}: .MADE
861 .endif
862 ${_DEST.OBJ}/${_LIB.so.full}: ${_LIB.so.full}
863 .endif
864 ${_MKTARGET_INSTALL}
865 ${INSTALL_FILE} -o ${LIBOWN} -g ${LIBGRP} -m ${LIBMODE} \
866 ${.ALLSRC} ${.TARGET}
867 .if ${_LIBSODIR} != ${LIBDIR}
868 ${INSTALL_SYMLINK} -l r ${_DEST.OBJ}/${_LIB.so.full} \
869 ${_DEST.LIB}/${_LIB.so.full}
870 .endif
871 .if defined(SHLIB_FULLVERSION) && defined(SHLIB_MAJOR) && \
872 "${SHLIB_FULLVERSION}" != "${SHLIB_MAJOR}"
873 ${INSTALL_SYMLINK} ${_LIB.so.full} ${_DEST.OBJ}/${_LIB.so.major}
874 .if ${_LIBSODIR} != ${LIBDIR}
875 ${INSTALL_SYMLINK} -l r ${_DEST.OBJ}/${_LIB.so.full} \
876 ${_DEST.LIB}/${_LIB.so.major}
877 .endif
878 .endif
879 .if ${MKLINKLIB} != "no"
880 ${INSTALL_SYMLINK} ${_LIB.so.full} ${_DEST.OBJ}/${_LIB.so}
881 .if ${_LIBSODIR} != ${LIBDIR}
882 ${INSTALL_SYMLINK} -l r ${_DEST.OBJ}/${_LIB.so.full} \
883 ${_DEST.LIB}/${_LIB.so}
884 .endif
885 .endif
886 .endif
888 .if defined(_LIB.so.debug)
889 libinstall:: ${_DEST.DEBUG}/${_LIB.so.debug}
890 .PRECIOUS: ${_DEST.DEBUG}/${_LIB.so.debug}
892 ${_DEST.DEBUG}/${_LIB.so.debug}: ${_LIB.so.debug}
893 ${_MKTARGET_INSTALL}
894 ${INSTALL_FILE} -o ${DEBUGOWN} -g ${DEBUGGRP} -m ${DEBUGMODE} \
895 ${.ALLSRC} ${.TARGET}
896 .if ${_LIBSODIR} != ${LIBDIR}
897 ${INSTALL_SYMLINK} -l r ${_DEST.DEBUG}/${_LIB.so.debug} \
898 ${_DEST.ODEBUG}/${_LIB.so.debug}
899 .endif
900 .endif
902 .if ${MKLINT} != "no" && !empty(LOBJS)
903 libinstall:: ${_DEST.LINT}/${_LIB.ln}
904 .PRECIOUS: ${_DEST.LINT}/${_LIB.ln}
906 .if ${MKUPDATE} == "no"
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 .else
912 .if !defined(BUILD) && !make(all) && !make(${_LIB.ln})
913 ${_DEST.LINT}/${_LIB.ln}: .MADE
914 .endif
915 ${_DEST.LINT}/${_LIB.ln}: ${_LIB.ln}
916 .endif
917 ${_MKTARGET_INSTALL}
918 ${INSTALL_FILE} -o ${LIBOWN} -g ${LIBGRP} -m ${LIBMODE} \
919 ${.ALLSRC} ${_DEST.LINT}
920 .endif
921 .endif # !target(libinstall) # }
923 ##### Pull in related .mk logic
924 LINKSOWN?= ${LIBOWN}
925 LINKSGRP?= ${LIBGRP}
926 LINKSMODE?= ${LIBMODE}
927 .include <bsd.man.mk>
928 .include <bsd.nls.mk>
929 .include <bsd.files.mk>
930 .include <bsd.inc.mk>
931 .include <bsd.links.mk>
932 .include <bsd.dep.mk>
933 .include <bsd.clang-analyze.mk>
934 .include <bsd.clean.mk>
936 ${TARGETS}: # ensure existence