bsd.lib.mk revision 1.21 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:N*.h: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 rm -f .depend
111 files="${.ALLSRC:M*.c}"; \
112 if [ "$$files" != "" ]; then \
113 mkdep -a ${MKDEP} ${CFLAGS:M-[ID]*} $$files; \
114 fi
115 files="${.ALLSRC:M*.cc} ${.ALLSRC:M*.C} ${.ALLSRC:M*.cxx}"; \
116 if [ "$$files" != " " ]; then \
117 mkdep -a ${MKDEP} -+ ${CXXFLAGS:M-[ID]*} $$files; \
118 fi
119 @(TMP=/tmp/_depend$$$$; \
120 sed -e 's/^\([^\.]*\).o[ ]*:/\1.o \1.po:/' < .depend > $$TMP; \
121 mv $$TMP .depend)
122 .endif
123
124 .if !target(install)
125 .if !target(beforeinstall)
126 beforeinstall:
127 @if [ ! -d "${DESTDIR}${LIBDIR}" ]; then \
128 /bin/rm -f ${DESTDIR}${LIBDIR} ; \
129 mkdir -p ${DESTDIR}${LIBDIR} ; \
130 chown root.wheel ${DESTDIR}${LIBDIR} ; \
131 chmod 755 ${DESTDIR}${LIBDIR} ; \
132 else \
133 true ; \
134 fi
135 .endif
136
137 realinstall:
138 # ranlib lib${LIB}.a
139 install ${COPY} -o ${LIBOWN} -g ${LIBGRP} -m ${LIBMODE} lib${LIB}.a \
140 ${DESTDIR}${LIBDIR}
141 ${RANLIB} -t ${DESTDIR}${LIBDIR}/lib${LIB}.a
142 .if !defined(NOPROFILE)
143 # ranlib lib${LIB}_p.a
144 install ${COPY} -o ${LIBOWN} -g ${LIBGRP} -m ${LIBMODE} \
145 lib${LIB}_p.a ${DESTDIR}${LIBDIR}
146 ${RANLIB} -t ${DESTDIR}${LIBDIR}/lib${LIB}_p.a
147 .endif
148 # install ${COPY} -o ${LIBOWN} -g ${LIBGRP} -m ${LIBMODE} \
149 # llib-l${LIB}.ln ${DESTDIR}${LINTLIBDIR}
150 .if defined(LINKS) && !empty(LINKS)
151 @set ${LINKS}; \
152 while test $$# -ge 2; do \
153 l=${DESTDIR}$$1; \
154 shift; \
155 t=${DESTDIR}$$1; \
156 shift; \
157 echo $$t -\> $$l; \
158 rm -f $$t; \
159 ln $$l $$t; \
160 done; true
161 .endif
162
163 install: maninstall
164 maninstall: afterinstall
165 afterinstall: realinstall
166 realinstall: beforeinstall
167 .endif
168
169 .if !target(lint)
170 lint:
171 .endif
172
173 .if !target(tags)
174 tags: ${SRCS}
175 -cd ${.CURDIR}; ctags -f /dev/stdout ${.ALLSRC:M*.c} | \
176 sed "s;\${.CURDIR}/;;" > tags
177 .endif
178
179 .if !defined(NOMAN)
180 .include <bsd.man.mk>
181 .endif
182
183 .if !target(obj)
184 .if defined(NOOBJ)
185 obj:
186 .else
187 obj:
188 @cd ${.CURDIR}; rm -f obj > /dev/null 2>&1 || true; \
189 here=`pwd`; subdir=`echo $$here | sed 's,^/usr/src/,,'`; \
190 if test $$here != $$subdir ; then \
191 dest=/usr/obj/$$subdir ; \
192 echo "$$here -> $$dest"; ln -s $$dest obj; \
193 if test -d /usr/obj -a ! -d $$dest; then \
194 mkdir -p $$dest; \
195 else \
196 true; \
197 fi; \
198 else \
199 true ; \
200 dest=$$here/obj ; \
201 if test ! -d obj ; then \
202 echo "making $$dest" ; \
203 mkdir $$dest; \
204 fi; \
205 fi;
206 .endif
207 .endif
208