1 1.88 cgd # $NetBSD: bsd.lib.mk,v 1.88 1997/03/23 00:52:20 cgd 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.88 cgd SHLIB_LDSTARTFILE= 70 1.88 cgd SHLIB_LDENDFILE= 71 1.86 jonathan SHLIB_SOVERSION=${SHLIB_MAJOR}.${SHLIB_MINOR} 72 1.86 jonathan CPICFLAGS?= -fpic -DPIC 73 1.86 jonathan APICFLAGS?= -fpic -DPIC 74 1.86 jonathan 75 1.86 jonathan .endif 76 1.86 jonathan 77 1.86 jonathan 78 1.82 mikel CFLAGS+= ${COPTS} 79 1.1 cgd 80 1.1 cgd .c.o: 81 1.80 christos @echo ${COMPILE.c:Q} ${.IMPSRC} 82 1.62 christos @${COMPILE.c} ${.IMPSRC} -o ${.TARGET}.o 83 1.62 christos @${LD} -x -r ${.TARGET}.o -o ${.TARGET} 84 1.62 christos @rm -f ${.TARGET}.o 85 1.1 cgd 86 1.1 cgd .c.po: 87 1.80 christos @echo ${COMPILE.c:Q} -pg ${.IMPSRC} -o ${.TARGET} 88 1.68 cgd @${COMPILE.c} -pg ${.IMPSRC} -o ${.TARGET}.o 89 1.62 christos @${LD} -X -r ${.TARGET}.o -o ${.TARGET} 90 1.62 christos @rm -f ${.TARGET}.o 91 1.17 mycroft 92 1.27 pk .c.so: 93 1.86 jonathan @echo ${COMPILE.c:Q} ${CPICFLAGS} ${.IMPSRC} -o ${.TARGET} 94 1.86 jonathan @${COMPILE.c} ${CPICFLAGS} ${.IMPSRC} -o ${.TARGET}.o 95 1.62 christos @${LD} -x -r ${.TARGET}.o -o ${.TARGET} 96 1.62 christos @rm -f ${.TARGET}.o 97 1.27 pk 98 1.58 cgd .c.ln: 99 1.58 cgd ${LINT} ${LINTFLAGS} ${CFLAGS:M-[IDU]*} -i ${.IMPSRC} 100 1.58 cgd 101 1.18 mycroft .cc.o .C.o: 102 1.80 christos @echo ${COMPILE.cc:Q} ${.IMPSRC} 103 1.62 christos @${COMPILE.cc} ${.IMPSRC} -o ${.TARGET}.o 104 1.63 jtc @${LD} -x -r ${.TARGET}.o -o ${.TARGET} 105 1.62 christos @rm -f ${.TARGET}.o 106 1.17 mycroft 107 1.18 mycroft .cc.po .C.po: 108 1.80 christos @echo ${COMPILE.cc:Q} -pg ${.IMPSRC} -o ${.TARGET} 109 1.68 cgd @${COMPILE.cc} -pg ${.IMPSRC} -o ${.TARGET}.o 110 1.62 christos @${LD} -X -r ${.TARGET}.o -o ${.TARGET} 111 1.62 christos @rm -f ${.TARGET}.o 112 1.28 cgd 113 1.28 cgd .cc.so .C.so: 114 1.86 jonathan @echo ${COMPILE.cc:Q} ${CPICFLAGS} ${.IMPSRC} -o ${.TARGET} 115 1.86 jonathan @${COMPILE.cc} ${CPICFLAGS} ${.IMPSRC} -o ${.TARGET}.o 116 1.62 christos @${LD} -x -r ${.TARGET}.o -o ${.TARGET} 117 1.62 christos @rm -f ${.TARGET}.o 118 1.1 cgd 119 1.40 cgd .S.o .s.o: 120 1.80 christos @echo ${COMPILE.S:Q} ${CFLAGS:M-[ID]*} ${AINC} ${.IMPSRC} 121 1.69 jtc @${COMPILE.S} ${CFLAGS:M-[ID]*} ${AINC} ${.IMPSRC} -o ${.TARGET}.o 122 1.62 christos @${LD} -x -r ${.TARGET}.o -o ${.TARGET} 123 1.62 christos @rm -f ${.TARGET}.o 124 1.1 cgd 125 1.40 cgd .S.po .s.po: 126 1.80 christos @echo ${COMPILE.S:Q} -DGPROF -DPROF ${CFLAGS:M-[ID]*} ${AINC} ${.IMPSRC} -o ${.TARGET} 127 1.75 jtc @${COMPILE.S} -DGPROF -DPROF ${CFLAGS:M-[ID]*} ${AINC} ${.IMPSRC} -o ${.TARGET}.o 128 1.62 christos @${LD} -X -r ${.TARGET}.o -o ${.TARGET} 129 1.62 christos @rm -f ${.TARGET}.o 130 1.1 cgd 131 1.40 cgd .S.so .s.so: 132 1.86 jonathan @echo ${COMPILE.S:Q} ${APICFLAGS} ${CFLAGS:M-[ID]*} ${AINC} ${.IMPSRC} -o ${.TARGET} 133 1.86 jonathan @${COMPILE.S} ${APICFLAGS} ${CFLAGS:M-[ID]*} ${AINC} ${.IMPSRC} -o ${.TARGET}.o 134 1.62 christos @${LD} -x -r ${.TARGET}.o -o ${.TARGET} 135 1.62 christos @rm -f ${.TARGET}.o 136 1.27 pk 137 1.58 cgd 138 1.1 cgd .if !defined(NOPROFILE) 139 1.1 cgd _LIBS=lib${LIB}.a lib${LIB}_p.a 140 1.1 cgd .else 141 1.1 cgd _LIBS=lib${LIB}.a 142 1.1 cgd .endif 143 1.1 cgd 144 1.27 pk .if !defined(NOPIC) 145 1.27 pk _LIBS+=lib${LIB}_pic.a 146 1.37 cgd .if defined(SHLIB_MAJOR) && defined(SHLIB_MINOR) 147 1.37 cgd _LIBS+=lib${LIB}.so.${SHLIB_MAJOR}.${SHLIB_MINOR} 148 1.27 pk .endif 149 1.35 pk .endif 150 1.27 pk 151 1.58 cgd .if !defined(NOLINT) 152 1.58 cgd _LIBS+=llib-l${LIB}.ln 153 1.27 pk .endif 154 1.27 pk 155 1.58 cgd all: ${_LIBS} _SUBDIRUSE 156 1.1 cgd 157 1.21 mycroft OBJS+= ${SRCS:N*.h:R:S/$/.o/g} 158 1.1 cgd 159 1.1 cgd lib${LIB}.a:: ${OBJS} 160 1.1 cgd @echo building standard ${LIB} library 161 1.1 cgd @rm -f lib${LIB}.a 162 1.67 mycroft @${AR} cq lib${LIB}.a `lorder ${OBJS} | tsort -q` 163 1.13 cgd ${RANLIB} lib${LIB}.a 164 1.1 cgd 165 1.1 cgd POBJS+= ${OBJS:.o=.po} 166 1.1 cgd lib${LIB}_p.a:: ${POBJS} 167 1.1 cgd @echo building profiled ${LIB} library 168 1.1 cgd @rm -f lib${LIB}_p.a 169 1.67 mycroft @${AR} cq lib${LIB}_p.a `lorder ${POBJS} | tsort -q` 170 1.13 cgd ${RANLIB} lib${LIB}_p.a 171 1.1 cgd 172 1.27 pk SOBJS+= ${OBJS:.o=.so} 173 1.27 pk lib${LIB}_pic.a:: ${SOBJS} 174 1.27 pk @echo building shared object ${LIB} library 175 1.27 pk @rm -f lib${LIB}_pic.a 176 1.67 mycroft @${AR} cq lib${LIB}_pic.a `lorder ${SOBJS} | tsort -q` 177 1.27 pk ${RANLIB} lib${LIB}_pic.a 178 1.27 pk 179 1.88 cgd lib${LIB}.so.${SHLIB_MAJOR}.${SHLIB_MINOR}: lib${LIB}_pic.a ${DPADD} \ 180 1.88 cgd ${SHLIB_LDSTARTFILE} ${SHLIB_LDENDFILE} 181 1.38 cgd @echo building shared ${LIB} library \(version ${SHLIB_MAJOR}.${SHLIB_MINOR}\) 182 1.37 cgd @rm -f lib${LIB}.so.${SHLIB_MAJOR}.${SHLIB_MINOR} 183 1.86 jonathan .if (${SHLIB_TYPE} == "a.out") 184 1.53 pk $(LD) -x -Bshareable -Bforcearchive \ 185 1.42 mycroft -o lib${LIB}.so.${SHLIB_MAJOR}.${SHLIB_MINOR} lib${LIB}_pic.a ${LDADD} 186 1.86 jonathan .elif (${SHLIB_TYPE} == "ELF") 187 1.86 jonathan $(LD) -x -shared -o lib${LIB}.so.${SHLIB_MAJOR}.${SHLIB_MINOR} \ 188 1.86 jonathan -soname lib${LIB}.so.${SHLIB_SOVERSION} ${SHLIB_LDSTARTFILE} \ 189 1.77 cgd --whole-archive lib${LIB}_pic.a --no-whole-archive ${LDADD} \ 190 1.86 jonathan ${SHLIB_LDENDFILE} 191 1.72 cgd .endif 192 1.35 pk 193 1.58 cgd LOBJS+= ${LSRCS:.c=.ln} ${SRCS:M*.c:.c=.ln} 194 1.58 cgd LLIBS?= -lc 195 1.58 cgd llib-l${LIB}.ln: ${LOBJS} 196 1.58 cgd @echo building llib-l${LIB}.ln 197 1.58 cgd @rm -f llib-l${LIB}.ln 198 1.58 cgd @${LINT} -C${LIB} ${LOBJS} ${LLIBS} 199 1.1 cgd 200 1.1 cgd .if !target(clean) 201 1.81 cgd cleanlib: 202 1.48 mycroft rm -f a.out [Ee]rrs mklog core *.core ${CLEANFILES} 203 1.59 cgd rm -f lib${LIB}.a ${OBJS} 204 1.59 cgd rm -f lib${LIB}_p.a ${POBJS} 205 1.61 cgd rm -f lib${LIB}_pic.a lib${LIB}.so.*.* ${SOBJS} 206 1.59 cgd rm -f llib-l${LIB}.ln ${LOBJS} 207 1.1 cgd 208 1.81 cgd clean: _SUBDIRUSE cleanlib 209 1.81 cgd cleandir: _SUBDIRUSE cleanlib 210 1.81 cgd .else 211 1.49 cgd cleandir: _SUBDIRUSE clean 212 1.81 cgd .endif 213 1.25 mycroft 214 1.26 mycroft .if defined(SRCS) 215 1.64 christos afterdepend: .depend 216 1.1 cgd @(TMP=/tmp/_depend$$$$; \ 217 1.79 cgd sed -e 's/^\([^\.]*\).o[ ]*:/\1.o \1.po \1.so \1.ln:/' \ 218 1.58 cgd < .depend > $$TMP; \ 219 1.1 cgd mv $$TMP .depend) 220 1.26 mycroft .endif 221 1.1 cgd 222 1.1 cgd .if !target(install) 223 1.1 cgd .if !target(beforeinstall) 224 1.1 cgd beforeinstall: 225 1.1 cgd .endif 226 1.1 cgd 227 1.11 mycroft realinstall: 228 1.13 cgd # ranlib lib${LIB}.a 229 1.73 thorpej ${INSTALL} ${COPY} -o ${LIBOWN} -g ${LIBGRP} -m 600 lib${LIB}.a \ 230 1.1 cgd ${DESTDIR}${LIBDIR} 231 1.1 cgd ${RANLIB} -t ${DESTDIR}${LIBDIR}/lib${LIB}.a 232 1.56 cgd chmod ${LIBMODE} ${DESTDIR}${LIBDIR}/lib${LIB}.a 233 1.12 cgd .if !defined(NOPROFILE) 234 1.13 cgd # ranlib lib${LIB}_p.a 235 1.73 thorpej ${INSTALL} ${COPY} -o ${LIBOWN} -g ${LIBGRP} -m 600 \ 236 1.1 cgd lib${LIB}_p.a ${DESTDIR}${LIBDIR} 237 1.1 cgd ${RANLIB} -t ${DESTDIR}${LIBDIR}/lib${LIB}_p.a 238 1.56 cgd chmod ${LIBMODE} ${DESTDIR}${LIBDIR}/lib${LIB}_p.a 239 1.32 pk .endif 240 1.39 pk .if !defined(NOPIC) 241 1.32 pk # ranlib lib${LIB}_pic.a 242 1.73 thorpej ${INSTALL} ${COPY} -o ${LIBOWN} -g ${LIBGRP} -m 600 \ 243 1.32 pk lib${LIB}_pic.a ${DESTDIR}${LIBDIR} 244 1.32 pk ${RANLIB} -t ${DESTDIR}${LIBDIR}/lib${LIB}_pic.a 245 1.56 cgd chmod ${LIBMODE} ${DESTDIR}${LIBDIR}/lib${LIB}_pic.a 246 1.33 pk .endif 247 1.37 cgd .if !defined(NOPIC) && defined(SHLIB_MAJOR) && defined(SHLIB_MINOR) 248 1.73 thorpej ${INSTALL} ${COPY} -o ${LIBOWN} -g ${LIBGRP} -m ${LIBMODE} \ 249 1.37 cgd lib${LIB}.so.${SHLIB_MAJOR}.${SHLIB_MINOR} ${DESTDIR}${LIBDIR} 250 1.86 jonathan .if (${SHLIB_TYPE} == "ELF") 251 1.83 cgd rm -f ${DESTDIR}${LIBDIR}/lib${LIB}.so.${SHLIB_MAJOR} 252 1.83 cgd ln -s lib${LIB}.so.${SHLIB_MAJOR}.${SHLIB_MINOR} \ 253 1.83 cgd ${DESTDIR}${LIBDIR}/lib${LIB}.so.${SHLIB_MAJOR} 254 1.83 cgd rm -f ${DESTDIR}${LIBDIR}/lib${LIB}.so 255 1.83 cgd ln -s lib${LIB}.so.${SHLIB_MAJOR}.${SHLIB_MINOR} \ 256 1.83 cgd ${DESTDIR}${LIBDIR}/lib${LIB}.so 257 1.83 cgd .endif 258 1.12 cgd .endif 259 1.58 cgd .if !defined(NOLINT) 260 1.73 thorpej ${INSTALL} ${COPY} -o ${LIBOWN} -g ${LIBGRP} -m ${LIBMODE} \ 261 1.58 cgd llib-l${LIB}.ln ${DESTDIR}${LINTLIBDIR} 262 1.58 cgd .endif 263 1.1 cgd .if defined(LINKS) && !empty(LINKS) 264 1.1 cgd @set ${LINKS}; \ 265 1.1 cgd while test $$# -ge 2; do \ 266 1.1 cgd l=${DESTDIR}$$1; \ 267 1.1 cgd shift; \ 268 1.1 cgd t=${DESTDIR}$$1; \ 269 1.1 cgd shift; \ 270 1.1 cgd echo $$t -\> $$l; \ 271 1.1 cgd rm -f $$t; \ 272 1.1 cgd ln $$l $$t; \ 273 1.84 perry done; true 274 1.84 perry .endif 275 1.84 perry .if defined(SYMLINKS) && !empty(SYMLINKS) 276 1.84 perry @set ${SYMLINKS}; \ 277 1.84 perry while test $$# -ge 2; do \ 278 1.87 perry l=$$1; \ 279 1.84 perry shift; \ 280 1.84 perry t=${DESTDIR}$$1; \ 281 1.84 perry shift; \ 282 1.84 perry echo $$t -\> $$l; \ 283 1.84 perry rm -f $$t; \ 284 1.84 perry ln -s $$l $$t; \ 285 1.1 cgd done; true 286 1.1 cgd .endif 287 1.1 cgd 288 1.49 cgd install: maninstall _SUBDIRUSE 289 1.11 mycroft maninstall: afterinstall 290 1.11 mycroft afterinstall: realinstall 291 1.11 mycroft realinstall: beforeinstall 292 1.1 cgd .endif 293 1.1 cgd 294 1.10 mycroft .if !defined(NOMAN) 295 1.1 cgd .include <bsd.man.mk> 296 1.57 jtc .endif 297 1.57 jtc 298 1.57 jtc .if !defined(NONLS) 299 1.57 jtc .include <bsd.nls.mk> 300 1.10 mycroft .endif 301 1.10 mycroft 302 1.22 mycroft .include <bsd.obj.mk> 303 1.24 mycroft .include <bsd.dep.mk> 304 1.49 cgd .include <bsd.subdir.mk> 305 1.66 christos .include <bsd.sys.mk> 306