1 1.86 jonathan # $NetBSD: bsd.lib.mk,v 1.86 1997/03/15 11:35:04 jonathan Exp $ 2 1.50 cgd # @(#)bsd.lib.mk 5.26 (Berkeley) 5/2/91 3 1.1 cgd 4 1.1 cgd .if exists(${.CURDIR}/../Makefile.inc) 5 1.1 cgd .include "${.CURDIR}/../Makefile.inc" 6 1.1 cgd .endif 7 1.54 cgd 8 1.54 cgd .include <bsd.own.mk> # for 'NOPIC' definition 9 1.1 cgd 10 1.35 pk .if exists(${.CURDIR}/shlib_version) 11 1.37 cgd SHLIB_MAJOR != . ${.CURDIR}/shlib_version ; echo $$major 12 1.37 cgd SHLIB_MINOR != . ${.CURDIR}/shlib_version ; echo $$minor 13 1.35 pk .endif 14 1.35 pk 15 1.1 cgd .MAIN: all 16 1.1 cgd 17 1.58 cgd # prefer .S to a .c, add .po, remove stuff not used in the BSD libraries. 18 1.58 cgd # .so used for PIC object files. .ln used for lint output files. 19 1.1 cgd .SUFFIXES: 20 1.58 cgd .SUFFIXES: .out .o .po .so .S .s .c .cc .C .f .y .l .ln .m4 21 1.82 mikel 22 1.86 jonathan 23 1.86 jonathan # Set PICFLAGS to cc flags for producing position-independent code, 24 1.86 jonathan # if not already set. Includes -DPIC, if required. 25 1.86 jonathan 26 1.86 jonathan # Data-driven table using make variables to control how shared libraries 27 1.86 jonathan # are built for different platforms and object formats. 28 1.86 jonathan # SHLIB_TYPE: currently either "ELF" or "a.out". 29 1.86 jonathan # SHLIB_SOVERSION: version number to be compiled into a shared library 30 1.86 jonathan # via -soname. Usualy ${SHLIB_MAJOR} on ELF. 31 1.86 jonathan # NetBSD/pmax used to use ${SHLIB_MAJOR}.{SHLIB-MINOR}. 32 1.86 jonathan # SHLIB_LDSTARTFILE: ??? 33 1.86 jonathan # SHLIB_LDENDTILE: ?? 34 1.86 jonathan # CPICFLAGS: flags to compile .c files for .so objects. 35 1.86 jonathan # APICFLAGS: flags to assemble .S files for .so objects. 36 1.86 jonathan 37 1.86 jonathan .if (${MACHINE_ARCH} == "alpha") 38 1.86 jonathan 39 1.86 jonathan SHLIB_TYPE=ELF 40 1.86 jonathan SHLIB_LDSTARTFILE= ${DESTDIR}/usr/lib/crtbeginS.o 41 1.86 jonathan SHLIB_LDENDFILE= ${DESTDIR}/usr/lib/crtendS.o 42 1.86 jonathan SHLIB_SOVERSION=${SHLIB_MAJOR} 43 1.86 jonathan CPICFLAGS ?= -fpic -DPIC 44 1.86 jonathan APICFLAGS ?= -DPIC 45 1.86 jonathan 46 1.86 jonathan .elif (${MACHINE_ARCH} == "mips") 47 1.86 jonathan 48 1.86 jonathan SHLIB_TYPE=ELF 49 1.86 jonathan # still use gnu-derived ld.so on pmax; don't have or need lib<>.so support. 50 1.86 jonathan SHLIB_LDSTARTFILE= 51 1.86 jonathan SHLIB_LDENDFILE= 52 1.86 jonathan SHLIB_SOVERSION=${SHLIB_MAJOR} 53 1.86 jonathan 54 1.86 jonathan # On mips, all libs need to be compiled with ABIcalls, not just sharedlibs. 55 1.86 jonathan CPICFLAGS?= 56 1.86 jonathan APICFLAGS?= 57 1.86 jonathan #CPICFLAGS?= -fpic -DPIC 58 1.86 jonathan #APICFLAGS?= -DPIC 59 1.86 jonathan 60 1.86 jonathan # so turn shlib PIC flags on for ${CPP}, ${CC}, and ${AS} as follows: 61 1.86 jonathan AINC+=-DPIC -DABICALLS 62 1.86 jonathan COPTS+= -fPIC ${AINC} 63 1.86 jonathan AFLAGS+= -fPIC 64 1.86 jonathan AS+= -KPIC 65 1.86 jonathan 66 1.86 jonathan .else 67 1.86 jonathan 68 1.86 jonathan SHLIB_TYPE=a.out 69 1.86 jonathan SHLIB_SOVERSION=${SHLIB_MAJOR}.${SHLIB_MINOR} 70 1.86 jonathan CPICFLAGS?= -fpic -DPIC 71 1.86 jonathan APICFLAGS?= -fpic -DPIC 72 1.86 jonathan 73 1.86 jonathan .endif 74 1.86 jonathan 75 1.86 jonathan 76 1.82 mikel CFLAGS+= ${COPTS} 77 1.1 cgd 78 1.1 cgd .c.o: 79 1.80 christos @echo ${COMPILE.c:Q} ${.IMPSRC} 80 1.62 christos @${COMPILE.c} ${.IMPSRC} -o ${.TARGET}.o 81 1.62 christos @${LD} -x -r ${.TARGET}.o -o ${.TARGET} 82 1.62 christos @rm -f ${.TARGET}.o 83 1.1 cgd 84 1.1 cgd .c.po: 85 1.80 christos @echo ${COMPILE.c:Q} -pg ${.IMPSRC} -o ${.TARGET} 86 1.68 cgd @${COMPILE.c} -pg ${.IMPSRC} -o ${.TARGET}.o 87 1.62 christos @${LD} -X -r ${.TARGET}.o -o ${.TARGET} 88 1.62 christos @rm -f ${.TARGET}.o 89 1.17 mycroft 90 1.27 pk .c.so: 91 1.86 jonathan @echo ${COMPILE.c:Q} ${CPICFLAGS} ${.IMPSRC} -o ${.TARGET} 92 1.86 jonathan @${COMPILE.c} ${CPICFLAGS} ${.IMPSRC} -o ${.TARGET}.o 93 1.62 christos @${LD} -x -r ${.TARGET}.o -o ${.TARGET} 94 1.62 christos @rm -f ${.TARGET}.o 95 1.27 pk 96 1.58 cgd .c.ln: 97 1.58 cgd ${LINT} ${LINTFLAGS} ${CFLAGS:M-[IDU]*} -i ${.IMPSRC} 98 1.58 cgd 99 1.18 mycroft .cc.o .C.o: 100 1.80 christos @echo ${COMPILE.cc:Q} ${.IMPSRC} 101 1.62 christos @${COMPILE.cc} ${.IMPSRC} -o ${.TARGET}.o 102 1.63 jtc @${LD} -x -r ${.TARGET}.o -o ${.TARGET} 103 1.62 christos @rm -f ${.TARGET}.o 104 1.17 mycroft 105 1.18 mycroft .cc.po .C.po: 106 1.80 christos @echo ${COMPILE.cc:Q} -pg ${.IMPSRC} -o ${.TARGET} 107 1.68 cgd @${COMPILE.cc} -pg ${.IMPSRC} -o ${.TARGET}.o 108 1.62 christos @${LD} -X -r ${.TARGET}.o -o ${.TARGET} 109 1.62 christos @rm -f ${.TARGET}.o 110 1.28 cgd 111 1.28 cgd .cc.so .C.so: 112 1.86 jonathan @echo ${COMPILE.cc:Q} ${CPICFLAGS} ${.IMPSRC} -o ${.TARGET} 113 1.86 jonathan @${COMPILE.cc} ${CPICFLAGS} ${.IMPSRC} -o ${.TARGET}.o 114 1.62 christos @${LD} -x -r ${.TARGET}.o -o ${.TARGET} 115 1.62 christos @rm -f ${.TARGET}.o 116 1.1 cgd 117 1.40 cgd .S.o .s.o: 118 1.80 christos @echo ${COMPILE.S:Q} ${CFLAGS:M-[ID]*} ${AINC} ${.IMPSRC} 119 1.69 jtc @${COMPILE.S} ${CFLAGS:M-[ID]*} ${AINC} ${.IMPSRC} -o ${.TARGET}.o 120 1.62 christos @${LD} -x -r ${.TARGET}.o -o ${.TARGET} 121 1.62 christos @rm -f ${.TARGET}.o 122 1.1 cgd 123 1.40 cgd .S.po .s.po: 124 1.80 christos @echo ${COMPILE.S:Q} -DGPROF -DPROF ${CFLAGS:M-[ID]*} ${AINC} ${.IMPSRC} -o ${.TARGET} 125 1.75 jtc @${COMPILE.S} -DGPROF -DPROF ${CFLAGS:M-[ID]*} ${AINC} ${.IMPSRC} -o ${.TARGET}.o 126 1.62 christos @${LD} -X -r ${.TARGET}.o -o ${.TARGET} 127 1.62 christos @rm -f ${.TARGET}.o 128 1.1 cgd 129 1.40 cgd .S.so .s.so: 130 1.86 jonathan @echo ${COMPILE.S:Q} ${APICFLAGS} ${CFLAGS:M-[ID]*} ${AINC} ${.IMPSRC} -o ${.TARGET} 131 1.86 jonathan @${COMPILE.S} ${APICFLAGS} ${CFLAGS:M-[ID]*} ${AINC} ${.IMPSRC} -o ${.TARGET}.o 132 1.62 christos @${LD} -x -r ${.TARGET}.o -o ${.TARGET} 133 1.62 christos @rm -f ${.TARGET}.o 134 1.27 pk 135 1.58 cgd 136 1.1 cgd .if !defined(NOPROFILE) 137 1.1 cgd _LIBS=lib${LIB}.a lib${LIB}_p.a 138 1.1 cgd .else 139 1.1 cgd _LIBS=lib${LIB}.a 140 1.1 cgd .endif 141 1.1 cgd 142 1.27 pk .if !defined(NOPIC) 143 1.27 pk _LIBS+=lib${LIB}_pic.a 144 1.37 cgd .if defined(SHLIB_MAJOR) && defined(SHLIB_MINOR) 145 1.37 cgd _LIBS+=lib${LIB}.so.${SHLIB_MAJOR}.${SHLIB_MINOR} 146 1.27 pk .endif 147 1.35 pk .endif 148 1.27 pk 149 1.58 cgd .if !defined(NOLINT) 150 1.58 cgd _LIBS+=llib-l${LIB}.ln 151 1.27 pk .endif 152 1.27 pk 153 1.58 cgd all: ${_LIBS} _SUBDIRUSE 154 1.1 cgd 155 1.21 mycroft OBJS+= ${SRCS:N*.h:R:S/$/.o/g} 156 1.1 cgd 157 1.1 cgd lib${LIB}.a:: ${OBJS} 158 1.1 cgd @echo building standard ${LIB} library 159 1.1 cgd @rm -f lib${LIB}.a 160 1.67 mycroft @${AR} cq lib${LIB}.a `lorder ${OBJS} | tsort -q` 161 1.13 cgd ${RANLIB} lib${LIB}.a 162 1.1 cgd 163 1.1 cgd POBJS+= ${OBJS:.o=.po} 164 1.1 cgd lib${LIB}_p.a:: ${POBJS} 165 1.1 cgd @echo building profiled ${LIB} library 166 1.1 cgd @rm -f lib${LIB}_p.a 167 1.67 mycroft @${AR} cq lib${LIB}_p.a `lorder ${POBJS} | tsort -q` 168 1.13 cgd ${RANLIB} lib${LIB}_p.a 169 1.1 cgd 170 1.27 pk SOBJS+= ${OBJS:.o=.so} 171 1.27 pk lib${LIB}_pic.a:: ${SOBJS} 172 1.27 pk @echo building shared object ${LIB} library 173 1.27 pk @rm -f lib${LIB}_pic.a 174 1.67 mycroft @${AR} cq lib${LIB}_pic.a `lorder ${SOBJS} | tsort -q` 175 1.27 pk ${RANLIB} lib${LIB}_pic.a 176 1.27 pk 177 1.42 mycroft lib${LIB}.so.${SHLIB_MAJOR}.${SHLIB_MINOR}: lib${LIB}_pic.a ${DPADD} 178 1.38 cgd @echo building shared ${LIB} library \(version ${SHLIB_MAJOR}.${SHLIB_MINOR}\) 179 1.37 cgd @rm -f lib${LIB}.so.${SHLIB_MAJOR}.${SHLIB_MINOR} 180 1.86 jonathan .if (${SHLIB_TYPE} == "a.out") 181 1.53 pk $(LD) -x -Bshareable -Bforcearchive \ 182 1.42 mycroft -o lib${LIB}.so.${SHLIB_MAJOR}.${SHLIB_MINOR} lib${LIB}_pic.a ${LDADD} 183 1.86 jonathan .elif (${SHLIB_TYPE} == "ELF") 184 1.86 jonathan $(LD) -x -shared -o lib${LIB}.so.${SHLIB_MAJOR}.${SHLIB_MINOR} \ 185 1.86 jonathan -soname lib${LIB}.so.${SHLIB_SOVERSION} ${SHLIB_LDSTARTFILE} \ 186 1.77 cgd --whole-archive lib${LIB}_pic.a --no-whole-archive ${LDADD} \ 187 1.86 jonathan ${SHLIB_LDENDFILE} 188 1.72 cgd .endif 189 1.35 pk 190 1.58 cgd LOBJS+= ${LSRCS:.c=.ln} ${SRCS:M*.c:.c=.ln} 191 1.58 cgd LLIBS?= -lc 192 1.58 cgd llib-l${LIB}.ln: ${LOBJS} 193 1.58 cgd @echo building llib-l${LIB}.ln 194 1.58 cgd @rm -f llib-l${LIB}.ln 195 1.58 cgd @${LINT} -C${LIB} ${LOBJS} ${LLIBS} 196 1.1 cgd 197 1.1 cgd .if !target(clean) 198 1.81 cgd cleanlib: 199 1.48 mycroft rm -f a.out [Ee]rrs mklog core *.core ${CLEANFILES} 200 1.59 cgd rm -f lib${LIB}.a ${OBJS} 201 1.59 cgd rm -f lib${LIB}_p.a ${POBJS} 202 1.61 cgd rm -f lib${LIB}_pic.a lib${LIB}.so.*.* ${SOBJS} 203 1.59 cgd rm -f llib-l${LIB}.ln ${LOBJS} 204 1.1 cgd 205 1.81 cgd clean: _SUBDIRUSE cleanlib 206 1.81 cgd cleandir: _SUBDIRUSE cleanlib 207 1.81 cgd .else 208 1.49 cgd cleandir: _SUBDIRUSE clean 209 1.81 cgd .endif 210 1.25 mycroft 211 1.26 mycroft .if defined(SRCS) 212 1.64 christos afterdepend: .depend 213 1.1 cgd @(TMP=/tmp/_depend$$$$; \ 214 1.79 cgd sed -e 's/^\([^\.]*\).o[ ]*:/\1.o \1.po \1.so \1.ln:/' \ 215 1.58 cgd < .depend > $$TMP; \ 216 1.1 cgd mv $$TMP .depend) 217 1.26 mycroft .endif 218 1.1 cgd 219 1.1 cgd .if !target(install) 220 1.1 cgd .if !target(beforeinstall) 221 1.1 cgd beforeinstall: 222 1.1 cgd .endif 223 1.1 cgd 224 1.11 mycroft realinstall: 225 1.13 cgd # ranlib lib${LIB}.a 226 1.73 thorpej ${INSTALL} ${COPY} -o ${LIBOWN} -g ${LIBGRP} -m 600 lib${LIB}.a \ 227 1.1 cgd ${DESTDIR}${LIBDIR} 228 1.1 cgd ${RANLIB} -t ${DESTDIR}${LIBDIR}/lib${LIB}.a 229 1.56 cgd chmod ${LIBMODE} ${DESTDIR}${LIBDIR}/lib${LIB}.a 230 1.12 cgd .if !defined(NOPROFILE) 231 1.13 cgd # ranlib lib${LIB}_p.a 232 1.73 thorpej ${INSTALL} ${COPY} -o ${LIBOWN} -g ${LIBGRP} -m 600 \ 233 1.1 cgd lib${LIB}_p.a ${DESTDIR}${LIBDIR} 234 1.1 cgd ${RANLIB} -t ${DESTDIR}${LIBDIR}/lib${LIB}_p.a 235 1.56 cgd chmod ${LIBMODE} ${DESTDIR}${LIBDIR}/lib${LIB}_p.a 236 1.32 pk .endif 237 1.39 pk .if !defined(NOPIC) 238 1.32 pk # ranlib lib${LIB}_pic.a 239 1.73 thorpej ${INSTALL} ${COPY} -o ${LIBOWN} -g ${LIBGRP} -m 600 \ 240 1.32 pk lib${LIB}_pic.a ${DESTDIR}${LIBDIR} 241 1.32 pk ${RANLIB} -t ${DESTDIR}${LIBDIR}/lib${LIB}_pic.a 242 1.56 cgd chmod ${LIBMODE} ${DESTDIR}${LIBDIR}/lib${LIB}_pic.a 243 1.33 pk .endif 244 1.37 cgd .if !defined(NOPIC) && defined(SHLIB_MAJOR) && defined(SHLIB_MINOR) 245 1.73 thorpej ${INSTALL} ${COPY} -o ${LIBOWN} -g ${LIBGRP} -m ${LIBMODE} \ 246 1.37 cgd lib${LIB}.so.${SHLIB_MAJOR}.${SHLIB_MINOR} ${DESTDIR}${LIBDIR} 247 1.86 jonathan .if (${SHLIB_TYPE} == "ELF") 248 1.83 cgd rm -f ${DESTDIR}${LIBDIR}/lib${LIB}.so.${SHLIB_MAJOR} 249 1.83 cgd ln -s lib${LIB}.so.${SHLIB_MAJOR}.${SHLIB_MINOR} \ 250 1.83 cgd ${DESTDIR}${LIBDIR}/lib${LIB}.so.${SHLIB_MAJOR} 251 1.83 cgd rm -f ${DESTDIR}${LIBDIR}/lib${LIB}.so 252 1.83 cgd ln -s lib${LIB}.so.${SHLIB_MAJOR}.${SHLIB_MINOR} \ 253 1.83 cgd ${DESTDIR}${LIBDIR}/lib${LIB}.so 254 1.83 cgd .endif 255 1.12 cgd .endif 256 1.58 cgd .if !defined(NOLINT) 257 1.73 thorpej ${INSTALL} ${COPY} -o ${LIBOWN} -g ${LIBGRP} -m ${LIBMODE} \ 258 1.58 cgd llib-l${LIB}.ln ${DESTDIR}${LINTLIBDIR} 259 1.58 cgd .endif 260 1.1 cgd .if defined(LINKS) && !empty(LINKS) 261 1.1 cgd @set ${LINKS}; \ 262 1.1 cgd while test $$# -ge 2; do \ 263 1.1 cgd l=${DESTDIR}$$1; \ 264 1.1 cgd shift; \ 265 1.1 cgd t=${DESTDIR}$$1; \ 266 1.1 cgd shift; \ 267 1.1 cgd echo $$t -\> $$l; \ 268 1.1 cgd rm -f $$t; \ 269 1.1 cgd ln $$l $$t; \ 270 1.84 perry done; true 271 1.84 perry .endif 272 1.84 perry .if defined(SYMLINKS) && !empty(SYMLINKS) 273 1.84 perry @set ${SYMLINKS}; \ 274 1.84 perry while test $$# -ge 2; do \ 275 1.84 perry l=${DESTDIR}$$1; \ 276 1.84 perry shift; \ 277 1.84 perry t=${DESTDIR}$$1; \ 278 1.84 perry shift; \ 279 1.84 perry echo $$t -\> $$l; \ 280 1.84 perry rm -f $$t; \ 281 1.84 perry ln -s $$l $$t; \ 282 1.1 cgd done; true 283 1.1 cgd .endif 284 1.1 cgd 285 1.49 cgd install: maninstall _SUBDIRUSE 286 1.11 mycroft maninstall: afterinstall 287 1.11 mycroft afterinstall: realinstall 288 1.11 mycroft realinstall: beforeinstall 289 1.1 cgd .endif 290 1.1 cgd 291 1.10 mycroft .if !defined(NOMAN) 292 1.1 cgd .include <bsd.man.mk> 293 1.57 jtc .endif 294 1.57 jtc 295 1.57 jtc .if !defined(NONLS) 296 1.57 jtc .include <bsd.nls.mk> 297 1.10 mycroft .endif 298 1.10 mycroft 299 1.22 mycroft .include <bsd.obj.mk> 300 1.24 mycroft .include <bsd.dep.mk> 301 1.49 cgd .include <bsd.subdir.mk> 302 1.66 christos .include <bsd.sys.mk> 303