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 39.if ${MK_CTF} != "no" && ${DEBUG_FLAGS:M-g} != "" 40CTFFLAGS+= -g 41.endif 42.endif 43 44.if !defined(DEBUG_FLAGS) 45STRIP?= -s 46.endif 47 48.include <bsd.libnames.mk> 49 50# prefer .s to a .c, add .po, remove stuff not used in the BSD libraries 51# .So used for PIC object files 52.SUFFIXES: 53.SUFFIXES: .out .o .po .So .S .asm .s .c .cc .cpp .cxx .C .f .y .l .ln 54 55.if !defined(PICFLAG) 56.if ${MACHINE_CPUARCH} == "sparc64" 57PICFLAG=-fPIC 58.else 59PICFLAG=-fpic 60.endif 61.endif 62 63PO_FLAG=-pg 64 65.c.o: 66 ${CC} ${STATIC_CFLAGS} ${CFLAGS} -c ${.IMPSRC} -o ${.TARGET} 67 ${CTFCONVERT_CMD} 68 69.c.po: 70 ${CC} ${PO_FLAG} ${STATIC_CFLAGS} ${PO_CFLAGS} -c ${.IMPSRC} -o ${.TARGET} 71 ${CTFCONVERT_CMD} 72 73.c.So: 74 ${CC} ${PICFLAG} -DPIC ${SHARED_CFLAGS} ${CFLAGS} -c ${.IMPSRC} -o ${.TARGET} 75 ${CTFCONVERT_CMD} 76 77.cc.o .C.o .cpp.o .cxx.o: 78 ${CXX} ${STATIC_CXXFLAGS} ${CXXFLAGS} -c ${.IMPSRC} -o ${.TARGET} 79 80.cc.po .C.po .cpp.po .cxx.po: 81 ${CXX} ${PO_FLAG} ${STATIC_CXXFLAGS} ${PO_CXXFLAGS} -c ${.IMPSRC} -o ${.TARGET} 82 83.cc.So .C.So .cpp.So .cxx.So: 84 ${CXX} ${PICFLAG} -DPIC ${SHARED_CXXFLAGS} ${CXXFLAGS} -c ${.IMPSRC} -o ${.TARGET} 85 86.f.po: 87 ${FC} -pg ${FFLAGS} -o ${.TARGET} -c ${.IMPSRC} 88 ${CTFCONVERT_CMD} 89 90.f.So: 91 ${FC} ${PICFLAG} -DPIC ${FFLAGS} -o ${.TARGET} -c ${.IMPSRC} 92 ${CTFCONVERT_CMD} 93 94.s.po .s.So: 95 ${AS} ${AFLAGS} -o ${.TARGET} ${.IMPSRC} 96 ${CTFCONVERT_CMD} 97 98.asm.po: 99 ${CC} -x assembler-with-cpp -DPROF ${PO_CFLAGS} ${ACFLAGS} \ 100 -c ${.IMPSRC} -o ${.TARGET} 101 ${CTFCONVERT_CMD} 102 103.asm.So: 104 ${CC} -x assembler-with-cpp ${PICFLAG} -DPIC ${CFLAGS} ${ACFLAGS} \ 105 -c ${.IMPSRC} -o ${.TARGET} 106 ${CTFCONVERT_CMD} 107 108.S.po: 109 ${CC} -DPROF ${PO_CFLAGS} ${ACFLAGS} -c ${.IMPSRC} -o ${.TARGET} 110 ${CTFCONVERT_CMD} 111 112.S.So: 113 ${CC} ${PICFLAG} -DPIC ${CFLAGS} ${ACFLAGS} -c ${.IMPSRC} -o ${.TARGET} 114 ${CTFCONVERT_CMD} 115 116all: objwarn 117 118.include <bsd.symver.mk> 119 120# Allow libraries to specify their own version map or have it 121# automatically generated (see bsd.symver.mk above). 122.if ${MK_SYMVER} == "yes" && !empty(VERSION_MAP) 123${SHLIB_NAME}: ${VERSION_MAP} 124LDFLAGS+= -Wl,--version-script=${VERSION_MAP} 125.endif 126 127.if defined(LIB) && !empty(LIB) || defined(SHLIB_NAME) 128OBJS+= ${SRCS:N*.h:R:S/$/.o/} 129.endif 130 131.if defined(LIB) && !empty(LIB) 132_LIBS= lib${LIB}.a 133 134lib${LIB}.a: ${OBJS} ${STATICOBJS} 135 @${ECHO} building static ${LIB} library 136 @rm -f ${.TARGET} 137.if !defined(NM) 138 @${AR} cq ${.TARGET} `lorder ${OBJS} ${STATICOBJS} | tsort -q` ${ARADD} 139.else 140 @${AR} cq ${.TARGET} `NM='${NM}' lorder ${OBJS} ${STATICOBJS} | tsort -q` ${ARADD} 141.endif 142 ${RANLIB} ${.TARGET} 143.endif 144 145.if !defined(INTERNALLIB) 146 147.if ${MK_PROFILE} != "no" && defined(LIB) && !empty(LIB) 148_LIBS+= lib${LIB}_p.a 149POBJS+= ${OBJS:.o=.po} ${STATICOBJS:.o=.po} 150 151lib${LIB}_p.a: ${POBJS} 152 @${ECHO} building profiled ${LIB} library 153 @rm -f ${.TARGET} 154.if !defined(NM) 155 @${AR} cq ${.TARGET} `lorder ${POBJS} | tsort -q` ${ARADD} 156.else 157 @${AR} cq ${.TARGET} `NM='${NM}' lorder ${POBJS} | tsort -q` ${ARADD} 158.endif 159 ${RANLIB} ${.TARGET} 160.endif 161 162.if defined(SHLIB_NAME) || \ 163 defined(INSTALL_PIC_ARCHIVE) && defined(LIB) && !empty(LIB) 164SOBJS+= ${OBJS:.o=.So} 165.endif 166 167.if defined(SHLIB_NAME) 168_LIBS+= ${SHLIB_NAME} 169 170SOLINKOPTS= -shared -Wl,-x 171.if !defined(ALLOW_SHARED_TEXTREL) 172SOLINKOPTS+= -Wl,--fatal-warnings -Wl,--warn-shared-textrel 173.endif 174 175.if target(beforelinking) 176${SHLIB_NAME}: ${SOBJS} beforelinking 177.else 178${SHLIB_NAME}: ${SOBJS} 179.endif 180 @${ECHO} building shared library ${SHLIB_NAME} 181 @rm -f ${.TARGET} ${SHLIB_LINK} 182.if defined(SHLIB_LINK) 183 @ln -fs ${.TARGET} ${SHLIB_LINK} 184.endif 185.if !defined(NM) 186 @${CC} ${LDFLAGS} ${SSP_CFLAGS} ${SOLINKOPTS} \ 187 -o ${.TARGET} -Wl,-soname,${SONAME} \ 188 `lorder ${SOBJS} | tsort -q` ${LDADD} 189.else 190 @${CC} ${LDFLAGS} ${SSP_CFLAGS} ${SOLINKOPTS} \ 191 -o ${.TARGET} -Wl,-soname,${SONAME} \ 192 `NM='${NM}' lorder ${SOBJS} | tsort -q` ${LDADD} 193.endif 194.if ${MK_CTF} != "no" 195 ${CTFMERGE} ${CTFFLAGS} -o ${.TARGET} ${SOBJS} 196.endif 197.endif 198 199.if defined(INSTALL_PIC_ARCHIVE) && defined(LIB) && !empty(LIB) && ${MK_TOOLCHAIN} != "no" 200_LIBS+= lib${LIB}_pic.a 201 202lib${LIB}_pic.a: ${SOBJS} 203 @${ECHO} building special pic ${LIB} library 204 @rm -f ${.TARGET} 205 @${AR} cq ${.TARGET} ${SOBJS} ${ARADD} 206 ${RANLIB} ${.TARGET} 207.endif 208 209.if defined(WANT_LINT) && !defined(NO_LINT) && defined(LIB) && !empty(LIB) 210LINTLIB= llib-l${LIB}.ln 211_LIBS+= ${LINTLIB} 212LINTOBJS+= ${SRCS:M*.c:.c=.ln} 213 214${LINTLIB}: ${LINTOBJS} 215 @${ECHO} building lint library ${.TARGET} 216 @rm -f ${.TARGET} 217 ${LINT} ${LINTLIBFLAGS} ${CFLAGS:M-[DIU]*} ${.ALLSRC} 218.endif 219 220.endif # !defined(INTERNALLIB) 221 222all: ${_LIBS} 223 224.if ${MK_MAN} != "no" 225all: _manpages 226.endif 227 228_EXTRADEPEND: 229 @TMP=_depend$$$$; \ 230 sed -e 's/^\([^\.]*\).o[ ]*:/\1.o \1.po \1.So:/' < ${DEPENDFILE} \ 231 > $$TMP; \ 232 mv $$TMP ${DEPENDFILE} 233.if !defined(NO_EXTRADEPEND) && defined(SHLIB_NAME) 234.if defined(DPADD) && !empty(DPADD) 235 echo ${SHLIB_NAME}: ${DPADD} >> ${DEPENDFILE} 236.endif 237.endif 238 239.if !target(install) 240 241.if defined(PRECIOUSLIB) 242.if !defined(NO_FSCHG) 243SHLINSTALLFLAGS+= -fschg 244.endif 245SHLINSTALLFLAGS+= -S 246.endif 247 248_INSTALLFLAGS:= ${INSTALLFLAGS} 249.for ie in ${INSTALLFLAGS_EDIT} 250_INSTALLFLAGS:= ${_INSTALLFLAGS${ie}} 251.endfor 252_SHLINSTALLFLAGS:= ${SHLINSTALLFLAGS} 253.for ie in ${INSTALLFLAGS_EDIT} 254_SHLINSTALLFLAGS:= ${_SHLINSTALLFLAGS${ie}} 255.endfor 256 257.if !defined(INTERNALLIB) 258realinstall: _libinstall 259.ORDER: beforeinstall _libinstall 260_libinstall: 261.if defined(LIB) && !empty(LIB) && ${MK_INSTALLLIB} != "no" 262 ${INSTALL} -C -o ${LIBOWN} -g ${LIBGRP} -m ${LIBMODE} \ 263 ${_INSTALLFLAGS} lib${LIB}.a ${DESTDIR}${LIBDIR} 264.endif 265.if ${MK_PROFILE} != "no" && defined(LIB) && !empty(LIB) 266 ${INSTALL} -C -o ${LIBOWN} -g ${LIBGRP} -m ${LIBMODE} \ 267 ${_INSTALLFLAGS} lib${LIB}_p.a ${DESTDIR}${LIBDIR} 268.endif 269.if defined(SHLIB_NAME) 270 ${INSTALL} ${STRIP} -o ${LIBOWN} -g ${LIBGRP} -m ${LIBMODE} \ 271 ${_INSTALLFLAGS} ${_SHLINSTALLFLAGS} \ 272 ${SHLIB_NAME} ${DESTDIR}${SHLIBDIR} 273.if defined(SHLIB_LINK) 274# ${_SHLIBDIRPREFIX} and ${_LDSCRIPTROOT} are both needed when cross-building 275# and when building 32 bits library shims. ${_SHLIBDIRPREFIX} is the directory 276# prefix where shared objects will be installed. ${_LDSCRIPTROOT} is the 277# directory prefix that will be used in generated ld(1) scripts. They cannot 278# be coalesced because of the way ld(1) handles the sysroot prefix (used in the 279# cross-toolchain): 280# - 64 bits libs are located under sysroot, so ${_LDSCRIPTROOT} must be empty. 281# - 32 bits shims are not, so ${_LDSCRIPTROOT} is used to specify their full 282# path. Note that ld(1) scripts are generated both during buildworld and 283# installworld; in the later case ${_LDSCRIPTROOT} must be obviously empty. 284# On the other hand, the use of ${_SHLIBDIRPREFIX} is more consistent since it 285# does not involve the logic of a tool we do not own. 286.if defined(SHLIB_LDSCRIPT) && !empty(SHLIB_LDSCRIPT) && exists(${.CURDIR}/${SHLIB_LDSCRIPT}) 287 sed -e 's,@@SHLIB@@,${_LDSCRIPTROOT}${SHLIBDIR}/${SHLIB_NAME},g' \ 288 -e 's,@@LIBDIR@@,${_LDSCRIPTROOT}${LIBDIR},g' \ 289 ${.CURDIR}/${SHLIB_LDSCRIPT} > lib${LIB}.ld 290 ${INSTALL} -S -C -o ${LIBOWN} -g ${LIBGRP} -m ${LIBMODE} \ 291 ${_INSTALLFLAGS} lib${LIB}.ld ${DESTDIR}${LIBDIR}/${SHLIB_LINK} 292.else 293.if ${SHLIBDIR} == ${LIBDIR} 294 ln -fs ${SHLIB_NAME} ${DESTDIR}${LIBDIR}/${SHLIB_LINK} 295.else 296 ln -fs ${_SHLIBDIRPREFIX}${SHLIBDIR}/${SHLIB_NAME} \ 297 ${DESTDIR}${LIBDIR}/${SHLIB_LINK} 298.if exists(${DESTDIR}${LIBDIR}/${SHLIB_NAME}) 299 -chflags noschg ${DESTDIR}${LIBDIR}/${SHLIB_NAME} 300 rm -f ${DESTDIR}${LIBDIR}/${SHLIB_NAME} 301.endif 302.endif 303.endif # SHLIB_LDSCRIPT 304.endif # SHLIB_LINK 305.endif # SHIB_NAME 306.if defined(INSTALL_PIC_ARCHIVE) && defined(LIB) && !empty(LIB) && ${MK_TOOLCHAIN} != "no" 307 ${INSTALL} -o ${LIBOWN} -g ${LIBGRP} -m ${LIBMODE} \ 308 ${_INSTALLFLAGS} lib${LIB}_pic.a ${DESTDIR}${LIBDIR} 309.endif 310.if defined(WANT_LINT) && !defined(NO_LINT) && defined(LIB) && !empty(LIB) 311 ${INSTALL} -o ${LIBOWN} -g ${LIBGRP} -m ${LIBMODE} \ 312 ${_INSTALLFLAGS} ${LINTLIB} ${DESTDIR}${LINTLIBDIR} 313.endif 314.endif # !defined(INTERNALLIB) 315 316.include <bsd.nls.mk> 317.include <bsd.files.mk> 318.include <bsd.incs.mk> 319.include <bsd.links.mk> 320 321.if ${MK_MAN} != "no" 322realinstall: _maninstall 323.ORDER: beforeinstall _maninstall 324.endif 325 326.endif 327 328.if !target(lint) 329lint: ${SRCS:M*.c} 330 ${LINT} ${LINTFLAGS} ${CFLAGS:M-[DIU]*} ${.ALLSRC} 331.endif 332 333.if ${MK_MAN} != "no" 334.include <bsd.man.mk> 335.endif 336 337.include <bsd.dep.mk> 338 339.if !exists(${.OBJDIR}/${DEPENDFILE}) 340.if defined(LIB) && !empty(LIB) 341${OBJS} ${STATICOBJS} ${POBJS}: ${SRCS:M*.h} 342.for _S in ${SRCS:N*.[hly]} 343${_S:R}.po: ${_S} 344.endfor 345.endif 346.if defined(SHLIB_NAME) || \ 347 defined(INSTALL_PIC_ARCHIVE) && defined(LIB) && !empty(LIB) 348${SOBJS}: ${SRCS:M*.h} 349.for _S in ${SRCS:N*.[hly]} 350${_S:R}.So: ${_S} 351.endfor 352.endif 353.endif 354 355.if !target(clean) 356clean: 357.if defined(CLEANFILES) && !empty(CLEANFILES) 358 rm -f ${CLEANFILES} 359.endif 360.if defined(LIB) && !empty(LIB) 361 rm -f a.out ${OBJS} ${OBJS:S/$/.tmp/} ${STATICOBJS} 362.endif 363.if !defined(INTERNALLIB) 364.if ${MK_PROFILE} != "no" && defined(LIB) && !empty(LIB) 365 rm -f ${POBJS} ${POBJS:S/$/.tmp/} 366.endif 367.if defined(SHLIB_NAME) || \ 368 defined(INSTALL_PIC_ARCHIVE) && defined(LIB) && !empty(LIB) 369 rm -f ${SOBJS} ${SOBJS:.So=.so} ${SOBJS:S/$/.tmp/} 370.endif 371.if defined(SHLIB_NAME) 372.if defined(SHLIB_LINK) 373.if defined(SHLIB_LDSCRIPT) && exists(${.CURDIR}/${SHLIB_LDSCRIPT}) 374 rm -f lib${LIB}.ld 375.endif 376 rm -f ${SHLIB_LINK} 377.endif 378.if defined(LIB) && !empty(LIB) 379 rm -f lib${LIB}.so.* lib${LIB}.so 380.endif 381.endif 382.if defined(WANT_LINT) && defined(LIB) && !empty(LIB) 383 rm -f ${LINTOBJS} 384.endif 385.endif # !defined(INTERNALLIB) 386.if defined(_LIBS) && !empty(_LIBS) 387 rm -f ${_LIBS} 388.endif 389.if defined(CLEANDIRS) && !empty(CLEANDIRS) 390 rm -rf ${CLEANDIRS} 391.endif 392.if !empty(VERSION_DEF) && !empty(SYMBOL_MAPS) 393 rm -f ${VERSION_MAP} 394.endif 395.endif 396 397.include <bsd.obj.mk> 398 399.include <bsd.sys.mk> 400