bsd.lib.mk revision 125119
1155192Srwatson# from: @(#)bsd.lib.mk 5.26 (Berkeley) 5/2/91 2155192Srwatson# $FreeBSD: head/share/mk/bsd.lib.mk 125119 2004-01-27 23:22:15Z ru $ 3155192Srwatson# 4155192Srwatson 5155192Srwatson.include <bsd.init.mk> 6155192Srwatson 7155192Srwatson# Set up the variables controlling shared libraries. After this section, 8155192Srwatson# SHLIB_NAME will be defined only if we are to create a shared library. 9155192Srwatson# SHLIB_LINK will be defined only if we are to create a link to it. 10155192Srwatson# INSTALL_PIC_ARCHIVE will be defined only if we are to create a PIC archive. 11155192Srwatson.if defined(NOPIC) 12155192Srwatson.undef SHLIB_NAME 13155192Srwatson.undef INSTALL_PIC_ARCHIVE 14155192Srwatson.else 15155192Srwatson.if !defined(SHLIB_NAME) && defined(LIB) && defined(SHLIB_MAJOR) 16155192SrwatsonSHLIB_NAME= lib${LIB}.so.${SHLIB_MAJOR} 17155192Srwatson.endif 18155192Srwatson.if defined(SHLIB_NAME) && !empty(SHLIB_NAME:M*.so.*) 19155192SrwatsonSHLIB_LINK?= ${SHLIB_NAME:R} 20155192Srwatson.endif 21155192SrwatsonSONAME?= ${SHLIB_NAME} 22155192Srwatson.endif 23155192Srwatson 24155192Srwatson.if defined(CRUNCH_CFLAGS) 25155192SrwatsonCFLAGS+= ${CRUNCH_CFLAGS} 26155192Srwatson.endif 27155192Srwatson 28155192Srwatson.if defined(DEBUG_FLAGS) 29155192SrwatsonCFLAGS+= ${DEBUG_FLAGS} 30155192Srwatson.endif 31155192Srwatson 32155192Srwatson.if !defined(DEBUG_FLAGS) 33155192SrwatsonSTRIP?= -s 34155192Srwatson.endif 35155192Srwatson 36155192Srwatson.include <bsd.libnames.mk> 37155192Srwatson 38155192Srwatson# prefer .s to a .c, add .po, remove stuff not used in the BSD libraries 39155192Srwatson# .So used for PIC object files 40155192Srwatson.SUFFIXES: 41155192Srwatson.SUFFIXES: .out .o .po .So .S .asm .s .c .cc .cpp .cxx .m .C .f .y .l .ln 42155192Srwatson 43155192Srwatson.if !defined(PICFLAG) 44155192Srwatson.if ${MACHINE_ARCH} == "sparc64" 45155192SrwatsonPICFLAG=-fPIC 46155192Srwatson.else 47155192SrwatsonPICFLAG=-fpic 48155192Srwatson.endif 49155192Srwatson.endif 50155192Srwatson 51155192Srwatson.c.po: 52155192Srwatson ${CC} -pg ${CFLAGS} -c ${.IMPSRC} -o ${.TARGET} 53155192Srwatson 54155192Srwatson.c.So: 55155192Srwatson ${CC} ${PICFLAG} -DPIC ${CFLAGS} -c ${.IMPSRC} -o ${.TARGET} 56155192Srwatson 57155192Srwatson.cc.po .C.po .cpp.po .cxx.po: 58155192Srwatson ${CXX} -pg ${CXXFLAGS} -c ${.IMPSRC} -o ${.TARGET} 59155192Srwatson 60155192Srwatson.cc.So .C.So .cpp.So .cxx.So: 61155192Srwatson ${CXX} ${PICFLAG} -DPIC ${CXXFLAGS} -c ${.IMPSRC} -o ${.TARGET} 62155192Srwatson 63155192Srwatson.f.po: 64155192Srwatson ${FC} -pg ${FFLAGS} -o ${.TARGET} -c ${.IMPSRC} 65155192Srwatson 66156889Srwatson.f.So: 67156889Srwatson ${FC} ${PICFLAG} -DPIC ${FFLAGS} -o ${.TARGET} -c ${.IMPSRC} 68155192Srwatson 69155192Srwatson.m.po: 70155192Srwatson ${OBJC} ${OBJCFLAGS} -pg -c ${.IMPSRC} -o ${.TARGET} 71155192Srwatson 72155192Srwatson.m.So: 73155192Srwatson ${OBJC} ${PICFLAG} -DPIC ${OBJCFLAGS} -c ${.IMPSRC} -o ${.TARGET} 74155192Srwatson 75155192Srwatson.s.po .s.So: 76155192Srwatson ${AS} ${AFLAGS} -o ${.TARGET} ${.IMPSRC} 77155192Srwatson 78155192Srwatson.asm.po: 79155192Srwatson ${CC} -x assembler-with-cpp -DPROF ${CFLAGS} -c ${.IMPSRC} -o ${.TARGET} 80155192Srwatson 81155192Srwatson.asm.So: 82155192Srwatson ${CC} -x assembler-with-cpp ${PICFLAG} -DPIC ${CFLAGS} \ 83155192Srwatson -c ${.IMPSRC} -o ${.TARGET} 84155192Srwatson 85155192Srwatson.S.po: 86155192Srwatson ${CC} -DPROF ${CFLAGS} -c ${.IMPSRC} -o ${.TARGET} 87155192Srwatson 88155192Srwatson.S.So: 89155192Srwatson ${CC} ${PICFLAG} -DPIC ${CFLAGS} -c ${.IMPSRC} -o ${.TARGET} 90155192Srwatson 91155192Srwatsonall: objwarn 92155192Srwatson 93156889Srwatson.if defined(LIB) && !empty(LIB) || defined(SHLIB_NAME) 94155192SrwatsonOBJS+= ${SRCS:N*.h:R:S/$/.o/} 95155192Srwatson.endif 96156889Srwatson 97155192Srwatson.if defined(LIB) && !empty(LIB) 98156889Srwatson_LIBS= lib${LIB}.a 99155192Srwatson 100155192Srwatsonlib${LIB}.a: ${OBJS} ${STATICOBJS} 101156889Srwatson @${ECHO} building static ${LIB} library 102155192Srwatson @rm -f ${.TARGET} 103155192Srwatson @${AR} cq ${.TARGET} `lorder ${OBJS} ${STATICOBJS} | tsort -q` ${ARADD} 104155192Srwatson ${RANLIB} ${.TARGET} 105155192Srwatson.endif 106155192Srwatson 107155192Srwatson.if !defined(INTERNALLIB) 108155192Srwatson 109155192Srwatson.if !defined(NOPROFILE) && defined(LIB) && !empty(LIB) 110155192Srwatson_LIBS+= lib${LIB}_p.a 111155192SrwatsonPOBJS+= ${OBJS:.o=.po} ${STATICOBJS:.o=.po} 112155192Srwatson 113155192Srwatsonlib${LIB}_p.a: ${POBJS} 114155192Srwatson @${ECHO} building profiled ${LIB} library 115155192Srwatson @rm -f ${.TARGET} 116155192Srwatson @${AR} cq ${.TARGET} `lorder ${POBJS} | tsort -q` ${ARADD} 117155192Srwatson ${RANLIB} ${.TARGET} 118155192Srwatson.endif 119155192Srwatson 120155192Srwatson.if defined(SHLIB_NAME) || \ 121155192Srwatson defined(INSTALL_PIC_ARCHIVE) && defined(LIB) && !empty(LIB) 122155192SrwatsonSOBJS+= ${OBJS:.o=.So} 123155192Srwatson.endif 124155192Srwatson 125155192Srwatson.if defined(SHLIB_NAME) 126155192Srwatson_LIBS+= ${SHLIB_NAME} 127155192Srwatson 128155192Srwatson${SHLIB_NAME}: ${SOBJS} 129155192Srwatson @${ECHO} building shared library ${SHLIB_NAME} 130156889Srwatson @rm -f ${.TARGET} ${SHLIB_LINK} 131155192Srwatson.if defined(SHLIB_LINK) 132155192Srwatson @ln -fs ${.TARGET} ${SHLIB_LINK} 133155192Srwatson.endif 134155192Srwatson @${CC} ${LDFLAGS} -shared -Wl,-x \ 135155192Srwatson -o ${.TARGET} -Wl,-soname,${SONAME} \ 136155192Srwatson `lorder ${SOBJS} | tsort -q` ${LDADD} 137155192Srwatson.endif 138155192Srwatson 139155192Srwatson.if defined(INSTALL_PIC_ARCHIVE) && defined(LIB) && !empty(LIB) 140155192Srwatson_LIBS+= lib${LIB}_pic.a 141155192Srwatson 142155192Srwatsonlib${LIB}_pic.a: ${SOBJS} 143155192Srwatson @${ECHO} building special pic ${LIB} library 144155192Srwatson @rm -f ${.TARGET} 145156889Srwatson @${AR} cq ${.TARGET} ${SOBJS} ${ARADD} 146155192Srwatson ${RANLIB} ${.TARGET} 147155192Srwatson.endif 148155192Srwatson 149155192Srwatson.if defined(WANT_LINT) && !defined(NOLINT) && defined(LIB) && !empty(LIB) 150155192SrwatsonLINTLIB= llib-l${LIB}.ln 151155192Srwatson_LIBS+= ${LINTLIB} 152155192SrwatsonLINTOBJS+= ${SRCS:M*.c:.c=.ln} 153155192Srwatson 154155192Srwatson${LINTLIB}: ${LINTOBJS} 155155192Srwatson @${ECHO} building lint library ${.TARGET} 156155192Srwatson @rm -f ${.TARGET} 157155192Srwatson ${LINT} ${LINTLIBFLAGS} ${CFLAGS:M-[DIU]*} ${.ALLSRC} 158155192Srwatson.endif 159155192Srwatson 160155192Srwatson.endif !defined(INTERNALLIB) 161155192Srwatson 162155192Srwatsonall: ${_LIBS} 163155192Srwatson 164155192Srwatson.if !defined(NOMAN) 165155192Srwatsonall: _manpages 166155192Srwatson.endif 167156889Srwatson 168155192Srwatson_EXTRADEPEND: 169155192Srwatson @TMP=_depend$$$$; \ 170155192Srwatson sed -e 's/^\([^\.]*\).o[ ]*:/\1.o \1.po \1.So:/' < ${DEPENDFILE} \ 171155192Srwatson > $$TMP; \ 172156889Srwatson mv $$TMP ${DEPENDFILE} 173155192Srwatson.if !defined(NOEXTRADEPEND) && defined(SHLIB_NAME) 174155192Srwatson.if defined(DPADD) && !empty(DPADD) 175156889Srwatson echo ${SHLIB_NAME}: ${DPADD} >> ${DEPENDFILE} 176155192Srwatson.endif 177155192Srwatson.endif 178156889Srwatson 179155192Srwatson.if !target(install) 180155192Srwatson 181155192Srwatson.if defined(PRECIOUSLIB) && !defined(NOFSCHG) 182155192SrwatsonSHLINSTALLFLAGS+= -fschg 183156889Srwatson.endif 184155192Srwatson 185155192Srwatson_INSTALLFLAGS:= ${INSTALLFLAGS} 186155192Srwatson.for ie in ${INSTALLFLAGS_EDIT} 187155192Srwatson_INSTALLFLAGS:= ${_INSTALLFLAGS${ie}} 188155192Srwatson.endfor 189155192Srwatson_SHLINSTALLFLAGS:= ${SHLINSTALLFLAGS} 190156889Srwatson.for ie in ${INSTALLFLAGS_EDIT} 191155192Srwatson_SHLINSTALLFLAGS:= ${_SHLINSTALLFLAGS${ie}} 192155192Srwatson.endfor 193155192Srwatson 194155192Srwatson.if !defined(INTERNALLIB) 195155192Srwatsonrealinstall: _libinstall 196155192Srwatson.ORDER: beforeinstall _libinstall 197155192Srwatson_libinstall: 198155192Srwatson.if defined(LIB) && !empty(LIB) && !defined(NOINSTALLLIB) 199155192Srwatson ${INSTALL} -C -o ${LIBOWN} -g ${LIBGRP} -m ${LIBMODE} \ 200155192Srwatson ${_INSTALLFLAGS} lib${LIB}.a ${DESTDIR}${LIBDIR} 201155192Srwatson.endif 202155192Srwatson.if !defined(NOPROFILE) && defined(LIB) && !empty(LIB) 203155192Srwatson ${INSTALL} -C -o ${LIBOWN} -g ${LIBGRP} -m ${LIBMODE} \ 204155192Srwatson ${_INSTALLFLAGS} lib${LIB}_p.a ${DESTDIR}${LIBDIR} 205155192Srwatson.endif 206155192Srwatson.if defined(SHLIB_NAME) 207155192Srwatson ${INSTALL} ${STRIP} -o ${LIBOWN} -g ${LIBGRP} -m ${LIBMODE} \ 208155192Srwatson ${_INSTALLFLAGS} ${_SHLINSTALLFLAGS} \ 209155192Srwatson ${SHLIB_NAME} ${DESTDIR}${SHLIBDIR} 210155192Srwatson.if defined(SHLIB_LINK) 211155192Srwatson.if ${SHLIBDIR} == ${LIBDIR} 212155192Srwatson ln -fs ${SHLIB_NAME} ${DESTDIR}${LIBDIR}/${SHLIB_LINK} 213155192Srwatson.else 214155192Srwatson ln -fs ${_SHLIBDIRPREFIX}${SHLIBDIR}/${SHLIB_NAME} \ 215155192Srwatson ${DESTDIR}${LIBDIR}/${SHLIB_LINK} 216155192Srwatson.if exists(${DESTDIR}${LIBDIR}/${SHLIB_NAME}) 217155192Srwatson -chflags noschg ${DESTDIR}${LIBDIR}/${SHLIB_NAME} 218155192Srwatson rm -f ${DESTDIR}${LIBDIR}/${SHLIB_NAME} 219155192Srwatson.endif 220155192Srwatson.endif 221155192Srwatson.endif 222155192Srwatson.endif 223155192Srwatson.if defined(INSTALL_PIC_ARCHIVE) && defined(LIB) && !empty(LIB) 224155192Srwatson ${INSTALL} -o ${LIBOWN} -g ${LIBGRP} -m ${LIBMODE} \ 225155192Srwatson ${_INSTALLFLAGS} lib${LIB}_pic.a ${DESTDIR}${LIBDIR} 226155192Srwatson.endif 227155192Srwatson.if defined(WANT_LINT) && !defined(NOLINT) && defined(LIB) && !empty(LIB) 228155192Srwatson ${INSTALL} -o ${LIBOWN} -g ${LIBGRP} -m ${LIBMODE} \ 229155192Srwatson ${_INSTALLFLAGS} ${LINTLIB} ${DESTDIR}${LINTLIBDIR} 230155192Srwatson.endif 231155192Srwatson.endif !defined(INTERNALLIB) 232155192Srwatson 233155192Srwatson.include <bsd.files.mk> 234155192Srwatson.include <bsd.incs.mk> 235155192Srwatson.include <bsd.links.mk> 236155192Srwatson 237155192Srwatson.if !defined(NOMAN) 238155192Srwatsonrealinstall: _maninstall 239155192Srwatson.ORDER: beforeinstall _maninstall 240155192Srwatson.endif 241155192Srwatson 242155192Srwatson.endif 243155192Srwatson 244156889Srwatson.if !target(lint) 245155192Srwatsonlint: ${SRCS:M*.c} 246155192Srwatson ${LINT} ${LINTFLAGS} ${CFLAGS:M-[DIU]*} ${.ALLSRC} 247155192Srwatson.endif 248156889Srwatson 249156889Srwatson.if !defined(NOMAN) 250155192Srwatson.include <bsd.man.mk> 251155192Srwatson.endif 252156889Srwatson 253156889Srwatson.include <bsd.dep.mk> 254156889Srwatson 255155192Srwatson.if !exists(${.OBJDIR}/${DEPENDFILE}) 256155192Srwatson.if defined(LIB) && !empty(LIB) 257155192Srwatson${OBJS} ${STATICOBJS} ${POBJS}: ${SRCS:M*.h} 258155192Srwatson.for _S in ${SRCS:N*.[hly]} 259155192Srwatson${_S:R}.po: ${_S} 260155192Srwatson.endfor 261155192Srwatson.endif 262155192Srwatson.if defined(SHLIB_NAME) || \ 263155192Srwatson defined(INSTALL_PIC_ARCHIVE) && defined(LIB) && !empty(LIB) 264155192Srwatson${SOBJS}: ${SRCS:M*.h} 265155192Srwatson.for _S in ${SRCS:N*.[hly]} 266155192Srwatson${_S:R}.So: ${_S} 267155192Srwatson.endfor 268155192Srwatson.endif 269155192Srwatson.endif 270155192Srwatson 271155192Srwatson.if !target(clean) 272155192Srwatsonclean: 273155192Srwatson.if defined(CLEANFILES) && !empty(CLEANFILES) 274155192Srwatson rm -f ${CLEANFILES} 275155192Srwatson.endif 276155192Srwatson.if defined(LIB) && !empty(LIB) 277155192Srwatson rm -f a.out ${OBJS} ${OBJS:S/$/.tmp/} ${STATICOBJS} 278155192Srwatson.endif 279155192Srwatson.if !defined(INTERNALLIB) 280155192Srwatson.if !defined(NOPROFILE) && defined(LIB) && !empty(LIB) 281155192Srwatson rm -f ${POBJS} ${POBJS:S/$/.tmp/} 282155192Srwatson.endif 283155192Srwatson.if defined(SHLIB_NAME) || \ 284155192Srwatson defined(INSTALL_PIC_ARCHIVE) && defined(LIB) && !empty(LIB) 285155192Srwatson rm -f ${SOBJS} ${SOBJS:.So=.so} ${SOBJS:S/$/.tmp/} 286155192Srwatson.endif 287155192Srwatson.if defined(SHLIB_NAME) 288155192Srwatson.if defined(SHLIB_LINK) 289155192Srwatson rm -f ${SHLIB_LINK} 290155192Srwatson.endif 291155192Srwatson.if defined(LIB) && !empty(LIB) 292155192Srwatson rm -f lib${LIB}.so.* lib${LIB}.so 293155192Srwatson.endif 294155192Srwatson.endif 295155192Srwatson.if defined(WANT_LINT) && defined(LIB) && !empty(LIB) 296155192Srwatson rm -f ${LINTOBJS} 297155192Srwatson.endif 298155192Srwatson.endif !defined(INTERNALLIB) 299155192Srwatson.if defined(_LIBS) && !empty(_LIBS) 300155192Srwatson rm -f ${_LIBS} 301155192Srwatson.endif 302155192Srwatson.if defined(CLEANDIRS) && !empty(CLEANDIRS) 303155192Srwatson rm -rf ${CLEANDIRS} 304155192Srwatson.endif 305155192Srwatson.endif 306155192Srwatson 307155192Srwatson.include <bsd.obj.mk> 308155192Srwatson 309155192Srwatson.include <bsd.sys.mk> 310155192Srwatson