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