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