bsd.lib.mk revision 1.72 1 # $NetBSD: bsd.lib.mk,v 1.72 1996/10/13 20:39:36 cgd Exp $
2 # @(#)bsd.lib.mk 5.26 (Berkeley) 5/2/91
3
4 .if exists(${.CURDIR}/../Makefile.inc)
5 .include "${.CURDIR}/../Makefile.inc"
6 .endif
7
8 .include <bsd.own.mk> # for 'NOPIC' definition
9
10 .if exists(${.CURDIR}/shlib_version)
11 SHLIB_MAJOR != . ${.CURDIR}/shlib_version ; echo $$major
12 SHLIB_MINOR != . ${.CURDIR}/shlib_version ; echo $$minor
13 .endif
14
15 .MAIN: all
16
17 # prefer .S to a .c, add .po, remove stuff not used in the BSD libraries.
18 # .so used for PIC object files. .ln used for lint output files.
19 .SUFFIXES:
20 .SUFFIXES: .out .o .po .so .S .s .c .cc .C .f .y .l .ln .m4
21
22 .c.o:
23 @echo "${COMPILE.c} ${.IMPSRC}"
24 @${COMPILE.c} ${.IMPSRC} -o ${.TARGET}.o
25 @${LD} -x -r ${.TARGET}.o -o ${.TARGET}
26 @rm -f ${.TARGET}.o
27
28 .c.po:
29 @echo "${COMPILE.c} -pg ${.IMPSRC} -o ${.TARGET}"
30 @${COMPILE.c} -pg ${.IMPSRC} -o ${.TARGET}.o
31 @${LD} -X -r ${.TARGET}.o -o ${.TARGET}
32 @rm -f ${.TARGET}.o
33
34 .c.so:
35 @echo "${COMPILE.c} ${PICFLAG} -DPIC ${.IMPSRC} -o ${.TARGET}"
36 @${COMPILE.c} ${PICFLAG} -DPIC ${.IMPSRC} -o ${.TARGET}.o
37 @${LD} -x -r ${.TARGET}.o -o ${.TARGET}
38 @rm -f ${.TARGET}.o
39
40 .c.ln:
41 ${LINT} ${LINTFLAGS} ${CFLAGS:M-[IDU]*} -i ${.IMPSRC}
42
43 .cc.o .C.o:
44 @echo "${COMPILE.cc} ${.IMPSRC}"
45 @${COMPILE.cc} ${.IMPSRC} -o ${.TARGET}.o
46 @${LD} -x -r ${.TARGET}.o -o ${.TARGET}
47 @rm -f ${.TARGET}.o
48
49 .cc.po .C.po:
50 @echo "${COMPILE.cc} -pg ${.IMPSRC} -o ${.TARGET}"
51 @${COMPILE.cc} -pg ${.IMPSRC} -o ${.TARGET}.o
52 @${LD} -X -r ${.TARGET}.o -o ${.TARGET}
53 @rm -f ${.TARGET}.o
54
55 .cc.so .C.so:
56 @echo "${COMPILE.cc} ${PICFLAG} -DPIC ${.IMPSRC} -o ${.TARGET}"
57 @${COMPILE.cc} ${PICFLAG} -DPIC ${.IMPSRC} -o ${.TARGET}.o
58 @${LD} -x -r ${.TARGET}.o -o ${.TARGET}
59 @rm -f ${.TARGET}.o
60
61 .S.o .s.o:
62 @echo "${COMPILE.S} ${CFLAGS:M-[ID]*} ${AINC} ${.IMPSRC}"
63 @${COMPILE.S} ${CFLAGS:M-[ID]*} ${AINC} ${.IMPSRC} -o ${.TARGET}.o
64 @${LD} -x -r ${.TARGET}.o -o ${.TARGET}
65 @rm -f ${.TARGET}.o
66
67 .S.po .s.po:
68 @echo "${COMPILE.S} -DPROF ${CFLAGS:M-[ID]*} ${AINC} ${.IMPSRC} -o ${.TARGET}.o"
69 @${COMPILE.S} -DPROF ${CFLAGS:M-[ID]*} ${AINC} ${.IMPSRC} -o ${.TARGET}.o
70 @${LD} -X -r ${.TARGET}.o -o ${.TARGET}
71 @rm -f ${.TARGET}.o
72
73 .S.so .s.so:
74 @echo "${COMPILE.S} ${PICFLAG} -DPIC ${CFLAGS:M-[ID]*} ${AINC} ${.IMPSRC} -o ${.TARGET}.o"
75 @${COMPILE.S} ${PICFLAG} -DPIC ${CFLAGS:M-[ID]*} ${AINC} ${.IMPSRC} -o ${.TARGET}.o
76 @${LD} -x -r ${.TARGET}.o -o ${.TARGET}
77 @rm -f ${.TARGET}.o
78
79 .if !defined(PICFLAG)
80 PICFLAG=-fpic
81 .endif
82
83 .if !defined(NOPROFILE)
84 _LIBS=lib${LIB}.a lib${LIB}_p.a
85 .else
86 _LIBS=lib${LIB}.a
87 .endif
88
89 .if !defined(NOPIC)
90 _LIBS+=lib${LIB}_pic.a
91 .if defined(SHLIB_MAJOR) && defined(SHLIB_MINOR)
92 _LIBS+=lib${LIB}.so.${SHLIB_MAJOR}.${SHLIB_MINOR}
93 .endif
94 .endif
95
96 .if !defined(NOLINT)
97 _LIBS+=llib-l${LIB}.ln
98 .endif
99
100 all: ${_LIBS} _SUBDIRUSE
101
102 OBJS+= ${SRCS:N*.h:R:S/$/.o/g}
103
104 lib${LIB}.a:: ${OBJS}
105 @echo building standard ${LIB} library
106 @rm -f lib${LIB}.a
107 @${AR} cq lib${LIB}.a `lorder ${OBJS} | tsort -q`
108 ${RANLIB} lib${LIB}.a
109
110 POBJS+= ${OBJS:.o=.po}
111 lib${LIB}_p.a:: ${POBJS}
112 @echo building profiled ${LIB} library
113 @rm -f lib${LIB}_p.a
114 @${AR} cq lib${LIB}_p.a `lorder ${POBJS} | tsort -q`
115 ${RANLIB} lib${LIB}_p.a
116
117 SOBJS+= ${OBJS:.o=.so}
118 lib${LIB}_pic.a:: ${SOBJS}
119 @echo building shared object ${LIB} library
120 @rm -f lib${LIB}_pic.a
121 @${AR} cq lib${LIB}_pic.a `lorder ${SOBJS} | tsort -q`
122 ${RANLIB} lib${LIB}_pic.a
123
124 lib${LIB}.so.${SHLIB_MAJOR}.${SHLIB_MINOR}: lib${LIB}_pic.a ${DPADD}
125 @echo building shared ${LIB} library \(version ${SHLIB_MAJOR}.${SHLIB_MINOR}\)
126 @rm -f lib${LIB}.so.${SHLIB_MAJOR}.${SHLIB_MINOR}
127 .if (${MACHINE_ARCH} != "alpha")
128 $(LD) -x -Bshareable -Bforcearchive \
129 -o lib${LIB}.so.${SHLIB_MAJOR}.${SHLIB_MINOR} lib${LIB}_pic.a ${LDADD}
130 .else
131 $(LD) -shared -o lib${LIB}.so.${SHLIB_MAJOR}.${SHLIB_MINOR} \
132 -soname lib${LIB}.so.${SHLIB_MAJOR}.${SHLIB_MINOR} \
133 --whole-archive lib${LIB}_pic.a --no-whole-archive ${LDADD}
134 .endif
135
136 LOBJS+= ${LSRCS:.c=.ln} ${SRCS:M*.c:.c=.ln}
137 # the following looks XXX to me... -- cgd
138 LLIBS?= -lc
139 llib-l${LIB}.ln: ${LOBJS}
140 @echo building llib-l${LIB}.ln
141 @rm -f llib-l${LIB}.ln
142 @${LINT} -C${LIB} ${LOBJS} ${LLIBS}
143
144 .if !target(clean)
145 clean: _SUBDIRUSE
146 rm -f a.out [Ee]rrs mklog core *.core ${CLEANFILES}
147 rm -f lib${LIB}.a ${OBJS}
148 rm -f lib${LIB}_p.a ${POBJS}
149 rm -f lib${LIB}_pic.a lib${LIB}.so.*.* ${SOBJS}
150 rm -f llib-l${LIB}.ln ${LOBJS}
151 .endif
152
153 cleandir: _SUBDIRUSE clean
154
155 .if defined(SRCS)
156 afterdepend: .depend
157 @(TMP=/tmp/_depend$$$$; \
158 sed -e 's/^\([^\.]*\).o[ ]*:/\1.o \1.po \1.so:/' \
159 < .depend > $$TMP; \
160 mv $$TMP .depend)
161 .endif
162
163 .if !target(install)
164 .if !target(beforeinstall)
165 beforeinstall:
166 .endif
167
168 realinstall:
169 # ranlib lib${LIB}.a
170 install ${COPY} -o ${LIBOWN} -g ${LIBGRP} -m 600 lib${LIB}.a \
171 ${DESTDIR}${LIBDIR}
172 ${RANLIB} -t ${DESTDIR}${LIBDIR}/lib${LIB}.a
173 chmod ${LIBMODE} ${DESTDIR}${LIBDIR}/lib${LIB}.a
174 .if !defined(NOPROFILE)
175 # ranlib lib${LIB}_p.a
176 install ${COPY} -o ${LIBOWN} -g ${LIBGRP} -m 600 \
177 lib${LIB}_p.a ${DESTDIR}${LIBDIR}
178 ${RANLIB} -t ${DESTDIR}${LIBDIR}/lib${LIB}_p.a
179 chmod ${LIBMODE} ${DESTDIR}${LIBDIR}/lib${LIB}_p.a
180 .endif
181 .if !defined(NOPIC)
182 # ranlib lib${LIB}_pic.a
183 install ${COPY} -o ${LIBOWN} -g ${LIBGRP} -m 600 \
184 lib${LIB}_pic.a ${DESTDIR}${LIBDIR}
185 ${RANLIB} -t ${DESTDIR}${LIBDIR}/lib${LIB}_pic.a
186 chmod ${LIBMODE} ${DESTDIR}${LIBDIR}/lib${LIB}_pic.a
187 .endif
188 .if !defined(NOPIC) && defined(SHLIB_MAJOR) && defined(SHLIB_MINOR)
189 install ${COPY} -o ${LIBOWN} -g ${LIBGRP} -m ${LIBMODE} \
190 lib${LIB}.so.${SHLIB_MAJOR}.${SHLIB_MINOR} ${DESTDIR}${LIBDIR}
191 .endif
192 .if !defined(NOLINT)
193 install ${COPY} -o ${LIBOWN} -g ${LIBGRP} -m ${LIBMODE} \
194 llib-l${LIB}.ln ${DESTDIR}${LINTLIBDIR}
195 .endif
196 .if defined(LINKS) && !empty(LINKS)
197 @set ${LINKS}; \
198 while test $$# -ge 2; do \
199 l=${DESTDIR}$$1; \
200 shift; \
201 t=${DESTDIR}$$1; \
202 shift; \
203 echo $$t -\> $$l; \
204 rm -f $$t; \
205 ln $$l $$t; \
206 done; true
207 .endif
208
209 install: maninstall _SUBDIRUSE
210 maninstall: afterinstall
211 afterinstall: realinstall
212 realinstall: beforeinstall
213 .endif
214
215 .if !defined(NOMAN)
216 .include <bsd.man.mk>
217 .endif
218
219 .if !defined(NONLS)
220 .include <bsd.nls.mk>
221 .endif
222
223 .include <bsd.obj.mk>
224 .include <bsd.dep.mk>
225 .include <bsd.subdir.mk>
226 .include <bsd.sys.mk>
227