bsd.lib.mk revision 1.150 1 # $NetBSD: bsd.lib.mk,v 1.150 1999/02/14 19:12:09 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} == "mips"
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 @echo ${COMPILE.c:Q} ${.IMPSRC}
115 @${COMPILE.c} ${.IMPSRC} -o ${.TARGET}.o
116 @${LD} -x -r ${.TARGET}.o -o ${.TARGET}
117 @rm -f ${.TARGET}.o
118
119 .c.po:
120 @echo ${COMPILE.c:Q} -pg ${.IMPSRC} -o ${.TARGET}
121 @${COMPILE.c} -pg ${.IMPSRC} -o ${.TARGET}.o
122 @${LD} -X -r ${.TARGET}.o -o ${.TARGET}
123 @rm -f ${.TARGET}.o
124
125 .c.so:
126 @echo ${COMPILE.c:Q} ${CPICFLAGS} ${.IMPSRC} -o ${.TARGET}
127 @${COMPILE.c} ${CPICFLAGS} ${.IMPSRC} -o ${.TARGET}.o
128 @${LD} -x -r ${.TARGET}.o -o ${.TARGET}
129 @rm -f ${.TARGET}.o
130
131 .c.ln:
132 ${LINT} ${LINTFLAGS} ${CPPFLAGS:M-[IDU]*} -i ${.IMPSRC}
133
134 .cc.o .C.o:
135 @echo ${COMPILE.cc:Q} ${.IMPSRC}
136 @${COMPILE.cc} ${.IMPSRC} -o ${.TARGET}.o
137 @${LD} -x -r ${.TARGET}.o -o ${.TARGET}
138 @rm -f ${.TARGET}.o
139
140 .cc.po .C.po:
141 @echo ${COMPILE.cc:Q} -pg ${.IMPSRC} -o ${.TARGET}
142 @${COMPILE.cc} -pg ${.IMPSRC} -o ${.TARGET}.o
143 @${LD} -X -r ${.TARGET}.o -o ${.TARGET}
144 @rm -f ${.TARGET}.o
145
146 .cc.so .C.so:
147 @echo ${COMPILE.cc:Q} ${CPICFLAGS} ${.IMPSRC} -o ${.TARGET}
148 @${COMPILE.cc} ${CPICFLAGS} ${.IMPSRC} -o ${.TARGET}.o
149 @${LD} -x -r ${.TARGET}.o -o ${.TARGET}
150 @rm -f ${.TARGET}.o
151
152 .m.o:
153 @echo ${COMPILE.m:Q} ${.IMPSRC}
154 @${COMPILE.m} ${.IMPSRC} -o ${.TARGET}.o
155 @${LD} -x -r ${.TARGET}.o -o ${.TARGET}
156 @rm -f ${.TARGET}.o
157
158 .m.po:
159 @echo ${COMPILE.m:Q} -pg ${.IMPSRC} -o ${.TARGET}
160 @${COMPILE.m} -pg ${.IMPSRC} -o ${.TARGET}.o
161 @${LD} -X -r ${.TARGET}.o -o ${.TARGET}
162 @rm -f ${.TARGET}.o
163
164 .m.so:
165 @echo ${COMPILE.m:Q} ${CPICFLAGS} ${.IMPSRC} -o ${.TARGET}
166 @${COMPILE.m} ${CPICFLAGS} ${.IMPSRC} -o ${.TARGET}.o
167 @${LD} -x -r ${.TARGET}.o -o ${.TARGET}
168 @rm -f ${.TARGET}.o
169
170 .S.o .s.o:
171 @echo ${COMPILE.S:Q} ${CFLAGS:M-[ID]*} ${AINC} ${.IMPSRC}
172 @${COMPILE.S} ${CFLAGS:M-[ID]*} ${AINC} ${.IMPSRC} -o ${.TARGET}.o
173 @${LD} -x -r ${.TARGET}.o -o ${.TARGET}
174 @rm -f ${.TARGET}.o
175
176 .S.po .s.po:
177 @echo ${COMPILE.S:Q} -DGPROF -DPROF ${CFLAGS:M-[ID]*} ${AINC} ${.IMPSRC} -o ${.TARGET}
178 @${COMPILE.S} -DGPROF -DPROF ${CFLAGS:M-[ID]*} ${AINC} ${.IMPSRC} -o ${.TARGET}.o
179 @${LD} -X -r ${.TARGET}.o -o ${.TARGET}
180 @rm -f ${.TARGET}.o
181
182 .S.so .s.so:
183 @echo ${COMPILE.S:Q} ${CAPICFLAGS} ${CFLAGS:M-[ID]*} ${AINC} ${.IMPSRC} -o ${.TARGET}
184 @${COMPILE.S} ${CAPICFLAGS} ${CFLAGS:M-[ID]*} ${AINC} ${.IMPSRC} -o ${.TARGET}.o
185 @${LD} -x -r ${.TARGET}.o -o ${.TARGET}
186 @rm -f ${.TARGET}.o
187
188 .if ${MKPIC} == "no" || (defined(LDSTATIC) && ${LDSTATIC} != "") \
189 || ${MKLINKLIB} != "no"
190 _LIBS=lib${LIB}.a
191 .else
192 _LIBS=
193 .endif
194
195 .if ${MKPROFILE} != "no"
196 _LIBS+=lib${LIB}_p.a
197 .endif
198
199 .if ${MKPIC} != "no"
200 _LIBS+=lib${LIB}_pic.a
201 .if defined(SHLIB_MAJOR) && defined(SHLIB_MINOR)
202 _LIBS+=lib${LIB}.so.${SHLIB_MAJOR}.${SHLIB_MINOR}
203 .endif
204 .endif
205
206 .if ${MKLINT} != "no" && ${MKLINKLIB} != "no"
207 _LIBS+=llib-l${LIB}.ln
208 .endif
209
210 all: ${SRCS} ${_LIBS}
211
212 __archivebuild: .USE
213 @rm -f ${.TARGET}
214 @${AR} cq ${.TARGET} `NM=${NM} ${LORDER} ${.ALLSRC:M*o} | ${TSORT}`
215 ${RANLIB} ${.TARGET}
216
217 __archiveinstall: .USE
218 ${INSTALL} ${RENAME} ${PRESERVE} ${COPY} -o ${LIBOWN} -g ${LIBGRP} \
219 -m 600 ${.ALLSRC} ${.TARGET}
220 ${RANLIB} -t ${.TARGET}
221 chmod ${LIBMODE} ${.TARGET}
222
223 DPSRCS+= ${SRCS:M*.l:.l=.c} ${SRCS:M*.y:.y=.c}
224 CLEANFILES+= ${DPSRCS}
225 .if defined(YHEADER)
226 CLEANFILES+= ${SRCS:M*.y:.y=.h}
227 .endif
228
229 OBJS+= ${SRCS:N*.h:N*.sh:R:S/$/.o/g}
230 lib${LIB}.a:: ${OBJS} __archivebuild
231 @echo building standard ${LIB} library
232
233 POBJS+= ${OBJS:.o=.po}
234 lib${LIB}_p.a:: ${POBJS} __archivebuild
235 @echo building profiled ${LIB} library
236
237 SOBJS+= ${OBJS:.o=.so}
238 lib${LIB}_pic.a:: ${SOBJS} __archivebuild
239 @echo building shared object ${LIB} library
240
241 lib${LIB}.so.${SHLIB_MAJOR}.${SHLIB_MINOR}: lib${LIB}_pic.a ${DPADD} \
242 ${SHLIB_LDSTARTFILE} ${SHLIB_LDENDFILE}
243 @echo building shared ${LIB} library \(version ${SHLIB_MAJOR}.${SHLIB_MINOR}\)
244 @rm -f lib${LIB}.so.${SHLIB_MAJOR}.${SHLIB_MINOR}
245 $(LD) -x -shared ${SHLIB_SHFLAGS} -o ${.TARGET} \
246 ${SHLIB_LDSTARTFILE} \
247 --whole-archive lib${LIB}_pic.a --no-whole-archive ${LDADD} \
248 ${SHLIB_LDENDFILE}
249 .if ${OBJECT_FMT} == "ELF"
250 rm -f lib${LIB}.so.${SHLIB_MAJOR}
251 ln -s lib${LIB}.so.${SHLIB_MAJOR}.${SHLIB_MINOR} \
252 lib${LIB}.so.${SHLIB_MAJOR}
253 rm -f lib${LIB}.so
254 ln -s lib${LIB}.so.${SHLIB_MAJOR}.${SHLIB_MINOR} \
255 lib${LIB}.so
256 .endif
257
258 LOBJS+= ${LSRCS:.c=.ln} ${SRCS:M*.c:.c=.ln}
259 LLIBS?= -lc
260 llib-l${LIB}.ln: ${LOBJS}
261 @echo building llib-l${LIB}.ln
262 @rm -f llib-l${LIB}.ln
263 @${LINT} -C${LIB} ${.ALLSRC} ${LLIBS}
264
265 cleanlib:
266 rm -f a.out [Ee]rrs mklog core *.core ${CLEANFILES}
267 rm -f lib${LIB}.a ${OBJS}
268 rm -f lib${LIB}_p.a ${POBJS}
269 rm -f lib${LIB}_pic.a lib${LIB}.so.* lib${LIB}.so ${SOBJS}
270 rm -f llib-l${LIB}.ln ${LOBJS}
271
272 .if defined(SRCS)
273 afterdepend: .depend
274 @(TMP=/tmp/_depend$$$$; \
275 sed -e 's/^\([^\.]*\).o[ ]*:/\1.o \1.po \1.so \1.ln:/' \
276 < .depend > $$TMP; \
277 mv $$TMP .depend)
278 .endif
279
280 .if !target(libinstall)
281 # Make sure it gets defined, in case MKPIC==no && MKLINKLIB==no
282 libinstall::
283
284 .if ${MKLINKLIB} != "no"
285 libinstall:: ${DESTDIR}${LIBDIR}/lib${LIB}.a
286 .if !defined(UPDATE)
287 .PHONY: ${DESTDIR}${LIBDIR}/lib${LIB}.a
288 .endif
289 .if !defined(BUILD)
290 ${DESTDIR}${LIBDIR}/lib${LIB}.a: .MADE
291 .endif
292
293 .PRECIOUS: ${DESTDIR}${LIBDIR}/lib${LIB}.a
294 ${DESTDIR}${LIBDIR}/lib${LIB}.a: lib${LIB}.a __archiveinstall
295 .endif
296
297 .if ${MKPROFILE} != "no"
298 libinstall:: ${DESTDIR}${LIBDIR}/lib${LIB}_p.a
299 .if !defined(UPDATE)
300 .PHONY: ${DESTDIR}${LIBDIR}/lib${LIB}_p.a
301 .endif
302 .if !defined(BUILD)
303 ${DESTDIR}${LIBDIR}/lib${LIB}_p.a: .MADE
304 .endif
305
306 .PRECIOUS: ${DESTDIR}${LIBDIR}/lib${LIB}_p.a
307 ${DESTDIR}${LIBDIR}/lib${LIB}_p.a: lib${LIB}_p.a __archiveinstall
308 .endif
309
310 .if ${MKPIC} != "no" && ${MKPICINSTALL} != "no"
311 libinstall:: ${DESTDIR}${LIBDIR}/lib${LIB}_pic.a
312 .if !defined(UPDATE)
313 .PHONY: ${DESTDIR}${LIBDIR}/lib${LIB}_pic.a
314 .endif
315 .if !defined(BUILD)
316 ${DESTDIR}${LIBDIR}/lib${LIB}_pic.a: .MADE
317 .endif
318
319 .PRECIOUS: ${DESTDIR}${LIBDIR}/lib${LIB}_pic.a
320 ${DESTDIR}${LIBDIR}/lib${LIB}_pic.a: lib${LIB}_pic.a __archiveinstall
321 .endif
322
323 .if ${MKPIC} != "no" && defined(SHLIB_MAJOR) && defined(SHLIB_MINOR)
324 libinstall:: ${DESTDIR}${LIBDIR}/lib${LIB}.so.${SHLIB_MAJOR}.${SHLIB_MINOR}
325 .if !defined(UPDATE)
326 .PHONY: ${DESTDIR}${LIBDIR}/lib${LIB}.so.${SHLIB_MAJOR}.${SHLIB_MINOR}
327 .endif
328 .if !defined(BUILD)
329 ${DESTDIR}${LIBDIR}/lib${LIB}.so.${SHLIB_MAJOR}.${SHLIB_MINOR}: .MADE
330 .endif
331
332 .PRECIOUS: ${DESTDIR}${LIBDIR}/lib${LIB}.so.${SHLIB_MAJOR}.${SHLIB_MINOR}
333 ${DESTDIR}${LIBDIR}/lib${LIB}.so.${SHLIB_MAJOR}.${SHLIB_MINOR}: lib${LIB}.so.${SHLIB_MAJOR}.${SHLIB_MINOR}
334 ${INSTALL} ${RENAME} ${PRESERVE} ${COPY} -o ${LIBOWN} -g ${LIBGRP} \
335 -m ${LIBMODE} ${.ALLSRC} ${.TARGET}
336 .if ${OBJECT_FMT} == "a.out" && !defined(DESTDIR)
337 /sbin/ldconfig -m ${LIBDIR}
338 .endif
339 .if ${OBJECT_FMT} == "ELF"
340 rm -f ${DESTDIR}${LIBDIR}/lib${LIB}.so.${SHLIB_MAJOR}
341 ln -s lib${LIB}.so.${SHLIB_MAJOR}.${SHLIB_MINOR} \
342 ${DESTDIR}${LIBDIR}/lib${LIB}.so.${SHLIB_MAJOR}
343 rm -f ${DESTDIR}${LIBDIR}/lib${LIB}.so
344 .if ${MKLINKLIB} != "no"
345 ln -s lib${LIB}.so.${SHLIB_MAJOR}.${SHLIB_MINOR} \
346 ${DESTDIR}${LIBDIR}/lib${LIB}.so
347 .endif
348 .endif
349 .endif
350
351 .if ${MKLINT} != "no" && ${MKLINKLIB} != "no"
352 libinstall:: ${DESTDIR}${LINTLIBDIR}/llib-l${LIB}.ln
353 .if !defined(UPDATE)
354 .PHONY: ${DESTDIR}${LINTLIBDIR}/llib-l${LIB}.ln
355 .endif
356 .if !defined(BUILD)
357 ${DESTDIR}${LINTLIBDIR}/llib-l${LIB}.ln: .MADE
358 .endif
359
360 .PRECIOUS: ${DESTDIR}${LINTLIBDIR}/llib-l${LIB}.ln
361 ${DESTDIR}${LINTLIBDIR}/llib-l${LIB}.ln: llib-l${LIB}.ln
362 ${INSTALL} ${RENAME} ${PRESERVE} ${COPY} -o ${LIBOWN} -g ${LIBGRP} \
363 -m ${LIBMODE} ${.ALLSRC} ${DESTDIR}${LINTLIBDIR}
364 .endif
365 .endif
366
367 .include <bsd.man.mk>
368 .include <bsd.nls.mk>
369 .include <bsd.files.mk>
370 .include <bsd.inc.mk>
371 .include <bsd.links.mk>
372 .include <bsd.dep.mk>
373 .include <bsd.sys.mk>
374
375 # Make sure all of the standard targets are defined, even if they do nothing.
376 lint regress:
377