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