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