]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - share/mk/bsd.lib.mk
This commit was generated by cvs2svn to compensate for changes in r159825,
[FreeBSD/FreeBSD.git] / share / mk / bsd.lib.mk
1 #       from: @(#)bsd.lib.mk    5.26 (Berkeley) 5/2/91
2 # $FreeBSD$
3 #
4
5 .include <bsd.init.mk>
6
7 # Set up the variables controlling shared libraries.  After this section,
8 # SHLIB_NAME will be defined only if we are to create a shared library.
9 # SHLIB_LINK will be defined only if we are to create a link to it.
10 # INSTALL_PIC_ARCHIVE will be defined only if we are to create a PIC archive.
11 .if defined(NO_PIC)
12 .undef SHLIB_NAME
13 .undef INSTALL_PIC_ARCHIVE
14 .else
15 .if !defined(SHLIB) && defined(LIB)
16 SHLIB=          ${LIB}
17 .endif
18 .if !defined(SHLIB_NAME) && defined(SHLIB) && defined(SHLIB_MAJOR)
19 SHLIB_NAME=     lib${SHLIB}.so.${SHLIB_MAJOR}
20 .endif
21 .if defined(SHLIB_NAME) && !empty(SHLIB_NAME:M*.so.*)
22 SHLIB_LINK?=    ${SHLIB_NAME:R}
23 .endif
24 SONAME?=        ${SHLIB_NAME}
25 .endif
26
27 .if defined(CRUNCH_CFLAGS)
28 CFLAGS+=        ${CRUNCH_CFLAGS}
29 .endif
30
31 .if defined(DEBUG_FLAGS)
32 CFLAGS+= ${DEBUG_FLAGS}
33 .endif
34
35 .if !defined(DEBUG_FLAGS)
36 STRIP?= -s
37 .endif
38
39 .include <bsd.libnames.mk>
40
41 # prefer .s to a .c, add .po, remove stuff not used in the BSD libraries
42 # .So used for PIC object files
43 .SUFFIXES:
44 .SUFFIXES: .out .o .po .So .S .asm .s .c .cc .cpp .cxx .m .C .f .y .l .ln
45
46 .if !defined(PICFLAG)
47 .if ${MACHINE_ARCH} == "sparc64"
48 PICFLAG=-fPIC
49 .else
50 PICFLAG=-fpic
51 .endif
52 .endif
53
54 .if ${CC} == "icc"
55 PO_FLAG=-p
56 .else
57 PO_FLAG=-pg
58 .endif
59
60 .c.po:
61         ${CC} ${PO_FLAG} ${CFLAGS} -c ${.IMPSRC} -o ${.TARGET}
62
63 .c.So:
64         ${CC} ${PICFLAG} -DPIC ${CFLAGS} -c ${.IMPSRC} -o ${.TARGET}
65
66 .cc.po .C.po .cpp.po .cxx.po:
67         ${CXX} ${PO_FLAG} ${CXXFLAGS} -c ${.IMPSRC} -o ${.TARGET}
68
69 .cc.So .C.So .cpp.So .cxx.So:
70         ${CXX} ${PICFLAG} -DPIC ${CXXFLAGS} -c ${.IMPSRC} -o ${.TARGET}
71
72 .f.po:
73         ${FC} -pg ${FFLAGS} -o ${.TARGET} -c ${.IMPSRC}
74
75 .f.So:
76         ${FC} ${PICFLAG} -DPIC ${FFLAGS} -o ${.TARGET} -c ${.IMPSRC}
77
78 .m.po:
79         ${OBJC} ${OBJCFLAGS} -pg -c ${.IMPSRC} -o ${.TARGET}
80
81 .m.So:
82         ${OBJC} ${PICFLAG} -DPIC ${OBJCFLAGS} -c ${.IMPSRC} -o ${.TARGET}
83
84 .s.po .s.So:
85         ${AS} ${AFLAGS} -o ${.TARGET} ${.IMPSRC}
86
87 .asm.po:
88         ${CC} -x assembler-with-cpp -DPROF ${CFLAGS} -c ${.IMPSRC} -o ${.TARGET}
89
90 .asm.So:
91         ${CC} -x assembler-with-cpp ${PICFLAG} -DPIC ${CFLAGS} \
92             -c ${.IMPSRC} -o ${.TARGET}
93
94 .S.po:
95         ${CC} -DPROF ${CFLAGS} -c ${.IMPSRC} -o ${.TARGET}
96
97 .S.So:
98         ${CC} ${PICFLAG} -DPIC ${CFLAGS} -c ${.IMPSRC} -o ${.TARGET}
99
100 all: objwarn
101
102 # Generate the version map given the version definitions
103 # and symbol maps.
104 .if !empty(VERSION_DEF) && !empty(SYMBOL_MAPS)
105 # Find the awk script that generates the version map.
106 VERSION_GEN?=   version_gen.awk
107 VERSION_MAP?=   Version.map
108
109 # Compute the make's -m path.
110 _mpath=
111 _oarg=
112 .for _arg in ${.MAKEFLAGS}
113 .if ${_oarg} == "-m"
114 _mpath+= ${_arg}
115 .endif
116 _oarg=  ${_arg}
117 .endfor
118 _mpath+= /usr/share/mk
119
120 # Look up ${VERSION_GEN} in ${_mpath}.
121 _vgen=
122 .for path in ${_mpath}
123 .if empty(_vgen)
124 .if exists(${path}/${VERSION_GEN})
125 _vgen=  ${path}/${VERSION_GEN}
126 .endif
127 .endif
128 .endfor
129
130 ${VERSION_MAP}: ${VERSION_DEF} ${_vgen} ${SYMBOL_MAPS}
131         awk -v vfile=${VERSION_DEF} -f ${_vgen} ${SYMBOL_MAPS} \
132             > ${.TARGET}
133 .endif  # !empty(VERSION_DEF) && !empty(SYMBOL_MAPS)
134
135 # Allow librararies to specify their own version map or have it
136 # automatically generated (see above).
137 .if !empty(VERSION_MAP)
138 ${SHLIB_NAME}:  ${VERSION_MAP}
139 LDFLAGS+=       -Wl,--version-script=${VERSION_MAP}
140 .endif
141
142 .if defined(LIB) && !empty(LIB) || defined(SHLIB_NAME)
143 OBJS+=          ${SRCS:N*.h:R:S/$/.o/}
144 .endif
145
146 .if defined(LIB) && !empty(LIB)
147 _LIBS=          lib${LIB}.a
148
149 lib${LIB}.a: ${OBJS} ${STATICOBJS}
150         @${ECHO} building static ${LIB} library
151         @rm -f ${.TARGET}
152         @${AR} cq ${.TARGET} `lorder ${OBJS} ${STATICOBJS} | tsort -q` ${ARADD}
153         ${RANLIB} ${.TARGET}
154 .endif
155
156 .if !defined(INTERNALLIB)
157
158 .if ${MK_PROFILE} != "no" && defined(LIB) && !empty(LIB)
159 _LIBS+=         lib${LIB}_p.a
160 POBJS+=         ${OBJS:.o=.po} ${STATICOBJS:.o=.po}
161
162 lib${LIB}_p.a: ${POBJS}
163         @${ECHO} building profiled ${LIB} library
164         @rm -f ${.TARGET}
165         @${AR} cq ${.TARGET} `lorder ${POBJS} | tsort -q` ${ARADD}
166         ${RANLIB} ${.TARGET}
167 .endif
168
169 .if defined(SHLIB_NAME) || \
170     defined(INSTALL_PIC_ARCHIVE) && defined(LIB) && !empty(LIB)
171 SOBJS+=         ${OBJS:.o=.So}
172 .endif
173
174 .if defined(SHLIB_NAME)
175 _LIBS+=         ${SHLIB_NAME}
176
177 ${SHLIB_NAME}: ${SOBJS}
178         @${ECHO} building shared library ${SHLIB_NAME}
179         @rm -f ${.TARGET} ${SHLIB_LINK}
180 .if defined(SHLIB_LINK)
181         @ln -fs ${.TARGET} ${SHLIB_LINK}
182 .endif
183         @${CC} ${LDFLAGS} -shared -Wl,-x \
184             -o ${.TARGET} -Wl,-soname,${SONAME} \
185             `lorder ${SOBJS} | tsort -q` ${LDADD}
186 .endif
187
188 .if defined(INSTALL_PIC_ARCHIVE) && defined(LIB) && !empty(LIB) && ${MK_TOOLCHAIN} != "no"
189 _LIBS+=         lib${LIB}_pic.a
190
191 lib${LIB}_pic.a: ${SOBJS}
192         @${ECHO} building special pic ${LIB} library
193         @rm -f ${.TARGET}
194         @${AR} cq ${.TARGET} ${SOBJS} ${ARADD}
195         ${RANLIB} ${.TARGET}
196 .endif
197
198 .if defined(WANT_LINT) && !defined(NO_LINT) && defined(LIB) && !empty(LIB)
199 LINTLIB=        llib-l${LIB}.ln
200 _LIBS+=         ${LINTLIB}
201 LINTOBJS+=      ${SRCS:M*.c:.c=.ln}
202
203 ${LINTLIB}: ${LINTOBJS}
204         @${ECHO} building lint library ${.TARGET}
205         @rm -f ${.TARGET}
206         ${LINT} ${LINTLIBFLAGS} ${CFLAGS:M-[DIU]*} ${.ALLSRC}
207 .endif
208
209 .endif # !defined(INTERNALLIB)
210
211 all: ${_LIBS}
212
213 .if ${MK_MAN} != "no"
214 all: _manpages
215 .endif
216
217 _EXTRADEPEND:
218         @TMP=_depend$$$$; \
219         sed -e 's/^\([^\.]*\).o[ ]*:/\1.o \1.po \1.So:/' < ${DEPENDFILE} \
220             > $$TMP; \
221         mv $$TMP ${DEPENDFILE}
222 .if !defined(NO_EXTRADEPEND) && defined(SHLIB_NAME)
223 .if defined(DPADD) && !empty(DPADD)
224         echo ${SHLIB_NAME}: ${DPADD} >> ${DEPENDFILE}
225 .endif
226 .endif
227
228 .if !target(install)
229
230 .if defined(PRECIOUSLIB)
231 .if !defined(NO_FSCHG)
232 SHLINSTALLFLAGS+= -fschg
233 .endif
234 SHLINSTALLFLAGS+= -S
235 .endif
236
237 _INSTALLFLAGS:= ${INSTALLFLAGS}
238 .for ie in ${INSTALLFLAGS_EDIT}
239 _INSTALLFLAGS:= ${_INSTALLFLAGS${ie}}
240 .endfor
241 _SHLINSTALLFLAGS:=      ${SHLINSTALLFLAGS}
242 .for ie in ${INSTALLFLAGS_EDIT}
243 _SHLINSTALLFLAGS:=      ${_SHLINSTALLFLAGS${ie}}
244 .endfor
245
246 .if !defined(INTERNALLIB)
247 realinstall: _libinstall
248 .ORDER: beforeinstall _libinstall
249 _libinstall:
250 .if defined(LIB) && !empty(LIB) && !defined(NO_INSTALLLIB)
251         ${INSTALL} -C -o ${LIBOWN} -g ${LIBGRP} -m ${LIBMODE} \
252             ${_INSTALLFLAGS} lib${LIB}.a ${DESTDIR}${LIBDIR}
253 .endif
254 .if ${MK_PROFILE} != "no" && defined(LIB) && !empty(LIB)
255         ${INSTALL} -C -o ${LIBOWN} -g ${LIBGRP} -m ${LIBMODE} \
256             ${_INSTALLFLAGS} lib${LIB}_p.a ${DESTDIR}${LIBDIR}
257 .endif
258 .if defined(SHLIB_NAME)
259         ${INSTALL} ${STRIP} -o ${LIBOWN} -g ${LIBGRP} -m ${LIBMODE} \
260             ${_INSTALLFLAGS} ${_SHLINSTALLFLAGS} \
261             ${SHLIB_NAME} ${DESTDIR}${SHLIBDIR}
262 .if defined(SHLIB_LINK)
263 .if ${SHLIBDIR} == ${LIBDIR}
264         ln -fs ${SHLIB_NAME} ${DESTDIR}${LIBDIR}/${SHLIB_LINK}
265 .else
266         ln -fs ${_SHLIBDIRPREFIX}${SHLIBDIR}/${SHLIB_NAME} \
267             ${DESTDIR}${LIBDIR}/${SHLIB_LINK}
268 .if exists(${DESTDIR}${LIBDIR}/${SHLIB_NAME})
269         -chflags noschg ${DESTDIR}${LIBDIR}/${SHLIB_NAME}
270         rm -f ${DESTDIR}${LIBDIR}/${SHLIB_NAME}
271 .endif
272 .endif
273 .endif
274 .endif
275 .if defined(INSTALL_PIC_ARCHIVE) && defined(LIB) && !empty(LIB) && ${MK_TOOLCHAIN} != "no"
276         ${INSTALL} -o ${LIBOWN} -g ${LIBGRP} -m ${LIBMODE} \
277             ${_INSTALLFLAGS} lib${LIB}_pic.a ${DESTDIR}${LIBDIR}
278 .endif
279 .if defined(WANT_LINT) && !defined(NO_LINT) && defined(LIB) && !empty(LIB)
280         ${INSTALL} -o ${LIBOWN} -g ${LIBGRP} -m ${LIBMODE} \
281             ${_INSTALLFLAGS} ${LINTLIB} ${DESTDIR}${LINTLIBDIR}
282 .endif
283 .endif # !defined(INTERNALLIB)
284
285 .include <bsd.nls.mk>
286 .include <bsd.files.mk>
287 .include <bsd.incs.mk>
288 .include <bsd.links.mk>
289
290 .if ${MK_MAN} != "no"
291 realinstall: _maninstall
292 .ORDER: beforeinstall _maninstall
293 .endif
294
295 .endif
296
297 .if !target(lint)
298 lint: ${SRCS:M*.c}
299         ${LINT} ${LINTFLAGS} ${CFLAGS:M-[DIU]*} ${.ALLSRC}
300 .endif
301
302 .if ${MK_MAN} != "no"
303 .include <bsd.man.mk>
304 .endif
305
306 .include <bsd.dep.mk>
307
308 .if !exists(${.OBJDIR}/${DEPENDFILE})
309 .if defined(LIB) && !empty(LIB)
310 ${OBJS} ${STATICOBJS} ${POBJS}: ${SRCS:M*.h}
311 .for _S in ${SRCS:N*.[hly]}
312 ${_S:R}.po: ${_S}
313 .endfor
314 .endif
315 .if defined(SHLIB_NAME) || \
316     defined(INSTALL_PIC_ARCHIVE) && defined(LIB) && !empty(LIB)
317 ${SOBJS}: ${SRCS:M*.h}
318 .for _S in ${SRCS:N*.[hly]}
319 ${_S:R}.So: ${_S}
320 .endfor
321 .endif
322 .endif
323
324 .if !target(clean)
325 clean:
326 .if defined(CLEANFILES) && !empty(CLEANFILES)
327         rm -f ${CLEANFILES}
328 .endif
329 .if defined(LIB) && !empty(LIB)
330         rm -f a.out ${OBJS} ${OBJS:S/$/.tmp/} ${STATICOBJS}
331 .endif
332 .if !defined(INTERNALLIB)
333 .if ${MK_PROFILE} != "no" && defined(LIB) && !empty(LIB)
334         rm -f ${POBJS} ${POBJS:S/$/.tmp/}
335 .endif
336 .if defined(SHLIB_NAME) || \
337     defined(INSTALL_PIC_ARCHIVE) && defined(LIB) && !empty(LIB)
338         rm -f ${SOBJS} ${SOBJS:.So=.so} ${SOBJS:S/$/.tmp/}
339 .endif
340 .if defined(SHLIB_NAME)
341 .if defined(SHLIB_LINK)
342         rm -f ${SHLIB_LINK}
343 .endif
344 .if defined(LIB) && !empty(LIB)
345         rm -f lib${LIB}.so.* lib${LIB}.so
346 .endif
347 .endif
348 .if defined(WANT_LINT) && defined(LIB) && !empty(LIB)
349         rm -f ${LINTOBJS}
350 .endif
351 .endif # !defined(INTERNALLIB)
352 .if defined(_LIBS) && !empty(_LIBS)
353         rm -f ${_LIBS}
354 .endif
355 .if defined(CLEANDIRS) && !empty(CLEANDIRS)
356         rm -rf ${CLEANDIRS}
357 .endif
358 .if !empty(VERSION_DEF) && !empty(SYMBOL_MAPS)
359         rm -f ${VERSION_MAP}
360 .endif
361 .endif
362
363 .include <bsd.obj.mk>
364
365 .include <bsd.sys.mk>