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