]> CyberLeo.Net >> Repos - FreeBSD/stable/8.git/blob - share/mk/bsd.lib.mk
MFC 206082,206179,207056,207057,210612,210636,210656,212423,212426,228121,
[FreeBSD/stable/8.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 ${MK_ASSERT_DEBUG} == "no"
32 CFLAGS+= -DNDEBUG
33 NO_WERROR=
34 .endif
35
36 .if defined(DEBUG_FLAGS)
37 CFLAGS+= ${DEBUG_FLAGS}
38
39 .if ${MK_CTF} != "no" && ${DEBUG_FLAGS:M-g} != ""
40 CTFFLAGS+= -g
41 .endif
42 .endif
43
44 .if !defined(DEBUG_FLAGS)
45 STRIP?= -s
46 .endif
47
48 .include <bsd.libnames.mk>
49
50 # prefer .s to a .c, add .po, remove stuff not used in the BSD libraries
51 # .So used for PIC object files
52 .SUFFIXES:
53 .SUFFIXES: .out .o .po .So .S .asm .s .c .cc .cpp .cxx .m .C .f .y .l .ln
54
55 .if !defined(PICFLAG)
56 .if ${MACHINE_ARCH} == "sparc64"
57 PICFLAG=-fPIC
58 .else
59 PICFLAG=-fpic
60 .endif
61 .endif
62
63 .if ${CC} == "icc"
64 PO_FLAG=-p
65 .else
66 PO_FLAG=-pg
67 .endif
68
69 .c.po:
70         ${CC} ${PO_FLAG} ${CFLAGS} -c ${.IMPSRC} -o ${.TARGET}
71         ${CTFCONVERT_CMD}
72
73 .c.So:
74         ${CC} ${PICFLAG} -DPIC ${CFLAGS} -c ${.IMPSRC} -o ${.TARGET}
75         ${CTFCONVERT_CMD}
76
77 .cc.po .C.po .cpp.po .cxx.po:
78         ${CXX} ${PO_FLAG} ${CXXFLAGS} -c ${.IMPSRC} -o ${.TARGET}
79
80 .cc.So .C.So .cpp.So .cxx.So:
81         ${CXX} ${PICFLAG} -DPIC ${CXXFLAGS} -c ${.IMPSRC} -o ${.TARGET}
82
83 .f.po:
84         ${FC} -pg ${FFLAGS} -o ${.TARGET} -c ${.IMPSRC}
85         ${CTFCONVERT_CMD}
86
87 .f.So:
88         ${FC} ${PICFLAG} -DPIC ${FFLAGS} -o ${.TARGET} -c ${.IMPSRC}
89         ${CTFCONVERT_CMD}
90
91 .m.po:
92         ${OBJC} ${OBJCFLAGS} -pg -c ${.IMPSRC} -o ${.TARGET}
93         ${CTFCONVERT_CMD}
94
95 .m.So:
96         ${OBJC} ${PICFLAG} -DPIC ${OBJCFLAGS} -c ${.IMPSRC} -o ${.TARGET}
97         ${CTFCONVERT_CMD}
98
99 .s.po .s.So:
100         ${AS} ${AFLAGS} -o ${.TARGET} ${.IMPSRC}
101         ${CTFCONVERT_CMD}
102
103 .asm.po:
104         ${CC} -x assembler-with-cpp -DPROF ${CFLAGS} -c ${.IMPSRC} -o ${.TARGET}
105         ${CTFCONVERT_CMD}
106
107 .asm.So:
108         ${CC} -x assembler-with-cpp ${PICFLAG} -DPIC ${CFLAGS} \
109             -c ${.IMPSRC} -o ${.TARGET}
110         ${CTFCONVERT_CMD}
111
112 .S.po:
113         ${CC} -DPROF ${CFLAGS} -c ${.IMPSRC} -o ${.TARGET}
114         ${CTFCONVERT_CMD}
115
116 .S.So:
117         ${CC} ${PICFLAG} -DPIC ${CFLAGS} -c ${.IMPSRC} -o ${.TARGET}
118         ${CTFCONVERT_CMD}
119
120 all: objwarn
121
122 .include <bsd.symver.mk>
123
124 # Allow libraries to specify their own version map or have it
125 # automatically generated (see bsd.symver.mk above).
126 .if ${MK_SYMVER} == "yes" && !empty(VERSION_MAP)
127 ${SHLIB_NAME}:  ${VERSION_MAP}
128 LDFLAGS+=       -Wl,--version-script=${VERSION_MAP}
129 .endif
130
131 .if defined(LIB) && !empty(LIB) || defined(SHLIB_NAME)
132 OBJS+=          ${SRCS:N*.h:R:S/$/.o/}
133 .endif
134
135 .if defined(LIB) && !empty(LIB)
136 _LIBS=          lib${LIB}.a
137
138 lib${LIB}.a: ${OBJS} ${STATICOBJS}
139         @${ECHO} building static ${LIB} library
140         @rm -f ${.TARGET}
141 .if !defined(NM)
142         @${AR} cq ${.TARGET} `lorder ${OBJS} ${STATICOBJS} | tsort -q` ${ARADD}
143 .else
144         @${AR} cq ${.TARGET} `NM='${NM}' lorder ${OBJS} ${STATICOBJS} | tsort -q` ${ARADD}
145 .endif
146         ${RANLIB} ${.TARGET}
147 .endif
148
149 .if !defined(INTERNALLIB)
150
151 .if ${MK_PROFILE} != "no" && defined(LIB) && !empty(LIB)
152 _LIBS+=         lib${LIB}_p.a
153 POBJS+=         ${OBJS:.o=.po} ${STATICOBJS:.o=.po}
154
155 lib${LIB}_p.a: ${POBJS}
156         @${ECHO} building profiled ${LIB} library
157         @rm -f ${.TARGET}
158 .if !defined(NM)
159         @${AR} cq ${.TARGET} `lorder ${POBJS} | tsort -q` ${ARADD}
160 .else
161         @${AR} cq ${.TARGET} `NM='${NM}' lorder ${POBJS} | tsort -q` ${ARADD}
162 .endif
163         ${RANLIB} ${.TARGET}
164 .endif
165
166 .if defined(SHLIB_NAME) || \
167     defined(INSTALL_PIC_ARCHIVE) && defined(LIB) && !empty(LIB)
168 SOBJS+=         ${OBJS:.o=.So}
169 .endif
170
171 .if defined(SHLIB_NAME)
172 _LIBS+=         ${SHLIB_NAME}
173
174 .if target(beforelinking)
175 ${SHLIB_NAME}: ${SOBJS} beforelinking
176 .else
177 ${SHLIB_NAME}: ${SOBJS}
178 .endif
179         @${ECHO} building shared library ${SHLIB_NAME}
180         @rm -f ${.TARGET} ${SHLIB_LINK}
181 .if defined(SHLIB_LINK)
182         @ln -fs ${.TARGET} ${SHLIB_LINK}
183 .endif
184 .if !defined(NM)
185         @${CC} ${LDFLAGS} ${SSP_CFLAGS} -shared -Wl,-x \
186             -o ${.TARGET} -Wl,-soname,${SONAME} \
187             `lorder ${SOBJS} | tsort -q` ${LDADD}
188 .else
189         @${CC} ${LDFLAGS} ${SSP_CFLAGS} -shared -Wl,-x \
190             -o ${.TARGET} -Wl,-soname,${SONAME} \
191             `NM='${NM}' lorder ${SOBJS} | tsort -q` ${LDADD}
192 .endif
193 .if ${MK_CTF} != "no"
194         ${CTFMERGE} ${CTFFLAGS} -o ${.TARGET} ${SOBJS}
195 .endif
196 .endif
197
198 .if defined(INSTALL_PIC_ARCHIVE) && defined(LIB) && !empty(LIB) && ${MK_TOOLCHAIN} != "no"
199 _LIBS+=         lib${LIB}_pic.a
200
201 lib${LIB}_pic.a: ${SOBJS}
202         @${ECHO} building special pic ${LIB} library
203         @rm -f ${.TARGET}
204         @${AR} cq ${.TARGET} ${SOBJS} ${ARADD}
205         ${RANLIB} ${.TARGET}
206 .endif
207
208 .if defined(WANT_LINT) && !defined(NO_LINT) && defined(LIB) && !empty(LIB)
209 LINTLIB=        llib-l${LIB}.ln
210 _LIBS+=         ${LINTLIB}
211 LINTOBJS+=      ${SRCS:M*.c:.c=.ln}
212
213 ${LINTLIB}: ${LINTOBJS}
214         @${ECHO} building lint library ${.TARGET}
215         @rm -f ${.TARGET}
216         ${LINT} ${LINTLIBFLAGS} ${CFLAGS:M-[DIU]*} ${.ALLSRC}
217 .endif
218
219 .endif # !defined(INTERNALLIB)
220
221 all: ${_LIBS}
222
223 .if ${MK_MAN} != "no"
224 all: _manpages
225 .endif
226
227 _EXTRADEPEND:
228         @TMP=_depend$$$$; \
229         sed -e 's/^\([^\.]*\).o[ ]*:/\1.o \1.po \1.So:/' < ${DEPENDFILE} \
230             > $$TMP; \
231         mv $$TMP ${DEPENDFILE}
232 .if !defined(NO_EXTRADEPEND) && defined(SHLIB_NAME)
233 .if defined(DPADD) && !empty(DPADD)
234         echo ${SHLIB_NAME}: ${DPADD} >> ${DEPENDFILE}
235 .endif
236 .endif
237
238 .if !target(install)
239
240 .if defined(PRECIOUSLIB)
241 .if !defined(NO_FSCHG)
242 SHLINSTALLFLAGS+= -fschg
243 .endif
244 SHLINSTALLFLAGS+= -S
245 .endif
246
247 _INSTALLFLAGS:= ${INSTALLFLAGS}
248 .for ie in ${INSTALLFLAGS_EDIT}
249 _INSTALLFLAGS:= ${_INSTALLFLAGS${ie}}
250 .endfor
251 _SHLINSTALLFLAGS:=      ${SHLINSTALLFLAGS}
252 .for ie in ${INSTALLFLAGS_EDIT}
253 _SHLINSTALLFLAGS:=      ${_SHLINSTALLFLAGS${ie}}
254 .endfor
255
256 .if !defined(INTERNALLIB)
257 realinstall: _libinstall
258 .ORDER: beforeinstall _libinstall
259 _libinstall:
260 .if defined(LIB) && !empty(LIB) && ${MK_INSTALLLIB} != "no"
261         ${INSTALL} -C -o ${LIBOWN} -g ${LIBGRP} -m ${LIBMODE} \
262             ${_INSTALLFLAGS} lib${LIB}.a ${DESTDIR}${LIBDIR}
263 .endif
264 .if ${MK_PROFILE} != "no" && defined(LIB) && !empty(LIB)
265         ${INSTALL} -C -o ${LIBOWN} -g ${LIBGRP} -m ${LIBMODE} \
266             ${_INSTALLFLAGS} lib${LIB}_p.a ${DESTDIR}${LIBDIR}
267 .endif
268 .if defined(SHLIB_NAME)
269         ${INSTALL} ${STRIP} -o ${LIBOWN} -g ${LIBGRP} -m ${LIBMODE} \
270             ${_INSTALLFLAGS} ${_SHLINSTALLFLAGS} \
271             ${SHLIB_NAME} ${DESTDIR}${SHLIBDIR}
272 .if defined(SHLIB_LINK)
273 # ${_SHLIBDIRPREFIX} and ${_LDSCRIPTROOT} are both needed when cross-building
274 # and when building 32 bits library shims.  ${_SHLIBDIRPREFIX} is the directory
275 # prefix where shared objects will be installed.  ${_LDSCRIPTROOT} is the
276 # directory prefix that will be used in generated ld(1) scripts.  They cannot
277 # be coalesced because of the way ld(1) handles the sysroot prefix (used in the
278 # cross-toolchain):
279 # - 64 bits libs are located under sysroot, so ${_LDSCRIPTROOT} must be empty.
280 # - 32 bits shims are not, so ${_LDSCRIPTROOT} is used to specify their full
281 #   path.  Note that ld(1) scripts are generated both during buildworld and
282 #   installworld; in the later case ${_LDSCRIPTROOT} must be obviously empty.
283 # On the other hand, the use of ${_SHLIBDIRPREFIX} is more consistent since it
284 # does not involve the logic of a tool we do not own.
285 .if defined(SHLIB_LDSCRIPT) && !empty(SHLIB_LDSCRIPT) && exists(${.CURDIR}/${SHLIB_LDSCRIPT})
286         sed -e 's,@@SHLIB@@,${_LDSCRIPTROOT}${SHLIBDIR}/${SHLIB_NAME},g' \
287             -e 's,@@LIBDIR@@,${_LDSCRIPTROOT}${LIBDIR},g' \
288             ${.CURDIR}/${SHLIB_LDSCRIPT} > lib${LIB}.ld
289         ${INSTALL} -S -C -o ${LIBOWN} -g ${LIBGRP} -m ${LIBMODE} \
290             ${_INSTALLFLAGS} lib${LIB}.ld ${DESTDIR}${LIBDIR}/${SHLIB_LINK}
291 .else
292 .if ${SHLIBDIR} == ${LIBDIR}
293         ln -fs ${SHLIB_NAME} ${DESTDIR}${LIBDIR}/${SHLIB_LINK}
294 .else
295         ln -fs ${_SHLIBDIRPREFIX}${SHLIBDIR}/${SHLIB_NAME} \
296             ${DESTDIR}${LIBDIR}/${SHLIB_LINK}
297 .if exists(${DESTDIR}${LIBDIR}/${SHLIB_NAME})
298         -chflags noschg ${DESTDIR}${LIBDIR}/${SHLIB_NAME}
299         rm -f ${DESTDIR}${LIBDIR}/${SHLIB_NAME}
300 .endif
301 .endif
302 .endif # SHLIB_LDSCRIPT
303 .endif # SHLIB_LINK
304 .endif # SHIB_NAME
305 .if defined(INSTALL_PIC_ARCHIVE) && defined(LIB) && !empty(LIB) && ${MK_TOOLCHAIN} != "no"
306         ${INSTALL} -o ${LIBOWN} -g ${LIBGRP} -m ${LIBMODE} \
307             ${_INSTALLFLAGS} lib${LIB}_pic.a ${DESTDIR}${LIBDIR}
308 .endif
309 .if defined(WANT_LINT) && !defined(NO_LINT) && defined(LIB) && !empty(LIB)
310         ${INSTALL} -o ${LIBOWN} -g ${LIBGRP} -m ${LIBMODE} \
311             ${_INSTALLFLAGS} ${LINTLIB} ${DESTDIR}${LINTLIBDIR}
312 .endif
313 .endif # !defined(INTERNALLIB)
314
315 .include <bsd.nls.mk>
316 .include <bsd.files.mk>
317 .include <bsd.incs.mk>
318 .include <bsd.links.mk>
319
320 .if ${MK_MAN} != "no"
321 realinstall: _maninstall
322 .ORDER: beforeinstall _maninstall
323 .endif
324
325 .endif
326
327 .if !target(lint)
328 lint: ${SRCS:M*.c}
329         ${LINT} ${LINTFLAGS} ${CFLAGS:M-[DIU]*} ${.ALLSRC}
330 .endif
331
332 .if ${MK_MAN} != "no"
333 .include <bsd.man.mk>
334 .endif
335
336 .include <bsd.dep.mk>
337
338 .if !exists(${.OBJDIR}/${DEPENDFILE})
339 .if defined(LIB) && !empty(LIB)
340 ${OBJS} ${STATICOBJS} ${POBJS}: ${SRCS:M*.h}
341 .for _S in ${SRCS:N*.[hly]}
342 ${_S:R}.po: ${_S}
343 .endfor
344 .endif
345 .if defined(SHLIB_NAME) || \
346     defined(INSTALL_PIC_ARCHIVE) && defined(LIB) && !empty(LIB)
347 ${SOBJS}: ${SRCS:M*.h}
348 .for _S in ${SRCS:N*.[hly]}
349 ${_S:R}.So: ${_S}
350 .endfor
351 .endif
352 .endif
353
354 .if !target(clean)
355 clean:
356 .if defined(CLEANFILES) && !empty(CLEANFILES)
357         rm -f ${CLEANFILES}
358 .endif
359 .if defined(LIB) && !empty(LIB)
360         rm -f a.out ${OBJS} ${OBJS:S/$/.tmp/} ${STATICOBJS}
361 .endif
362 .if !defined(INTERNALLIB)
363 .if ${MK_PROFILE} != "no" && defined(LIB) && !empty(LIB)
364         rm -f ${POBJS} ${POBJS:S/$/.tmp/}
365 .endif
366 .if defined(SHLIB_NAME) || \
367     defined(INSTALL_PIC_ARCHIVE) && defined(LIB) && !empty(LIB)
368         rm -f ${SOBJS} ${SOBJS:.So=.so} ${SOBJS:S/$/.tmp/}
369 .endif
370 .if defined(SHLIB_NAME)
371 .if defined(SHLIB_LINK)
372 .if defined(SHLIB_LDSCRIPT) && exists(${.CURDIR}/${SHLIB_LDSCRIPT})
373         rm -f lib${LIB}.ld
374 .endif
375         rm -f ${SHLIB_LINK}
376 .endif
377 .if defined(LIB) && !empty(LIB)
378         rm -f lib${LIB}.so.* lib${LIB}.so
379 .endif
380 .endif
381 .if defined(WANT_LINT) && defined(LIB) && !empty(LIB)
382         rm -f ${LINTOBJS}
383 .endif
384 .endif # !defined(INTERNALLIB)
385 .if defined(_LIBS) && !empty(_LIBS)
386         rm -f ${_LIBS}
387 .endif
388 .if defined(CLEANDIRS) && !empty(CLEANDIRS)
389         rm -rf ${CLEANDIRS}
390 .endif
391 .if !empty(VERSION_DEF) && !empty(SYMBOL_MAPS)
392         rm -f ${VERSION_MAP}
393 .endif
394 .endif
395
396 .include <bsd.obj.mk>
397
398 .include <bsd.sys.mk>