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