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