1 # from: @(#)bsd.lib.mk 5.26 (Berkeley) 5/2/91
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.
13 .undef INSTALL_PIC_ARCHIVE
15 .if !defined(SHLIB) && defined(LIB)
18 .if !defined(SHLIB_NAME) && defined(SHLIB) && defined(SHLIB_MAJOR)
19 SHLIB_NAME= lib${SHLIB}.so.${SHLIB_MAJOR}
21 .if defined(SHLIB_NAME) && !empty(SHLIB_NAME:M*.so.*)
22 SHLIB_LINK?= ${SHLIB_NAME:R}
24 SONAME?= ${SHLIB_NAME}
27 .if defined(CRUNCH_CFLAGS)
28 CFLAGS+= ${CRUNCH_CFLAGS}
31 .if ${MK_ASSERT_DEBUG} == "no"
36 .if defined(DEBUG_FLAGS)
37 CFLAGS+= ${DEBUG_FLAGS}
39 .if ${MK_CTF} != "no" && ${DEBUG_FLAGS:M-g} != ""
46 .include <bsd.libnames.mk>
48 # prefer .s to a .c, add .po, remove stuff not used in the BSD libraries
49 # .So used for PIC object files
51 .SUFFIXES: .out .o .po .So .S .asm .s .c .cc .cpp .cxx .C .f .y .l .ln
54 .if ${MACHINE_CPUARCH} == "sparc64"
64 ${CC} ${STATIC_CFLAGS} ${CFLAGS} -c ${.IMPSRC} -o ${.TARGET}
68 ${CC} ${PO_FLAG} ${STATIC_CFLAGS} ${PO_CFLAGS} -c ${.IMPSRC} -o ${.TARGET}
72 ${CC} ${PICFLAG} -DPIC ${SHARED_CFLAGS} ${CFLAGS} -c ${.IMPSRC} -o ${.TARGET}
75 .cc.o .C.o .cpp.o .cxx.o:
76 ${CXX} ${STATIC_CXXFLAGS} ${CXXFLAGS} -c ${.IMPSRC} -o ${.TARGET}
78 .cc.po .C.po .cpp.po .cxx.po:
79 ${CXX} ${PO_FLAG} ${STATIC_CXXFLAGS} ${PO_CXXFLAGS} -c ${.IMPSRC} -o ${.TARGET}
81 .cc.So .C.So .cpp.So .cxx.So:
82 ${CXX} ${PICFLAG} -DPIC ${SHARED_CXXFLAGS} ${CXXFLAGS} -c ${.IMPSRC} -o ${.TARGET}
85 ${FC} -pg ${FFLAGS} -o ${.TARGET} -c ${.IMPSRC}
89 ${FC} ${PICFLAG} -DPIC ${FFLAGS} -o ${.TARGET} -c ${.IMPSRC}
93 ${AS} ${AFLAGS} -o ${.TARGET} ${.IMPSRC}
97 ${CC} -x assembler-with-cpp -DPROF ${PO_CFLAGS} ${ACFLAGS} \
98 -c ${.IMPSRC} -o ${.TARGET}
102 ${CC} -x assembler-with-cpp ${PICFLAG} -DPIC ${CFLAGS} ${ACFLAGS} \
103 -c ${.IMPSRC} -o ${.TARGET}
107 ${CC} -DPROF ${PO_CFLAGS} ${ACFLAGS} -c ${.IMPSRC} -o ${.TARGET}
111 ${CC} ${PICFLAG} -DPIC ${CFLAGS} ${ACFLAGS} -c ${.IMPSRC} -o ${.TARGET}
116 .include <bsd.symver.mk>
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}
125 .if defined(LIB) && !empty(LIB) || defined(SHLIB_NAME)
126 OBJS+= ${SRCS:N*.h:R:S/$/.o/}
129 .if defined(LIB) && !empty(LIB)
132 lib${LIB}.a: ${OBJS} ${STATICOBJS}
133 @${ECHO} building static ${LIB} library
136 @${AR} cq ${.TARGET} `lorder ${OBJS} ${STATICOBJS} | tsort -q` ${ARADD}
138 @${AR} cq ${.TARGET} `NM='${NM}' lorder ${OBJS} ${STATICOBJS} | tsort -q` ${ARADD}
143 .if !defined(INTERNALLIB)
145 .if ${MK_PROFILE} != "no" && defined(LIB) && !empty(LIB)
146 _LIBS+= lib${LIB}_p.a
147 POBJS+= ${OBJS:.o=.po} ${STATICOBJS:.o=.po}
149 lib${LIB}_p.a: ${POBJS}
150 @${ECHO} building profiled ${LIB} library
153 @${AR} cq ${.TARGET} `lorder ${POBJS} | tsort -q` ${ARADD}
155 @${AR} cq ${.TARGET} `NM='${NM}' lorder ${POBJS} | tsort -q` ${ARADD}
160 .if defined(SHLIB_NAME) || \
161 defined(INSTALL_PIC_ARCHIVE) && defined(LIB) && !empty(LIB)
162 SOBJS+= ${OBJS:.o=.So}
165 .if defined(SHLIB_NAME)
166 _LIBS+= ${SHLIB_NAME}
168 SOLINKOPTS= -shared -Wl,-x
169 .if !defined(ALLOW_SHARED_TEXTREL)
170 SOLINKOPTS+= -Wl,--fatal-warnings -Wl,--warn-shared-textrel
173 .if target(beforelinking)
174 ${SHLIB_NAME}: beforelinking
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}
183 @${CC} ${LDFLAGS} ${SSP_CFLAGS} ${SOLINKOPTS} \
184 -o ${.TARGET} -Wl,-soname,${SONAME} \
185 `lorder ${SOBJS} | tsort -q` ${LDADD}
187 @${CC} ${LDFLAGS} ${SSP_CFLAGS} ${SOLINKOPTS} \
188 -o ${.TARGET} -Wl,-soname,${SONAME} \
189 `NM='${NM}' lorder ${SOBJS} | tsort -q` ${LDADD}
191 .if ${MK_CTF} != "no"
192 ${CTFMERGE} ${CTFFLAGS} -o ${.TARGET} ${SOBJS}
196 .if defined(INSTALL_PIC_ARCHIVE) && defined(LIB) && !empty(LIB) && ${MK_TOOLCHAIN} != "no"
197 _LIBS+= lib${LIB}_pic.a
199 lib${LIB}_pic.a: ${SOBJS}
200 @${ECHO} building special pic ${LIB} library
202 @${AR} cq ${.TARGET} ${SOBJS} ${ARADD}
206 .if defined(WANT_LINT) && !defined(NO_LINT) && defined(LIB) && !empty(LIB)
207 LINTLIB= llib-l${LIB}.ln
209 LINTOBJS+= ${SRCS:M*.c:.c=.ln}
211 ${LINTLIB}: ${LINTOBJS}
212 @${ECHO} building lint library ${.TARGET}
214 ${LINT} ${LINTLIBFLAGS} ${CFLAGS:M-[DIU]*} ${.ALLSRC}
217 .endif # !defined(INTERNALLIB)
221 .if ${MK_MAN} != "no"
227 sed -e 's/^\([^\.]*\).o[ ]*:/\1.o \1.po \1.So:/' < ${DEPENDFILE} \
229 mv $$TMP ${DEPENDFILE}
230 .if !defined(NO_EXTRADEPEND) && defined(SHLIB_NAME)
231 .if defined(DPADD) && !empty(DPADD)
232 echo ${SHLIB_NAME}: ${DPADD} >> ${DEPENDFILE}
238 .if defined(PRECIOUSLIB)
239 .if !defined(NO_FSCHG)
240 SHLINSTALLFLAGS+= -fschg
245 _INSTALLFLAGS:= ${INSTALLFLAGS}
246 .for ie in ${INSTALLFLAGS_EDIT}
247 _INSTALLFLAGS:= ${_INSTALLFLAGS${ie}}
249 _SHLINSTALLFLAGS:= ${SHLINSTALLFLAGS}
250 .for ie in ${INSTALLFLAGS_EDIT}
251 _SHLINSTALLFLAGS:= ${_SHLINSTALLFLAGS${ie}}
254 .if !defined(INTERNALLIB)
255 realinstall: _libinstall
256 .ORDER: beforeinstall _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}
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}
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.
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}
295 .if ${SHLIBDIR} == ${LIBDIR}
296 ${INSTALL_SYMLINK} ${SHLIB_NAME} ${DESTDIR}${LIBDIR}/${SHLIB_LINK}
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}
305 .endif # SHLIB_LDSCRIPT
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}
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}
316 .endif # !defined(INTERNALLIB)
318 .if !defined(LIBRARIES_ONLY)
319 .include <bsd.nls.mk>
320 .include <bsd.files.mk>
321 .include <bsd.incs.mk>
324 .include <bsd.links.mk>
326 .if ${MK_MAN} != "no" && !defined(LIBRARIES_ONLY)
327 realinstall: _maninstall
328 .ORDER: beforeinstall _maninstall
335 ${LINT} ${LINTFLAGS} ${CFLAGS:M-[DIU]*} ${.ALLSRC}
338 .if ${MK_MAN} != "no" && !defined(LIBRARIES_ONLY)
339 .include <bsd.man.mk>
342 .include <bsd.dep.mk>
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]}
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]}
362 .if defined(CLEANFILES) && !empty(CLEANFILES)
365 .if defined(LIB) && !empty(LIB)
366 rm -f a.out ${OBJS} ${OBJS:S/$/.tmp/} ${STATICOBJS}
368 .if !defined(INTERNALLIB)
369 .if ${MK_PROFILE} != "no" && defined(LIB) && !empty(LIB)
370 rm -f ${POBJS} ${POBJS:S/$/.tmp/}
372 .if defined(SHLIB_NAME) || \
373 defined(INSTALL_PIC_ARCHIVE) && defined(LIB) && !empty(LIB)
374 rm -f ${SOBJS} ${SOBJS:.So=.so} ${SOBJS:S/$/.tmp/}
376 .if defined(SHLIB_NAME)
377 .if defined(SHLIB_LINK)
378 .if defined(SHLIB_LDSCRIPT) && exists(${.CURDIR}/${SHLIB_LDSCRIPT})
383 .if defined(LIB) && !empty(LIB)
384 rm -f lib${LIB}.so.* lib${LIB}.so
387 .if defined(WANT_LINT) && defined(LIB) && !empty(LIB)
390 .endif # !defined(INTERNALLIB)
391 .if defined(_LIBS) && !empty(_LIBS)
394 .if defined(CLEANDIRS) && !empty(CLEANDIRS)
397 .if !empty(VERSION_DEF) && !empty(SYMBOL_MAPS)
402 .include <bsd.obj.mk>
404 .include <bsd.sys.mk>