No empty .Rs/.Re
[netbsd-mini2440.git] / share / mk / bsd.lib.mk
blob33da70d58545d3b5d71d93129d4b02f13b68e537
1 # $NetBSD: bsd.lib.mk,v 1.301 2009/12/12 21:33:50 mrg 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
40 clean: cleanlib
42 ##### LIB specific flags.
43 # XXX: This is needed for programs that link with .a libraries
44 # Perhaps a more correct solution is to always generate _pic.a
45 # files or always have a shared library.
46 .if defined(MKPIE) && (${MKPIE} != "no")
47 CFLAGS+= ${PIE_CFLAGS}
48 AFLAGS+= ${PIE_AFLAGS}
49 .endif
51 ##### Libraries that this may depend upon.
52 .if defined(LIBDPLIBS) && ${MKPIC} != "no" # {
53 .for _lib _dir in ${LIBDPLIBS}
54 .if !defined(LIBDO.${_lib})
55 LIBDO.${_lib}!= cd ${_dir} && ${PRINTOBJDIR}
56 .MAKEOVERRIDES+=LIBDO.${_lib}
57 .endif
58 LDADD+= -L${LIBDO.${_lib}} -l${_lib}
59 DPADD+= ${LIBDO.${_lib}}/lib${_lib}.so
60 .endfor
61 .endif # }
63 ##### Build and install rules
64 MKDEP_SUFFIXES?= .o .po .so .go .ln
66 # Use purely kernel private headers in rump builds
67 .if !defined(RUMPKERNEL)
68 .if empty(CPPFLAGS:M-nostdinc)
69 CPPFLAGS+= ${DESTDIR:D-nostdinc ${CPPFLAG_ISYSTEM} ${DESTDIR}/usr/include}
70 .endif
71 .if empty(CXXFLAGS:M-nostdinc++)
72 CXXFLAGS+= ${DESTDIR:D-nostdinc++ ${CPPFLAG_ISYSTEMXX} ${DESTDIR}/usr/include/g++}
73 .endif
74 .endif
76 .if !defined(SHLIB_MAJOR) && exists(${SHLIB_VERSION_FILE}) # {
77 SHLIB_MAJOR != . ${SHLIB_VERSION_FILE} ; echo $$major
78 SHLIB_MINOR != . ${SHLIB_VERSION_FILE} ; echo $$minor
79 SHLIB_TEENY != . ${SHLIB_VERSION_FILE} ; echo $$teeny
81 DPADD+= ${SHLIB_VERSION_FILE}
83 # Check for higher installed library versions.
84 .if !defined(NOCHECKVER) && !defined(NOCHECKVER_${LIB}) && \
85 exists(${NETBSDSRCDIR}/lib/checkver)
86 checkver:
87 @(cd ${.CURDIR} && \
88 HOST_SH=${HOST_SH:Q} AWK=${TOOL_AWK:Q} \
89 ${HOST_SH} ${NETBSDSRCDIR}/lib/checkver -v ${SHLIB_VERSION_FILE} \
90 -d ${DESTDIR}${_LIBSODIR} ${LIB})
91 .endif
92 .endif # }
94 .if !target(checkver)
95 checkver:
96 .endif
98 print-shlib-major:
99 .if defined(SHLIB_MAJOR) && ${MKPIC} != "no"
100 @echo ${SHLIB_MAJOR}
101 .else
102 @false
103 .endif
105 print-shlib-minor:
106 .if defined(SHLIB_MINOR) && ${MKPIC} != "no"
107 @echo ${SHLIB_MINOR}
108 .else
109 @false
110 .endif
112 print-shlib-teeny:
113 .if defined(SHLIB_TEENY) && ${MKPIC} != "no"
114 @echo ${SHLIB_TEENY}
115 .else
116 @false
117 .endif
119 .if defined(SHLIB_MAJOR) && !empty(SHLIB_MAJOR) # {
120 .if defined(SHLIB_MINOR) && !empty(SHLIB_MINOR)
121 .if defined(SHLIB_TEENY) && !empty(SHLIB_TEENY)
122 SHLIB_FULLVERSION=${SHLIB_MAJOR}.${SHLIB_MINOR}.${SHLIB_TEENY}
123 .else
124 SHLIB_FULLVERSION=${SHLIB_MAJOR}.${SHLIB_MINOR}
125 .endif
126 .else
127 SHLIB_FULLVERSION=${SHLIB_MAJOR}
128 .endif
129 .endif # }
131 # add additional suffixes not exported.
132 # .po is used for profiling object files.
133 # .so is used for PIC object files.
134 .SUFFIXES: .out .a .ln .so .po .go .o .s .S .c .cc .cpp .cxx .C .m .F .f .r .y .l .cl .p .h
135 .SUFFIXES: .sh .m4 .m
138 # Set PICFLAGS to cc flags for producing position-independent code,
139 # if not already set. Includes -DPIC, if required.
141 # Data-driven table using make variables to control how shared libraries
142 # are built for different platforms and object formats.
143 # OBJECT_FMT: currently either "ELF" or "a.out", from <bsd.own.mk>
144 # SHLIB_MAJOR, SHLIB_MINOR, SHLIB_TEENY: Major, minor, and teeny version
145 # numbers of shared library
146 # SHLIB_SOVERSION: version number to be compiled into a shared library
147 # via -soname. Usualy ${SHLIB_MAJOR} on ELF.
148 # NetBSD/pmax used to use ${SHLIB_MAJOR}[.${SHLIB_MINOR}
149 # [.${SHLIB_TEENY}]]
150 # SHLIB_SHFLAGS: Flags to tell ${LD} to emit shared library.
151 # with ELF, also set shared-lib version for ld.so.
152 # SHLIB_LDSTARTFILE: support .o file, call C++ file-level constructors
153 # SHLIB_LDENDFILE: support .o file, call C++ file-level destructors
154 # FPICFLAGS: flags for ${FC} to compile .[fF] files to .so objects.
155 # CPPPICFLAGS: flags for ${CPP} to preprocess .[sS] files for ${AS}
156 # CPICFLAGS: flags for ${CC} to compile .[cC] files to pic objects.
157 # CSHLIBFLAGS: flags for ${CC} to compile .[cC] files to .so objects.
158 # (usually includes ${CPICFLAGS})
159 # CAPICFLAGS: flags for ${CC} to compiling .[Ss] files
160 # (usually just ${CPPPICFLAGS} ${CPICFLAGS})
161 # APICFLAGS: flags for ${AS} to assemble .[sS] to .so objects.
163 .if ${MACHINE_ARCH} == "alpha" # {
165 FPICFLAGS ?= -fPIC
166 CPICFLAGS ?= -fPIC -DPIC
167 CPPPICFLAGS?= -DPIC
168 CAPICFLAGS?= ${CPPPICFLAGS} ${CPICFLAGS}
169 APICFLAGS ?=
171 .elif (${MACHINE_ARCH} == "sparc" || ${MACHINE_ARCH} == "sparc64") && \
172 ${OBJECT_FMT} == "ELF" # } {
174 # If you use -fPIC you need to define BIGPIC to turn on 32-bit
175 # relocations in asm code
176 FPICFLAGS ?= -fPIC
177 CPICFLAGS ?= -fPIC -DPIC
178 CPPPICFLAGS?= -DPIC -DBIGPIC
179 CAPICFLAGS?= ${CPPPICFLAGS} ${CPICFLAGS}
180 APICFLAGS ?= -KPIC
182 .else # } {
184 # Platform-independent flags for NetBSD shared libraries
185 SHLIB_SOVERSION=${SHLIB_FULLVERSION}
186 SHLIB_SHFLAGS=
187 FPICFLAGS ?= -fPIC
188 CPICFLAGS?= -fPIC -DPIC
189 CPPPICFLAGS?= -DPIC
190 CAPICFLAGS?= ${CPPPICFLAGS} ${CPICFLAGS}
191 APICFLAGS?= -k
193 .endif # }
195 .if ${MKPICLIB} != "no"
196 CSHLIBFLAGS+= ${CPICFLAGS}
197 .endif
199 .if defined(CSHLIBFLAGS) && !empty(CSHLIBFLAGS)
200 MKSHLIBOBJS= yes
201 .else
202 MKSHLIBOBJS= no
203 .endif
205 # Platform-independent linker flags for ELF shared libraries
206 .if ${OBJECT_FMT} == "ELF"
207 SHLIB_SOVERSION= ${SHLIB_MAJOR}
208 SHLIB_SHFLAGS= -Wl,-soname,${_LIB_PREFIX}${LIB}.so.${SHLIB_SOVERSION}
209 SHLIB_SHFLAGS+= -Wl,--warn-shared-textrel
210 SHLIB_LDSTARTFILE?= ${_GCC_CRTDIR}/crti.o ${_GCC_CRTBEGINS}
211 SHLIB_LDENDFILE?= ${_GCC_CRTENDS} ${_GCC_CRTDIR}/crtn.o
212 .endif
214 CFLAGS+= ${COPTS}
215 OBJCFLAGS+= ${OBJCOPTS}
216 AFLAGS+= ${COPTS}
217 FFLAGS+= ${FOPTS}
219 .c.o:
220 ${_MKTARGET_COMPILE}
221 ${COMPILE.c} ${COPTS.${.IMPSRC:T}} ${CPUFLAGS.${.IMPSRC:T}} ${CPPFLAGS.${.IMPSRC:T}} ${.IMPSRC} -o ${.TARGET}
222 .if !defined(CFLAGS) || empty(CFLAGS:M*-g*)
223 ${OBJCOPY} -x ${.TARGET}
224 .endif
226 .c.po:
227 ${_MKTARGET_COMPILE}
228 ${COMPILE.c} ${PROFFLAGS} ${COPTS.${.IMPSRC:T}} ${CPUFLAGS.${.IMPSRC:T}} ${CPPFLAGS.${.IMPSRC:T}} -pg ${.IMPSRC} -o ${.TARGET}
229 .if !defined(CFLAGS) || empty(CFLAGS:M*-g*)
230 ${OBJCOPY} -X ${.TARGET}
231 .endif
233 .c.go:
234 ${_MKTARGET_COMPILE}
235 ${COMPILE.c} ${DEBUGFLAGS} ${COPTS.${.IMPSRC:T}} ${CPUFLAGS.${.IMPSRC:T}} ${CPPFLAGS.${.IMPSRC:T}} -g ${.IMPSRC} -o ${.TARGET}
237 .c.so:
238 ${_MKTARGET_COMPILE}
239 ${COMPILE.c} ${COPTS.${.IMPSRC:T}} ${CPUFLAGS.${.IMPSRC:T}} ${CPPFLAGS.${.IMPSRC:T}} ${CSHLIBFLAGS} ${.IMPSRC} -o ${.TARGET}
240 .if !defined(CFLAGS) || empty(CFLAGS:M*-g*)
241 ${OBJCOPY} -x ${.TARGET}
242 .endif
244 .cc.o .cpp.o .cxx.o .C.o:
245 ${_MKTARGET_COMPILE}
246 ${COMPILE.cc} ${COPTS.${.IMPSRC:T}} ${CPUFLAGS.${.IMPSRC:T}} ${CPPFLAGS.${.IMPSRC:T}} ${.IMPSRC} -o ${.TARGET}
247 .if !defined(CFLAGS) || empty(CFLAGS:M*-g*)
248 ${OBJCOPY} -x ${.TARGET}
249 .endif
251 .cc.po .cpp.po .cxx.po .C.po:
252 ${_MKTARGET_COMPILE}
253 ${COMPILE.cc} ${PROFFLAGS} ${COPTS.${.IMPSRC:T}} ${CPUFLAGS.${.IMPSRC:T}} ${CPPFLAGS.${.IMPSRC:T}} -pg ${.IMPSRC} -o ${.TARGET}
254 .if !defined(CFLAGS) || empty(CFLAGS:M*-g*)
255 ${OBJCOPY} -X ${.TARGET}
256 .endif
258 .cc.go .cpp.go .cxx.go .C.go:
259 ${_MKTARGET_COMPILE}
260 ${COMPILE.cc} ${DEBUGFLAGS} ${COPTS.${.IMPSRC:T}} ${CPUFLAGS.${.IMPSRC:T}} ${CPPFLAGS.${.IMPSRC:T}} -g ${.IMPSRC} -o ${.TARGET}
262 .cc.so .cpp.so .cxx.so .C.so:
263 ${_MKTARGET_COMPILE}
264 ${COMPILE.cc} ${COPTS.${.IMPSRC:T}} ${CPUFLAGS.${.IMPSRC:T}} ${CPPFLAGS.${.IMPSRC:T}} ${CSHLIBFLAGS} ${.IMPSRC} -o ${.TARGET}
265 .if !defined(CFLAGS) || empty(CFLAGS:M*-g*)
266 ${OBJCOPY} -x ${.TARGET}
267 .endif
269 .f.o:
270 ${_MKTARGET_COMPILE}
271 ${COMPILE.f} ${.IMPSRC} -o ${.TARGET}
272 .if !defined(FOPTS) || empty(FOPTS:M*-g*)
273 ${OBJCOPY} -x ${.TARGET}
274 .endif
276 .f.po:
277 ${_MKTARGET_COMPILE}
278 ${COMPILE.f} ${PROFFLAGS} -pg ${.IMPSRC} -o ${.TARGET}
279 .if !defined(FOPTS) || empty(FOPTS:M*-g*)
280 ${OBJCOPY} -X ${.TARGET}
281 .endif
283 .f.go:
284 ${_MKTARGET_COMPILE}
285 ${COMPILE.f} ${DEBUGFLAGS} -g ${.IMPSRC} -o ${.TARGET}
287 .f.so:
288 ${_MKTARGET_COMPILE}
289 ${COMPILE.f} ${FPICFLAGS} ${.IMPSRC} -o ${.TARGET}
290 .if !defined(FOPTS) || empty(FOPTS:M*-g*)
291 ${OBJCOPY} -x ${.TARGET}
292 .endif
294 .f.ln:
295 ${_MKTARGET_COMPILE}
296 @echo Skipping lint for Fortran libraries.
298 .m.o:
299 ${_MKTARGET_COMPILE}
300 ${COMPILE.m} ${OBJCOPTS.${.IMPSRC:T}} ${.IMPSRC} -o ${.TARGET}
301 .if !defined(OBJCFLAGS) || empty(OBJCFLAGS:M*-g*)
302 ${OBJCOPY} -x ${.TARGET}
303 .endif
305 .m.po:
306 ${_MKTARGET_COMPILE}
307 ${COMPILE.m} ${PROFFLAGS} -pg ${OBJCOPTS.${.IMPSRC:T}} ${.IMPSRC} -o ${.TARGET}
308 .if !defined(OBJCFLAGS) || empty(OBJCFLAGS:M*-g*)
309 ${OBJCOPY} -X ${.TARGET}
310 .endif
312 .m.go:
313 ${_MKTARGET_COMPILE}
314 ${COMPILE.m} ${DEBUGFLAGS} -g ${OBJCOPTS.${.IMPSRC:T}} ${.IMPSRC} -o ${.TARGET}
315 .if !defined(OBJCFLAGS) || empty(OBJCFLAGS:M*-g*)
316 ${OBJCOPY} -X ${.TARGET}
317 .endif
319 .m.so:
320 ${_MKTARGET_COMPILE}
321 ${COMPILE.m} ${CSHLIBFLAGS} ${OBJCOPTS.${.IMPSRC:T}} ${.IMPSRC} -o ${.TARGET}
322 .if !defined(OBJCFLAGS) || empty(OBJCFLAGS:M*-g*)
323 ${OBJCOPY} -x ${.TARGET}
324 .endif
326 .s.o:
327 ${_MKTARGET_COMPILE}
328 ${COMPILE.s} ${COPTS.${.IMPSRC:T}} ${CPUFLAGS.${.IMPSRC:T}} ${CPPFLAGS.${.IMPSRC:T}} ${.IMPSRC} -o ${.TARGET}
329 ${OBJCOPY} -x ${.TARGET}
331 .S.o:
332 ${_MKTARGET_COMPILE}
333 ${COMPILE.S} ${COPTS.${.IMPSRC:T}} ${CPUFLAGS.${.IMPSRC:T}} ${CPPFLAGS.${.IMPSRC:T}} ${.IMPSRC} -o ${.TARGET}
334 ${OBJCOPY} -x ${.TARGET}
336 .s.po:
337 ${_MKTARGET_COMPILE}
338 ${COMPILE.s} ${PROFFLAGS} ${COPTS.${.IMPSRC:T}} ${CPUFLAGS.${.IMPSRC:T}} ${CPPFLAGS.${.IMPSRC:T}} ${.IMPSRC} -o ${.TARGET}
339 ${OBJCOPY} -X ${.TARGET}
341 .S.po:
342 ${_MKTARGET_COMPILE}
343 ${COMPILE.S} ${PROFFLAGS} ${COPTS.${.IMPSRC:T}} ${CPUFLAGS.${.IMPSRC:T}} ${CPPFLAGS.${.IMPSRC:T}} ${.IMPSRC} -o ${.TARGET}
344 ${OBJCOPY} -X ${.TARGET}
346 .s.go:
347 ${_MKTARGET_COMPILE}
348 ${COMPILE.s} ${DEBUGFLAGS} ${COPTS.${.IMPSRC:T}} ${CPUFLAGS.${.IMPSRC:T}} ${CPPFLAGS.${.IMPSRC:T}} ${.IMPSRC} -o ${.TARGET}
350 .S.go:
351 ${_MKTARGET_COMPILE}
352 ${COMPILE.S} ${DEBUGFLAGS} ${COPTS.${.IMPSRC:T}} ${CPUFLAGS.${.IMPSRC:T}} ${CPPFLAGS.${.IMPSRC:T}} ${.IMPSRC} -o ${.TARGET}
354 .s.so:
355 ${_MKTARGET_COMPILE}
356 ${COMPILE.s} ${CAPICFLAGS} ${COPTS.${.IMPSRC:T}} ${CPUFLAGS.${.IMPSRC:T}} ${CPPFLAGS.${.IMPSRC:T}} ${.IMPSRC} -o ${.TARGET}
357 ${OBJCOPY} -x ${.TARGET}
359 .S.so:
360 ${_MKTARGET_COMPILE}
361 ${COMPILE.S} ${CAPICFLAGS} ${COPTS.${.IMPSRC:T}} ${CPUFLAGS.${.IMPSRC:T}} ${CPPFLAGS.${.IMPSRC:T}} ${.IMPSRC} -o ${.TARGET}
362 ${OBJCOPY} -x ${.TARGET}
364 .if defined(LIB) # {
365 .if (${MKPIC} == "no" || (defined(LDSTATIC) && ${LDSTATIC} != "") \
366 || ${MKLINKLIB} != "no") && ${MKSTATICLIB} != "no"
367 _LIBS=lib${LIB}.a
368 .else
369 _LIBS=
370 .endif
372 OBJS+=${SRCS:N*.h:N*.sh:R:S/$/.o/g}
374 STOBJS+=${OBJS}
376 LOBJS+=${LSRCS:.c=.ln} ${SRCS:M*.c:.c=.ln}
378 .if ${LIBISPRIVATE} != "no"
379 # No installation is required
380 libinstall::
381 .endif # ${LIBISPRIVATE} == "no" # {
383 .if ${MKDEBUGLIB} != "no"
384 _LIBS+=lib${LIB}_g.a
385 GOBJS+=${OBJS:.o=.go}
386 DEBUGFLAGS?=-DDEBUG
387 .endif
389 .if ${MKPROFILE} != "no"
390 _LIBS+=lib${LIB}_p.a
391 POBJS+=${OBJS:.o=.po}
392 PROFFLAGS?=-DGPROF -DPROF
393 .endif
395 .if ${MKPIC} != "no" # {
396 .if ${MKPICLIB} == "no"
397 .if ${MKSHLIBOBJS} != "no"
398 # make _pic.a, which isn't really pic,
399 # since it's needed for making shared lib.
400 # but don't install it.
401 SOLIB=lib${LIB}_pic.a
402 SOBJS+=${OBJS:.o=.so}
403 .else
404 SOLIB=lib${LIB}.a
405 .endif
406 .else
407 SOLIB=lib${LIB}_pic.a
408 _LIBS+=${SOLIB}
409 SOBJS+=${OBJS:.o=.so}
410 .endif
411 .if defined(SHLIB_FULLVERSION)
412 _LIBS+=lib${LIB}.so.${SHLIB_FULLVERSION}
413 .endif
414 .endif # }
416 .if ${MKLINT} != "no" && !empty(LOBJS)
417 _LIBS+=llib-l${LIB}.ln
418 .endif
420 ALLOBJS=
421 .if (${MKPIC} == "no" || (defined(LDSTATIC) && ${LDSTATIC} != "") \
422 || ${MKLINKLIB} != "no") && ${MKSTATICLIB} != "no"
423 ALLOBJS+=${STOBJS}
424 .endif
425 ALLOBJS+=${POBJS} ${SOBJS}
426 .if ${MKLINT} != "no" && !empty(LOBJS)
427 ALLOBJS+=${LOBJS}
428 .endif
429 .else # !defined(LIB) # } {
430 LOBJS=
431 SOBJS=
432 .endif # !defined(LIB) # }
434 _YLSRCS= ${SRCS:M*.[ly]:C/\..$/.c/} ${YHEADER:D${SRCS:M*.y:.y=.h}}
436 .NOPATH: ${ALLOBJS} ${_LIBS} ${_YLSRCS}
438 realall: ${SRCS} ${ALLOBJS:O} ${_LIBS}
440 MKARZERO?=no
442 .if ${MKARZERO} == "yes"
443 _ARFL=crsD
444 _ARRANFL=sD
445 _INSTRANLIB=
446 .else
447 _ARFL=crs
448 _ARRANFL=s
449 _INSTRANLIB=${empty(PRESERVE):?-a "${RANLIB} -t":}
450 .endif
452 # If you change this, please consider reflecting the change in
453 # the override in sys/rump/Makefile.rump.
454 .if !target(__archivebuild)
455 __archivebuild: .USE
456 ${_MKTARGET_BUILD}
457 rm -f ${.TARGET}
458 ${AR} ${_ARFL} ${.TARGET} `NM=${NM} ${LORDER} ${.ALLSRC:M*o} | ${TSORT}`
459 .endif
461 .if !target(__archiveinstall)
462 __archiveinstall: .USE
463 ${_MKTARGET_INSTALL}
464 ${INSTALL_FILE} -o ${LIBOWN} -g ${LIBGRP} -m ${LIBMODE} \
465 ${_INSTRANLIB} ${.ALLSRC} ${.TARGET}
466 .endif
468 __archivesymlinkpic: .USE
469 ${_MKTARGET_INSTALL}
470 ${INSTALL_SYMLINK} ${.ALLSRC} ${.TARGET}
472 DPSRCS+= ${_YLSRCS}
473 CLEANFILES+= ${_YLSRCS}
475 ${STOBJS} ${POBJS} ${GOBJS} ${SOBJS} ${LOBJS}: ${DPSRCS}
477 lib${LIB}.a:: ${STOBJS} __archivebuild
479 lib${LIB}_p.a:: ${POBJS} __archivebuild
481 lib${LIB}_pic.a:: ${SOBJS} __archivebuild
483 lib${LIB}_g.a:: ${GOBJS} __archivebuild
486 _LIBLDOPTS=
487 .if ${SHLIBDIR} != "/usr/lib"
488 _LIBLDOPTS+= -Wl,-rpath-link,${DESTDIR}${SHLIBDIR}:${DESTDIR}/usr/lib \
489 -R${SHLIBDIR} \
490 -L${DESTDIR}${SHLIBDIR}
491 .elif ${SHLIBINSTALLDIR} != "/usr/lib"
492 _LIBLDOPTS+= -Wl,-rpath-link,${DESTDIR}${SHLIBINSTALLDIR}:${DESTDIR}/usr/lib \
493 -L${DESTDIR}${SHLIBINSTALLDIR}
494 .endif
496 # gcc -shared now adds -lc automatically. For libraries other than libc and
497 # libgcc* we add as a dependency the installed shared libc. For libc and
498 # libgcc* we avoid adding libc as a dependency by using -nostdlib. Note that
499 # -Xl,-nostdlib is not enough because we want to tell the compiler-driver not
500 # to add standard libraries, not the linker.
501 .if !defined(LIB)
502 DPLIBC ?= ${DESTDIR}${LIBC_SO}
503 .else
504 .if ${LIB} != "c" && ${LIB:Mgcc*} == ""
505 DPLIBC ?= ${DESTDIR}${LIBC_SO}
506 .else
507 LDLIBC ?= -nodefaultlibs
508 .if ${LIB} == "c"
509 LDADD+= -lgcc_pic
510 .endif
511 .endif
512 .endif
514 .if ${LIBISCXX} != "no"
515 LIBCC:= ${CXX}
516 .else
517 LIBCC:= ${CC}
518 .endif
520 _LDADD.lib${LIB}= ${LDADD} ${LDADD.lib${LIB}}
521 _LDFLAGS.lib${LIB}= ${LDFLAGS} ${LDFLAGS.lib${LIB}}
523 lib${LIB}.so.${SHLIB_FULLVERSION}: ${SOLIB} ${DPADD} ${DPLIBC} \
524 ${SHLIB_LDSTARTFILE} ${SHLIB_LDENDFILE}
525 ${_MKTARGET_BUILD}
526 rm -f lib${LIB}.so.${SHLIB_FULLVERSION}
527 .if defined(DESTDIR)
528 ${LIBCC} ${LDLIBC} -Wl,-nostdlib -B${_GCC_CRTDIR}/ -B${DESTDIR}${SHLIBDIR}/ \
529 -Wl,-x -shared ${SHLIB_SHFLAGS} -o ${.TARGET} \
530 -Wl,--whole-archive ${SOLIB} \
531 -Wl,--no-whole-archive ${_LDADD.lib${LIB}} \
532 ${_LIBLDOPTS} ${_LDFLAGS.lib${LIB}} \
533 -L${_GCC_LIBGCCDIR}
534 .else
535 ${LIBCC} ${LDLIBC} -Wl,-x -shared ${SHLIB_SHFLAGS} ${_LDFLAGS.lib${LIB}} \
536 -o ${.TARGET} ${_LIBLDOPTS} \
537 -Wl,--whole-archive ${SOLIB} -Wl,--no-whole-archive ${_LDADD.lib${LIB}}
538 .endif
539 .if ${OBJECT_FMT} == "ELF"
540 # We don't use INSTALL_SYMLINK here because this is just
541 # happening inside the build directory/objdir. XXX Why does
542 # this spend so much effort on libraries that aren't live??? XXX
543 .if defined(SHLIB_FULLVERSION) && defined(SHLIB_MAJOR) && \
544 "${SHLIB_FULLVERSION}" != "${SHLIB_MAJOR}"
545 ${HOST_LN} -sf lib${LIB}.so.${SHLIB_FULLVERSION} lib${LIB}.so.${SHLIB_MAJOR}.tmp
546 mv -f lib${LIB}.so.${SHLIB_MAJOR}.tmp lib${LIB}.so.${SHLIB_MAJOR}
547 .endif
548 ${HOST_LN} -sf lib${LIB}.so.${SHLIB_FULLVERSION} lib${LIB}.so.tmp
549 mv -f lib${LIB}.so.tmp lib${LIB}.so
550 .endif
551 .if ${MKSTRIPIDENT} != "no"
552 ${OBJCOPY} -R .ident ${.TARGET}
553 .endif
555 .if !empty(LOBJS) # {
556 LLIBS?= -lc
557 llib-l${LIB}.ln: ${LOBJS}
558 ${_MKTARGET_COMPILE}
559 rm -f llib-l${LIB}.ln
560 .if defined(DESTDIR)
561 ${LINT} -C${LIB} ${.ALLSRC} -L${DESTDIR}/usr/libdata ${LLIBS}
562 .else
563 ${LINT} -C${LIB} ${.ALLSRC} ${LLIBS}
564 .endif
565 .endif # }
567 lint: ${LOBJS}
568 .if defined(LOBJS) && !empty(LOBJS)
569 ${LINT} ${LINTFLAGS} ${LOBJS}
570 .endif
572 cleanlib: .PHONY
573 rm -f a.out [Ee]rrs mklog core *.core ${CLEANFILES}
574 rm -f lib${LIB}.a ${STOBJS}
575 rm -f lib${LIB}_p.a ${POBJS}
576 rm -f lib${LIB}_g.a ${GOBJS}
577 rm -f lib${LIB}_pic.a lib${LIB}.so.* lib${LIB}.so ${SOBJS}
578 rm -f ${STOBJS:=.tmp} ${POBJS:=.tmp} ${SOBJS:=.tmp} ${GOBJS:=.tmp}
579 rm -f llib-l${LIB}.ln ${LOBJS}
582 .if !target(libinstall) # {
583 # Make sure it gets defined, in case MKPIC==no && MKLINKLIB==no
584 libinstall::
586 .if ${MKLINKLIB} != "no" && ${MKSTATICLIB} != "no"
587 libinstall:: ${DESTDIR}${LIBDIR}/lib${LIB}.a
588 .PRECIOUS: ${DESTDIR}${LIBDIR}/lib${LIB}.a
590 .if ${MKUPDATE} == "no"
591 .if !defined(BUILD) && !make(all) && !make(lib${LIB}.a)
592 ${DESTDIR}${LIBDIR}/lib${LIB}.a! .MADE
593 .endif
594 ${DESTDIR}${LIBDIR}/lib${LIB}.a! lib${LIB}.a __archiveinstall
595 .else
596 .if !defined(BUILD) && !make(all) && !make(lib${LIB}.a)
597 ${DESTDIR}${LIBDIR}/lib${LIB}.a: .MADE
598 .endif
599 ${DESTDIR}${LIBDIR}/lib${LIB}.a: lib${LIB}.a __archiveinstall
600 .endif
601 .endif
603 .if ${MKPROFILE} != "no"
604 libinstall:: ${DESTDIR}${LIBDIR}/lib${LIB}_p.a
605 .PRECIOUS: ${DESTDIR}${LIBDIR}/lib${LIB}_p.a
607 .if ${MKUPDATE} == "no"
608 .if !defined(BUILD) && !make(all) && !make(lib${LIB}_p.a)
609 ${DESTDIR}${LIBDIR}/lib${LIB}_p.a! .MADE
610 .endif
611 ${DESTDIR}${LIBDIR}/lib${LIB}_p.a! lib${LIB}_p.a __archiveinstall
612 .else
613 .if !defined(BUILD) && !make(all) && !make(lib${LIB}_p.a)
614 ${DESTDIR}${LIBDIR}/lib${LIB}_p.a: .MADE
615 .endif
616 ${DESTDIR}${LIBDIR}/lib${LIB}_p.a: lib${LIB}_p.a __archiveinstall
617 .endif
618 .endif
620 .if ${MKDEBUGLIB} != "no"
621 libinstall:: ${DESTDIR}${LIBDIR}/lib${LIB}_g.a
622 .PRECIOUS: ${DESTDIR}${LIBDIR}/lib${LIB}_g.a
624 .if ${MKUPDATE} == "no"
625 .if !defined(BUILD) && !make(all) && !make(lib${LIB}_g.a)
626 ${DESTDIR}${LIBDIR}/lib${LIB}_g.a! .MADE
627 .endif
628 ${DESTDIR}${LIBDIR}/lib${LIB}_g.a! lib${LIB}_g.a __archiveinstall
629 .else
630 .if !defined(BUILD) && !make(all) && !make(lib${LIB}_g.a)
631 ${DESTDIR}${LIBDIR}/lib${LIB}_g.a: .MADE
632 .endif
633 ${DESTDIR}${LIBDIR}/lib${LIB}_g.a: lib${LIB}_g.a __archiveinstall
634 .endif
635 .endif
637 .if ${MKPIC} != "no" && ${MKPICINSTALL} != "no"
638 libinstall:: ${DESTDIR}${LIBDIR}/lib${LIB}_pic.a
639 .PRECIOUS: ${DESTDIR}${LIBDIR}/lib${LIB}_pic.a
641 .if ${MKUPDATE} == "no"
642 .if !defined(BUILD) && !make(all) && !make(lib${LIB}_pic.a)
643 ${DESTDIR}${LIBDIR}/lib${LIB}_pic.a! .MADE
644 .endif
645 .if ${MKPICLIB} == "no"
646 ${DESTDIR}${LIBDIR}/lib${LIB}_pic.a! lib${LIB}.a __archivesymlinkpic
647 .else
648 ${DESTDIR}${LIBDIR}/lib${LIB}_pic.a! lib${LIB}_pic.a __archiveinstall
649 .endif
650 .else
651 .if !defined(BUILD) && !make(all) && !make(lib${LIB}_pic.a)
652 ${DESTDIR}${LIBDIR}/lib${LIB}_pic.a: .MADE
653 .endif
654 .if ${MKPICLIB} == "no"
655 ${DESTDIR}${LIBDIR}/lib${LIB}_pic.a: lib${LIB}.a __archivesymlinkpic
656 .else
657 ${DESTDIR}${LIBDIR}/lib${LIB}_pic.a: lib${LIB}_pic.a __archiveinstall
658 .endif
659 .endif
660 .endif
662 .if ${MKPIC} != "no" && defined(SHLIB_FULLVERSION)
663 _LIB_SO_TGT= ${DESTDIR}${_LIBSODIR}/${_LIB_PREFIX}${LIB}.so
664 _LIB_SO_TGTLIBDIR= ${DESTDIR}${LIBDIR}/${_LIB_PREFIX}${LIB}.so
666 libinstall:: ${_LIB_SO_TGT}.${SHLIB_FULLVERSION}
667 .PRECIOUS: ${_LIB_SO_TGT}.${SHLIB_FULLVERSION}
669 .if ${MKUPDATE} == "no"
670 .if !defined(BUILD) && !make(all) && !make(lib${LIB}.so.${SHLIB_FULLVERSION})
671 ${_LIB_SO_TGT}.${SHLIB_FULLVERSION}! .MADE
672 .endif
673 ${_LIB_SO_TGT}.${SHLIB_FULLVERSION}! lib${LIB}.so.${SHLIB_FULLVERSION}
674 .else
675 .if !defined(BUILD) && !make(all) && !make(lib${LIB}.so.${SHLIB_FULLVERSION})
676 ${_LIB_SO_TGT}.${SHLIB_FULLVERSION}: .MADE
677 .endif
678 ${_LIB_SO_TGT}.${SHLIB_FULLVERSION}: lib${LIB}.so.${SHLIB_FULLVERSION}
679 .endif
680 ${_MKTARGET_INSTALL}
681 ${INSTALL_FILE} -o ${LIBOWN} -g ${LIBGRP} -m ${LIBMODE} \
682 ${.ALLSRC} ${.TARGET}
683 .if ${_LIBSODIR} != ${LIBDIR}
684 ${INSTALL_SYMLINK} -l r \
685 ${_LIB_SO_TGT}.${SHLIB_FULLVERSION} \
686 ${_LIB_SO_TGTLIBDIR}.${SHLIB_FULLVERSION}
687 .endif
688 .if ${OBJECT_FMT} == "a.out" && !defined(DESTDIR)
689 /sbin/ldconfig -m ${_LIBSODIR} ${LIBDIR}
690 .endif
691 .if ${OBJECT_FMT} == "ELF"
692 .if defined(SHLIB_FULLVERSION) && defined(SHLIB_MAJOR) && \
693 "${SHLIB_FULLVERSION}" != "${SHLIB_MAJOR}"
694 ${INSTALL_SYMLINK} \
695 ${_LIB_PREFIX}${LIB}.so.${SHLIB_FULLVERSION} \
696 ${_LIB_SO_TGT}.${SHLIB_MAJOR}
697 .if ${_LIBSODIR} != ${LIBDIR}
698 ${INSTALL_SYMLINK} -l r \
699 ${_LIB_SO_TGT}.${SHLIB_FULLVERSION} \
700 ${_LIB_SO_TGTLIBDIR}.${SHLIB_MAJOR}
701 .endif
702 .endif
703 .if ${MKLINKLIB} != "no"
704 ${INSTALL_SYMLINK} \
705 ${_LIB_PREFIX}${LIB}.so.${SHLIB_FULLVERSION} \
706 ${_LIB_SO_TGT}
707 .if ${_LIBSODIR} != ${LIBDIR}
708 ${INSTALL_SYMLINK} -l r \
709 ${_LIB_SO_TGT}.${SHLIB_FULLVERSION} \
710 ${_LIB_SO_TGTLIBDIR}
711 .endif
712 .endif
713 .endif
714 .endif
716 .if ${MKLINT} != "no" && !empty(LOBJS)
717 libinstall:: ${DESTDIR}${LINTLIBDIR}/llib-l${LIB}.ln
718 .PRECIOUS: ${DESTDIR}${LINTLIBDIR}/llib-l${LIB}.ln
720 .if ${MKUPDATE} == "no"
721 .if !defined(BUILD) && !make(all) && !make(llib-l${LIB}.ln)
722 ${DESTDIR}${LINTLIBDIR}/llib-l${LIB}.ln! .MADE
723 .endif
724 ${DESTDIR}${LINTLIBDIR}/llib-l${LIB}.ln! llib-l${LIB}.ln
725 .else
726 .if !defined(BUILD) && !make(all) && !make(llib-l${LIB}.ln)
727 ${DESTDIR}${LINTLIBDIR}/llib-l${LIB}.ln: .MADE
728 .endif
729 ${DESTDIR}${LINTLIBDIR}/llib-l${LIB}.ln: llib-l${LIB}.ln
730 .endif
731 ${_MKTARGET_INSTALL}
732 ${INSTALL_FILE} -o ${LIBOWN} -g ${LIBGRP} -m ${LIBMODE} \
733 ${.ALLSRC} ${DESTDIR}${LINTLIBDIR}
734 .endif
735 .endif # !target(libinstall) # }
737 ##### Pull in related .mk logic
738 LINKSOWN?= ${LIBOWN}
739 LINKSGRP?= ${LIBGRP}
740 LINKSMODE?= ${LIBMODE}
741 .include <bsd.man.mk>
742 .include <bsd.nls.mk>
743 .include <bsd.files.mk>
744 .include <bsd.inc.mk>
745 .include <bsd.links.mk>
746 .include <bsd.dep.mk>
748 ${TARGETS}: # ensure existence