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} != ""
44 .if !defined(DEBUG_FLAGS)
48 .include <bsd.libnames.mk>
50 # prefer .s to a .c, add .po, remove stuff not used in the BSD libraries
51 # .So used for PIC object files
53 .SUFFIXES: .out .o .po .So .S .asm .s .c .cc .cpp .cxx .m .C .f .y .l .ln
56 .if ${MACHINE_ARCH} == "sparc64"
70 ${CC} ${PO_FLAG} ${CFLAGS} -c ${.IMPSRC} -o ${.TARGET}
74 ${CC} ${PICFLAG} -DPIC ${CFLAGS} -c ${.IMPSRC} -o ${.TARGET}
77 .cc.po .C.po .cpp.po .cxx.po:
78 ${CXX} ${PO_FLAG} ${CXXFLAGS} -c ${.IMPSRC} -o ${.TARGET}
80 .cc.So .C.So .cpp.So .cxx.So:
81 ${CXX} ${PICFLAG} -DPIC ${CXXFLAGS} -c ${.IMPSRC} -o ${.TARGET}
84 ${FC} -pg ${FFLAGS} -o ${.TARGET} -c ${.IMPSRC}
88 ${FC} ${PICFLAG} -DPIC ${FFLAGS} -o ${.TARGET} -c ${.IMPSRC}
92 ${OBJC} ${OBJCFLAGS} -pg -c ${.IMPSRC} -o ${.TARGET}
96 ${OBJC} ${PICFLAG} -DPIC ${OBJCFLAGS} -c ${.IMPSRC} -o ${.TARGET}
100 ${AS} ${AFLAGS} -o ${.TARGET} ${.IMPSRC}
104 ${CC} -x assembler-with-cpp -DPROF ${CFLAGS} -c ${.IMPSRC} -o ${.TARGET}
108 ${CC} -x assembler-with-cpp ${PICFLAG} -DPIC ${CFLAGS} \
109 -c ${.IMPSRC} -o ${.TARGET}
113 ${CC} -DPROF ${CFLAGS} -c ${.IMPSRC} -o ${.TARGET}
117 ${CC} ${PICFLAG} -DPIC ${CFLAGS} -c ${.IMPSRC} -o ${.TARGET}
122 .include <bsd.symver.mk>
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}
131 .if defined(LIB) && !empty(LIB) || defined(SHLIB_NAME)
132 OBJS+= ${SRCS:N*.h:R:S/$/.o/}
135 .if defined(LIB) && !empty(LIB)
138 lib${LIB}.a: ${OBJS} ${STATICOBJS}
139 @${ECHO} building static ${LIB} library
141 @${AR} cq ${.TARGET} `NM='${NM}' lorder ${OBJS} ${STATICOBJS} | tsort -q` ${ARADD}
145 .if !defined(INTERNALLIB)
147 .if ${MK_PROFILE} != "no" && defined(LIB) && !empty(LIB)
148 _LIBS+= lib${LIB}_p.a
149 POBJS+= ${OBJS:.o=.po} ${STATICOBJS:.o=.po}
151 lib${LIB}_p.a: ${POBJS}
152 @${ECHO} building profiled ${LIB} library
154 @${AR} cq ${.TARGET} `NM='${NM}' lorder ${POBJS} | tsort -q` ${ARADD}
158 .if defined(SHLIB_NAME) || \
159 defined(INSTALL_PIC_ARCHIVE) && defined(LIB) && !empty(LIB)
160 SOBJS+= ${OBJS:.o=.So}
163 .if defined(SHLIB_NAME)
164 _LIBS+= ${SHLIB_NAME}
166 .if target(beforelinking)
167 ${SHLIB_NAME}: ${SOBJS} beforelinking
169 ${SHLIB_NAME}: ${SOBJS}
171 @${ECHO} building shared library ${SHLIB_NAME}
172 @rm -f ${.TARGET} ${SHLIB_LINK}
173 .if defined(SHLIB_LINK)
174 @ln -fs ${.TARGET} ${SHLIB_LINK}
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}
184 .if defined(INSTALL_PIC_ARCHIVE) && defined(LIB) && !empty(LIB) && ${MK_TOOLCHAIN} != "no"
185 _LIBS+= lib${LIB}_pic.a
187 lib${LIB}_pic.a: ${SOBJS}
188 @${ECHO} building special pic ${LIB} library
190 @${AR} cq ${.TARGET} ${SOBJS} ${ARADD}
194 .if defined(WANT_LINT) && !defined(NO_LINT) && defined(LIB) && !empty(LIB)
195 LINTLIB= llib-l${LIB}.ln
197 LINTOBJS+= ${SRCS:M*.c:.c=.ln}
199 ${LINTLIB}: ${LINTOBJS}
200 @${ECHO} building lint library ${.TARGET}
202 ${LINT} ${LINTLIBFLAGS} ${CFLAGS:M-[DIU]*} ${.ALLSRC}
205 .endif # !defined(INTERNALLIB)
209 .if ${MK_MAN} != "no"
215 sed -e 's/^\([^\.]*\).o[ ]*:/\1.o \1.po \1.So:/' < ${DEPENDFILE} \
217 mv $$TMP ${DEPENDFILE}
218 .if !defined(NO_EXTRADEPEND) && defined(SHLIB_NAME)
219 .if defined(DPADD) && !empty(DPADD)
220 echo ${SHLIB_NAME}: ${DPADD} >> ${DEPENDFILE}
226 .if defined(PRECIOUSLIB)
227 .if !defined(NO_FSCHG)
228 SHLINSTALLFLAGS+= -fschg
233 _INSTALLFLAGS:= ${INSTALLFLAGS}
234 .for ie in ${INSTALLFLAGS_EDIT}
235 _INSTALLFLAGS:= ${_INSTALLFLAGS${ie}}
237 _SHLINSTALLFLAGS:= ${SHLINSTALLFLAGS}
238 .for ie in ${INSTALLFLAGS_EDIT}
239 _SHLINSTALLFLAGS:= ${_SHLINSTALLFLAGS${ie}}
242 .if !defined(INTERNALLIB)
243 realinstall: _libinstall
244 .ORDER: beforeinstall _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}
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}
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
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}
278 .if ${SHLIBDIR} == ${LIBDIR}
279 ln -fs ${SHLIB_NAME} ${DESTDIR}${LIBDIR}/${SHLIB_LINK}
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}
288 .endif # SHLIB_LDSCRIPT
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}
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}
299 .endif # !defined(INTERNALLIB)
301 .include <bsd.nls.mk>
302 .include <bsd.files.mk>
303 .include <bsd.incs.mk>
304 .include <bsd.links.mk>
306 .if ${MK_MAN} != "no"
307 realinstall: _maninstall
308 .ORDER: beforeinstall _maninstall
315 ${LINT} ${LINTFLAGS} ${CFLAGS:M-[DIU]*} ${.ALLSRC}
318 .if ${MK_MAN} != "no"
319 .include <bsd.man.mk>
322 .include <bsd.dep.mk>
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]}
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]}
342 .if defined(CLEANFILES) && !empty(CLEANFILES)
345 .if defined(LIB) && !empty(LIB)
346 rm -f a.out ${OBJS} ${OBJS:S/$/.tmp/} ${STATICOBJS}
348 .if !defined(INTERNALLIB)
349 .if ${MK_PROFILE} != "no" && defined(LIB) && !empty(LIB)
350 rm -f ${POBJS} ${POBJS:S/$/.tmp/}
352 .if defined(SHLIB_NAME) || \
353 defined(INSTALL_PIC_ARCHIVE) && defined(LIB) && !empty(LIB)
354 rm -f ${SOBJS} ${SOBJS:.So=.so} ${SOBJS:S/$/.tmp/}
356 .if defined(SHLIB_NAME)
357 .if defined(SHLIB_LINK)
358 .if defined(SHLIB_LDSCRIPT) && exists(${.CURDIR}/${SHLIB_LDSCRIPT})
363 .if defined(LIB) && !empty(LIB)
364 rm -f lib${LIB}.so.* lib${LIB}.so
367 .if defined(WANT_LINT) && defined(LIB) && !empty(LIB)
370 .endif # !defined(INTERNALLIB)
371 .if defined(_LIBS) && !empty(_LIBS)
374 .if defined(CLEANDIRS) && !empty(CLEANDIRS)
377 .if !empty(VERSION_DEF) && !empty(SYMBOL_MAPS)
382 .include <bsd.obj.mk>
384 .include <bsd.sys.mk>