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