Annotation of src/share/mk/bsd.lib.mk, Revision 1.23
1.23 ! rahnds 1: # $OpenBSD: bsd.lib.mk,v 1.22 2000/05/16 06:15:00 niklas Exp $
1.5 mickey 2: # $NetBSD: bsd.lib.mk,v 1.67 1996/01/17 20:39:26 mycroft Exp $
1.1 deraadt 3: # @(#)bsd.lib.mk 5.26 (Berkeley) 5/2/91
4:
5: .if exists(${.CURDIR}/../Makefile.inc)
6: .include "${.CURDIR}/../Makefile.inc"
7: .endif
8:
9: .include <bsd.own.mk> # for 'NOPIC' definition
10:
11: .if exists(${.CURDIR}/shlib_version)
12: SHLIB_MAJOR != . ${.CURDIR}/shlib_version ; echo $$major
13: SHLIB_MINOR != . ${.CURDIR}/shlib_version ; echo $$minor
14: .endif
15:
16: .MAIN: all
17:
18: # prefer .S to a .c, add .po, remove stuff not used in the BSD libraries.
19: # .so used for PIC object files. .ln used for lint output files.
1.20 espie 20: # .m for objective c files.
1.1 deraadt 21: .SUFFIXES:
1.21 niklas 22: .SUFFIXES: .out .o .go .po .so .S .s .c .cc .C .cxx .f .y .l .ln .m4 .m
1.1 deraadt 23:
24: .c.o:
1.14 grr 25: @echo "${COMPILE.c} ${.IMPSRC} -o ${.TARGET}"
1.1 deraadt 26: @${COMPILE.c} ${.IMPSRC} -o ${.TARGET}.o
27: @${LD} -x -r ${.TARGET}.o -o ${.TARGET}
28: @rm -f ${.TARGET}.o
29:
1.21 niklas 30: .c.go:
31: @echo "${COMPILE.c} -g ${.IMPSRC} -o ${.TARGET}"
32: @${COMPILE.c} -g ${.IMPSRC} -o ${.TARGET}.o
33: @${LD} -X -r ${.TARGET}.o -o ${.TARGET}
34: @rm -f ${.TARGET}.o
35:
1.1 deraadt 36: .c.po:
37: @echo "${COMPILE.c} -p ${.IMPSRC} -o ${.TARGET}"
38: @${COMPILE.c} -p ${.IMPSRC} -o ${.TARGET}.o
39: @${LD} -X -r ${.TARGET}.o -o ${.TARGET}
40: @rm -f ${.TARGET}.o
41:
42: .c.so:
43: @echo "${COMPILE.c} ${PICFLAG} -DPIC ${.IMPSRC} -o ${.TARGET}"
44: @${COMPILE.c} ${PICFLAG} -DPIC ${.IMPSRC} -o ${.TARGET}.o
45: @${LD} -x -r ${.TARGET}.o -o ${.TARGET}
46: @rm -f ${.TARGET}.o
47:
48: .c.ln:
49: ${LINT} ${LINTFLAGS} ${CFLAGS:M-[IDU]*} -i ${.IMPSRC}
50:
1.16 deraadt 51: .cc.o .C.o .cxx.o:
1.19 espie 52: @echo "${COMPILE.cc} ${.IMPSRC} -o ${.TARGET}"
1.1 deraadt 53: @${COMPILE.cc} ${.IMPSRC} -o ${.TARGET}.o
54: @${LD} -x -r ${.TARGET}.o -o ${.TARGET}
55: @rm -f ${.TARGET}.o
56:
1.21 niklas 57: .cc.go .C.go .cxx.go:
58: @echo "${COMPILE.cc} -g ${.IMPSRC} -o ${.TARGET}"
59: @${COMPILE.cc} -g ${.IMPSRC} -o ${.TARGET}.o
60: @${LD} -X -r ${.TARGET}.o -o ${.TARGET}
61: @rm -f ${.TARGET}.o
62:
1.16 deraadt 63: .cc.po .C.po .cxx.po:
1.1 deraadt 64: @echo "${COMPILE.cc} -p ${.IMPSRC} -o ${.TARGET}"
65: @${COMPILE.cc} -p ${.IMPSRC} -o ${.TARGET}.o
66: @${LD} -X -r ${.TARGET}.o -o ${.TARGET}
67: @rm -f ${.TARGET}.o
68:
1.16 deraadt 69: .cc.so .C.so .cxx.so:
1.1 deraadt 70: @echo "${COMPILE.cc} ${PICFLAG} -DPIC ${.IMPSRC} -o ${.TARGET}"
71: @${COMPILE.cc} ${PICFLAG} -DPIC ${.IMPSRC} -o ${.TARGET}.o
72: @${LD} -x -r ${.TARGET}.o -o ${.TARGET}
73: @rm -f ${.TARGET}.o
74:
75: .S.o .s.o:
76: @echo "${CPP} ${CPPFLAGS} ${CFLAGS:M-[ID]*} ${AINC} ${.IMPSRC} | \
77: ${AS} -o ${.TARGET}"
78: @${CPP} ${CPPFLAGS} ${CFLAGS:M-[ID]*} ${AINC} ${.IMPSRC} | \
79: ${AS} -o ${.TARGET}.o
80: @${LD} -x -r ${.TARGET}.o -o ${.TARGET}
81: @rm -f ${.TARGET}.o
82:
1.21 niklas 83: .S.go .s.go:
84: @echo "${CPP} ${CPPFLAGS} ${CFLAGS:M-[ID]*} ${AINC} ${.IMPSRC} |\
85: ${AS} -o ${.TARGET}"
86: @${CPP} ${CPPFLAGS} ${CFLAGS:M-[ID]*} ${AINC} ${.IMPSRC} | \
87: ${AS} -o ${.TARGET}.o
88: @${LD} -X -r ${.TARGET}.o -o ${.TARGET}
89: @rm -f ${.TARGET}.o
90:
1.1 deraadt 91: .S.po .s.po:
92: @echo "${CPP} -DPROF ${CPPFLAGS} ${CFLAGS:M-[ID]*} ${AINC} ${.IMPSRC} |\
93: ${AS} -o ${.TARGET}"
94: @${CPP} -DPROF ${CPPFLAGS} ${CFLAGS:M-[ID]*} ${AINC} ${.IMPSRC} | \
95: ${AS} -o ${.TARGET}.o
96: @${LD} -X -r ${.TARGET}.o -o ${.TARGET}
97: @rm -f ${.TARGET}.o
98:
99: .S.so .s.so:
100: @echo "${CPP} -DPIC ${CPPFLAGS} ${CFLAGS:M-[ID]*} ${AINC} ${.IMPSRC} | \
101: ${AS} -k -o ${.TARGET}"
102: @${CPP} -DPIC ${CPPFLAGS} ${CFLAGS:M-[ID]*} ${AINC} ${.IMPSRC} | \
103: ${AS} -k -o ${.TARGET}.o
104: @${LD} -x -r ${.TARGET}.o -o ${.TARGET}
105: @rm -f ${.TARGET}.o
1.7 deraadt 106:
1.18 millert 107: CFLAGS+= ${COPTS}
1.1 deraadt 108:
1.6 pefo 109: .if !defined(PICFLAG) && (${MACHINE_ARCH} != "mips")
1.1 deraadt 110: PICFLAG=-fpic
1.15 niklas 111: .if ${MACHINE_ARCH} == "m68k"
112: # Function CSE makes gas -k not recognize external function calls as lazily
113: # resolvable symbols, thus sometimes making ld.so report undefined symbol
114: # errors on symbols found in shared library members that would never be
115: # called. Ask niklas@openbsd.org for details.
116: PICFLAG+=-fno-function-cse
117: .endif
1.1 deraadt 118: .endif
119:
1.21 niklas 120: _LIBS=lib${LIB}.a
1.22 niklas 121: .if (${DEBUGLIBS} == "yes")
1.21 niklas 122: _LIBS+=lib${LIB}_g.a
123: .endif
1.1 deraadt 124: .if !defined(NOPROFILE)
1.21 niklas 125: _LIBS+=lib${LIB}_p.a
1.1 deraadt 126: .endif
127:
128: .if !defined(NOPIC)
1.6 pefo 129: .if (${MACHINE_ARCH} != "mips")
1.1 deraadt 130: _LIBS+=lib${LIB}_pic.a
1.6 pefo 131: .endif
1.1 deraadt 132: .if defined(SHLIB_MAJOR) && defined(SHLIB_MINOR)
133: _LIBS+=lib${LIB}.so.${SHLIB_MAJOR}.${SHLIB_MINOR}
134: .endif
135: .endif
136:
137: .if !defined(NOLINT)
138: _LIBS+=llib-l${LIB}.ln
139: .endif
140:
141: all: ${_LIBS} _SUBDIRUSE
142:
143: OBJS+= ${SRCS:N*.h:R:S/$/.o/g}
144:
145: lib${LIB}.a:: ${OBJS}
146: @echo building standard ${LIB} library
147: @rm -f lib${LIB}.a
1.12 niklas 148: @${AR} cq lib${LIB}.a `${LORDER} ${OBJS} | tsort -q`
1.1 deraadt 149: ${RANLIB} lib${LIB}.a
150:
1.21 niklas 151: GOBJS+= ${OBJS:.o=.go}
152: lib${LIB}_g.a:: ${GOBJS}
153: @echo building debugging ${LIB} library
154: @rm -f lib${LIB}_g.a
155: @${AR} cq lib${LIB}_g.a `${LORDER} ${GOBJS} | tsort -q`
156: ${RANLIB} lib${LIB}_g.a
157:
1.1 deraadt 158: POBJS+= ${OBJS:.o=.po}
159: lib${LIB}_p.a:: ${POBJS}
160: @echo building profiled ${LIB} library
161: @rm -f lib${LIB}_p.a
1.12 niklas 162: @${AR} cq lib${LIB}_p.a `${LORDER} ${POBJS} | tsort -q`
1.1 deraadt 163: ${RANLIB} lib${LIB}_p.a
164:
165: SOBJS+= ${OBJS:.o=.so}
166: lib${LIB}_pic.a:: ${SOBJS}
167: @echo building shared object ${LIB} library
168: @rm -f lib${LIB}_pic.a
1.12 niklas 169: @${AR} cq lib${LIB}_pic.a `${LORDER} ${SOBJS} | tsort -q`
1.1 deraadt 170: ${RANLIB} lib${LIB}_pic.a
171:
1.23 ! rahnds 172: .if (${MACHINE_ARCH} == "mips")
! 173: lib${LIB}.so.${SHLIB_MAJOR}.${SHLIB_MINOR}: lib${LIB}.a ${DPADD}
! 174: @echo building shared ${LIB} library \(version ${SHLIB_MAJOR}.${SHLIB_MINOR}\)
! 175: @rm -f lib${LIB}.so.${SHLIB_MAJOR}.${SHLIB_MINOR}
! 176: $(LD) -x -shared --whole-archive -soname lib${LIB}.so.${SHLIB_MAJOR} \
! 177: -o lib${LIB}.so.${SHLIB_MAJOR}.${SHLIB_MINOR} lib${LIB}.a ${LDADD}
! 178: .elif (${MACHINE_ARCH} == "powerpc" )
1.1 deraadt 179: lib${LIB}.so.${SHLIB_MAJOR}.${SHLIB_MINOR}: lib${LIB}_pic.a ${DPADD}
180: @echo building shared ${LIB} library \(version ${SHLIB_MAJOR}.${SHLIB_MINOR}\)
181: @rm -f lib${LIB}.so.${SHLIB_MAJOR}.${SHLIB_MINOR}
1.23 ! rahnds 182: $(LD) -x -shared --whole-archive \
! 183: -soname lib${LIB}.so.${SHLIB_MAJOR}.${SHLIB_MINOR} \
1.1 deraadt 184: -o lib${LIB}.so.${SHLIB_MAJOR}.${SHLIB_MINOR} lib${LIB}_pic.a ${LDADD}
1.6 pefo 185: .else
1.23 ! rahnds 186: lib${LIB}.so.${SHLIB_MAJOR}.${SHLIB_MINOR}: lib${LIB}_pic.a ${DPADD}
1.6 pefo 187: @echo building shared ${LIB} library \(version ${SHLIB_MAJOR}.${SHLIB_MINOR}\)
188: @rm -f lib${LIB}.so.${SHLIB_MAJOR}.${SHLIB_MINOR}
1.23 ! rahnds 189: $(LD) -x -Bshareable -Bforcearchive \
! 190: -o lib${LIB}.so.${SHLIB_MAJOR}.${SHLIB_MINOR} lib${LIB}_pic.a ${LDADD}
1.6 pefo 191: .endif
1.1 deraadt 192:
193: LOBJS+= ${LSRCS:.c=.ln} ${SRCS:M*.c:.c=.ln}
194: # the following looks XXX to me... -- cgd
195: LLIBS?= -lc
196: llib-l${LIB}.ln: ${LOBJS}
197: @echo building llib-l${LIB}.ln
198: @rm -f llib-l${LIB}.ln
199: @${LINT} -C${LIB} ${LOBJS} ${LLIBS}
200:
201: .if !target(clean)
202: clean: _SUBDIRUSE
203: rm -f a.out [Ee]rrs mklog core *.core ${CLEANFILES}
204: rm -f lib${LIB}.a ${OBJS}
1.21 niklas 205: rm -f lib${LIB}_g.a ${GOBJS}
1.1 deraadt 206: rm -f lib${LIB}_p.a ${POBJS}
207: rm -f lib${LIB}_pic.a lib${LIB}.so.*.* ${SOBJS}
208: rm -f llib-l${LIB}.ln ${LOBJS}
209: .endif
210:
211: cleandir: _SUBDIRUSE clean
212:
213: .if defined(SRCS)
214: afterdepend: .depend
1.11 deraadt 215: @(TMP=`mktemp -q /tmp/_dependXXXXXXXXXX`; \
216: if [ $$? -ne 0 ]; then \
217: echo "$$0: cannot create temp file, exiting..."; \
218: exit 1; \
219: fi; \
220: sed -e 's/^\([^\.]*\).o[ ]*:/\1.o \1.po \1.so:/' \
1.1 deraadt 221: < .depend > $$TMP; \
1.11 deraadt 222: mv $$TMP .depend)
1.1 deraadt 223: .endif
224:
225: .if !target(install)
226: .if !target(beforeinstall)
227: beforeinstall:
228: .endif
229:
230: realinstall:
231: # ranlib lib${LIB}.a
1.13 millert 232: ${INSTALL} ${INSTALL_COPY} -o ${LIBOWN} -g ${LIBGRP} -m 600 lib${LIB}.a \
1.1 deraadt 233: ${DESTDIR}${LIBDIR}
1.13 millert 234: .if (${INSTALL_COPY} != "-p")
1.1 deraadt 235: ${RANLIB} -t ${DESTDIR}${LIBDIR}/lib${LIB}.a
1.8 millert 236: .endif
1.1 deraadt 237: chmod ${LIBMODE} ${DESTDIR}${LIBDIR}/lib${LIB}.a
1.22 niklas 238: .if (${DEBUGLIBS} == "yes")
1.21 niklas 239: # ranlib lib${LIB}_g.a
240: ${INSTALL} ${INSTALL_COPY} -o ${LIBOWN} -g ${LIBGRP} -m 600 \
241: lib${LIB}_g.a ${DESTDIR}${LIBDIR}/debug/lib${LIB}.a
242: .if (${INSTALL_COPY} != "-p")
243: ${RANLIB} -t ${DESTDIR}${LIBDIR}/debug/lib${LIB}.a
244: .endif
245: chmod ${LIBMODE} ${DESTDIR}${LIBDIR}/debug/lib${LIB}.a
246: .endif
1.1 deraadt 247: .if !defined(NOPROFILE)
248: # ranlib lib${LIB}_p.a
1.13 millert 249: ${INSTALL} ${INSTALL_COPY} -o ${LIBOWN} -g ${LIBGRP} -m 600 \
1.1 deraadt 250: lib${LIB}_p.a ${DESTDIR}${LIBDIR}
1.13 millert 251: .if (${INSTALL_COPY} != "-p")
1.1 deraadt 252: ${RANLIB} -t ${DESTDIR}${LIBDIR}/lib${LIB}_p.a
1.8 millert 253: .endif
1.1 deraadt 254: chmod ${LIBMODE} ${DESTDIR}${LIBDIR}/lib${LIB}_p.a
255: .endif
1.6 pefo 256: .if !defined(NOPIC) && (${MACHINE_ARCH} != "mips")
1.1 deraadt 257: # ranlib lib${LIB}_pic.a
1.13 millert 258: ${INSTALL} ${INSTALL_COPY} -o ${LIBOWN} -g ${LIBGRP} -m 600 \
1.1 deraadt 259: lib${LIB}_pic.a ${DESTDIR}${LIBDIR}
1.13 millert 260: .if (${INSTALL_COPY} != "-p")
1.1 deraadt 261: ${RANLIB} -t ${DESTDIR}${LIBDIR}/lib${LIB}_pic.a
1.8 millert 262: .endif
1.1 deraadt 263: chmod ${LIBMODE} ${DESTDIR}${LIBDIR}/lib${LIB}_pic.a
264: .endif
265: .if !defined(NOPIC) && defined(SHLIB_MAJOR) && defined(SHLIB_MINOR)
1.13 millert 266: ${INSTALL} ${INSTALL_COPY} -o ${LIBOWN} -g ${LIBGRP} -m ${LIBMODE} \
1.1 deraadt 267: lib${LIB}.so.${SHLIB_MAJOR}.${SHLIB_MINOR} ${DESTDIR}${LIBDIR}
268: .endif
269: .if !defined(NOLINT)
1.13 millert 270: ${INSTALL} ${INSTALL_COPY} -o ${LIBOWN} -g ${LIBGRP} -m ${LIBMODE} \
1.1 deraadt 271: llib-l${LIB}.ln ${DESTDIR}${LINTLIBDIR}
272: .endif
273: .if defined(LINKS) && !empty(LINKS)
274: @set ${LINKS}; \
275: while test $$# -ge 2; do \
1.9 mickey 276: l=${DESTDIR}${BINDIR}/$$1; \
1.1 deraadt 277: shift; \
1.9 mickey 278: t=${DESTDIR}${BINDIR}/$$1; \
1.1 deraadt 279: shift; \
280: echo $$t -\> $$l; \
281: rm -f $$t; \
282: ln $$l $$t; \
283: done; true
284: .endif
285:
286: install: maninstall _SUBDIRUSE
287: maninstall: afterinstall
288: afterinstall: realinstall
289: realinstall: beforeinstall
290: .endif
291:
292: .if !defined(NOMAN)
293: .include <bsd.man.mk>
294: .endif
295:
296: .if !defined(NONLS)
297: .include <bsd.nls.mk>
298: .endif
299:
300: .include <bsd.obj.mk>
301: .include <bsd.dep.mk>
302: .include <bsd.subdir.mk>
1.2 deraadt 303: .include <bsd.sys.mk>