bsd.lib.mk revision 1.169.2.2 1 # $NetBSD: bsd.lib.mk,v 1.169.2.2 2000/07/26 23:15:49 mycroft Exp $
2 # @(#)bsd.lib.mk 8.3 (Berkeley) 4/22/94
3
4 .if !target(__initialized__)
5 __initialized__:
6 .if exists(${.CURDIR}/../Makefile.inc)
7 .include "${.CURDIR}/../Makefile.inc"
8 .endif
9 .include <bsd.own.mk>
10 .include <bsd.obj.mk>
11 .include <bsd.depall.mk>
12 .MAIN: all
13 .endif
14
15 .PHONY: checkver cleanlib libinstall
16 realinstall: checkver libinstall
17 clean cleandir distclean: cleanlib
18
19 .if exists(${SHLIB_VERSION_FILE})
20 SHLIB_MAJOR != . ${SHLIB_VERSION_FILE} ; echo $$major
21 SHLIB_MINOR != . ${SHLIB_VERSION_FILE} ; echo $$minor
22
23 # Check for higher installed library versions.
24 .if !defined(NOCHECKVER) && !defined(NOCHECKVER_${LIB}) && \
25 exists(${BSDSRCDIR}/lib/checkver)
26 checkver:
27 @(cd ${.CURDIR} && \
28 ${BSDSRCDIR}/lib/checkver -v ${SHLIB_VERSION_FILE} \
29 -d ${DESTDIR}${LIBDIR} ${LIB})
30 .else
31 checkver:
32 .endif
33 print-shlib-major:
34 @echo ${SHLIB_MAJOR}
35
36 print-shlib-minor:
37 @echo ${SHLIB_MINOR}
38 .else
39 checkver:
40
41 print-shlib-major:
42 @false
43
44 print-shlib-minor:
45 @false
46 .endif
47
48 # add additional suffixes not exported.
49 # .po is used for profiling object files.
50 # .so is used for PIC object files.
51 .SUFFIXES: .out .a .ln .so .po .o .s .S .c .cc .C .m .F .f .r .y .l .cl .p .h
52 .SUFFIXES: .sh .m4 .m
53
54
55 # Set PICFLAGS to cc flags for producing position-independent code,
56 # if not already set. Includes -DPIC, if required.
57
58 # Data-driven table using make variables to control how shared libraries
59 # are built for different platforms and object formats.
60 # OBJECT_FMT: currently either "ELF" or "a.out", from <bsd.own.mk>
61 # SHLIB_SOVERSION: version number to be compiled into a shared library
62 # via -soname. Usualy ${SHLIB_MAJOR} on ELF.
63 # NetBSD/pmax used to use ${SHLIB_MAJOR}.{SHLIB-MINOR}.
64 # SHLIB_SHFLAGS: Flags to tell ${LD} to emit shared library.
65 # with ELF, also set shared-lib version for ld.so.
66 # SHLIB_LDSTARTFILE: support .o file, call C++ file-level constructors
67 # SHLIB_LDENDFILE: support .o file, call C++ file-level destructors
68 # CPPICFLAGS: flags for ${CPP} to preprocess .[sS] files for ${AS}
69 # CPICFLAGS: flags for ${CC} to compile .[cC] files to .so objects.
70 # CAPICFLAGS flags for {$CC} to compiling .[Ss] files
71 # (usually just ${CPPPICFLAGS} ${CPICFLAGS})
72 # APICFLAGS: flags for ${AS} to assemble .[sS] to .so objects.
73
74 .if ${MACHINE_ARCH} == "alpha"
75 # Alpha-specific shared library flags
76 CPICFLAGS ?= -fPIC -DPIC
77 CPPPICFLAGS?= -DPIC
78 CAPICFLAGS?= ${CPPPICFLAGS} ${CPICFLAGS}
79 APICFLAGS ?=
80 .elif ${MACHINE_ARCH} == "mipsel" || ${MACHINE_ARCH} == "mipseb"
81 # mips-specific shared library flags
82
83 # On mips, all libs are compiled with ABIcalls, not just sharedlibs.
84 MKPICLIB= no
85
86 # so turn shlib PIC flags on for ${AS}.
87 AINC+=-DABICALLS
88 AFLAGS+= -fPIC
89 AS+= -KPIC
90
91 .elif ${MACHINE_ARCH} == "sparc" && ${OBJECT_FMT} == "ELF"
92
93 CPICFLAGS ?= -fPIC -DPIC
94 CPPPICFLAGS?= -DPIC
95 CAPICFLAGS?= ${CPPPICFLAGS} ${CPICFLAGS}
96 APICFLAGS ?= -KPIC
97
98 .elif ${MACHINE_ARCH} == "sparc64" && ${OBJECT_FMT} == "ELF"
99
100 CPICFLAGS ?= -fPIC -DPIC
101 CPPPICFLAGS?= -DPIC
102 CAPICFLAGS?= ${CPPPICFLAGS} ${CPICFLAGS}
103 APICFLAGS ?= -KPIC
104
105 .else
106
107 # Platform-independent flags for NetBSD a.out shared libraries (and PowerPC)
108 SHLIB_LDSTARTFILE=
109 SHLIB_LDENDFILE=
110 SHLIB_SHFLAGS=
111 SHLIB_SOVERSION=${SHLIB_MAJOR}.${SHLIB_MINOR}
112 CPICFLAGS?= -fPIC -DPIC
113 CPPPICFLAGS?= -DPIC
114 CAPICFLAGS?= ${CPPPICFLAGS} ${CPICFLAGS}
115 APICFLAGS?= -k
116
117 .endif
118
119 MKPICLIB?= yes
120
121 # Platform-independent linker flags for ELF shared libraries
122 .if ${OBJECT_FMT} == "ELF"
123 SHLIB_SOVERSION=${SHLIB_MAJOR}
124 SHLIB_SHFLAGS=-soname lib${LIB}.so.${SHLIB_SOVERSION}
125 SHLIB_LDSTARTFILE= ${DESTDIR}/usr/lib/crtbeginS.o
126 SHLIB_LDENDFILE= ${DESTDIR}/usr/lib/crtendS.o
127 .endif
128
129 CFLAGS+= ${COPTS}
130
131 .c.o:
132 .if defined(COPTS) && !empty(COPTS:M*-g*)
133 ${COMPILE.c} ${.IMPSRC}
134 .else
135 @echo ${COMPILE.c:Q} ${.IMPSRC}
136 @${COMPILE.c} ${.IMPSRC} -o ${.TARGET}.o
137 @${LD} -x -r ${.TARGET}.o -o ${.TARGET}
138 @rm -f ${.TARGET}.o
139 .endif
140
141 .c.po:
142 .if defined(COPTS) && !empty(COPTS:M*-g*)
143 ${COMPILE.c} -pg ${.IMPSRC} -o ${.TARGET}
144 .else
145 @echo ${COMPILE.c:Q} -pg ${.IMPSRC} -o ${.TARGET}
146 @${COMPILE.c} -pg ${.IMPSRC} -o ${.TARGET}.o
147 @${LD} -X -r ${.TARGET}.o -o ${.TARGET}
148 @rm -f ${.TARGET}.o
149 .endif
150
151 .c.so:
152 .if defined(COPTS) && !empty(COPTS:M*-g*)
153 ${COMPILE.c} ${CPICFLAGS} ${.IMPSRC} -o ${.TARGET}
154 .else
155 @echo ${COMPILE.c:Q} ${CPICFLAGS} ${.IMPSRC} -o ${.TARGET}
156 @${COMPILE.c} ${CPICFLAGS} ${.IMPSRC} -o ${.TARGET}.o
157 @${LD} -x -r ${.TARGET}.o -o ${.TARGET}
158 @rm -f ${.TARGET}.o
159 .endif
160
161 .c.ln:
162 ${LINT} ${LINTFLAGS} ${CPPFLAGS:M-[IDU]*} -i ${.IMPSRC}
163
164 .cc.o .C.o:
165 .if defined(COPTS) && !empty(COPTS:M*-g*)
166 ${COMPILE.cc} ${.IMPSRC}
167 .else
168 @echo ${COMPILE.cc:Q} ${.IMPSRC}
169 @${COMPILE.cc} ${.IMPSRC} -o ${.TARGET}.o
170 @${LD} -x -r ${.TARGET}.o -o ${.TARGET}
171 @rm -f ${.TARGET}.o
172 .endif
173
174 .cc.po .C.po:
175 .if defined(COPTS) && !empty(COPTS:M*-g*)
176 ${COMPILE.cc} -pg ${.IMPSRC} -o ${.TARGET}
177 .else
178 @echo ${COMPILE.cc:Q} -pg ${.IMPSRC} -o ${.TARGET}
179 @${COMPILE.cc} -pg ${.IMPSRC} -o ${.TARGET}.o
180 @${LD} -X -r ${.TARGET}.o -o ${.TARGET}
181 @rm -f ${.TARGET}.o
182 .endif
183
184 .cc.so .C.so:
185 .if defined(COPTS) && !empty(COPTS:M*-g*)
186 ${COMPILE.cc} ${CPICFLAGS} ${.IMPSRC} -o ${.TARGET}
187 .else
188 @echo ${COMPILE.cc:Q} ${CPICFLAGS} ${.IMPSRC} -o ${.TARGET}
189 @${COMPILE.cc} ${CPICFLAGS} ${.IMPSRC} -o ${.TARGET}.o
190 @${LD} -x -r ${.TARGET}.o -o ${.TARGET}
191 @rm -f ${.TARGET}.o
192 .endif
193
194 .m.o:
195 .if defined(OBJCFLAGS) && !empty(OBJCFLAGS:M*-g*)
196 ${COMPILE.m} ${.IMPSRC}
197 .else
198 @echo ${COMPILE.m:Q} ${.IMPSRC}
199 @${COMPILE.m} ${.IMPSRC} -o ${.TARGET}.o
200 @${LD} -x -r ${.TARGET}.o -o ${.TARGET}
201 @rm -f ${.TARGET}.o
202 .endif
203
204 .m.po:
205 .if defined(OBJCFLAGS) && !empty(OBJCFLAGS:M*-g*)
206 ${COMPILE.m} -pg ${.IMPSRC} -o ${.TARGET}
207 .else
208 @echo ${COMPILE.m:Q} -pg ${.IMPSRC} -o ${.TARGET}
209 @${COMPILE.m} -pg ${.IMPSRC} -o ${.TARGET}.o
210 @${LD} -X -r ${.TARGET}.o -o ${.TARGET}
211 @rm -f ${.TARGET}.o
212 .endif
213
214 .m.so:
215 .if defined(OBJCFLAGS) && !empty(OBJCFLAGS:M*-g*)
216 ${COMPILE.m} ${CPICFLAGS} ${.IMPSRC} -o ${.TARGET}
217 .else
218 @echo ${COMPILE.m:Q} ${CPICFLAGS} ${.IMPSRC} -o ${.TARGET}
219 @${COMPILE.m} ${CPICFLAGS} ${.IMPSRC} -o ${.TARGET}.o
220 @${LD} -x -r ${.TARGET}.o -o ${.TARGET}
221 @rm -f ${.TARGET}.o
222 .endif
223
224 .S.o .s.o:
225 @echo ${COMPILE.S:Q} ${CFLAGS:M-[ID]*} ${AINC} ${.IMPSRC}
226 @${COMPILE.S} ${CFLAGS:M-[ID]*} ${AINC} ${.IMPSRC} -o ${.TARGET}.o
227 @${LD} -x -r ${.TARGET}.o -o ${.TARGET}
228 @rm -f ${.TARGET}.o
229
230 .S.po .s.po:
231 @echo ${COMPILE.S:Q} -DGPROF -DPROF ${CFLAGS:M-[ID]*} ${AINC} ${.IMPSRC} -o ${.TARGET}
232 @${COMPILE.S} -DGPROF -DPROF ${CFLAGS:M-[ID]*} ${AINC} ${.IMPSRC} -o ${.TARGET}.o
233 @${LD} -X -r ${.TARGET}.o -o ${.TARGET}
234 @rm -f ${.TARGET}.o
235
236 .S.so .s.so:
237 @echo ${COMPILE.S:Q} ${CAPICFLAGS} ${CFLAGS:M-[ID]*} ${AINC} ${.IMPSRC} -o ${.TARGET}
238 @${COMPILE.S} ${CAPICFLAGS} ${CFLAGS:M-[ID]*} ${AINC} ${.IMPSRC} -o ${.TARGET}.o
239 @${LD} -x -r ${.TARGET}.o -o ${.TARGET}
240 @rm -f ${.TARGET}.o
241
242 .if ${MKPIC} == "no" || (defined(LDSTATIC) && ${LDSTATIC} != "") \
243 || ${MKLINKLIB} != "no"
244 _LIBS=lib${LIB}.a
245 .else
246 _LIBS=
247 .endif
248
249 OBJS+=${SRCS:N*.h:N*.sh:R:S/$/.o/g}
250
251 .if ${MKPROFILE} != "no"
252 _LIBS+=lib${LIB}_p.a
253 POBJS+=${OBJS:.o=.po}
254 .endif
255
256 .if ${MKPIC} != "no"
257 .if ${MKPICLIB} == "no"
258 SOLIB=lib${LIB}.a
259 .else
260 SOLIB=lib${LIB}_pic.a
261 _LIBS+=${SOLIB}
262 SOBJS+=${OBJS:.o=.so}
263 .endif
264 .if defined(SHLIB_MAJOR) && defined(SHLIB_MINOR)
265 _LIBS+=lib${LIB}.so.${SHLIB_MAJOR}.${SHLIB_MINOR}
266 .endif
267 .endif
268
269 .if ${MKLINT} != "no" && ${MKLINKLIB} != "no"
270 _LIBS+=llib-l${LIB}.ln
271 LOBJS+=${LSRCS:.c=.ln} ${SRCS:M*.c:.c=.ln}
272 .endif
273
274 .if ${MKPIC} == "no" || (defined(LDSTATIC) && ${LDSTATIC} != "") \
275 || ${MKLINKLIB} != "no"
276 ALLOBJS=${OBJS} ${POBJS} ${SOBJS} ${LOBJS}
277 .else
278 ALLOBJS=${POBJS} ${SOBJS} ${LOBJS}
279 .endif
280 .NOPATH: ${ALLOBJS} ${_LIBS}
281
282 realall: ${SRCS} ${ALLOBJS:O} ${_LIBS}
283
284 __archivebuild: .USE
285 @rm -f ${.TARGET}
286 @${AR} cq ${.TARGET} `NM=${NM} ${LORDER} ${.ALLSRC:M*o} | ${TSORT}`
287 ${RANLIB} ${.TARGET}
288
289 __archiveinstall: .USE
290 ${INSTALL} ${RENAME} ${PRESERVE} ${COPY} ${INSTPRIV} -o ${LIBOWN} \
291 -g ${LIBGRP} -m 600 ${.ALLSRC} ${.TARGET}
292 ${RANLIB} -t ${.TARGET}
293 chmod ${LIBMODE} ${.TARGET}
294
295 DPSRCS+= ${SRCS:M*.l:.l=.c} ${SRCS:M*.y:.y=.c}
296 CLEANFILES+= ${DPSRCS}
297 .if defined(YHEADER)
298 CLEANFILES+= ${SRCS:M*.y:.y=.h}
299 .endif
300
301 lib${LIB}.a:: ${OBJS} __archivebuild
302 @echo building standard ${LIB} library
303
304 lib${LIB}_p.a:: ${POBJS} __archivebuild
305 @echo building profiled ${LIB} library
306
307 lib${LIB}_pic.a:: ${SOBJS} __archivebuild
308 @echo building shared object ${LIB} library
309
310 lib${LIB}.so.${SHLIB_MAJOR}.${SHLIB_MINOR}: ${SOLIB} ${DPADD} \
311 ${SHLIB_LDSTARTFILE} ${SHLIB_LDENDFILE}
312 @echo building shared ${LIB} library \(version ${SHLIB_MAJOR}.${SHLIB_MINOR}\)
313 @rm -f lib${LIB}.so.${SHLIB_MAJOR}.${SHLIB_MINOR}
314 .if defined(DESTDIR)
315 $(LD) -nostdlib -x -shared ${SHLIB_SHFLAGS} -o ${.TARGET} \
316 ${SHLIB_LDSTARTFILE} \
317 --whole-archive ${SOLIB} \
318 --no-whole-archive ${LDADD} \
319 -L${DESTDIR}${LIBDIR} -R${LIBDIR} \
320 ${SHLIB_LDENDFILE}
321 .else
322 $(LD) -x -shared ${SHLIB_SHFLAGS} -o ${.TARGET} \
323 ${SHLIB_LDSTARTFILE} \
324 --whole-archive ${SOLIB} --no-whole-archive ${LDADD} \
325 ${SHLIB_LDENDFILE}
326 .endif
327 .if ${OBJECT_FMT} == "ELF"
328 rm -f lib${LIB}.so.${SHLIB_MAJOR}
329 ln -s lib${LIB}.so.${SHLIB_MAJOR}.${SHLIB_MINOR} \
330 lib${LIB}.so.${SHLIB_MAJOR}
331 rm -f lib${LIB}.so
332 ln -s lib${LIB}.so.${SHLIB_MAJOR}.${SHLIB_MINOR} \
333 lib${LIB}.so
334 .endif
335
336 LLIBS?= -lc
337 llib-l${LIB}.ln: ${LOBJS}
338 @echo building llib-l${LIB}.ln
339 @rm -f llib-l${LIB}.ln
340 @${LINT} -C${LIB} ${.ALLSRC} ${LLIBS}
341
342 cleanlib:
343 rm -f a.out [Ee]rrs mklog core *.core ${CLEANFILES}
344 rm -f lib${LIB}.a ${OBJS}
345 rm -f lib${LIB}_p.a ${POBJS}
346 rm -f lib${LIB}_pic.a lib${LIB}.so.* lib${LIB}.so ${SOBJS}
347 rm -f llib-l${LIB}.ln ${LOBJS}
348
349 .if defined(SRCS)
350 afterdepend: .depend
351 @(TMP=/tmp/_depend$$$$; \
352 sed -e 's/^\([^\.]*\).o[ ]*:/\1.o \1.po \1.so \1.ln:/' \
353 < .depend > $$TMP; \
354 mv $$TMP .depend)
355 .endif
356
357 .if !target(libinstall)
358 # Make sure it gets defined, in case MKPIC==no && MKLINKLIB==no
359 libinstall::
360
361 .if ${MKLINKLIB} != "no"
362 libinstall:: ${DESTDIR}${LIBDIR}/lib${LIB}.a
363 .PRECIOUS: ${DESTDIR}${LIBDIR}/lib${LIB}.a
364 .if !defined(UPDATE)
365 .PHONY: ${DESTDIR}${LIBDIR}/lib${LIB}.a
366 .endif
367
368 .if !defined(BUILD) && !make(all) && !make(lib${LIB}.a)
369 ${DESTDIR}${LIBDIR}/lib${LIB}.a: .MADE
370 .endif
371 ${DESTDIR}${LIBDIR}/lib${LIB}.a: lib${LIB}.a __archiveinstall
372 .endif
373
374 .if ${MKPROFILE} != "no"
375 libinstall:: ${DESTDIR}${LIBDIR}/lib${LIB}_p.a
376 .PRECIOUS: ${DESTDIR}${LIBDIR}/lib${LIB}_p.a
377 .if !defined(UPDATE)
378 .PHONY: ${DESTDIR}${LIBDIR}/lib${LIB}_p.a
379 .endif
380
381 .if !defined(BUILD) && !make(all) && !make(lib${LIB}_p.a)
382 ${DESTDIR}${LIBDIR}/lib${LIB}_p.a: .MADE
383 .endif
384 ${DESTDIR}${LIBDIR}/lib${LIB}_p.a: lib${LIB}_p.a __archiveinstall
385 .endif
386
387 .if ${MKPIC} != "no" && ${MKPICINSTALL} != "no"
388 libinstall:: ${DESTDIR}${LIBDIR}/lib${LIB}_pic.a
389 .PRECIOUS: ${DESTDIR}${LIBDIR}/lib${LIB}_pic.a
390 .if !defined(UPDATE)
391 .PHONY: ${DESTDIR}${LIBDIR}/lib${LIB}_pic.a
392 .endif
393
394 .if !defined(BUILD) && !make(all) && !make(lib${LIB}_pic.a)
395 ${DESTDIR}${LIBDIR}/lib${LIB}_pic.a: .MADE
396 .endif
397 .if ${MKPICLIB} == "no"
398 ${DESTDIR}${LIBDIR}/lib${LIB}_pic.a:
399 rm -f ${DESTDIR}${LIBDIR}/lib${LIB}_pic.a
400 ln -s lib${LIB}.a ${DESTDIR}${LIBDIR}/lib${LIB}_pic.a
401 .else
402 ${DESTDIR}${LIBDIR}/lib${LIB}_pic.a: lib${LIB}_pic.a __archiveinstall
403 .endif
404 .endif
405
406 .if ${MKPIC} != "no" && defined(SHLIB_MAJOR) && defined(SHLIB_MINOR)
407 libinstall:: ${DESTDIR}${LIBDIR}/lib${LIB}.so.${SHLIB_MAJOR}.${SHLIB_MINOR}
408 .PRECIOUS: ${DESTDIR}${LIBDIR}/lib${LIB}.so.${SHLIB_MAJOR}.${SHLIB_MINOR}
409 .if !defined(UPDATE)
410 .PHONY: ${DESTDIR}${LIBDIR}/lib${LIB}.so.${SHLIB_MAJOR}.${SHLIB_MINOR}
411 .endif
412
413 .if !defined(BUILD) && !make(all) && !make(lib${LIB}.so.${SHLIB_MAJOR}.${SHLIB_MINOR})
414 ${DESTDIR}${LIBDIR}/lib${LIB}.so.${SHLIB_MAJOR}.${SHLIB_MINOR}: .MADE
415 .endif
416 ${DESTDIR}${LIBDIR}/lib${LIB}.so.${SHLIB_MAJOR}.${SHLIB_MINOR}: lib${LIB}.so.${SHLIB_MAJOR}.${SHLIB_MINOR}
417 ${INSTALL} ${RENAME} ${PRESERVE} ${COPY} ${INSTPRIV} -o ${LIBOWN} \
418 -g ${LIBGRP} -m ${LIBMODE} ${.ALLSRC} ${.TARGET}
419 .if ${OBJECT_FMT} == "a.out" && !defined(DESTDIR)
420 /sbin/ldconfig -m ${LIBDIR}
421 .endif
422 .if ${OBJECT_FMT} == "ELF"
423 rm -f ${DESTDIR}${LIBDIR}/lib${LIB}.so.${SHLIB_MAJOR}
424 ln -s lib${LIB}.so.${SHLIB_MAJOR}.${SHLIB_MINOR} \
425 ${DESTDIR}${LIBDIR}/lib${LIB}.so.${SHLIB_MAJOR}
426 rm -f ${DESTDIR}${LIBDIR}/lib${LIB}.so
427 .if ${MKLINKLIB} != "no"
428 ln -s lib${LIB}.so.${SHLIB_MAJOR}.${SHLIB_MINOR} \
429 ${DESTDIR}${LIBDIR}/lib${LIB}.so
430 .endif
431 .endif
432 .endif
433
434 .if ${MKLINT} != "no" && ${MKLINKLIB} != "no"
435 libinstall:: ${DESTDIR}${LINTLIBDIR}/llib-l${LIB}.ln
436 .PRECIOUS: ${DESTDIR}${LINTLIBDIR}/llib-l${LIB}.ln
437 .if !defined(UPDATE)
438 .PHONY: ${DESTDIR}${LINTLIBDIR}/llib-l${LIB}.ln
439 .endif
440
441 .if !defined(BUILD) && !make(all) && !make(llib-l${LIB}.ln)
442 ${DESTDIR}${LINTLIBDIR}/llib-l${LIB}.ln: .MADE
443 .endif
444 ${DESTDIR}${LINTLIBDIR}/llib-l${LIB}.ln: llib-l${LIB}.ln
445 ${INSTALL} ${RENAME} ${PRESERVE} ${COPY} ${INSTPRIV} -o ${LIBOWN} \
446 -g ${LIBGRP} -m ${LIBMODE} ${.ALLSRC} ${DESTDIR}${LINTLIBDIR}
447 .endif
448 .endif
449
450 .include <bsd.man.mk>
451 .include <bsd.nls.mk>
452 .include <bsd.files.mk>
453 .include <bsd.inc.mk>
454 .include <bsd.links.mk>
455 .include <bsd.dep.mk>
456 .include <bsd.sys.mk>
457
458 # Make sure all of the standard targets are defined, even if they do nothing.
459 lint regress:
460