bsd.lib.mk revision 1.18 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 .cc .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 .cc.o .C.o:
39 ${CXX} ${CXXFLAGS} -c ${.IMPSRC}
40 @${LD} -x -r ${.TARGET}
41 @mv a.out ${.TARGET}
42
43 .cc.po .C.po:
44 ${CXX} -p ${CXXFLAGS} -c ${.IMPSRC} -o ${.TARGET}
45 @${LD} -X -r ${.TARGET}
46 @mv a.out ${.TARGET}
47
48 .s.o:
49 ${CPP} -E ${CFLAGS:M-[ID]*} ${AINC} ${.IMPSRC} | \
50 ${AS} -o ${.TARGET}
51 @${LD} -x -r ${.TARGET}
52 @mv a.out ${.TARGET}
53
54 .s.po:
55 ${CPP} -E -DPROF ${CFLAGS:M-[ID]*} ${AINC} ${.IMPSRC} | \
56 ${AS} -o ${.TARGET}
57 @${LD} -X -r ${.TARGET}
58 @mv a.out ${.TARGET}
59
60 .if !defined(NOMAN)
61 MANALL= ${MAN1} ${MAN2} ${MAN3} ${MAN4} ${MAN5} ${MAN6} ${MAN7} ${MAN8}
62 .endif
63
64 .if !defined(NOPROFILE)
65 _LIBS=lib${LIB}.a lib${LIB}_p.a
66 .else
67 _LIBS=lib${LIB}.a
68 .endif
69
70 all: ${_LIBS} ${MANALL}# llib-l${LIB}.ln
71
72 OBJS+= ${SRCS:R:S/$/.o/g}
73
74 lib${LIB}.a:: ${OBJS}
75 @echo building standard ${LIB} library
76 @rm -f lib${LIB}.a
77 @${AR} cTq lib${LIB}.a `lorder ${OBJS} | tsort` ${LDADD}
78 ${RANLIB} lib${LIB}.a
79
80 POBJS+= ${OBJS:.o=.po}
81 lib${LIB}_p.a:: ${POBJS}
82 @echo building profiled ${LIB} library
83 @rm -f lib${LIB}_p.a
84 @${AR} cTq lib${LIB}_p.a `lorder ${POBJS} | tsort` ${LDADD}
85 ${RANLIB} lib${LIB}_p.a
86
87 llib-l${LIB}.ln: ${SRCS}
88 ${LINT} -C${LIB} ${CFLAGS} ${.ALLSRC:M*.c}
89
90 .if !target(clean)
91 clean:
92 rm -f a.out Errs errs mklog core ${CLEANFILES}
93 rm -f ${OBJS}
94 rm -f ${POBJS} profiled/*.o
95 rm -f lib${LIB}.a lib${LIB}_p.a llib-l${LIB}.ln
96 .endif
97
98 .if !target(cleandir)
99 cleandir:
100 rm -f a.out Errs errs mklog core ${CLEANFILES}
101 rm -f ${OBJS}
102 rm -f ${POBJS} profiled/*.o
103 rm -f 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)
108 depend: .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)
118 beforeinstall:
119 @if [ ! -d "${DESTDIR}${LIBDIR}" ]; then \
120 /bin/rm -f ${DESTDIR}${LIBDIR} ; \
121 mkdir -p ${DESTDIR}${LIBDIR} ; \
122 chown root.wheel ${DESTDIR}${LIBDIR} ; \
123 chmod 755 ${DESTDIR}${LIBDIR} ; \
124 else \
125 true ; \
126 fi
127 .endif
128
129 realinstall:
130 # ranlib lib${LIB}.a
131 install ${COPY} -o ${LIBOWN} -g ${LIBGRP} -m ${LIBMODE} lib${LIB}.a \
132 ${DESTDIR}${LIBDIR}
133 ${RANLIB} -t ${DESTDIR}${LIBDIR}/lib${LIB}.a
134 .if !defined(NOPROFILE)
135 # ranlib lib${LIB}_p.a
136 install ${COPY} -o ${LIBOWN} -g ${LIBGRP} -m ${LIBMODE} \
137 lib${LIB}_p.a ${DESTDIR}${LIBDIR}
138 ${RANLIB} -t ${DESTDIR}${LIBDIR}/lib${LIB}_p.a
139 .endif
140 # install ${COPY} -o ${LIBOWN} -g ${LIBGRP} -m ${LIBMODE} \
141 # llib-l${LIB}.ln ${DESTDIR}${LINTLIBDIR}
142 .if defined(LINKS) && !empty(LINKS)
143 @set ${LINKS}; \
144 while test $$# -ge 2; do \
145 l=${DESTDIR}$$1; \
146 shift; \
147 t=${DESTDIR}$$1; \
148 shift; \
149 echo $$t -\> $$l; \
150 rm -f $$t; \
151 ln $$l $$t; \
152 done; true
153 .endif
154
155 install: maninstall
156 maninstall: afterinstall
157 afterinstall: realinstall
158 realinstall: beforeinstall
159 .endif
160
161 .if !target(lint)
162 lint:
163 .endif
164
165 .if !target(tags)
166 tags: ${SRCS}
167 -cd ${.CURDIR}; ctags -f /dev/stdout ${.ALLSRC:M*.c} | \
168 sed "s;\${.CURDIR}/;;" > tags
169 .endif
170
171 .if !defined(NOMAN)
172 .include <bsd.man.mk>
173 .endif
174
175 .if !target(obj)
176 .if defined(NOOBJ)
177 obj:
178 .else
179 obj:
180 @cd ${.CURDIR}; rm -f obj > /dev/null 2>&1 || true; \
181 here=`pwd`; subdir=`echo $$here | sed 's,^/usr/src/,,'`; \
182 if test $$here != $$subdir ; then \
183 dest=/usr/obj/$$subdir ; \
184 echo "$$here -> $$dest"; ln -s $$dest obj; \
185 if test -d /usr/obj -a ! -d $$dest; then \
186 mkdir -p $$dest; \
187 else \
188 true; \
189 fi; \
190 else \
191 true ; \
192 dest=$$here/obj ; \
193 echo "making $$here/obj" ; \
194 if test ! -d obj ; then \
195 mkdir $$here/obj; \
196 fi; \
197 fi;
198 .endif
199 .endif
200