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