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) 16SHLIB= ${LIB} 17.endif 18.if !defined(SHLIB_NAME) && defined(SHLIB) && defined(SHLIB_MAJOR) 19SHLIB_NAME= lib${SHLIB}.so.${SHLIB_MAJOR} 20.endif 21.if defined(SHLIB_NAME) && !empty(SHLIB_NAME:M*.so.*) 22SHLIB_LINK?= ${SHLIB_NAME:R} 23.endif 24SONAME?= ${SHLIB_NAME} 25.endif 26 27.if defined(CRUNCH_CFLAGS) 28CFLAGS+= ${CRUNCH_CFLAGS} 29.endif 30 31.if ${MK_ASSERT_DEBUG} == "no" 32CFLAGS+= -DNDEBUG 33NO_WERROR= 34.endif 35 36.if defined(DEBUG_FLAGS) 37CFLAGS+= ${DEBUG_FLAGS} 38.endif 39 40.if !defined(DEBUG_FLAGS) 41STRIP?= -s 42.endif 43 44.include <bsd.libnames.mk> 45 46# prefer .s to a .c, add .po, remove stuff not used in the BSD libraries 47# .So used for PIC object files 48.SUFFIXES: 49.SUFFIXES: .out .o .po .So .S .asm .s .c .cc .cpp .cxx .m .C .f .y .l .ln 50 51.if !defined(PICFLAG) 52.if ${MACHINE_ARCH} == "sparc64" 53PICFLAG=-fPIC 54.else 55PICFLAG=-fpic 56.endif 57.endif 58 59.if ${CC} == "icc" 60PO_FLAG=-p 61.else 62PO_FLAG=-pg 63.endif 64 65.c.po: 66 ${CC} ${PO_FLAG} ${CFLAGS} -c ${.IMPSRC} -o ${.TARGET} 67 68.c.So: 69 ${CC} ${PICFLAG} -DPIC ${CFLAGS} -c ${.IMPSRC} -o ${.TARGET} 70 71.cc.po .C.po .cpp.po .cxx.po: 72 ${CXX} ${PO_FLAG} ${CXXFLAGS} -c ${.IMPSRC} -o ${.TARGET} 73 74.cc.So .C.So .cpp.So .cxx.So: 75 ${CXX} ${PICFLAG} -DPIC ${CXXFLAGS} -c ${.IMPSRC} -o ${.TARGET} 76 77.f.po: 78 ${FC} -pg ${FFLAGS} -o ${.TARGET} -c ${.IMPSRC} 79 80.f.So: 81 ${FC} ${PICFLAG} -DPIC ${FFLAGS} -o ${.TARGET} -c ${.IMPSRC} 82 83.m.po: 84 ${OBJC} ${OBJCFLAGS} -pg -c ${.IMPSRC} -o ${.TARGET} 85 86.m.So: 87 ${OBJC} ${PICFLAG} -DPIC ${OBJCFLAGS} -c ${.IMPSRC} -o ${.TARGET} 88 89.s.po .s.So: 90 ${AS} ${AFLAGS} -o ${.TARGET} ${.IMPSRC} 91 92.asm.po: 93 ${CC} -x assembler-with-cpp -DPROF ${CFLAGS} -c ${.IMPSRC} -o ${.TARGET} 94 95.asm.So: 96 ${CC} -x assembler-with-cpp ${PICFLAG} -DPIC ${CFLAGS} \ 97 -c ${.IMPSRC} -o ${.TARGET} 98 99.S.po: 100 ${CC} -DPROF ${CFLAGS} -c ${.IMPSRC} -o ${.TARGET} 101 102.S.So: 103 ${CC} ${PICFLAG} -DPIC ${CFLAGS} -c ${.IMPSRC} -o ${.TARGET} 104 105all: objwarn 106 107# Generate the version map given the version definitions 108# and symbol maps. 109.if !empty(VERSION_DEF) && !empty(SYMBOL_MAPS) 110# Find the awk script that generates the version map. 111VERSION_GEN?= version_gen.awk 112VERSION_MAP?= Version.map 113 114# Compute the make's -m path. 115_mpath= 116_oarg= 117.for _arg in ${.MAKEFLAGS} 118.if ${_oarg} == "-m" 119_mpath+= ${_arg} 120.endif 121_oarg= ${_arg} 122.endfor 123_mpath+= /usr/share/mk 124 125# Look up ${VERSION_GEN} in ${_mpath}. 126_vgen= 127.for path in ${_mpath} 128.if empty(_vgen) 129.if exists(${path}/${VERSION_GEN}) 130_vgen= ${path}/${VERSION_GEN} 131.endif 132.endif 133.endfor 134 135${VERSION_MAP}: ${VERSION_DEF} ${_vgen} ${SYMBOL_MAPS} 136 awk -v vfile=${VERSION_DEF} -f ${_vgen} ${SYMBOL_MAPS} \ 137 > ${.TARGET} 138.endif # !empty(VERSION_DEF) && !empty(SYMBOL_MAPS) 139 140# Allow librararies to specify their own version map or have it 141# automatically generated (see above). 142.if !empty(VERSION_MAP) 143${SHLIB_NAME}: ${VERSION_MAP} 144LDFLAGS+= -Wl,--version-script=${VERSION_MAP} 145.endif 146 147.if defined(LIB) && !empty(LIB) || defined(SHLIB_NAME) 148OBJS+= ${SRCS:N*.h:R:S/$/.o/} 149.endif 150 151.if defined(LIB) && !empty(LIB) 152_LIBS= lib${LIB}.a 153 154lib${LIB}.a: ${OBJS} ${STATICOBJS} 155 @${ECHO} building static ${LIB} library 156 @rm -f ${.TARGET} 157.if !defined(NM) 158 @${AR} cq ${.TARGET} `lorder ${OBJS} ${STATICOBJS} | tsort -q` ${ARADD} 159.else 160 @${AR} cq ${.TARGET} `NM='${NM}' lorder ${OBJS} ${STATICOBJS} | tsort -q` ${ARADD} 161.endif 162 ${RANLIB} ${.TARGET} 163.endif 164 165.if !defined(INTERNALLIB) 166 167.if ${MK_PROFILE} != "no" && defined(LIB) && !empty(LIB) 168_LIBS+= lib${LIB}_p.a 169POBJS+= ${OBJS:.o=.po} ${STATICOBJS:.o=.po} 170 171lib${LIB}_p.a: ${POBJS} 172 @${ECHO} building profiled ${LIB} library 173 @rm -f ${.TARGET} 174.if !defined(NM) 175 @${AR} cq ${.TARGET} `lorder ${POBJS} | tsort -q` ${ARADD} 176.else 177 @${AR} cq ${.TARGET} `NM='${NM}' lorder ${POBJS} | tsort -q` ${ARADD} 178.endif 179 ${RANLIB} ${.TARGET} 180.endif 181 182.if defined(SHLIB_NAME) || \ 183 defined(INSTALL_PIC_ARCHIVE) && defined(LIB) && !empty(LIB) 184SOBJS+= ${OBJS:.o=.So} 185.endif 186 187.if defined(SHLIB_NAME) 188_LIBS+= ${SHLIB_NAME} 189 190${SHLIB_NAME}: ${SOBJS} 191 @${ECHO} building shared library ${SHLIB_NAME} 192 @rm -f ${.TARGET} ${SHLIB_LINK} 193.if defined(SHLIB_LINK) 194 @ln -fs ${.TARGET} ${SHLIB_LINK} 195.endif 196.if !defined(NM) 197 @${CC} ${LDFLAGS} -shared -Wl,-x \ 198 -o ${.TARGET} -Wl,-soname,${SONAME} \ 199 `lorder ${SOBJS} | tsort -q` ${LDADD} 200.else 201 @${CC} ${LDFLAGS} -shared -Wl,-x \ 202 -o ${.TARGET} -Wl,-soname,${SONAME} \ 203 `NM='${NM}' lorder ${SOBJS} | tsort -q` ${LDADD} 204.endif 205.endif 206 207.if defined(INSTALL_PIC_ARCHIVE) && defined(LIB) && !empty(LIB) && ${MK_TOOLCHAIN} != "no" 208_LIBS+= lib${LIB}_pic.a 209 210lib${LIB}_pic.a: ${SOBJS} 211 @${ECHO} building special pic ${LIB} library 212 @rm -f ${.TARGET} 213 @${AR} cq ${.TARGET} ${SOBJS} ${ARADD} 214 ${RANLIB} ${.TARGET} 215.endif 216 217.if defined(WANT_LINT) && !defined(NO_LINT) && defined(LIB) && !empty(LIB) 218LINTLIB= llib-l${LIB}.ln 219_LIBS+= ${LINTLIB} 220LINTOBJS+= ${SRCS:M*.c:.c=.ln} 221 222${LINTLIB}: ${LINTOBJS} 223 @${ECHO} building lint library ${.TARGET} 224 @rm -f ${.TARGET} 225 ${LINT} ${LINTLIBFLAGS} ${CFLAGS:M-[DIU]*} ${.ALLSRC} 226.endif 227 228.endif # !defined(INTERNALLIB) 229 230all: ${_LIBS} 231 232.if ${MK_MAN} != "no" 233all: _manpages 234.endif 235 236_EXTRADEPEND: 237 @TMP=_depend$$$$; \ 238 sed -e 's/^\([^\.]*\).o[ ]*:/\1.o \1.po \1.So:/' < ${DEPENDFILE} \ 239 > $$TMP; \ 240 mv $$TMP ${DEPENDFILE} 241.if !defined(NO_EXTRADEPEND) && defined(SHLIB_NAME) 242.if defined(DPADD) && !empty(DPADD) 243 echo ${SHLIB_NAME}: ${DPADD} >> ${DEPENDFILE} 244.endif 245.endif 246 247.if !target(install) 248 249.if defined(PRECIOUSLIB) 250.if !defined(NO_FSCHG) 251SHLINSTALLFLAGS+= -fschg 252.endif 253SHLINSTALLFLAGS+= -S 254.endif 255 256_INSTALLFLAGS:= ${INSTALLFLAGS} 257.for ie in ${INSTALLFLAGS_EDIT} 258_INSTALLFLAGS:= ${_INSTALLFLAGS${ie}} 259.endfor 260_SHLINSTALLFLAGS:= ${SHLINSTALLFLAGS} 261.for ie in ${INSTALLFLAGS_EDIT} 262_SHLINSTALLFLAGS:= ${_SHLINSTALLFLAGS${ie}} 263.endfor 264 265.if !defined(INTERNALLIB) 266realinstall: _libinstall 267.ORDER: beforeinstall _libinstall 268_libinstall: 269.if defined(LIB) && !empty(LIB) && !defined(NO_INSTALLLIB) 270 ${INSTALL} -C -o ${LIBOWN} -g ${LIBGRP} -m ${LIBMODE} \ 271 ${_INSTALLFLAGS} lib${LIB}.a ${DESTDIR}${LIBDIR} 272.endif 273.if ${MK_PROFILE} != "no" && defined(LIB) && !empty(LIB) 274 ${INSTALL} -C -o ${LIBOWN} -g ${LIBGRP} -m ${LIBMODE} \ 275 ${_INSTALLFLAGS} lib${LIB}_p.a ${DESTDIR}${LIBDIR} 276.endif 277.if defined(SHLIB_NAME) 278 ${INSTALL} ${STRIP} -o ${LIBOWN} -g ${LIBGRP} -m ${LIBMODE} \ 279 ${_INSTALLFLAGS} ${_SHLINSTALLFLAGS} \ 280 ${SHLIB_NAME} ${DESTDIR}${SHLIBDIR} 281.if defined(SHLIB_LINK) 282.if ${SHLIBDIR} == ${LIBDIR} 283 ln -fs ${SHLIB_NAME} ${DESTDIR}${LIBDIR}/${SHLIB_LINK} 284.else 285 ln -fs ${_SHLIBDIRPREFIX}${SHLIBDIR}/${SHLIB_NAME} \ 286 ${DESTDIR}${LIBDIR}/${SHLIB_LINK} 287.if exists(${DESTDIR}${LIBDIR}/${SHLIB_NAME}) 288 -chflags noschg ${DESTDIR}${LIBDIR}/${SHLIB_NAME} 289 rm -f ${DESTDIR}${LIBDIR}/${SHLIB_NAME} 290.endif 291.endif 292.endif 293.endif 294.if defined(INSTALL_PIC_ARCHIVE) && defined(LIB) && !empty(LIB) && ${MK_TOOLCHAIN} != "no" 295 ${INSTALL} -o ${LIBOWN} -g ${LIBGRP} -m ${LIBMODE} \ 296 ${_INSTALLFLAGS} lib${LIB}_pic.a ${DESTDIR}${LIBDIR} 297.endif 298.if defined(WANT_LINT) && !defined(NO_LINT) && defined(LIB) && !empty(LIB) 299 ${INSTALL} -o ${LIBOWN} -g ${LIBGRP} -m ${LIBMODE} \ 300 ${_INSTALLFLAGS} ${LINTLIB} ${DESTDIR}${LINTLIBDIR} 301.endif 302.endif # !defined(INTERNALLIB) 303 304.include <bsd.nls.mk> 305.include <bsd.files.mk> 306.include <bsd.incs.mk> 307.include <bsd.links.mk> 308 309.if ${MK_MAN} != "no" 310realinstall: _maninstall 311.ORDER: beforeinstall _maninstall 312.endif 313 314.endif 315 316.if !target(lint) 317lint: ${SRCS:M*.c} 318 ${LINT} ${LINTFLAGS} ${CFLAGS:M-[DIU]*} ${.ALLSRC} 319.endif 320 321.if ${MK_MAN} != "no" 322.include <bsd.man.mk> 323.endif 324 325.include <bsd.dep.mk> 326 327.if !exists(${.OBJDIR}/${DEPENDFILE}) 328.if defined(LIB) && !empty(LIB) 329${OBJS} ${STATICOBJS} ${POBJS}: ${SRCS:M*.h} 330.for _S in ${SRCS:N*.[hly]} 331${_S:R}.po: ${_S} 332.endfor 333.endif 334.if defined(SHLIB_NAME) || \ 335 defined(INSTALL_PIC_ARCHIVE) && defined(LIB) && !empty(LIB) 336${SOBJS}: ${SRCS:M*.h} 337.for _S in ${SRCS:N*.[hly]} 338${_S:R}.So: ${_S} 339.endfor 340.endif 341.endif 342 343.if !target(clean) 344clean: 345.if defined(CLEANFILES) && !empty(CLEANFILES) 346 rm -f ${CLEANFILES} 347.endif 348.if defined(LIB) && !empty(LIB) 349 rm -f a.out ${OBJS} ${OBJS:S/$/.tmp/} ${STATICOBJS} 350.endif 351.if !defined(INTERNALLIB) 352.if ${MK_PROFILE} != "no" && defined(LIB) && !empty(LIB) 353 rm -f ${POBJS} ${POBJS:S/$/.tmp/} 354.endif 355.if defined(SHLIB_NAME) || \ 356 defined(INSTALL_PIC_ARCHIVE) && defined(LIB) && !empty(LIB) 357 rm -f ${SOBJS} ${SOBJS:.So=.so} ${SOBJS:S/$/.tmp/} 358.endif 359.if defined(SHLIB_NAME) 360.if defined(SHLIB_LINK) 361 rm -f ${SHLIB_LINK} 362.endif 363.if defined(LIB) && !empty(LIB) 364 rm -f lib${LIB}.so.* lib${LIB}.so 365.endif 366.endif 367.if defined(WANT_LINT) && defined(LIB) && !empty(LIB) 368 rm -f ${LINTOBJS} 369.endif 370.endif # !defined(INTERNALLIB) 371.if defined(_LIBS) && !empty(_LIBS) 372 rm -f ${_LIBS} 373.endif 374.if defined(CLEANDIRS) && !empty(CLEANDIRS) 375 rm -rf ${CLEANDIRS} 376.endif 377.if !empty(VERSION_DEF) && !empty(SYMBOL_MAPS) 378 rm -f ${VERSION_MAP} 379.endif 380.endif 381 382.include <bsd.obj.mk> 383 384.include <bsd.sys.mk> 385