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(NOPIC) 12.undef SHLIB_NAME 13.undef INSTALL_PIC_ARCHIVE 14.else 15.if !defined(SHLIB_NAME) && defined(LIB) && defined(SHLIB_MAJOR) 16SHLIB_NAME= lib${LIB}.so.${SHLIB_MAJOR} 17.endif 18.if defined(SHLIB_NAME) && ${SHLIB_NAME:M*.so.*} 19SHLIB_LINK?= ${SHLIB_NAME:R} 20.endif 21SONAME?= ${SHLIB_NAME} 22.endif 23 24CFLAGS+= ${CRUNCH_CFLAGS} 25 26.if defined(DEBUG_FLAGS) 27CFLAGS+= ${DEBUG_FLAGS} 28.endif 29 30.if !defined(DEBUG_FLAGS) 31STRIP?= -s 32.endif 33 34.include <bsd.libnames.mk> 35 36# prefer .s to a .c, add .po, remove stuff not used in the BSD libraries 37# .So used for PIC object files 38.SUFFIXES: 39.SUFFIXES: .out .o .po .So .S .s .asm .c .cc .cpp .cxx .m .C .f .y .l .ln 40 41.if !defined(PICFLAG) 42.if ${MACHINE_ARCH} == "sparc64" 43PICFLAG=-fPIC 44.else 45PICFLAG=-fpic 46.endif 47.endif 48 49.c.ln: 50 ${LINT} ${LINTOBJFLAGS} ${CFLAGS:M-[DIU]*} ${.IMPSRC} || \ 51 touch ${.TARGET} 52 53.cc.ln .C.ln .cpp.ln .cxx.ln: 54 ${LINT} ${LINTOBJFLAGS} ${CXXFLAGS:M-[DIU]*} ${.IMPSRC} || \ 55 touch ${.TARGET} 56 57.c.o: 58 ${CC} ${CFLAGS} -c ${.IMPSRC} -o ${.TARGET} 59 @${LD} ${LDFLAGS} -o ${.TARGET}.tmp -x -r ${.TARGET} 60 @mv ${.TARGET}.tmp ${.TARGET} 61 62.c.po: 63 ${CC} -pg ${CFLAGS} -c ${.IMPSRC} -o ${.TARGET} 64 @${LD} ${LDFLAGS} -o ${.TARGET}.tmp -X -r ${.TARGET} 65 @mv ${.TARGET}.tmp ${.TARGET} 66 67.c.So: 68 ${CC} ${PICFLAG} -DPIC ${CFLAGS} -c ${.IMPSRC} -o ${.TARGET} 69 @${LD} ${LDFLAGS} -o ${.TARGET}.tmp -x -r ${.TARGET} 70 @mv ${.TARGET}.tmp ${.TARGET} 71 72.cc.o .C.o .cpp.o .cxx.o: 73 ${CXX} ${CXXFLAGS} -c ${.IMPSRC} -o ${.TARGET} 74 @${LD} ${LDFLAGS} -o ${.TARGET}.tmp -x -r ${.TARGET} 75 @mv ${.TARGET}.tmp ${.TARGET} 76 77.cc.po .C.po .cpp.po .cxx.po: 78 ${CXX} -pg ${CXXFLAGS} -c ${.IMPSRC} -o ${.TARGET} 79 @${LD} ${LDFLAGS} -o ${.TARGET}.tmp -X -r ${.TARGET} 80 @mv ${.TARGET}.tmp ${.TARGET} 81 82.cc.So .C.So .cpp.So .cxx.So: 83 ${CXX} ${PICFLAG} -DPIC ${CXXFLAGS} -c ${.IMPSRC} -o ${.TARGET} 84 @${LD} ${LDFLAGS} -o ${.TARGET}.tmp -x -r ${.TARGET} 85 @mv ${.TARGET}.tmp ${.TARGET} 86 87.f.o: 88 ${FC} ${FFLAGS} -o ${.TARGET} -c ${.IMPSRC} 89 @${LD} ${LDFLAGS} -o ${.TARGET}.tmp -x -r ${.TARGET} 90 @mv ${.TARGET}.tmp ${.TARGET} 91 92.f.po: 93 ${FC} -pg ${FFLAGS} -o ${.TARGET} -c ${.IMPSRC} 94 @${LD} ${LDFLAGS} -o ${.TARGET}.tmp -X -r ${.TARGET} 95 @mv ${.TARGET}.tmp ${.TARGET} 96 97.f.So: 98 ${FC} ${PICFLAG} -DPIC ${FFLAGS} -o ${.TARGET} -c ${.IMPSRC} 99 @${LD} ${LDFLAGS} -o ${.TARGET}.tmp -x -r ${.TARGET} 100 @mv ${.TARGET}.tmp ${.TARGET} 101 102.m.o: 103 ${OBJC} ${OBJCFLAGS} -c ${.IMPSRC} -o ${.TARGET} 104 @${LD} ${LDFLAGS} -o ${.TARGET}.tmp -x -r ${.TARGET} 105 @mv ${.TARGET}.tmp ${.TARGET} 106 107.m.po: 108 ${OBJC} ${OBJCFLAGS} -pg -c ${.IMPSRC} -o ${.TARGET} 109 @${LD} ${LDFLAGS} -o ${.TARGET}.tmp -X -r ${.TARGET} 110 @mv ${.TARGET}.tmp ${.TARGET} 111 112.m.So: 113 ${OBJC} ${PICFLAG} -DPIC ${OBJCFLAGS} -c ${.IMPSRC} -o ${.TARGET} 114 @${LD} ${LDFLAGS} -o ${.TARGET}.tmp -x -r ${.TARGET} 115 @mv ${.TARGET}.tmp ${.TARGET} 116 117.s.o .asm.o: 118 ${CC} -x assembler-with-cpp ${CFLAGS} ${AINC} -c \ 119 ${.IMPSRC} -o ${.TARGET} 120 @${LD} ${LDFLAGS} -o ${.TARGET}.tmp -x -r ${.TARGET} 121 @mv ${.TARGET}.tmp ${.TARGET} 122 123.s.po .asm.po: 124 ${CC} -x assembler-with-cpp -DPROF ${CFLAGS} ${AINC} -c \ 125 ${.IMPSRC} -o ${.TARGET} 126 @${LD} ${LDFLAGS} -o ${.TARGET}.tmp -X -r ${.TARGET} 127 @mv ${.TARGET}.tmp ${.TARGET} 128 129.s.So .asm.So: 130 ${CC} -x assembler-with-cpp ${PICFLAG} -DPIC ${CFLAGS} \ 131 ${AINC} -c ${.IMPSRC} -o ${.TARGET} 132 @${LD} ${LDFLAGS} -o ${.TARGET}.tmp -x -r ${.TARGET} 133 @mv ${.TARGET}.tmp ${.TARGET} 134 135.S.o: 136 ${CC} ${CFLAGS} ${AINC} -c ${.IMPSRC} -o ${.TARGET} 137 @${LD} ${LDFLAGS} -o ${.TARGET}.tmp -x -r ${.TARGET} 138 @mv ${.TARGET}.tmp ${.TARGET} 139 140.S.po: 141 ${CC} -DPROF ${CFLAGS} ${AINC} -c ${.IMPSRC} -o ${.TARGET} 142 @${LD} ${LDFLAGS} -o ${.TARGET}.tmp -X -r ${.TARGET} 143 @mv ${.TARGET}.tmp ${.TARGET} 144 145.S.So: 146 ${CC} ${PICFLAG} -DPIC ${CFLAGS} ${AINC} -c ${.IMPSRC} \ 147 -o ${.TARGET} 148 @${LD} ${LDFLAGS} -o ${.TARGET}.tmp -x -r ${.TARGET} 149 @mv ${.TARGET}.tmp ${.TARGET} 150 151all: objwarn 152 153.if defined(LIB) && !empty(LIB) || defined(SHLIB_NAME) 154OBJS+= ${SRCS:N*.h:R:S/$/.o/} 155.endif 156 157.if defined(LIB) && !empty(LIB) 158_LIBS= lib${LIB}.a 159 160lib${LIB}.a: ${OBJS} ${STATICOBJS} 161 @${ECHO} building static ${LIB} library 162 @rm -f ${.TARGET} 163 @${AR} cq ${.TARGET} `lorder ${OBJS} ${STATICOBJS} | tsort -q` ${ARADD} 164 ${RANLIB} ${.TARGET} 165.endif 166 167.if !defined(INTERNALLIB) 168 169.if !defined(NOPROFILE) && defined(LIB) && !empty(LIB) 170_LIBS+= lib${LIB}_p.a 171POBJS+= ${OBJS:.o=.po} ${STATICOBJS:.o=.po} 172 173lib${LIB}_p.a: ${POBJS} 174 @${ECHO} building profiled ${LIB} library 175 @rm -f ${.TARGET} 176 @${AR} cq ${.TARGET} `lorder ${POBJS} | tsort -q` ${ARADD} 177 ${RANLIB} ${.TARGET} 178.endif 179 180.if defined(SHLIB_NAME) || \ 181 defined(INSTALL_PIC_ARCHIVE) && defined(LIB) && !empty(LIB) 182SOBJS+= ${OBJS:.o=.So} 183.endif 184 185.if defined(SHLIB_NAME) 186_LIBS+= ${SHLIB_NAME} 187 188${SHLIB_NAME}: ${SOBJS} 189 @${ECHO} building shared library ${SHLIB_NAME} 190 @rm -f ${.TARGET} ${SHLIB_LINK} 191.if defined(SHLIB_LINK) 192 @ln -fs ${.TARGET} ${SHLIB_LINK} 193.endif 194 @${CC} ${LDFLAGS} -shared -Wl,-x \ 195 -o ${.TARGET} -Wl,-soname,${SONAME} \ 196 `lorder ${SOBJS} | tsort -q` ${LDADD} 197.endif 198 199.if defined(INSTALL_PIC_ARCHIVE) && defined(LIB) && !empty(LIB) 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(NOLINT) && 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 !defined(NOMAN) 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(NOEXTRADEPEND) && 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) && !defined(NOFSCHG) 242SHLINSTALLFLAGS+= -fschg 243.endif 244 245_INSTALLFLAGS:= ${INSTALLFLAGS} 246.for ie in ${INSTALLFLAGS_EDIT} 247_INSTALLFLAGS:= ${_INSTALLFLAGS${ie}} 248.endfor 249_SHLINSTALLFLAGS:= ${SHLINSTALLFLAGS} 250.for ie in ${INSTALLFLAGS_EDIT} 251_SHLINSTALLFLAGS:= ${_SHLINSTALLFLAGS${ie}} 252.endfor 253 254.if !defined(INTERNALLIB) 255realinstall: _libinstall 256.ORDER: beforeinstall _libinstall 257_libinstall: 258.if defined(LIB) && !empty(LIB) && !defined(NOINSTALLLIB) 259 ${INSTALL} -C -o ${LIBOWN} -g ${LIBGRP} -m ${LIBMODE} \ 260 ${_INSTALLFLAGS} lib${LIB}.a ${DESTDIR}${LIBDIR} 261.endif 262.if !defined(NOPROFILE) && defined(LIB) && !empty(LIB) 263 ${INSTALL} -C -o ${LIBOWN} -g ${LIBGRP} -m ${LIBMODE} \ 264 ${_INSTALLFLAGS} lib${LIB}_p.a ${DESTDIR}${LIBDIR} 265.endif 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 ln -fs ${SHLIB_NAME} ${DESTDIR}${SHLIBDIR}/${SHLIB_LINK} 272.endif 273.endif 274.if defined(INSTALL_PIC_ARCHIVE) && defined(LIB) && !empty(LIB) 275 ${INSTALL} -o ${LIBOWN} -g ${LIBGRP} -m ${LIBMODE} \ 276 ${_INSTALLFLAGS} lib${LIB}_pic.a ${DESTDIR}${LIBDIR} 277.endif 278.if defined(WANT_LINT) && !defined(NOLINT) && defined(LIB) && !empty(LIB) 279 ${INSTALL} -o ${LIBOWN} -g ${LIBGRP} -m ${LIBMODE} \ 280 ${_INSTALLFLAGS} ${LINTLIB} ${DESTDIR}${LINTLIBDIR} 281.endif 282.endif !defined(INTERNALLIB) 283 284.include <bsd.files.mk> 285.include <bsd.incs.mk> 286.include <bsd.links.mk> 287 288.if !defined(NOMAN) 289realinstall: _maninstall 290.ORDER: beforeinstall _maninstall 291.endif 292 293.endif 294 295.if !target(lint) 296lint: ${SRCS:M*.c} 297 ${LINT} ${LINTFLAGS} ${CFLAGS:M-[DIU]*} ${.ALLSRC} 298.endif 299 300.if !defined(NOMAN) 301.include <bsd.man.mk> 302.endif 303 304.include <bsd.dep.mk> 305 306.if !exists(${.OBJDIR}/${DEPENDFILE}) 307.if defined(LIB) && !empty(LIB) 308${OBJS} ${STATICOBJS} ${POBJS}: ${SRCS:M*.h} 309.endif 310.if defined(SHLIB_NAME) || \ 311 defined(INSTALL_PIC_ARCHIVE) && defined(LIB) && !empty(LIB) 312${SOBJS}: ${SRCS:M*.h} 313.endif 314.endif 315 316.if !target(clean) 317clean: 318.if defined(CLEANFILES) && !empty(CLEANFILES) 319 rm -f ${CLEANFILES} 320.endif 321.if defined(LIB) && !empty(LIB) 322 rm -f a.out ${OBJS} ${OBJS:S/$/.tmp/} ${STATICOBJS} 323.endif 324.if !defined(INTERNALLIB) 325.if !defined(NOPROFILE) && defined(LIB) && !empty(LIB) 326 rm -f ${POBJS} ${POBJS:S/$/.tmp/} 327.endif 328.if defined(SHLIB_NAME) || \ 329 defined(INSTALL_PIC_ARCHIVE) && defined(LIB) && !empty(LIB) 330 rm -f ${SOBJS} ${SOBJS:.So=.so} ${SOBJS:S/$/.tmp/} 331.endif 332.if defined(SHLIB_NAME) 333.if defined(SHLIB_LINK) 334 rm -f ${SHLIB_LINK} 335.endif 336.if defined(LIB) && !empty(LIB) 337 rm -f lib${LIB}.so.* lib${LIB}.so 338.endif 339.endif 340.if defined(WANT_LINT) && defined(LIB) && !empty(LIB) 341 rm -f ${LINTOBJS} 342.endif 343.endif !defined(INTERNALLIB) 344.if defined(_LIBS) && !empty(_LIBS) 345 rm -f ${_LIBS} 346.endif 347.if defined(CLEANDIRS) && !empty(CLEANDIRS) 348 rm -rf ${CLEANDIRS} 349.endif 350.endif 351 352.include <bsd.obj.mk> 353 354.include <bsd.sys.mk> 355