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