bsd.lib.mk revision 1.153 1 # $NetBSD: bsd.lib.mk,v 1.153 1999/06/07 01:37:00 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(${.CURDIR}/shlib_version)
19 SHLIB_MAJOR != . ${.CURDIR}/shlib_version ; echo $$major
20 SHLIB_MINOR != . ${.CURDIR}/shlib_version ; 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 -d ${DESTDIR}${LIBDIR} ${LIB})
28 .else
29 checkver:
30 .endif
31 .else
32 checkver:
33 .endif
34
35 # add additional suffixes not exported.
36 # .po is used for profiling object files.
37 # .so is used for PIC object files.
38 .SUFFIXES: .out .a .ln .so .po .o .s .S .c .cc .C .m .F .f .r .y .l .cl .p .h
39 .SUFFIXES: .sh .m4 .m
40
41
42 # Set PICFLAGS to cc flags for producing position-independent code,
43 # if not already set. Includes -DPIC, if required.
44
45 # Data-driven table using make variables to control how shared libraries
46 # are built for different platforms and object formats.
47 # OBJECT_FMT: currently either "ELF" or "a.out", from <bsd.own.mk>
48 # SHLIB_SOVERSION: version number to be compiled into a shared library
49 # via -soname. Usualy ${SHLIB_MAJOR} on ELF.
50 # NetBSD/pmax used to use ${SHLIB_MAJOR}.{SHLIB-MINOR}.
51 # SHLIB_SHFLAGS: Flags to tell ${LD} to emit shared library.
52 # with ELF, also set shared-lib version for ld.so.
53 # SHLIB_LDSTARTFILE: support .o file, call C++ file-level constructors
54 # SHLIB_LDENDFILE: support .o file, call C++ file-level destructors
55 # CPPICFLAGS: flags for ${CPP} to preprocess .[sS] files for ${AS}
56 # CPICFLAGS: flags for ${CC} to compile .[cC] files to .so objects.
57 # CAPICFLAGS flags for {$CC} to compiling .[Ss] files
58 # (usually just ${CPPPICFLAGS} ${CPICFLAGS})
59 # APICFLAGS: flags for ${AS} to assemble .[sS] to .so objects.
60
61 .if ${MACHINE_ARCH} == "alpha"
62 # Alpha-specific shared library flags
63 CPICFLAGS ?= -fpic -DPIC
64 CPPPICFLAGS?= -DPIC
65 CAPICFLAGS?= ${CPPPICFLAGS} ${CPICFLAGS}
66 APICFLAGS ?=
67 .elif ${MACHINE_ARCH} == "mipsel" || ${MACHINE_ARCH} == "mipseb"
68 # mips-specific shared library flags
69
70 # On mips, all libs need to be compiled with ABIcalls, not just sharedlibs.
71 CPICFLAGS?=
72 APICFLAGS?=
73 #CPICFLAGS?= -fpic -DPIC
74 #APICFLAGS?= -DPIC
75
76 # so turn shlib PIC flags on for ${CPP}, ${CC}, and ${AS} as follows:
77 AINC+=-DPIC -DABICALLS
78 COPTS+= -fPIC ${AINC}
79 AFLAGS+= -fPIC
80 AS+= -KPIC
81
82 .elif ${MACHINE_ARCH} == "sparc" && ${OBJECT_FMT} == "ELF"
83
84 CPICFLAGS ?= -fpic -DPIC
85 CPPPICFLAGS?= -DPIC
86 CAPICFLAGS?= ${CPPPICFLAGS} ${CPICFLAGS}
87 APICFLAGS ?= -KPIC
88
89 .else
90
91 # Platform-independent flags for NetBSD a.out shared libraries (and PowerPC)
92 SHLIB_LDSTARTFILE=
93 SHLIB_LDENDFILE=
94 SHLIB_SHFLAGS=
95 SHLIB_SOVERSION=${SHLIB_MAJOR}.${SHLIB_MINOR}
96 CPICFLAGS?= -fpic -DPIC
97 CPPPICFLAGS?= -DPIC
98 CAPICFLAGS?= ${CPPPICFLAGS} ${CPICFLAGS}
99 APICFLAGS?= -k
100
101 .endif
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 .if ${MKPROFILE} != "no"
232 _LIBS+=lib${LIB}_p.a
233 .endif
234
235 .if ${MKPIC} != "no"
236 _LIBS+=lib${LIB}_pic.a
237 .if defined(SHLIB_MAJOR) && defined(SHLIB_MINOR)
238 _LIBS+=lib${LIB}.so.${SHLIB_MAJOR}.${SHLIB_MINOR}
239 .endif
240 .endif
241
242 .if ${MKLINT} != "no" && ${MKLINKLIB} != "no"
243 _LIBS+=llib-l${LIB}.ln
244 .endif
245
246 all: ${SRCS} ${_LIBS}
247
248 __archivebuild: .USE
249 @rm -f ${.TARGET}
250 @${AR} cq ${.TARGET} `NM=${NM} ${LORDER} ${.ALLSRC:M*o} | ${TSORT}`
251 ${RANLIB} ${.TARGET}
252
253 __archiveinstall: .USE
254 ${INSTALL} ${RENAME} ${PRESERVE} ${COPY} -o ${LIBOWN} -g ${LIBGRP} \
255 -m 600 ${.ALLSRC} ${.TARGET}
256 ${RANLIB} -t ${.TARGET}
257 chmod ${LIBMODE} ${.TARGET}
258
259 DPSRCS+= ${SRCS:M*.l:.l=.c} ${SRCS:M*.y:.y=.c}
260 CLEANFILES+= ${DPSRCS}
261 .if defined(YHEADER)
262 CLEANFILES+= ${SRCS:M*.y:.y=.h}
263 .endif
264
265 OBJS+= ${SRCS:N*.h:N*.sh:R:S/$/.o/g}
266 lib${LIB}.a:: ${OBJS} __archivebuild
267 @echo building standard ${LIB} library
268
269 POBJS+= ${OBJS:.o=.po}
270 lib${LIB}_p.a:: ${POBJS} __archivebuild
271 @echo building profiled ${LIB} library
272
273 SOBJS+= ${OBJS:.o=.so}
274 lib${LIB}_pic.a:: ${SOBJS} __archivebuild
275 @echo building shared object ${LIB} library
276
277 lib${LIB}.so.${SHLIB_MAJOR}.${SHLIB_MINOR}: lib${LIB}_pic.a ${DPADD} \
278 ${SHLIB_LDSTARTFILE} ${SHLIB_LDENDFILE}
279 @echo building shared ${LIB} library \(version ${SHLIB_MAJOR}.${SHLIB_MINOR}\)
280 @rm -f lib${LIB}.so.${SHLIB_MAJOR}.${SHLIB_MINOR}
281 .if defined(DESTDIR)
282 $(LD) -x -shared ${SHLIB_SHFLAGS} -o ${.TARGET} \
283 ${SHLIB_LDSTARTFILE} \
284 --whole-archive lib${LIB}_pic.a \
285 -nostdlib -L${DESTDIR}${LIBDIR} -R${LIBDIR} \
286 --no-whole-archive ${LDADD} \
287 ${SHLIB_LDENDFILE}
288 .else
289 $(LD) -x -shared ${SHLIB_SHFLAGS} -o ${.TARGET} \
290 ${SHLIB_LDSTARTFILE} \
291 --whole-archive lib${LIB}_pic.a --no-whole-archive ${LDADD} \
292 ${SHLIB_LDENDFILE}
293 .endif
294 .if ${OBJECT_FMT} == "ELF"
295 rm -f lib${LIB}.so.${SHLIB_MAJOR}
296 ln -s lib${LIB}.so.${SHLIB_MAJOR}.${SHLIB_MINOR} \
297 lib${LIB}.so.${SHLIB_MAJOR}
298 rm -f lib${LIB}.so
299 ln -s lib${LIB}.so.${SHLIB_MAJOR}.${SHLIB_MINOR} \
300 lib${LIB}.so
301 .endif
302
303 LOBJS+= ${LSRCS:.c=.ln} ${SRCS:M*.c:.c=.ln}
304 LLIBS?= -lc
305 llib-l${LIB}.ln: ${LOBJS}
306 @echo building llib-l${LIB}.ln
307 @rm -f llib-l${LIB}.ln
308 @${LINT} -C${LIB} ${.ALLSRC} ${LLIBS}
309
310 cleanlib:
311 rm -f a.out [Ee]rrs mklog core *.core ${CLEANFILES}
312 rm -f lib${LIB}.a ${OBJS}
313 rm -f lib${LIB}_p.a ${POBJS}
314 rm -f lib${LIB}_pic.a lib${LIB}.so.* lib${LIB}.so ${SOBJS}
315 rm -f llib-l${LIB}.ln ${LOBJS}
316
317 .if defined(SRCS)
318 afterdepend: .depend
319 @(TMP=/tmp/_depend$$$$; \
320 sed -e 's/^\([^\.]*\).o[ ]*:/\1.o \1.po \1.so \1.ln:/' \
321 < .depend > $$TMP; \
322 mv $$TMP .depend)
323 .endif
324
325 .if !target(libinstall)
326 # Make sure it gets defined, in case MKPIC==no && MKLINKLIB==no
327 libinstall::
328
329 .if ${MKLINKLIB} != "no"
330 libinstall:: ${DESTDIR}${LIBDIR}/lib${LIB}.a
331 .if !defined(UPDATE)
332 .PHONY: ${DESTDIR}${LIBDIR}/lib${LIB}.a
333 .endif
334 .if !defined(BUILD)
335 ${DESTDIR}${LIBDIR}/lib${LIB}.a: .MADE
336 .endif
337
338 .PRECIOUS: ${DESTDIR}${LIBDIR}/lib${LIB}.a
339 ${DESTDIR}${LIBDIR}/lib${LIB}.a: lib${LIB}.a __archiveinstall
340 .endif
341
342 .if ${MKPROFILE} != "no"
343 libinstall:: ${DESTDIR}${LIBDIR}/lib${LIB}_p.a
344 .if !defined(UPDATE)
345 .PHONY: ${DESTDIR}${LIBDIR}/lib${LIB}_p.a
346 .endif
347 .if !defined(BUILD)
348 ${DESTDIR}${LIBDIR}/lib${LIB}_p.a: .MADE
349 .endif
350
351 .PRECIOUS: ${DESTDIR}${LIBDIR}/lib${LIB}_p.a
352 ${DESTDIR}${LIBDIR}/lib${LIB}_p.a: lib${LIB}_p.a __archiveinstall
353 .endif
354
355 .if ${MKPIC} != "no" && ${MKPICINSTALL} != "no"
356 libinstall:: ${DESTDIR}${LIBDIR}/lib${LIB}_pic.a
357 .if !defined(UPDATE)
358 .PHONY: ${DESTDIR}${LIBDIR}/lib${LIB}_pic.a
359 .endif
360 .if !defined(BUILD)
361 ${DESTDIR}${LIBDIR}/lib${LIB}_pic.a: .MADE
362 .endif
363
364 .PRECIOUS: ${DESTDIR}${LIBDIR}/lib${LIB}_pic.a
365 ${DESTDIR}${LIBDIR}/lib${LIB}_pic.a: lib${LIB}_pic.a __archiveinstall
366 .endif
367
368 .if ${MKPIC} != "no" && defined(SHLIB_MAJOR) && defined(SHLIB_MINOR)
369 libinstall:: ${DESTDIR}${LIBDIR}/lib${LIB}.so.${SHLIB_MAJOR}.${SHLIB_MINOR}
370 .if !defined(UPDATE)
371 .PHONY: ${DESTDIR}${LIBDIR}/lib${LIB}.so.${SHLIB_MAJOR}.${SHLIB_MINOR}
372 .endif
373 .if !defined(BUILD)
374 ${DESTDIR}${LIBDIR}/lib${LIB}.so.${SHLIB_MAJOR}.${SHLIB_MINOR}: .MADE
375 .endif
376
377 .PRECIOUS: ${DESTDIR}${LIBDIR}/lib${LIB}.so.${SHLIB_MAJOR}.${SHLIB_MINOR}
378 ${DESTDIR}${LIBDIR}/lib${LIB}.so.${SHLIB_MAJOR}.${SHLIB_MINOR}: lib${LIB}.so.${SHLIB_MAJOR}.${SHLIB_MINOR}
379 ${INSTALL} ${RENAME} ${PRESERVE} ${COPY} -o ${LIBOWN} -g ${LIBGRP} \
380 -m ${LIBMODE} ${.ALLSRC} ${.TARGET}
381 .if ${OBJECT_FMT} == "a.out" && !defined(DESTDIR)
382 /sbin/ldconfig -m ${LIBDIR}
383 .endif
384 .if ${OBJECT_FMT} == "ELF"
385 rm -f ${DESTDIR}${LIBDIR}/lib${LIB}.so.${SHLIB_MAJOR}
386 ln -s lib${LIB}.so.${SHLIB_MAJOR}.${SHLIB_MINOR} \
387 ${DESTDIR}${LIBDIR}/lib${LIB}.so.${SHLIB_MAJOR}
388 rm -f ${DESTDIR}${LIBDIR}/lib${LIB}.so
389 .if ${MKLINKLIB} != "no"
390 ln -s lib${LIB}.so.${SHLIB_MAJOR}.${SHLIB_MINOR} \
391 ${DESTDIR}${LIBDIR}/lib${LIB}.so
392 .endif
393 .endif
394 .endif
395
396 .if ${MKLINT} != "no" && ${MKLINKLIB} != "no"
397 libinstall:: ${DESTDIR}${LINTLIBDIR}/llib-l${LIB}.ln
398 .if !defined(UPDATE)
399 .PHONY: ${DESTDIR}${LINTLIBDIR}/llib-l${LIB}.ln
400 .endif
401 .if !defined(BUILD)
402 ${DESTDIR}${LINTLIBDIR}/llib-l${LIB}.ln: .MADE
403 .endif
404
405 .PRECIOUS: ${DESTDIR}${LINTLIBDIR}/llib-l${LIB}.ln
406 ${DESTDIR}${LINTLIBDIR}/llib-l${LIB}.ln: llib-l${LIB}.ln
407 ${INSTALL} ${RENAME} ${PRESERVE} ${COPY} -o ${LIBOWN} -g ${LIBGRP} \
408 -m ${LIBMODE} ${.ALLSRC} ${DESTDIR}${LINTLIBDIR}
409 .endif
410 .endif
411
412 .include <bsd.man.mk>
413 .include <bsd.nls.mk>
414 .include <bsd.files.mk>
415 .include <bsd.inc.mk>
416 .include <bsd.links.mk>
417 .include <bsd.dep.mk>
418 .include <bsd.sys.mk>
419
420 # Make sure all of the standard targets are defined, even if they do nothing.
421 lint regress:
422