1# from: @(#)bsd.lib.mk 5.26 (Berkeley) 5/2/91 2# $Id: bsd.lib.mk,v 1.77 1998/08/08 13:22:06 peter Exp $ 3# 4 5.if !target(__initialized__) 6__initialized__: 7.if exists(${.CURDIR}/../Makefile.inc) 8.include "${.CURDIR}/../Makefile.inc" 9.endif 10.endif 11 12# Default executable format 13.if ${MACHINE} == "alpha" 14OBJFORMAT?= elf 15.else 16OBJFORMAT?= aout 17.endif 18 19.if exists(${.CURDIR}/shlib_version) 20SHLIB_MAJOR != . ${.CURDIR}/shlib_version ; echo $$major 21.if ${OBJFORMAT} == aout 22SHLIB_MINOR != . ${.CURDIR}/shlib_version ; echo $$minor 23.endif 24.endif 25 26.if !defined(NOPIC) && ${OBJFORMAT} == elf 27SONAME?= lib${LIB}.so.${SHLIB_MAJOR} 28.endif 29 30.if defined(DESTDIR) 31CFLAGS+= -I${DESTDIR}/usr/include 32CXXINCLUDES+= -I${DESTDIR}/usr/include/g++ 33.endif 34 35.if defined(DEBUG_FLAGS) 36CFLAGS+= ${DEBUG_FLAGS} 37.endif 38 39.if !defined(DEBUG_FLAGS) 40STRIP?= -s 41.endif 42 43.if ${OBJFORMAT} != aout || make(checkdpadd) 44.include <bsd.libnames.mk> 45.endif 46 47.MAIN: all 48 49# prefer .s to a .c, add .po, remove stuff not used in the BSD libraries 50# .so used for PIC object files 51.SUFFIXES: 52.SUFFIXES: .out .o .po .so .s .S .c .cc .cpp .cxx .m .C .f .y .l 53 54.c.o: 55 ${CC} ${CFLAGS} -c ${.IMPSRC} -o ${.TARGET} 56 @${LD} -o ${.TARGET}.tmp -x -r ${.TARGET} 57 @mv ${.TARGET}.tmp ${.TARGET} 58 59.c.po: 60 ${CC} -pg ${CFLAGS} -c ${.IMPSRC} -o ${.TARGET} 61 @${LD} -o ${.TARGET}.tmp -X -r ${.TARGET} 62 @mv ${.TARGET}.tmp ${.TARGET} 63 64.c.so: 65 ${CC} ${PICFLAG} -DPIC ${CFLAGS} -c ${.IMPSRC} -o ${.TARGET} 66 @${LD} -o ${.TARGET}.tmp -x -r ${.TARGET} 67 @mv ${.TARGET}.tmp ${.TARGET} 68 69.cc.o .C.o .cpp.o .cxx.o: 70 ${CXX} ${CXXFLAGS} -c ${.IMPSRC} -o ${.TARGET} 71 @${LD} -o ${.TARGET}.tmp -x -r ${.TARGET} 72 @mv ${.TARGET}.tmp ${.TARGET} 73 74.cc.po .C.po .cpp.po .cxx.po: 75 ${CXX} -pg ${CXXFLAGS} -c ${.IMPSRC} -o ${.TARGET} 76 @${LD} -o ${.TARGET}.tmp -X -r ${.TARGET} 77 @mv ${.TARGET}.tmp ${.TARGET} 78 79.cc.so .C.so .cpp.so .cxx.so: 80 ${CXX} ${PICFLAG} -DPIC ${CXXFLAGS} -c ${.IMPSRC} -o ${.TARGET} 81 @${LD} -o ${.TARGET}.tmp -x -r ${.TARGET} 82 @mv ${.TARGET}.tmp ${.TARGET} 83 84.f.o: 85 ${FC} ${FFLAGS} -o ${.TARGET} -c ${.IMPSRC} 86 @${LD} -o ${.TARGET}.tmp -x -r ${.TARGET} 87 @mv ${.TARGET}.tmp ${.TARGET} 88 89.f.po: 90 ${FC} -pg ${FFLAGS} -o ${.TARGET} -c ${.IMPSRC} 91 @${LD} -o ${.TARGET}.tmp -X -r ${.TARGET} 92 @mv ${.TARGET}.tmp ${.TARGET} 93 94.f.so: 95 ${FC} ${PICFLAG} -DPIC ${FFLAGS} -o ${.TARGET} -c ${.IMPSRC} 96 @${LD} -o ${.TARGET}.tmp -x -r ${.TARGET} 97 @mv ${.TARGET}.tmp ${.TARGET} 98 99.m.o: 100 ${OBJC} ${OBJCFLAGS} -c ${.IMPSRC} -o ${.TARGET} 101 @${LD} -o ${.TARGET}.tmp -x -r ${.TARGET} 102 @mv ${.TARGET}.tmp ${.TARGET} 103 104.m.po: 105 ${OBJC} ${OBJCFLAGS} -pg -c ${.IMPSRC} -o ${.TARGET} 106 @${LD} -o ${.TARGET}.tmp -X -r ${.TARGET} 107 @mv ${.TARGET}.tmp ${.TARGET} 108 109.m.so: 110 ${OBJC} ${PICFLAG} -DPIC ${OBJCFLAGS} -c ${.IMPSRC} -o ${.TARGET} 111 @${LD} -o ${.TARGET}.tmp -x -r ${.TARGET} 112 @mv ${.TARGET}.tmp ${.TARGET} 113 114.s.o: 115 ${CC} -x assembler-with-cpp ${CFLAGS:M-[BID]*} ${AINC} -c \ 116 ${.IMPSRC} -o ${.TARGET} 117 @${LD} -o ${.TARGET}.tmp -x -r ${.TARGET} 118 @mv ${.TARGET}.tmp ${.TARGET} 119 120.s.po: 121 ${CC} -x assembler-with-cpp -DPROF ${CFLAGS:M-[BID]*} ${AINC} -c \ 122 ${.IMPSRC} -o ${.TARGET} 123 @${LD} -o ${.TARGET}.tmp -X -r ${.TARGET} 124 @mv ${.TARGET}.tmp ${.TARGET} 125 126.s.so: 127 ${CC} -x assembler-with-cpp -fpic -DPIC ${CFLAGS:M-[BID]*} ${AINC} -c \ 128 ${.IMPSRC} -o ${.TARGET} 129 @${LD} -o ${.TARGET}.tmp -x -r ${.TARGET} 130 @mv ${.TARGET}.tmp ${.TARGET} 131 132.S.o: 133 ${CC} ${CFLAGS:M-[BID]*} ${AINC} -c ${.IMPSRC} -o ${.TARGET} 134 @${LD} -o ${.TARGET}.tmp -x -r ${.TARGET} 135 @mv ${.TARGET}.tmp ${.TARGET} 136 137.S.po: 138 ${CC} -DPROF ${CFLAGS:M-[BID]*} ${AINC} -c ${.IMPSRC} -o ${.TARGET} 139 @${LD} -o ${.TARGET}.tmp -X -r ${.TARGET} 140 @mv ${.TARGET}.tmp ${.TARGET} 141 142.S.so: 143 ${CC} -fpic -DPIC ${CFLAGS:M-[BID]*} ${AINC} -c ${.IMPSRC} -o ${.TARGET} 144 @${LD} -o ${.TARGET}.tmp -x -r ${.TARGET} 145 @mv ${.TARGET}.tmp ${.TARGET} 146 147.if !defined(INTERNALLIB) || defined(INTERNALSTATICLIB) 148.if !defined(NOPROFILE) && !defined(INTERNALLIB) 149_LIBS=lib${LIB}.a lib${LIB}_p.a 150.else 151_LIBS=lib${LIB}.a 152.endif 153.endif 154 155.if !defined(NOPIC) 156.if ${OBJFORMAT} == aout 157.if defined(SHLIB_MAJOR) && defined(SHLIB_MINOR) 158_LIBS+=lib${LIB}.so.${SHLIB_MAJOR}.${SHLIB_MINOR} 159.endif 160.else 161.if defined(SHLIB_MAJOR) 162_LIBS+=lib${LIB}.so.${SHLIB_MAJOR} 163.endif 164.endif 165.if defined(INSTALL_PIC_ARCHIVE) 166_LIBS+=lib${LIB}_pic.a 167.endif 168.endif 169 170.if !defined(PICFLAG) 171PICFLAG=-fpic 172.endif 173 174all: objwarn ${_LIBS} all-man _SUBDIR # llib-l${LIB}.ln 175 176OBJS+= ${SRCS:N*.h:R:S/$/.o/g} 177 178lib${LIB}.a:: ${OBJS} 179 @${ECHO} building standard ${LIB} library 180 @rm -f lib${LIB}.a 181 @${AR} cq lib${LIB}.a `lorder ${OBJS} | tsort -q` ${ARADD} 182 ${RANLIB} lib${LIB}.a 183 184POBJS+= ${OBJS:.o=.po} 185.if !defined(NOPROFILE) 186lib${LIB}_p.a:: ${POBJS} 187 @${ECHO} building profiled ${LIB} library 188 @rm -f lib${LIB}_p.a 189 @${AR} cq lib${LIB}_p.a `lorder ${POBJS} | tsort -q` ${ARADD} 190 ${RANLIB} lib${LIB}_p.a 191.endif 192 193.if defined(DESTDIR) 194LDDESTDIRENV?= LIBRARY_PATH=${DESTDIR}${SHLIBDIR}:${DESTDIR}${LIBDIR} 195.endif 196 197SOBJS+= ${OBJS:.o=.so} 198 199.if !defined(NOPIC) 200.if ${OBJFORMAT} == aout 201lib${LIB}.so.${SHLIB_MAJOR}.${SHLIB_MINOR}: ${SOBJS} 202 @${ECHO} building shared ${LIB} library \(version ${SHLIB_MAJOR}.${SHLIB_MINOR}\) 203 @rm -f lib${LIB}.so.${SHLIB_MAJOR}.${SHLIB_MINOR} 204 @${LDDESTDIRENV} ${CC} -shared -Wl,-x -Wl,-assert -Wl,pure-text \ 205 -o lib${LIB}.so.${SHLIB_MAJOR}.${SHLIB_MINOR} \ 206 `lorder ${SOBJS} | tsort -q` ${LDDESTDIR} ${LDADD} 207.else 208lib${LIB}.so.${SHLIB_MAJOR}: ${SOBJS} 209 @${ECHO} building shared ${LIB} library \(version ${SHLIB_MAJOR}\) 210 @rm -f lib${LIB}.so.${SHLIB_MAJOR} 211 @${LDDESTDIRENV} ${CC} -shared -Wl,-x \ 212 -o lib${LIB}.so.${SHLIB_MAJOR} -Wl,-soname,${SONAME} \ 213 `lorder ${SOBJS} | tsort -q` ${LDDESTDIR} ${LDADD} 214.endif 215 216lib${LIB}_pic.a:: ${SOBJS} 217 @${ECHO} building special pic ${LIB} library 218 @rm -f lib${LIB}_pic.a 219 @${AR} cq lib${LIB}_pic.a ${SOBJS} ${ARADD} 220 ${RANLIB} lib${LIB}_pic.a 221.endif 222 223llib-l${LIB}.ln: ${SRCS} 224 ${LINT} -C${LIB} ${CFLAGS} ${.ALLSRC:M*.c} 225 226.if !target(clean) 227clean: _SUBDIR 228 rm -f a.out ${OBJS} ${OBJS:S/$/.tmp/} ${CLEANFILES} 229 rm -f lib${LIB}.a # llib-l${LIB}.ln 230 rm -f ${POBJS} ${POBJS:S/$/.tmp/} lib${LIB}_p.a 231 rm -f ${SOBJS} ${SOBJS:S/$/.tmp/} lib${LIB}.so.*.* lib${LIB}_pic.a 232.if defined(CLEANDIRS) && !empty(CLEANDIRS) 233 rm -rf ${CLEANDIRS} 234.endif 235.endif 236 237_EXTRADEPEND: 238 @TMP=_depend$$$$; \ 239 sed -e 's/^\([^\.]*\).o[ ]*:/\1.o \1.po \1.so:/' < ${DEPENDFILE} \ 240 > $$TMP; \ 241 mv $$TMP ${DEPENDFILE} 242.if !defined(NOEXTRADEPEND) && !defined(NOPIC) 243.if ${OBJFORMAT} == aout 244 echo lib${LIB}.so.${SHLIB_MAJOR}.${SHLIB_MINOR}: \ 245 `${LDDESTDIRENV} ${CC} -shared -Wl,-f ${LDDESTDIR} ${LDADD}` \ 246 >> ${DEPENDFILE} 247.else 248.if defined(DPADD) && !empty(DPADD) 249 echo lib${LIB}.so.${SHLIB_MAJOR}.${SHLIB_MINOR}: \ 250 ${DPADD} >> ${DEPENDFILE} 251.endif 252.endif 253.endif 254 255.if !target(install) 256.if !target(beforeinstall) 257beforeinstall: 258.endif 259 260.if defined(PRECIOUSLIB) 261SHLINSTALLFLAGS+= -fschg 262.endif 263 264realinstall: beforeinstall 265.if !defined(INTERNALLIB) 266 ${INSTALL} ${COPY} -o ${LIBOWN} -g ${LIBGRP} -m ${LIBMODE} \ 267 ${INSTALLFLAGS} lib${LIB}.a ${DESTDIR}${LIBDIR} 268.if !defined(NOPROFILE) 269 ${INSTALL} ${COPY} -o ${LIBOWN} -g ${LIBGRP} -m ${LIBMODE} \ 270 ${INSTALLFLAGS} lib${LIB}_p.a ${DESTDIR}${LIBDIR} 271.endif 272.endif 273.if !defined(NOPIC) 274.if ${OBJFORMAT} == aout 275.if defined(SHLIB_MAJOR) && defined(SHLIB_MINOR) 276 ${INSTALL} ${COPY} -o ${LIBOWN} -g ${LIBGRP} -m ${LIBMODE} \ 277 ${INSTALLFLAGS} ${SHLINSTALLFLAGS} \ 278 lib${LIB}.so.${SHLIB_MAJOR}.${SHLIB_MINOR} \ 279 ${DESTDIR}${SHLIBDIR} 280.endif 281.else 282.if defined(SHLIB_MAJOR) 283 ${INSTALL} ${COPY} -o ${LIBOWN} -g ${LIBGRP} -m ${LIBMODE} \ 284 ${INSTALLFLAGS} ${SHLINSTALLFLAGS} \ 285 lib${LIB}.so.${SHLIB_MAJOR} \ 286 ${DESTDIR}${SHLIBDIR} 287 ln ${LN_FLAGS} -sf lib${LIB}.so.${SHLIB_MAJOR} \ 288 ${DESTDIR}${SHLIBDIR}/lib${LIB}.so 289.endif 290.endif 291.if defined(INSTALL_PIC_ARCHIVE) 292 ${INSTALL} ${COPY} -o ${LIBOWN} -g ${LIBGRP} -m ${LIBMODE} \ 293 ${INSTALLFLAGS} lib${LIB}_pic.a ${DESTDIR}${LIBDIR} 294.endif 295.endif 296.if defined(LINKS) && !empty(LINKS) 297 @set ${LINKS}; \ 298 while test $$# -ge 2; do \ 299 l=${DESTDIR}$$1; \ 300 shift; \ 301 t=${DESTDIR}$$1; \ 302 shift; \ 303 ${ECHO} $$t -\> $$l; \ 304 rm -f $$t; \ 305 ln ${LN_FLAGS} $$l $$t; \ 306 done; true 307.endif 308 309install: afterinstall _SUBDIR 310.if !defined(NOMAN) 311afterinstall: realinstall maninstall 312.else 313afterinstall: realinstall 314.endif 315.endif 316 317.if !target(regress) 318regress: 319.endif 320 321DISTRIBUTION?= bin 322.if !target(distribute) 323distribute: _SUBDIR 324.for dist in ${DISTRIBUTION} 325 cd ${.CURDIR} ; $(MAKE) install DESTDIR=${DISTDIR}/${dist} SHARED=copies 326.endfor 327.endif 328 329.if !target(lint) 330lint: 331.endif 332 333.if !defined(NOMAN) 334.include <bsd.man.mk> 335.elif !target(maninstall) 336maninstall: 337all-man: 338.endif 339 340.include <bsd.dep.mk> 341 342.if !exists(${DEPENDFILE}) 343${OBJS} ${POBJS} ${SOBJS}: ${SRCS:M*.h} 344.endif 345 346.include <bsd.obj.mk> 347