Update FILES section and add a few extra cross references.
[dragonfly.git] / share / mk / bsd.lib.mk
blob2cd02f5c05345b189aea7664686b8bfcab302900
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 $
3 # $DragonFly: src/share/mk/bsd.lib.mk,v 1.17 2008/05/19 10:26:02 corecode Exp $
6 .include <bsd.init.mk>
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
16 .if !defined(SHLIB_NAME) && defined(LIB) && defined(SHLIB_MAJOR)
17 SHLIB_NAME= lib${LIB}.so.${SHLIB_MAJOR}
18 .endif
19 .if defined(SHLIB_NAME) && ${SHLIB_NAME:M*.so.*}
20 SHLIB_LINK?= ${SHLIB_NAME:R}
21 .endif
22 SONAME?= ${SHLIB_NAME}
23 .endif
25 .if defined(DEBUG_FLAGS)
26 CFLAGS+= ${DEBUG_FLAGS}
27 .endif
29 .if !defined(DEBUG_FLAGS)
30 STRIP?= -s
31 .endif
33 .include <bsd.libnames.mk>
35 TARGET_LIBDIR?= ${LIBDIR}
36 TARGET_DEBUGLIBDIR?= ${DEBUGLIBDIR}
37 TARGET_PROFLIBDIR?= ${PROFLIBDIR}
38 TARGET_SHLIBDIR?= ${SHLIBDIR}
40 # prefer .s to a .c, add .po, remove stuff not used in the BSD libraries
41 # .So used for PIC object files
42 .SUFFIXES:
43 .SUFFIXES: .out .o .po .So .S .s .c .cc .cpp .cxx .m .C .f .y .l
45 .if !defined(PICFLAG)
46 PICFLAG=-fpic
47 .endif
49 PO_FLAG=-pg
51 .c.o:
52 ${CC} ${CFLAGS} -c ${.IMPSRC} -o ${.TARGET}
53 @${LD} -o ${.TARGET}.tmp -x -r ${.TARGET}
54 @mv ${.TARGET}.tmp ${.TARGET}
56 .c.po:
57 ${CC} ${PO_FLAG} ${CFLAGS} -c ${.IMPSRC} -o ${.TARGET}
58 @${LD} -o ${.TARGET}.tmp -X -r ${.TARGET}
59 @mv ${.TARGET}.tmp ${.TARGET}
61 .c.So:
62 ${CC} ${PICFLAG} -DPIC ${CFLAGS} -c ${.IMPSRC} -o ${.TARGET}
63 @${LD} ${LDFLAGS} -o ${.TARGET}.tmp -x -r ${.TARGET}
64 @mv ${.TARGET}.tmp ${.TARGET}
66 .cc.o .C.o .cpp.o .cxx.o:
67 ${CXX} ${CXXFLAGS} -c ${.IMPSRC} -o ${.TARGET}
68 @${LD} -o ${.TARGET}.tmp -x -r ${.TARGET}
69 @mv ${.TARGET}.tmp ${.TARGET}
71 .cc.po .C.po .cpp.po .cxx.po:
72 ${CXX} ${PO_FLAG} ${CXXFLAGS} -c ${.IMPSRC} -o ${.TARGET}
73 @${LD} -o ${.TARGET}.tmp -X -r ${.TARGET}
74 @mv ${.TARGET}.tmp ${.TARGET}
76 .cc.So .C.So .cpp.So .cxx.So:
77 ${CXX} ${PICFLAG} -DPIC ${CXXFLAGS} -c ${.IMPSRC} -o ${.TARGET}
78 @${LD} ${LDFLAGS} -o ${.TARGET}.tmp -x -r ${.TARGET}
79 @mv ${.TARGET}.tmp ${.TARGET}
81 .f.o:
82 ${FC} ${FFLAGS} -o ${.TARGET} -c ${.IMPSRC}
83 @${LD} -o ${.TARGET}.tmp -x -r ${.TARGET}
84 @mv ${.TARGET}.tmp ${.TARGET}
86 .f.po:
87 ${FC} -pg ${FFLAGS} -o ${.TARGET} -c ${.IMPSRC}
88 @${LD} -o ${.TARGET}.tmp -X -r ${.TARGET}
89 @mv ${.TARGET}.tmp ${.TARGET}
91 .f.So:
92 ${FC} ${PICFLAG} -DPIC ${FFLAGS} -o ${.TARGET} -c ${.IMPSRC}
93 @${LD} ${LDFLAGS} -o ${.TARGET}.tmp -x -r ${.TARGET}
94 @mv ${.TARGET}.tmp ${.TARGET}
96 .m.o:
97 ${OBJC} ${OBJCFLAGS} -c ${.IMPSRC} -o ${.TARGET}
98 @${LD} -o ${.TARGET}.tmp -x -r ${.TARGET}
99 @mv ${.TARGET}.tmp ${.TARGET}
101 .m.po:
102 ${OBJC} ${OBJCFLAGS} -pg -c ${.IMPSRC} -o ${.TARGET}
103 @${LD} -o ${.TARGET}.tmp -X -r ${.TARGET}
104 @mv ${.TARGET}.tmp ${.TARGET}
106 .m.So:
107 ${OBJC} ${PICFLAG} -DPIC ${OBJCFLAGS} -c ${.IMPSRC} -o ${.TARGET}
108 @${LD} ${LDFLAGS} -o ${.TARGET}.tmp -x -r ${.TARGET}
109 @mv ${.TARGET}.tmp ${.TARGET}
111 .s.o:
112 ${CC} -x assembler-with-cpp ${CFLAGS} ${AINC} -c \
113 ${.IMPSRC} -o ${.TARGET}
114 @${LD} ${LDFLAGS} -o ${.TARGET}.tmp -x -r ${.TARGET}
115 @mv ${.TARGET}.tmp ${.TARGET}
117 .s.po:
118 ${CC} -x assembler-with-cpp -DPROF ${CFLAGS} ${AINC} -c \
119 ${.IMPSRC} -o ${.TARGET}
120 @${LD} ${LDFLAGS} -o ${.TARGET}.tmp -X -r ${.TARGET}
121 @mv ${.TARGET}.tmp ${.TARGET}
123 .s.So:
124 ${CC} -x assembler-with-cpp ${PICFLAG} -DPIC ${CFLAGS} \
125 ${AINC} -c ${.IMPSRC} -o ${.TARGET}
126 @${LD} -o ${.TARGET}.tmp -x -r ${.TARGET}
127 @mv ${.TARGET}.tmp ${.TARGET}
129 .S.o:
130 ${CC} ${CFLAGS} ${AINC} -c ${.IMPSRC} -o ${.TARGET}
131 @${LD} ${LDFLAGS} -o ${.TARGET}.tmp -x -r ${.TARGET}
132 @mv ${.TARGET}.tmp ${.TARGET}
134 .S.po:
135 ${CC} -DPROF ${CFLAGS} ${AINC} -c ${.IMPSRC} -o ${.TARGET}
136 @${LD} ${LDFLAGS} -o ${.TARGET}.tmp -X -r ${.TARGET}
137 @mv ${.TARGET}.tmp ${.TARGET}
139 .S.So:
140 ${CC} ${PICFLAG} -DPIC ${CFLAGS} ${AINC} -c ${.IMPSRC} \
141 -o ${.TARGET}
142 @${LD} -o ${.TARGET}.tmp -x -r ${.TARGET}
143 @mv ${.TARGET}.tmp ${.TARGET}
145 all: objwarn
147 .include <bsd.patch.mk>
149 .if defined(LIB) && !empty(LIB) || defined(SHLIB_NAME)
150 OBJS+= ${SRCS:N*.h:N*.patch:R:S/$/.o/g}
151 .endif
153 .if defined(LIB) && !empty(LIB)
154 _LIBS= lib${LIB}.a
156 lib${LIB}.a: ${OBJS} ${STATICOBJS}
157 @${ECHO} building static ${LIB} library
158 rm -f ${.TARGET}
159 ${AR} cq ${.TARGET} `lorder ${OBJS} ${STATICOBJS} | tsort -q` ${ARADD}
160 ${RANLIB} ${.TARGET}
161 .endif
163 .if !defined(INTERNALLIB) && !defined(NOPROFILE) && defined(LIB) && !empty(LIB)
164 _LIBS+= lib${LIB}_p.a
165 POBJS+= ${OBJS:.o=.po} ${STATICOBJS:.o=.po}
167 lib${LIB}_p.a: ${POBJS}
168 @${ECHO} building profiled ${LIB} library
169 rm -f ${.TARGET}
170 ${AR} cq ${.TARGET} `lorder ${POBJS} | tsort -q` ${ARADD}
171 ${RANLIB} ${.TARGET}
172 .endif
174 .if !defined(INTERNALLIB) && defined(SHLIB_NAME) || \
175 defined(INSTALL_PIC_ARCHIVE) && defined(LIB) && !empty(LIB)
176 SOBJS+= ${OBJS:.o=.So}
177 .endif
179 .if !defined(INTERNALLIB) && defined(SHLIB_NAME)
180 _LIBS+= ${SHLIB_NAME}
182 ${SHLIB_NAME}: ${SOBJS}
183 @${ECHO} building shared library ${SHLIB_NAME}
184 rm -f ${.TARGET} ${SHLIB_LINK}
185 .if defined(SHLIB_LINK)
186 ${LN} -fs ${.TARGET} ${SHLIB_LINK}
187 .endif
188 ${CC_LINK} ${LDFLAGS} -shared -Wl,-x \
189 -o ${.TARGET} -Wl,-soname,${SONAME} \
190 `lorder ${SOBJS} | tsort -q` ${LDADD}
191 .endif
193 .if defined(INSTALL_PIC_ARCHIVE) && defined(LIB) && !empty(LIB)
194 _LIBS+= lib${LIB}_pic.a
196 lib${LIB}_pic.a: ${SOBJS}
197 @${ECHO} building special pic ${LIB} library
198 rm -f ${.TARGET}
199 ${AR} cq ${.TARGET} ${SOBJS} ${ARADD}
200 ${RANLIB} ${.TARGET}
201 .endif
203 all: ${_LIBS}
205 .if !defined(NOMAN)
206 all: _manpages
207 .endif
209 _EXTRADEPEND:
210 @TMP=_depend$$$$; \
211 sed -e 's/^\([^\.]*\).o[ ]*:/\1.o \1.po \1.So:/' < ${DEPENDFILE} \
212 > $$TMP; \
213 mv $$TMP ${DEPENDFILE}
214 .if !defined(NOEXTRADEPEND) && defined(SHLIB_NAME)
215 .if defined(DPADD) && !empty(DPADD)
216 echo ${SHLIB_NAME}: ${DPADD} >> ${DEPENDFILE}
217 .endif
218 .endif
220 .if !target(install)
222 .if defined(PRECIOUSLIB) && !defined(NOFSCHG)
223 SHLINSTALLFLAGS+= -fschg
224 .endif
226 _INSTALLFLAGS:= ${INSTALLFLAGS}
227 .for ie in ${INSTALLFLAGS_EDIT}
228 _INSTALLFLAGS:= ${_INSTALLFLAGS${ie}}
229 .endfor
230 _SHLINSTALLFLAGS:= ${SHLINSTALLFLAGS}
231 .for ie in ${INSTALLFLAGS_EDIT}
232 _SHLINSTALLFLAGS:= ${_SHLINSTALLFLAGS${ie}}
233 .endfor
235 .if !defined(INTERNALLIB)
236 realinstall: _libinstall
237 .ORDER: beforeinstall _libinstall
238 _libinstall:
239 .if defined(LIB) && !empty(LIB) && !defined(NOINSTALLLIB)
240 ${INSTALL} -C -o ${LIBOWN} -g ${LIBGRP} -m ${LIBMODE} \
241 ${_INSTALLFLAGS} lib${LIB}.a ${DESTDIR}${TARGET_LIBDIR}
242 .endif
243 .if !defined(NOPROFILE) && defined(LIB) && !empty(LIB)
244 ${INSTALL} -C -o ${LIBOWN} -g ${LIBGRP} -m ${LIBMODE} \
245 ${_INSTALLFLAGS} lib${LIB}_p.a ${DESTDIR}${TARGET_PROFLIBDIR}/lib${LIB}.a
246 .endif
247 .if defined(SHLIB_NAME)
248 ${INSTALL} ${STRIP} -o ${LIBOWN} -g ${LIBGRP} -m ${LIBMODE} \
249 ${_INSTALLFLAGS} ${_SHLINSTALLFLAGS} \
250 ${SHLIB_NAME} ${DESTDIR}${TARGET_SHLIBDIR}
251 .if defined(SHLIB_LINK)
252 ${LN} -fs ${SHLIB_NAME} ${DESTDIR}${TARGET_SHLIBDIR}/${SHLIB_LINK}
253 .endif
254 .endif
255 .if defined(INSTALL_PIC_ARCHIVE) && defined(LIB) && !empty(LIB)
256 ${INSTALL} -o ${LIBOWN} -g ${LIBGRP} -m ${LIBMODE} \
257 ${_INSTALLFLAGS} lib${LIB}_pic.a ${DESTDIR}${TARGET_LIBDIR}
258 .endif
259 .endif # !defined(INTERNALLIB)
261 .include <bsd.nls.mk>
262 .include <bsd.files.mk>
263 .include <bsd.incs.mk>
264 .include <bsd.links.mk>
266 .if !defined(NOMAN)
267 realinstall: _maninstall
268 .ORDER: beforeinstall _maninstall
269 .endif
271 .endif
273 .if !defined(NOMAN)
274 .include <bsd.man.mk>
275 .endif
277 .include <bsd.dep.mk>
279 .if !exists(${.OBJDIR}/${DEPENDFILE})
280 .if defined(LIB) && !empty(LIB)
281 ${OBJS} ${STATICOBJS} ${POBJS}: ${SRCS:M*.h}
282 .endif
283 .if defined(SHLIB_NAME) || \
284 defined(INSTALL_PIC_ARCHIVE) && defined(LIB) && !empty(LIB)
285 ${SOBJS}: ${SRCS:M*.h}
286 .endif
287 .endif
289 .if !target(clean)
290 clean:
291 .if defined(CLEANFILES) && !empty(CLEANFILES)
292 rm -f ${CLEANFILES}
293 .endif
294 .if defined(LIB) && !empty(LIB)
295 rm -f a.out ${OBJS} ${OBJS:S/$/.tmp/} ${STATICOBJS}
296 .endif
297 .if defined(SHLIB_NAME) || \
298 defined(INSTALL_PIC_ARCHIVE) && defined(LIB) && !empty(LIB)
299 rm -f ${SOBJS} ${SOBJS:.So=.so} ${SOBJS:S/$/.tmp/}
300 .endif
301 .if !defined(INTERNALLIB)
302 .if !defined(NOPROFILE) && defined(LIB) && !empty(LIB)
303 rm -f ${POBJS} ${POBJS:S/$/.tmp/}
304 .endif
305 .if defined(SHLIB_NAME)
306 .if defined(SHLIB_LINK)
307 rm -f ${SHLIB_LINK}
308 .endif
309 .if defined(LIB) && !empty(LIB)
310 rm -f lib${LIB}.so.* lib${LIB}.so
311 .endif
312 .endif
313 .endif # !defined(INTERNALLIB)
314 .if defined(_LIBS) && !empty(_LIBS)
315 rm -f ${_LIBS}
316 .endif
317 .if defined(CLEANDIRS) && !empty(CLEANDIRS)
318 rm -rf ${CLEANDIRS}
319 .endif
320 .endif
322 .include <bsd.obj.mk>
324 .include <bsd.sys.mk>