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