]> CyberLeo.Net >> Repos - FreeBSD/stable/8.git/blob - share/mk/bsd.lib.mk
MFC r362623:
[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         @${AR} cq ${.TARGET} `NM='${NM}' lorder ${OBJS} ${STATICOBJS} | tsort -q` ${ARADD}
142         ${RANLIB} ${.TARGET}
143 .endif
144
145 .if !defined(INTERNALLIB)
146
147 .if ${MK_PROFILE} != "no" && defined(LIB) && !empty(LIB)
148 _LIBS+=         lib${LIB}_p.a
149 POBJS+=         ${OBJS:.o=.po} ${STATICOBJS:.o=.po}
150
151 lib${LIB}_p.a: ${POBJS}
152         @${ECHO} building profiled ${LIB} library
153         @rm -f ${.TARGET}
154         @${AR} cq ${.TARGET} `NM='${NM}' lorder ${POBJS} | tsort -q` ${ARADD}
155         ${RANLIB} ${.TARGET}
156 .endif
157
158 .if defined(SHLIB_NAME) || \
159     defined(INSTALL_PIC_ARCHIVE) && defined(LIB) && !empty(LIB)
160 SOBJS+=         ${OBJS:.o=.So}
161 .endif
162
163 .if defined(SHLIB_NAME)
164 _LIBS+=         ${SHLIB_NAME}
165
166 .if target(beforelinking)
167 ${SHLIB_NAME}: ${SOBJS} beforelinking
168 .else
169 ${SHLIB_NAME}: ${SOBJS}
170 .endif
171         @${ECHO} building shared library ${SHLIB_NAME}
172         @rm -f ${.TARGET} ${SHLIB_LINK}
173 .if defined(SHLIB_LINK)
174         @ln -fs ${.TARGET} ${SHLIB_LINK}
175 .endif
176         ${CC} ${LDFLAGS} ${SSP_CFLAGS} -shared -Wl,-x \
177             -o ${.TARGET} -Wl,-soname,${SONAME} \
178             `NM='${NM}' lorder ${SOBJS} | tsort -q` ${LDADD}
179 .if ${MK_CTF} != "no"
180         ${CTFMERGE} ${CTFFLAGS} -o ${.TARGET} ${SOBJS}
181 .endif
182 .endif
183
184 .if defined(INSTALL_PIC_ARCHIVE) && defined(LIB) && !empty(LIB) && ${MK_TOOLCHAIN} != "no"
185 _LIBS+=         lib${LIB}_pic.a
186
187 lib${LIB}_pic.a: ${SOBJS}
188         @${ECHO} building special pic ${LIB} library
189         @rm -f ${.TARGET}
190         @${AR} cq ${.TARGET} ${SOBJS} ${ARADD}
191         ${RANLIB} ${.TARGET}
192 .endif
193
194 .if defined(WANT_LINT) && !defined(NO_LINT) && defined(LIB) && !empty(LIB)
195 LINTLIB=        llib-l${LIB}.ln
196 _LIBS+=         ${LINTLIB}
197 LINTOBJS+=      ${SRCS:M*.c:.c=.ln}
198
199 ${LINTLIB}: ${LINTOBJS}
200         @${ECHO} building lint library ${.TARGET}
201         @rm -f ${.TARGET}
202         ${LINT} ${LINTLIBFLAGS} ${CFLAGS:M-[DIU]*} ${.ALLSRC}
203 .endif
204
205 .endif # !defined(INTERNALLIB)
206
207 all: ${_LIBS}
208
209 .if ${MK_MAN} != "no"
210 all: _manpages
211 .endif
212
213 _EXTRADEPEND:
214         @TMP=_depend$$$$; \
215         sed -e 's/^\([^\.]*\).o[ ]*:/\1.o \1.po \1.So:/' < ${DEPENDFILE} \
216             > $$TMP; \
217         mv $$TMP ${DEPENDFILE}
218 .if !defined(NO_EXTRADEPEND) && defined(SHLIB_NAME)
219 .if defined(DPADD) && !empty(DPADD)
220         echo ${SHLIB_NAME}: ${DPADD} >> ${DEPENDFILE}
221 .endif
222 .endif
223
224 .if !target(install)
225
226 .if defined(PRECIOUSLIB)
227 .if !defined(NO_FSCHG)
228 SHLINSTALLFLAGS+= -fschg
229 .endif
230 SHLINSTALLFLAGS+= -S
231 .endif
232
233 _INSTALLFLAGS:= ${INSTALLFLAGS}
234 .for ie in ${INSTALLFLAGS_EDIT}
235 _INSTALLFLAGS:= ${_INSTALLFLAGS${ie}}
236 .endfor
237 _SHLINSTALLFLAGS:=      ${SHLINSTALLFLAGS}
238 .for ie in ${INSTALLFLAGS_EDIT}
239 _SHLINSTALLFLAGS:=      ${_SHLINSTALLFLAGS${ie}}
240 .endfor
241
242 .if !defined(INTERNALLIB)
243 realinstall: _libinstall
244 .ORDER: beforeinstall _libinstall
245 _libinstall:
246 .if defined(LIB) && !empty(LIB) && ${MK_INSTALLLIB} != "no"
247         ${INSTALL} -C -o ${LIBOWN} -g ${LIBGRP} -m ${LIBMODE} \
248             ${_INSTALLFLAGS} lib${LIB}.a ${DESTDIR}${LIBDIR}
249 .endif
250 .if ${MK_PROFILE} != "no" && defined(LIB) && !empty(LIB)
251         ${INSTALL} -C -o ${LIBOWN} -g ${LIBGRP} -m ${LIBMODE} \
252             ${_INSTALLFLAGS} lib${LIB}_p.a ${DESTDIR}${LIBDIR}
253 .endif
254 .if defined(SHLIB_NAME)
255         ${INSTALL} ${STRIP} -o ${LIBOWN} -g ${LIBGRP} -m ${LIBMODE} \
256             ${_INSTALLFLAGS} ${_SHLINSTALLFLAGS} \
257             ${SHLIB_NAME} ${DESTDIR}${SHLIBDIR}
258 .if defined(SHLIB_LINK)
259 # ${_SHLIBDIRPREFIX} and ${_LDSCRIPTROOT} are both needed when cross-building
260 # and when building 32 bits library shims.  ${_SHLIBDIRPREFIX} is the directory
261 # prefix where shared objects will be installed.  ${_LDSCRIPTROOT} is the
262 # directory prefix that will be used in generated ld(1) scripts.  They cannot
263 # be coalesced because of the way ld(1) handles the sysroot prefix (used in the
264 # cross-toolchain):
265 # - 64 bits libs are located under sysroot, so ${_LDSCRIPTROOT} must be empty.
266 # - 32 bits shims are not, so ${_LDSCRIPTROOT} is used to specify their full
267 #   path.  Note that ld(1) scripts are generated both during buildworld and
268 #   installworld; in the later case ${_LDSCRIPTROOT} must be obviously empty.
269 # On the other hand, the use of ${_SHLIBDIRPREFIX} is more consistent since it
270 # does not involve the logic of a tool we do not own.
271 .if defined(SHLIB_LDSCRIPT) && !empty(SHLIB_LDSCRIPT) && exists(${.CURDIR}/${SHLIB_LDSCRIPT})
272         sed -e 's,@@SHLIB@@,${_LDSCRIPTROOT}${SHLIBDIR}/${SHLIB_NAME},g' \
273             -e 's,@@LIBDIR@@,${_LDSCRIPTROOT}${LIBDIR},g' \
274             ${.CURDIR}/${SHLIB_LDSCRIPT} > lib${LIB}.ld
275         ${INSTALL} -S -C -o ${LIBOWN} -g ${LIBGRP} -m ${LIBMODE} \
276             ${_INSTALLFLAGS} lib${LIB}.ld ${DESTDIR}${LIBDIR}/${SHLIB_LINK}
277 .else
278 .if ${SHLIBDIR} == ${LIBDIR}
279         ln -fs ${SHLIB_NAME} ${DESTDIR}${LIBDIR}/${SHLIB_LINK}
280 .else
281         ln -fs ${_SHLIBDIRPREFIX}${SHLIBDIR}/${SHLIB_NAME} \
282             ${DESTDIR}${LIBDIR}/${SHLIB_LINK}
283 .if exists(${DESTDIR}${LIBDIR}/${SHLIB_NAME})
284         -chflags noschg ${DESTDIR}${LIBDIR}/${SHLIB_NAME}
285         rm -f ${DESTDIR}${LIBDIR}/${SHLIB_NAME}
286 .endif
287 .endif
288 .endif # SHLIB_LDSCRIPT
289 .endif # SHLIB_LINK
290 .endif # SHIB_NAME
291 .if defined(INSTALL_PIC_ARCHIVE) && defined(LIB) && !empty(LIB) && ${MK_TOOLCHAIN} != "no"
292         ${INSTALL} -o ${LIBOWN} -g ${LIBGRP} -m ${LIBMODE} \
293             ${_INSTALLFLAGS} lib${LIB}_pic.a ${DESTDIR}${LIBDIR}
294 .endif
295 .if defined(WANT_LINT) && !defined(NO_LINT) && defined(LIB) && !empty(LIB)
296         ${INSTALL} -o ${LIBOWN} -g ${LIBGRP} -m ${LIBMODE} \
297             ${_INSTALLFLAGS} ${LINTLIB} ${DESTDIR}${LINTLIBDIR}
298 .endif
299 .endif # !defined(INTERNALLIB)
300
301 .include <bsd.nls.mk>
302 .include <bsd.files.mk>
303 .include <bsd.incs.mk>
304 .include <bsd.links.mk>
305
306 .if ${MK_MAN} != "no"
307 realinstall: _maninstall
308 .ORDER: beforeinstall _maninstall
309 .endif
310
311 .endif
312
313 .if !target(lint)
314 lint: ${SRCS:M*.c}
315         ${LINT} ${LINTFLAGS} ${CFLAGS:M-[DIU]*} ${.ALLSRC}
316 .endif
317
318 .if ${MK_MAN} != "no"
319 .include <bsd.man.mk>
320 .endif
321
322 .include <bsd.dep.mk>
323
324 .if !exists(${.OBJDIR}/${DEPENDFILE})
325 .if defined(LIB) && !empty(LIB)
326 ${OBJS} ${STATICOBJS} ${POBJS}: ${SRCS:M*.h}
327 .for _S in ${SRCS:N*.[hly]}
328 ${_S:R}.po: ${_S}
329 .endfor
330 .endif
331 .if defined(SHLIB_NAME) || \
332     defined(INSTALL_PIC_ARCHIVE) && defined(LIB) && !empty(LIB)
333 ${SOBJS}: ${SRCS:M*.h}
334 .for _S in ${SRCS:N*.[hly]}
335 ${_S:R}.So: ${_S}
336 .endfor
337 .endif
338 .endif
339
340 .if !target(clean)
341 clean:
342 .if defined(CLEANFILES) && !empty(CLEANFILES)
343         rm -f ${CLEANFILES}
344 .endif
345 .if defined(LIB) && !empty(LIB)
346         rm -f a.out ${OBJS} ${OBJS:S/$/.tmp/} ${STATICOBJS}
347 .endif
348 .if !defined(INTERNALLIB)
349 .if ${MK_PROFILE} != "no" && defined(LIB) && !empty(LIB)
350         rm -f ${POBJS} ${POBJS:S/$/.tmp/}
351 .endif
352 .if defined(SHLIB_NAME) || \
353     defined(INSTALL_PIC_ARCHIVE) && defined(LIB) && !empty(LIB)
354         rm -f ${SOBJS} ${SOBJS:.So=.so} ${SOBJS:S/$/.tmp/}
355 .endif
356 .if defined(SHLIB_NAME)
357 .if defined(SHLIB_LINK)
358 .if defined(SHLIB_LDSCRIPT) && exists(${.CURDIR}/${SHLIB_LDSCRIPT})
359         rm -f lib${LIB}.ld
360 .endif
361         rm -f ${SHLIB_LINK}
362 .endif
363 .if defined(LIB) && !empty(LIB)
364         rm -f lib${LIB}.so.* lib${LIB}.so
365 .endif
366 .endif
367 .if defined(WANT_LINT) && defined(LIB) && !empty(LIB)
368         rm -f ${LINTOBJS}
369 .endif
370 .endif # !defined(INTERNALLIB)
371 .if defined(_LIBS) && !empty(_LIBS)
372         rm -f ${_LIBS}
373 .endif
374 .if defined(CLEANDIRS) && !empty(CLEANDIRS)
375         rm -rf ${CLEANDIRS}
376 .endif
377 .if !empty(VERSION_DEF) && !empty(SYMBOL_MAPS)
378         rm -f ${VERSION_MAP}
379 .endif
380 .endif
381
382 .include <bsd.obj.mk>
383
384 .include <bsd.sys.mk>