Start removing the old build infrastructure for the a.out
[dragonfly.git] / share / mk / bsd.lib.mk
CommitLineData
984263bc
MD
1# from: @(#)bsd.lib.mk 5.26 (Berkeley) 5/2/91
2# $FreeBSD: src/share/mk/bsd.lib.mk,v 1.91.2.15 2002/08/07 16:31:50 ru Exp $
aa8d5dcb 3# $DragonFly: src/share/mk/bsd.lib.mk,v 1.5 2004/03/20 16:27:41 drhodus Exp $
984263bc
MD
4#
5
6.include <bsd.init.mk>
7
8# Set up the variables controlling shared libraries. After this section,
9# SHLIB_NAME will be defined only if we are to create a shared library.
10# SHLIB_LINK will be defined only if we are to create a link to it.
11# INSTALL_PIC_ARCHIVE will be defined only if we are to create a PIC archive.
12.if defined(NOPIC)
13.undef SHLIB_NAME
14.undef INSTALL_PIC_ARCHIVE
15.else
984263bc
MD
16.if !defined(SHLIB_NAME) && defined(LIB) && defined(SHLIB_MAJOR)
17SHLIB_NAME= lib${LIB}.so.${SHLIB_MAJOR}
18.endif
19.if defined(SHLIB_NAME) && ${SHLIB_NAME:M*.so.*}
20SHLIB_LINK?= ${SHLIB_NAME:R}
21.endif
22SONAME?= ${SHLIB_NAME}
984263bc
MD
23.endif
24
25.if defined(DEBUG_FLAGS)
26CFLAGS+= ${DEBUG_FLAGS}
27.endif
28
29.if !defined(DEBUG_FLAGS)
30STRIP?= -s
31.endif
32
984263bc 33.include <bsd.libnames.mk>
4806ab2e
MD
34.if defined(USEGNUDIR)
35USELIBDIR?=${GCCLIBDIR}
36USESHLIBDIR?=${GCCSHLIBDIR}
37.else
38USELIBDIR?=${LIBDIR}
39USESHLIBDIR?=${SHLIBDIR}
40.endif
984263bc
MD
41
42# prefer .s to a .c, add .po, remove stuff not used in the BSD libraries
43# .So used for PIC object files
44.SUFFIXES:
45.SUFFIXES: .out .o .po .So .S .s .c .cc .cpp .cxx .m .C .f .y .l
46
47.if !defined(PICFLAG)
48PICFLAG=-fpic
49.endif
50
4806ab2e
MD
51PO_FLAG=-pg
52
984263bc
MD
53.c.o:
54 ${CC} ${CFLAGS} -c ${.IMPSRC} -o ${.TARGET}
55 @${LD} -o ${.TARGET}.tmp -x -r ${.TARGET}
56 @mv ${.TARGET}.tmp ${.TARGET}
57
58.c.po:
4806ab2e 59 ${CC} ${PO_FLAG} ${CFLAGS} -c ${.IMPSRC} -o ${.TARGET}
984263bc
MD
60 @${LD} -o ${.TARGET}.tmp -X -r ${.TARGET}
61 @mv ${.TARGET}.tmp ${.TARGET}
62
63.c.So:
64 ${CC} ${PICFLAG} -DPIC ${CFLAGS} -c ${.IMPSRC} -o ${.TARGET}
65 @${LD} ${LDFLAGS} -o ${.TARGET}.tmp -x -r ${.TARGET}
66 @mv ${.TARGET}.tmp ${.TARGET}
67
68.cc.o .C.o .cpp.o .cxx.o:
69 ${CXX} ${CXXFLAGS} -c ${.IMPSRC} -o ${.TARGET}
70 @${LD} -o ${.TARGET}.tmp -x -r ${.TARGET}
71 @mv ${.TARGET}.tmp ${.TARGET}
72
73.cc.po .C.po .cpp.po .cxx.po:
4806ab2e 74 ${CXX} ${PO_FLAG} ${CXXFLAGS} -c ${.IMPSRC} -o ${.TARGET}
984263bc
MD
75 @${LD} -o ${.TARGET}.tmp -X -r ${.TARGET}
76 @mv ${.TARGET}.tmp ${.TARGET}
77
78.cc.So .C.So .cpp.So .cxx.So:
79 ${CXX} ${PICFLAG} -DPIC ${CXXFLAGS} -c ${.IMPSRC} -o ${.TARGET}
80 @${LD} ${LDFLAGS} -o ${.TARGET}.tmp -x -r ${.TARGET}
81 @mv ${.TARGET}.tmp ${.TARGET}
82
83.f.o:
84 ${FC} ${FFLAGS} -o ${.TARGET} -c ${.IMPSRC}
85 @${LD} -o ${.TARGET}.tmp -x -r ${.TARGET}
86 @mv ${.TARGET}.tmp ${.TARGET}
87
88.f.po:
89 ${FC} -pg ${FFLAGS} -o ${.TARGET} -c ${.IMPSRC}
90 @${LD} -o ${.TARGET}.tmp -X -r ${.TARGET}
91 @mv ${.TARGET}.tmp ${.TARGET}
92
93.f.So:
94 ${FC} ${PICFLAG} -DPIC ${FFLAGS} -o ${.TARGET} -c ${.IMPSRC}
95 @${LD} ${LDFLAGS} -o ${.TARGET}.tmp -x -r ${.TARGET}
96 @mv ${.TARGET}.tmp ${.TARGET}
97
98.m.o:
99 ${OBJC} ${OBJCFLAGS} -c ${.IMPSRC} -o ${.TARGET}
100 @${LD} -o ${.TARGET}.tmp -x -r ${.TARGET}
101 @mv ${.TARGET}.tmp ${.TARGET}
102
103.m.po:
104 ${OBJC} ${OBJCFLAGS} -pg -c ${.IMPSRC} -o ${.TARGET}
105 @${LD} -o ${.TARGET}.tmp -X -r ${.TARGET}
106 @mv ${.TARGET}.tmp ${.TARGET}
107
108.m.So:
109 ${OBJC} ${PICFLAG} -DPIC ${OBJCFLAGS} -c ${.IMPSRC} -o ${.TARGET}
110 @${LD} ${LDFLAGS} -o ${.TARGET}.tmp -x -r ${.TARGET}
111 @mv ${.TARGET}.tmp ${.TARGET}
112
113.s.o:
114 ${CC} -x assembler-with-cpp ${CFLAGS} ${AINC} -c \
115 ${.IMPSRC} -o ${.TARGET}
116 @${LD} ${LDFLAGS} -o ${.TARGET}.tmp -x -r ${.TARGET}
117 @mv ${.TARGET}.tmp ${.TARGET}
118
119.s.po:
120 ${CC} -x assembler-with-cpp -DPROF ${CFLAGS} ${AINC} -c \
121 ${.IMPSRC} -o ${.TARGET}
122 @${LD} ${LDFLAGS} -o ${.TARGET}.tmp -X -r ${.TARGET}
123 @mv ${.TARGET}.tmp ${.TARGET}
124
125.s.So:
126 ${CC} -x assembler-with-cpp ${PICFLAG} -DPIC ${CFLAGS} \
127 ${AINC} -c ${.IMPSRC} -o ${.TARGET}
128 @${LD} -o ${.TARGET}.tmp -x -r ${.TARGET}
129 @mv ${.TARGET}.tmp ${.TARGET}
130
131.S.o:
132 ${CC} ${CFLAGS} ${AINC} -c ${.IMPSRC} -o ${.TARGET}
133 @${LD} ${LDFLAGS} -o ${.TARGET}.tmp -x -r ${.TARGET}
134 @mv ${.TARGET}.tmp ${.TARGET}
135
136.S.po:
137 ${CC} -DPROF ${CFLAGS} ${AINC} -c ${.IMPSRC} -o ${.TARGET}
138 @${LD} ${LDFLAGS} -o ${.TARGET}.tmp -X -r ${.TARGET}
139 @mv ${.TARGET}.tmp ${.TARGET}
140
141.S.So:
142 ${CC} ${PICFLAG} -DPIC ${CFLAGS} ${AINC} -c ${.IMPSRC} \
143 -o ${.TARGET}
144 @${LD} -o ${.TARGET}.tmp -x -r ${.TARGET}
145 @mv ${.TARGET}.tmp ${.TARGET}
146
147all: objwarn
148
149.if defined(LIB) && !empty(LIB) || defined(SHLIB_NAME)
acbbf55b
JS
150OBJS+= ${SRCS:N*.h:N*.patch:R:S/$/.o/g}
151.for _PATCH in ${SRCS:T:N*.h.patch:M*.patch}
152.for _OBJ in ${_PATCH:R:R:S/$/.o/}
153OBJS:= ${OBJS:N${_OBJ}} ${_OBJ}
154.endfor
155.endfor
984263bc
MD
156.endif
157
158.if defined(LIB) && !empty(LIB)
159_LIBS= lib${LIB}.a
160
161lib${LIB}.a: ${OBJS} ${STATICOBJS}
162 @${ECHO} building static ${LIB} library
163 @rm -f ${.TARGET}
164 @${AR} cq ${.TARGET} `lorder ${OBJS} ${STATICOBJS} | tsort -q` ${ARADD}
165 ${RANLIB} ${.TARGET}
166.endif
167
168.if !defined(INTERNALLIB)
169
170.if !defined(NOPROFILE) && defined(LIB) && !empty(LIB)
171_LIBS+= lib${LIB}_p.a
172POBJS+= ${OBJS:.o=.po} ${STATICOBJS:.o=.po}
173
174lib${LIB}_p.a: ${POBJS}
175 @${ECHO} building profiled ${LIB} library
176 @rm -f ${.TARGET}
177 @${AR} cq ${.TARGET} `lorder ${POBJS} | tsort -q` ${ARADD}
178 ${RANLIB} ${.TARGET}
179.endif
180
181.if defined(SHLIB_NAME) || \
182 defined(INSTALL_PIC_ARCHIVE) && defined(LIB) && !empty(LIB)
183SOBJS+= ${OBJS:.o=.So}
184.endif
185
186.if defined(SHLIB_NAME)
187_LIBS+= ${SHLIB_NAME}
188
189${SHLIB_NAME}: ${SOBJS}
190 @${ECHO} building shared library ${SHLIB_NAME}
191 @rm -f ${.TARGET} ${SHLIB_LINK}
192.if defined(SHLIB_LINK)
193 @ln -fs ${.TARGET} ${SHLIB_LINK}
194.endif
984263bc
MD
195 @${CC} ${LDFLAGS} -shared -Wl,-x \
196 -o ${.TARGET} -Wl,-soname,${SONAME} \
197 `lorder ${SOBJS} | tsort -q` ${LDADD}
198.endif
984263bc
MD
199
200.if defined(INSTALL_PIC_ARCHIVE) && defined(LIB) && !empty(LIB)
201_LIBS+= lib${LIB}_pic.a
202
203lib${LIB}_pic.a: ${SOBJS}
204 @${ECHO} building special pic ${LIB} library
205 @rm -f ${.TARGET}
206 @${AR} cq ${.TARGET} ${SOBJS} ${ARADD}
207 ${RANLIB} ${.TARGET}
208.endif
209
4806ab2e 210.endif # !defined(INTERNALLIB)
984263bc
MD
211
212all: ${_LIBS}
213
214.if !defined(NOMAN)
215all: _manpages
216.endif
217
218_EXTRADEPEND:
219 @TMP=_depend$$$$; \
220 sed -e 's/^\([^\.]*\).o[ ]*:/\1.o \1.po \1.So:/' < ${DEPENDFILE} \
221 > $$TMP; \
222 mv $$TMP ${DEPENDFILE}
223.if !defined(NOEXTRADEPEND) && defined(SHLIB_NAME)
984263bc
MD
224.if defined(DPADD) && !empty(DPADD)
225 echo ${SHLIB_NAME}: ${DPADD} >> ${DEPENDFILE}
226.endif
227.endif
984263bc
MD
228
229.if !target(install)
230
231.if defined(PRECIOUSLIB) && !defined(NOFSCHG)
232SHLINSTALLFLAGS+= -fschg
233.endif
234
235_INSTALLFLAGS:= ${INSTALLFLAGS}
236.for ie in ${INSTALLFLAGS_EDIT}
237_INSTALLFLAGS:= ${_INSTALLFLAGS${ie}}
238.endfor
239_SHLINSTALLFLAGS:= ${SHLINSTALLFLAGS}
240.for ie in ${INSTALLFLAGS_EDIT}
241_SHLINSTALLFLAGS:= ${_SHLINSTALLFLAGS${ie}}
242.endfor
243
244.if !defined(INTERNALLIB)
245realinstall: _libinstall
246.ORDER: beforeinstall _libinstall
247_libinstall:
248.if defined(LIB) && !empty(LIB) && !defined(NOINSTALLLIB)
249 ${INSTALL} -C -o ${LIBOWN} -g ${LIBGRP} -m ${LIBMODE} \
4806ab2e 250 ${_INSTALLFLAGS} lib${LIB}.a ${DESTDIR}${USELIBDIR}
984263bc
MD
251.endif
252.if !defined(NOPROFILE) && defined(LIB) && !empty(LIB)
253 ${INSTALL} -C -o ${LIBOWN} -g ${LIBGRP} -m ${LIBMODE} \
4806ab2e 254 ${_INSTALLFLAGS} lib${LIB}_p.a ${DESTDIR}${USELIBDIR}
984263bc
MD
255.endif
256.if defined(SHLIB_NAME)
257 ${INSTALL} ${STRIP} -o ${LIBOWN} -g ${LIBGRP} -m ${LIBMODE} \
258 ${_INSTALLFLAGS} ${_SHLINSTALLFLAGS} \
4806ab2e 259 ${SHLIB_NAME} ${DESTDIR}${USESHLIBDIR}
984263bc 260.if defined(SHLIB_LINK)
4806ab2e 261 ln -fs ${SHLIB_NAME} ${DESTDIR}${USESHLIBDIR}/${SHLIB_LINK}
984263bc
MD
262.endif
263.endif
264.if defined(INSTALL_PIC_ARCHIVE) && defined(LIB) && !empty(LIB)
265 ${INSTALL} -o ${LIBOWN} -g ${LIBGRP} -m ${LIBMODE} \
4806ab2e 266 ${_INSTALLFLAGS} lib${LIB}_pic.a ${DESTDIR}${USELIBDIR}
984263bc
MD
267.endif
268.endif !defined(INTERNALLIB)
269
270.include <bsd.files.mk>
271.include <bsd.incs.mk>
272.include <bsd.links.mk>
273
274.if !defined(NOMAN)
275realinstall: _maninstall
276.ORDER: beforeinstall _maninstall
277.endif
278
279.endif
280
281.if !defined(NOMAN)
282.include <bsd.man.mk>
283.endif
284
285.include <bsd.dep.mk>
286
287.if !exists(${.OBJDIR}/${DEPENDFILE})
288.if defined(LIB) && !empty(LIB)
289${OBJS} ${STATICOBJS} ${POBJS}: ${SRCS:M*.h}
290.endif
291.if defined(SHLIB_NAME) || \
292 defined(INSTALL_PIC_ARCHIVE) && defined(LIB) && !empty(LIB)
293${SOBJS}: ${SRCS:M*.h}
294.endif
295.endif
296
297.if !target(clean)
298clean:
299.if defined(CLEANFILES) && !empty(CLEANFILES)
300 rm -f ${CLEANFILES}
301.endif
302.if defined(LIB) && !empty(LIB)
303 rm -f a.out ${OBJS} ${OBJS:S/$/.tmp/} ${STATICOBJS}
304.endif
305.if !defined(INTERNALLIB)
306.if !defined(NOPROFILE) && defined(LIB) && !empty(LIB)
307 rm -f ${POBJS} ${POBJS:S/$/.tmp/}
308.endif
309.if defined(SHLIB_NAME) || \
310 defined(INSTALL_PIC_ARCHIVE) && defined(LIB) && !empty(LIB)
311 rm -f ${SOBJS} ${SOBJS:.So=.so} ${SOBJS:S/$/.tmp/}
312.endif
313.if defined(SHLIB_NAME)
314.if defined(SHLIB_LINK)
315 rm -f ${SHLIB_LINK}
316.endif
317.if defined(LIB) && !empty(LIB)
318 rm -f lib${LIB}.so.* lib${LIB}.so
319.endif
320.endif
321.endif !defined(INTERNALLIB)
322.if defined(_LIBS) && !empty(_LIBS)
323 rm -f ${_LIBS}
324.endif
325.if defined(CLEANDIRS) && !empty(CLEANDIRS)
326 rm -rf ${CLEANDIRS}
327.endif
328.endif
329
330.include <bsd.obj.mk>
331
332.include <bsd.sys.mk>