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