Home | History | Annotate | Line # | Download | only in mk
bsd.lib.mk revision 1.15
      1 #	@(#)bsd.lib.mk	5.26 (Berkeley) 5/2/91
      2 
      3 .if exists(${.CURDIR}/../Makefile.inc)
      4 .include "${.CURDIR}/../Makefile.inc"
      5 .endif
      6 
      7 LIBDIR?=	/usr/lib
      8 LINTLIBDIR?=	/usr/libdata/lint
      9 LIBGRP?=	bin
     10 LIBOWN?=	bin
     11 LIBMODE?=	444
     12 
     13 STRIP?=	-s
     14 
     15 BINGRP?=	bin
     16 BINOWN?=	bin
     17 BINMODE?=	555
     18 
     19 .MAIN: all
     20 
     21 # prefer .s to a .c, add .po, remove stuff not used in the BSD libraries
     22 .SUFFIXES:
     23 .SUFFIXES: .out .o .po .s .c .f .y .l .8 .7 .6 .5 .4 .3 .2 .1 .0
     24 
     25 .8.0 .7.0 .6.0 .5.0 .4.0 .3.0 .2.0 .1.0:
     26 	nroff -mandoc ${.IMPSRC} > ${.TARGET}
     27 
     28 .c.o:
     29 	${CC} ${CFLAGS} -c ${.IMPSRC} 
     30 	@${LD} -x -r ${.TARGET}
     31 	@mv a.out ${.TARGET}
     32 
     33 .c.po:
     34 	${CC} -p ${CFLAGS} -c ${.IMPSRC} -o ${.TARGET}
     35 	@${LD} -X -r ${.TARGET}
     36 	@mv a.out ${.TARGET}
     37 
     38 .s.o:
     39 	${CPP} -E ${CFLAGS:M-[ID]*} ${AINC} ${.IMPSRC} | \
     40 	    ${AS} -o ${.TARGET}
     41 	@${LD} -x -r ${.TARGET}
     42 	@mv a.out ${.TARGET}
     43 
     44 .s.po:
     45 	${CPP} -E -DPROF ${CFLAGS:M-[ID]*} ${AINC} ${.IMPSRC} | \
     46 	    ${AS} -o ${.TARGET}
     47 	@${LD} -X -r ${.TARGET}
     48 	@mv a.out ${.TARGET}
     49 
     50 .if !defined(NOMAN)
     51 MANALL=	${MAN1} ${MAN2} ${MAN3} ${MAN4} ${MAN5} ${MAN6} ${MAN7} ${MAN8}
     52 .endif
     53 
     54 .if !defined(NOPROFILE)
     55 _LIBS=lib${LIB}.a lib${LIB}_p.a
     56 .else
     57 _LIBS=lib${LIB}.a
     58 .endif
     59 
     60 all: ${_LIBS} ${MANALL}# llib-l${LIB}.ln
     61 
     62 OBJS+=	${SRCS:R:S/$/.o/g}
     63 
     64 lib${LIB}.a:: ${OBJS}
     65 	@echo building standard ${LIB} library
     66 	@rm -f lib${LIB}.a
     67 	@${AR} cTq lib${LIB}.a ${OBJS} ${LDADD}
     68 	${RANLIB} lib${LIB}.a
     69 
     70 POBJS+=	${OBJS:.o=.po}
     71 lib${LIB}_p.a:: ${POBJS}
     72 	@echo building profiled ${LIB} library
     73 	@rm -f lib${LIB}_p.a
     74 	@${AR} cTq lib${LIB}_p.a ${POBJS} ${LDADD}
     75 	${RANLIB} lib${LIB}_p.a
     76 
     77 llib-l${LIB}.ln: ${SRCS}
     78 	${LINT} -C${LIB} ${CFLAGS} ${.ALLSRC:M*.c}
     79 
     80 .if !target(clean)
     81 clean:
     82 	rm -f a.out Errs errs mklog core ${CLEANFILES}
     83 	rm -f ${OBJS}
     84 	rm -f ${POBJS} profiled/*.o
     85 	rm -f lib${LIB}.a lib${LIB}_p.a llib-l${LIB}.ln
     86 .endif
     87 
     88 .if !target(cleandir)
     89 cleandir:
     90 	rm -f a.out Errs errs mklog core ${CLEANFILES}
     91 	rm -f ${OBJS}
     92 	rm -f ${POBJS} profiled/*.o
     93 	rm -f lib${LIB}.a lib${LIB}_p.a llib-l${LIB}.ln
     94 	rm -f ${MANALL} ${.CURDIR}/tags .depend
     95 .endif
     96 
     97 .if !target(depend)
     98 depend: .depend
     99 .depend: ${SRCS}
    100 	mkdep ${CFLAGS:M-[ID+]*} ${AINC} ${.ALLSRC}
    101 	@(TMP=/tmp/_depend$$$$; \
    102 	    sed -e 's/^\([^\.]*\).o[ ]*:/\1.o \1.po:/' < .depend > $$TMP; \
    103 	    mv $$TMP .depend)
    104 .endif
    105 
    106 .if !target(install)
    107 .if !target(beforeinstall)
    108 beforeinstall:
    109 	@if [ ! -d "${DESTDIR}${LIBDIR}" ]; then \
    110 		/bin/rm -f ${DESTDIR}${LIBDIR} ; \
    111 		mkdir -p ${DESTDIR}${LIBDIR} ; \
    112 		chown root.wheel ${DESTDIR}${LIBDIR} ; \
    113 		chmod 755 ${DESTDIR}${LIBDIR} ; \
    114 	else \
    115 		true ; \
    116 	fi
    117 .endif
    118 
    119 realinstall:
    120 #	ranlib lib${LIB}.a
    121 	install ${COPY} -o ${LIBOWN} -g ${LIBGRP} -m ${LIBMODE} lib${LIB}.a \
    122 	    ${DESTDIR}${LIBDIR}
    123 	${RANLIB} -t ${DESTDIR}${LIBDIR}/lib${LIB}.a
    124 .if !defined(NOPROFILE)
    125 #	ranlib lib${LIB}_p.a
    126 	install ${COPY} -o ${LIBOWN} -g ${LIBGRP} -m ${LIBMODE} \
    127 	    lib${LIB}_p.a ${DESTDIR}${LIBDIR}
    128 	${RANLIB} -t ${DESTDIR}${LIBDIR}/lib${LIB}_p.a
    129 .endif
    130 #	install ${COPY} -o ${LIBOWN} -g ${LIBGRP} -m ${LIBMODE} \
    131 #	    llib-l${LIB}.ln ${DESTDIR}${LINTLIBDIR}
    132 .if defined(LINKS) && !empty(LINKS)
    133 	@set ${LINKS}; \
    134 	while test $$# -ge 2; do \
    135 		l=${DESTDIR}$$1; \
    136 		shift; \
    137 		t=${DESTDIR}$$1; \
    138 		shift; \
    139 		echo $$t -\> $$l; \
    140 		rm -f $$t; \
    141 		ln $$l $$t; \
    142 	done; true
    143 .endif
    144 
    145 install: maninstall
    146 maninstall: afterinstall
    147 afterinstall: realinstall
    148 realinstall: beforeinstall
    149 .endif
    150 
    151 .if !target(lint)
    152 lint:
    153 .endif
    154 
    155 .if !target(tags)
    156 tags: ${SRCS}
    157 	-cd ${.CURDIR}; ctags -f /dev/stdout ${.ALLSRC:M*.c} | \
    158 	    sed "s;\${.CURDIR}/;;" > tags
    159 .endif
    160 
    161 .if !defined(NOMAN)
    162 .include <bsd.man.mk>
    163 .endif
    164 
    165 .if !target(obj)
    166 .if defined(NOOBJ)
    167 obj:
    168 .else
    169 obj:
    170 	@cd ${.CURDIR}; rm -f obj > /dev/null 2>&1 || true; \
    171 	here=`pwd`; subdir=`echo $$here | sed 's,^/usr/src/,,'`; \
    172 	if test $$here != $$subdir ; then \
    173 		dest=/usr/obj/$$subdir ; \
    174 		echo "$$here -> $$dest"; ln -s $$dest obj; \
    175 		if test -d /usr/obj -a ! -d $$dest; then \
    176 			mkdir -p $$dest; \
    177 		else \
    178 			true; \
    179 		fi; \
    180 	else \
    181 		true ; \
    182 		dest=$$here/obj ; \
    183 		echo "making $$here/obj" ; \
    184 		if test ! -d obj ; then \
    185 			mkdir $$here/obj; \
    186 		fi; \
    187 	fi;
    188 .endif
    189 .endif
    190