xref: /original-bsd/share/mk/bsd.lib.mk (revision e59fb703)
1#	@(#)bsd.lib.mk	5.31 (Berkeley) 12/12/91
2
3.if exists(${.CURDIR}/../Makefile.inc)
4.include "${.CURDIR}/../Makefile.inc"
5.endif
6
7LIBDIR?=	/usr/lib
8LINTLIBDIR?=	/usr/libdata/lint
9LIBGRP?=	bin
10LIBOWN?=	bin
11LIBMODE?=	444
12
13STRIP?=	-s
14
15BINGRP?=	bin
16BINOWN?=	bin
17BINMODE?=	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 -man ${.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.if (${MACHINE} == "mips")
39NOPROFILE=1
40.s.o:
41	${AS} ${CFLAGS:M-[ID]*} ${AINC} -o ${.TARGET} ${.IMPSRC}
42	@${LD} -x -r ${.TARGET}
43	@mv a.out ${.TARGET}
44.else
45.s.o:
46	${CPP} -E ${CFLAGS:M-[ID]*} ${AINC} ${.IMPSRC} | \
47	    ${AS} -o ${.TARGET}
48	@${LD} -x -r ${.TARGET}
49	@mv a.out ${.TARGET}
50
51.s.po:
52	${CPP} -E -DPROF ${CFLAGS:M-[ID]*} ${AINC} ${.IMPSRC} | \
53	    ${AS} -o ${.TARGET}
54	@${LD} -X -r ${.TARGET}
55	@mv a.out ${.TARGET}
56.endif
57
58MANALL=	${MAN1} ${MAN2} ${MAN3} ${MAN4} ${MAN5} ${MAN6} ${MAN7} ${MAN8}
59manpages: ${MANALL}
60
61.if !defined(NOPROFILE)
62_LIBS=lib${LIB}.a lib${LIB}_p.a
63.else
64_LIBS=lib${LIB}.a
65.endif
66
67all: ${_LIBS} # llib-l${LIB}.ln
68.if !defined(NOMAN)
69all: ${MANALL}
70.endif
71
72OBJS+=	${SRCS:R:S/$/.o/g}
73
74lib${LIB}.a:: ${OBJS}
75	@echo building standard ${LIB} library
76	@rm -f lib${LIB}.a
77.if (${MACHINE} == "mips")
78	@${AR} cq lib${LIB}.a `lorder ${OBJS} | tsort` ${LDADD}
79.else
80	@${AR} cTq lib${LIB}.a `lorder ${OBJS} | tsort` ${LDADD}
81.endif
82	ranlib lib${LIB}.a
83
84POBJS+=	${OBJS:.o=.po}
85lib${LIB}_p.a:: ${POBJS}
86	@echo building profiled ${LIB} library
87	@rm -f lib${LIB}_p.a
88	@${AR} cTq lib${LIB}_p.a `lorder ${POBJS} | tsort` ${LDADD}
89	ranlib lib${LIB}_p.a
90
91llib-l${LIB}.ln: ${SRCS}
92	${LINT} -C${LIB} ${CFLAGS} ${.ALLSRC:M*.c}
93
94.if !target(clean)
95clean:
96	rm -f a.out Errs errs mklog core ${CLEANFILES} ${OBJS} ${POBJS} \
97	    profiled/*.o lib${LIB}.a lib${LIB}_p.a llib-l${LIB}.ln
98.endif
99
100.if !target(cleandir)
101cleandir:
102	rm -f a.out Errs errs mklog core ${CLEANFILES} ${OBJS} ${POBJS} \
103	    profiled/*.o lib${LIB}.a lib${LIB}_p.a llib-l${LIB}.ln
104	rm -f ${MANALL} ${.CURDIR}/tags .depend
105.endif
106
107.if !target(depend)
108depend: .depend
109.depend: ${SRCS}
110	mkdep ${CFLAGS:M-[ID]*} ${AINC} ${.ALLSRC}
111	@(TMP=/tmp/_depend$$$$; \
112	    sed -e 's/^\([^\.]*\).o:/\1.o \1.po:/' < .depend > $$TMP; \
113	    mv $$TMP .depend)
114.endif
115
116.if !target(install)
117.if !target(beforeinstall)
118beforeinstall:
119.endif
120
121realinstall: beforeinstall
122	ranlib lib${LIB}.a
123	install -o ${LIBOWN} -g ${LIBGRP} -m ${LIBMODE} lib${LIB}.a \
124	    ${DESTDIR}${LIBDIR}
125	${RANLIB} -t ${DESTDIR}${LIBDIR}/lib${LIB}.a
126.if (${MACHINE} != "mips")
127	ranlib lib${LIB}_p.a
128	install -o ${LIBOWN} -g ${LIBGRP} -m ${LIBMODE} \
129	    lib${LIB}_p.a ${DESTDIR}${LIBDIR}
130	${RANLIB} -t ${DESTDIR}${LIBDIR}/lib${LIB}_p.a
131.endif
132#	install -c -o ${LIBOWN} -g ${LIBGRP} -m ${LIBMODE} \
133#	    llib-l${LIB}.ln ${DESTDIR}${LINTLIBDIR}
134.if defined(LINKS) && !empty(LINKS)
135	@set ${LINKS}; \
136	while test $$# -ge 2; do \
137		l=${DESTDIR}$$1; \
138		shift; \
139		t=${DESTDIR}$$1; \
140		shift; \
141		echo $$t -\> $$l; \
142		rm -f $$t; \
143		ln $$l $$t; \
144	done; true
145.endif
146
147install: afterinstall
148afterinstall: realinstall
149.if !defined(NOMAN)
150afterinstall: maninstall
151.endif
152.endif
153
154.if !target(lint)
155lint:
156.endif
157
158.if !target(tags)
159tags: ${SRCS}
160	-cd ${.CURDIR}; ctags -f /dev/stdout ${.ALLSRC:M*.c} | \
161	    sed "s;\${.CURDIR}/;;" > tags
162.endif
163
164.include <bsd.man.mk>
165.if !target(obj)
166.if defined(NOOBJ)
167obj:
168.else
169obj:
170	@cd ${.CURDIR}; rm -rf obj; \
171	here=`pwd`; dest=/usr/obj/`echo $$here | sed 's,/usr/src/,,'`; \
172	echo "$$here -> $$dest"; ln -s $$dest obj; \
173	if test -d /usr/obj -a ! -d $$dest; then \
174		mkdir -p $$dest; \
175	else \
176		true; \
177	fi;
178.endif
179.endif
180