Home | History | Annotate | Line # | Download | only in mk
bsd.lib.mk revision 1.157
      1 #	$NetBSD: bsd.lib.mk,v 1.157 1999/09/04 21:48:33 fredb Exp $
      2 #	@(#)bsd.lib.mk	8.3 (Berkeley) 4/22/94
      3 
      4 .if !target(__initialized__)
      5 __initialized__:
      6 .if exists(${.CURDIR}/../Makefile.inc)
      7 .include "${.CURDIR}/../Makefile.inc"
      8 .endif
      9 .include <bsd.own.mk>
     10 .include <bsd.obj.mk>
     11 .MAIN:		all
     12 .endif
     13 
     14 .PHONY:		checkver cleanlib libinstall
     15 realinstall:	checkver libinstall
     16 clean cleandir distclean: cleanlib
     17 
     18 .if exists(${SHLIB_VERSION_FILE})
     19 SHLIB_MAJOR != . ${SHLIB_VERSION_FILE} ; echo $$major
     20 SHLIB_MINOR != . ${SHLIB_VERSION_FILE} ; echo $$minor
     21 
     22 # Check for higher installed library versions.
     23 .if !defined(NOCHECKVER) && !defined(NOCHECKVER_${LIB}) && \
     24 	exists(${BSDSRCDIR}/lib/checkver)
     25 checkver:
     26 	@(cd ${.CURDIR} && \
     27 		${BSDSRCDIR}/lib/checkver -v ${SHLIB_VERSION_FILE} \
     28 		    -d ${DESTDIR}${LIBDIR} ${LIB})
     29 .else
     30 checkver:
     31 .endif
     32 .else
     33 checkver:
     34 .endif
     35 
     36 # add additional suffixes not exported.
     37 # .po is used for profiling object files.
     38 # .so is used for PIC object files.
     39 .SUFFIXES: .out .a .ln .so .po .o .s .S .c .cc .C .m .F .f .r .y .l .cl .p .h
     40 .SUFFIXES: .sh .m4 .m
     41 
     42 
     43 # Set PICFLAGS to cc flags for producing position-independent code,
     44 # if not already set.  Includes -DPIC, if required.
     45 
     46 # Data-driven table using make variables to control  how shared libraries
     47 # are built for different platforms and object formats.
     48 # OBJECT_FMT:		currently either "ELF" or "a.out", from <bsd.own.mk>
     49 # SHLIB_SOVERSION:  	version number to be compiled into a shared library
     50 #                    	via -soname. Usualy ${SHLIB_MAJOR} on ELF.
     51 #   			NetBSD/pmax used to use ${SHLIB_MAJOR}.{SHLIB-MINOR}.
     52 # SHLIB_SHFLAGS:	Flags to tell ${LD} to emit  shared library.
     53 #			with ELF, also set shared-lib version for ld.so.
     54 # SHLIB_LDSTARTFILE:	support .o file, call C++ file-level constructors
     55 # SHLIB_LDENDFILE:	support .o file, call C++ file-level destructors
     56 # CPPICFLAGS:	flags for ${CPP} to preprocess  .[sS]  files for ${AS}
     57 # CPICFLAGS:	flags for ${CC} to compile  .[cC] files to .so objects.
     58 # CAPICFLAGS	flags for {$CC} to compiling .[Ss] files
     59 #		 	(usually just ${CPPPICFLAGS} ${CPICFLAGS})
     60 # APICFLAGS:	flags for ${AS} to assemble .[sS]  to .so objects.
     61 
     62 .if ${MACHINE_ARCH} == "alpha"
     63 		# Alpha-specific shared library flags
     64 CPICFLAGS ?= -fpic -DPIC
     65 CPPPICFLAGS?= -DPIC 
     66 CAPICFLAGS?= ${CPPPICFLAGS} ${CPICFLAGS}
     67 APICFLAGS ?=
     68 .elif ${MACHINE_ARCH} == "mipsel" || ${MACHINE_ARCH} == "mipseb"
     69 		# mips-specific shared library flags
     70 
     71 # On mips, all libs need to be compiled with ABIcalls, not just sharedlibs.
     72 CPICFLAGS?=
     73 APICFLAGS?=
     74 #CPICFLAGS?= -fpic -DPIC
     75 #APICFLAGS?= -DPIC
     76 
     77 # so turn shlib PIC flags on for ${CPP}, ${CC}, and ${AS} as follows:
     78 AINC+=-DPIC -DABICALLS
     79 COPTS+=	-fPIC ${AINC}
     80 AFLAGS+= -fPIC
     81 AS+=	-KPIC
     82 
     83 .elif ${MACHINE_ARCH} == "sparc" && ${OBJECT_FMT} == "ELF"
     84 
     85 CPICFLAGS ?= -fpic -DPIC
     86 CPPPICFLAGS?= -DPIC 
     87 CAPICFLAGS?= ${CPPPICFLAGS} ${CPICFLAGS}
     88 APICFLAGS ?= -KPIC
     89 
     90 .else
     91 
     92 # Platform-independent flags for NetBSD a.out shared libraries (and PowerPC)
     93 SHLIB_LDSTARTFILE=
     94 SHLIB_LDENDFILE=
     95 SHLIB_SHFLAGS=
     96 SHLIB_SOVERSION=${SHLIB_MAJOR}.${SHLIB_MINOR}
     97 CPICFLAGS?= -fpic -DPIC
     98 CPPPICFLAGS?= -DPIC 
     99 CAPICFLAGS?= ${CPPPICFLAGS} ${CPICFLAGS}
    100 APICFLAGS?= -k
    101 
    102 .endif
    103 
    104 # Platform-independent linker flags for ELF shared libraries
    105 .if ${OBJECT_FMT} == "ELF"
    106 SHLIB_SOVERSION=${SHLIB_MAJOR}
    107 SHLIB_SHFLAGS=-soname lib${LIB}.so.${SHLIB_SOVERSION}
    108 SHLIB_LDSTARTFILE= ${DESTDIR}/usr/lib/crtbeginS.o
    109 SHLIB_LDENDFILE= ${DESTDIR}/usr/lib/crtendS.o
    110 .endif
    111 
    112 CFLAGS+=	${COPTS}
    113 
    114 .c.o:
    115 .if defined(COPTS) && !empty(COPTS:M*-g*)
    116 	${COMPILE.c} ${.IMPSRC}
    117 .else
    118 	@echo ${COMPILE.c:Q} ${.IMPSRC}
    119 	@${COMPILE.c} ${.IMPSRC} -o ${.TARGET}.o
    120 	@${LD} -x -r ${.TARGET}.o -o ${.TARGET}
    121 	@rm -f ${.TARGET}.o
    122 .endif
    123 
    124 .c.po:
    125 .if defined(COPTS) && !empty(COPTS:M*-g*)
    126 	${COMPILE.c} -pg ${.IMPSRC} -o ${.TARGET}
    127 .else
    128 	@echo ${COMPILE.c:Q} -pg ${.IMPSRC} -o ${.TARGET}
    129 	@${COMPILE.c} -pg ${.IMPSRC} -o ${.TARGET}.o
    130 	@${LD} -X -r ${.TARGET}.o -o ${.TARGET}
    131 	@rm -f ${.TARGET}.o
    132 .endif
    133 
    134 .c.so:
    135 .if defined(COPTS) && !empty(COPTS:M*-g*)
    136 	${COMPILE.c} ${CPICFLAGS} ${.IMPSRC} -o ${.TARGET}
    137 .else
    138 	@echo ${COMPILE.c:Q} ${CPICFLAGS} ${.IMPSRC} -o ${.TARGET}
    139 	@${COMPILE.c} ${CPICFLAGS} ${.IMPSRC} -o ${.TARGET}.o
    140 	@${LD} -x -r ${.TARGET}.o -o ${.TARGET}
    141 	@rm -f ${.TARGET}.o
    142 .endif
    143 
    144 .c.ln:
    145 	${LINT} ${LINTFLAGS} ${CPPFLAGS:M-[IDU]*} -i ${.IMPSRC}
    146 
    147 .cc.o .C.o:
    148 .if defined(COPTS) && !empty(COPTS:M*-g*)
    149 	${COMPILE.cc} ${.IMPSRC}
    150 .else
    151 	@echo ${COMPILE.cc:Q} ${.IMPSRC}
    152 	@${COMPILE.cc} ${.IMPSRC} -o ${.TARGET}.o
    153 	@${LD} -x -r ${.TARGET}.o -o ${.TARGET}
    154 	@rm -f ${.TARGET}.o
    155 .endif
    156 
    157 .cc.po .C.po:
    158 .if defined(COPTS) && !empty(COPTS:M*-g*)
    159 	${COMPILE.cc} -pg ${.IMPSRC} -o ${.TARGET}
    160 .else
    161 	@echo ${COMPILE.cc:Q} -pg ${.IMPSRC} -o ${.TARGET}
    162 	@${COMPILE.cc} -pg ${.IMPSRC} -o ${.TARGET}.o
    163 	@${LD} -X -r ${.TARGET}.o -o ${.TARGET}
    164 	@rm -f ${.TARGET}.o
    165 .endif
    166 
    167 .cc.so .C.so:
    168 .if defined(COPTS) && !empty(COPTS:M*-g*)
    169 	${COMPILE.cc} ${CPICFLAGS} ${.IMPSRC} -o ${.TARGET}
    170 .else
    171 	@echo ${COMPILE.cc:Q} ${CPICFLAGS} ${.IMPSRC} -o ${.TARGET}
    172 	@${COMPILE.cc} ${CPICFLAGS} ${.IMPSRC} -o ${.TARGET}.o
    173 	@${LD} -x -r ${.TARGET}.o -o ${.TARGET}
    174 	@rm -f ${.TARGET}.o
    175 .endif
    176 
    177 .m.o:
    178 .if defined(OBJCFLAGS) && !empty(OBJCFLAGS:M*-g*)
    179 	${COMPILE.m} ${.IMPSRC}
    180 .else
    181 	@echo ${COMPILE.m:Q} ${.IMPSRC}
    182 	@${COMPILE.m} ${.IMPSRC} -o ${.TARGET}.o
    183 	@${LD} -x -r ${.TARGET}.o -o ${.TARGET}
    184 	@rm -f ${.TARGET}.o
    185 .endif
    186 
    187 .m.po:
    188 .if defined(OBJCFLAGS) && !empty(OBJCFLAGS:M*-g*)
    189 	${COMPILE.m} -pg ${.IMPSRC} -o ${.TARGET}
    190 .else
    191 	@echo ${COMPILE.m:Q} -pg ${.IMPSRC} -o ${.TARGET}
    192 	@${COMPILE.m} -pg ${.IMPSRC} -o ${.TARGET}.o
    193 	@${LD} -X -r ${.TARGET}.o -o ${.TARGET}
    194 	@rm -f ${.TARGET}.o
    195 .endif
    196 
    197 .m.so:
    198 .if defined(OBJCFLAGS) && !empty(OBJCFLAGS:M*-g*)
    199 	${COMPILE.m} ${CPICFLAGS} ${.IMPSRC} -o ${.TARGET}
    200 .else
    201 	@echo ${COMPILE.m:Q} ${CPICFLAGS} ${.IMPSRC} -o ${.TARGET}
    202 	@${COMPILE.m} ${CPICFLAGS} ${.IMPSRC} -o ${.TARGET}.o
    203 	@${LD} -x -r ${.TARGET}.o -o ${.TARGET}
    204 	@rm -f ${.TARGET}.o
    205 .endif
    206 
    207 .S.o .s.o:
    208 	@echo ${COMPILE.S:Q} ${CFLAGS:M-[ID]*} ${AINC} ${.IMPSRC}
    209 	@${COMPILE.S} ${CFLAGS:M-[ID]*} ${AINC} ${.IMPSRC} -o ${.TARGET}.o
    210 	@${LD} -x -r ${.TARGET}.o -o ${.TARGET}
    211 	@rm -f ${.TARGET}.o
    212 
    213 .S.po .s.po:
    214 	@echo ${COMPILE.S:Q} -DGPROF -DPROF ${CFLAGS:M-[ID]*} ${AINC} ${.IMPSRC} -o ${.TARGET}
    215 	@${COMPILE.S} -DGPROF -DPROF ${CFLAGS:M-[ID]*} ${AINC} ${.IMPSRC} -o ${.TARGET}.o
    216 	@${LD} -X -r ${.TARGET}.o -o ${.TARGET}
    217 	@rm -f ${.TARGET}.o
    218 
    219 .S.so .s.so:
    220 	@echo ${COMPILE.S:Q} ${CAPICFLAGS} ${CFLAGS:M-[ID]*} ${AINC} ${.IMPSRC} -o ${.TARGET}
    221 	@${COMPILE.S} ${CAPICFLAGS} ${CFLAGS:M-[ID]*} ${AINC} ${.IMPSRC} -o ${.TARGET}.o
    222 	@${LD} -x -r ${.TARGET}.o -o ${.TARGET}
    223 	@rm -f ${.TARGET}.o
    224 
    225 .if ${MKPIC} == "no" || (defined(LDSTATIC) && ${LDSTATIC} != "") \
    226 	|| ${MKLINKLIB} != "no"
    227 _LIBS=lib${LIB}.a
    228 .else
    229 _LIBS=
    230 .endif
    231 
    232 .if ${MKPROFILE} != "no"
    233 _LIBS+=lib${LIB}_p.a
    234 .endif
    235 
    236 .if ${MKPIC} != "no"
    237 _LIBS+=lib${LIB}_pic.a
    238 .if defined(SHLIB_MAJOR) && defined(SHLIB_MINOR)
    239 _LIBS+=lib${LIB}.so.${SHLIB_MAJOR}.${SHLIB_MINOR}
    240 .endif
    241 .endif
    242 
    243 .if ${MKLINT} != "no" && ${MKLINKLIB} != "no"
    244 _LIBS+=llib-l${LIB}.ln
    245 .endif
    246 
    247 all: ${SRCS} ${_LIBS}
    248 
    249 __archivebuild: .USE
    250 	@rm -f ${.TARGET}
    251 	@${AR} cq ${.TARGET} `NM=${NM} ${LORDER} ${.ALLSRC:M*o} | ${TSORT}`
    252 	${RANLIB} ${.TARGET}
    253 
    254 __archiveinstall: .USE
    255 	${INSTALL} ${RENAME} ${PRESERVE} ${COPY} ${INSTPRIV} -o ${LIBOWN} \
    256 	    -g ${LIBGRP} -m 600 ${.ALLSRC} ${.TARGET}
    257 	${RANLIB} -t ${.TARGET}
    258 	chmod ${LIBMODE} ${.TARGET}
    259 
    260 DPSRCS+=	${SRCS:M*.l:.l=.c} ${SRCS:M*.y:.y=.c}
    261 CLEANFILES+=	${DPSRCS}
    262 .if defined(YHEADER)
    263 CLEANFILES+=	${SRCS:M*.y:.y=.h}
    264 .endif
    265 
    266 OBJS+=		${SRCS:N*.h:N*.sh:R:S/$/.o/g}
    267 lib${LIB}.a:: ${OBJS} __archivebuild
    268 	@echo building standard ${LIB} library
    269 
    270 POBJS+=		${OBJS:.o=.po}
    271 lib${LIB}_p.a:: ${POBJS} __archivebuild
    272 	@echo building profiled ${LIB} library
    273 
    274 SOBJS+=		${OBJS:.o=.so}
    275 lib${LIB}_pic.a:: ${SOBJS} __archivebuild
    276 	@echo building shared object ${LIB} library
    277 
    278 lib${LIB}.so.${SHLIB_MAJOR}.${SHLIB_MINOR}: lib${LIB}_pic.a ${DPADD} \
    279     ${SHLIB_LDSTARTFILE} ${SHLIB_LDENDFILE}
    280 	@echo building shared ${LIB} library \(version ${SHLIB_MAJOR}.${SHLIB_MINOR}\)
    281 	@rm -f lib${LIB}.so.${SHLIB_MAJOR}.${SHLIB_MINOR}
    282 .if defined(DESTDIR)
    283 	$(LD) -nostdlib -x -shared ${SHLIB_SHFLAGS} -o ${.TARGET} \
    284 	    ${SHLIB_LDSTARTFILE} \
    285 	    --whole-archive lib${LIB}_pic.a \
    286 	    -L${DESTDIR}${LIBDIR} -R${LIBDIR} \
    287 	    --no-whole-archive ${LDADD} \
    288 	    ${SHLIB_LDENDFILE}
    289 .else
    290 	$(LD) -x -shared ${SHLIB_SHFLAGS} -o ${.TARGET} \
    291 	    ${SHLIB_LDSTARTFILE} \
    292 	    --whole-archive lib${LIB}_pic.a --no-whole-archive ${LDADD} \
    293 	    ${SHLIB_LDENDFILE}
    294 .endif
    295 .if ${OBJECT_FMT} == "ELF"
    296 	rm -f lib${LIB}.so.${SHLIB_MAJOR}
    297 	ln -s lib${LIB}.so.${SHLIB_MAJOR}.${SHLIB_MINOR} \
    298 	    lib${LIB}.so.${SHLIB_MAJOR}
    299 	rm -f lib${LIB}.so
    300 	ln -s lib${LIB}.so.${SHLIB_MAJOR}.${SHLIB_MINOR} \
    301 	    lib${LIB}.so
    302 .endif
    303 
    304 LOBJS+=		${LSRCS:.c=.ln} ${SRCS:M*.c:.c=.ln}
    305 LLIBS?=		-lc
    306 llib-l${LIB}.ln: ${LOBJS}
    307 	@echo building llib-l${LIB}.ln
    308 	@rm -f llib-l${LIB}.ln
    309 	@${LINT} -C${LIB} ${.ALLSRC} ${LLIBS}
    310 
    311 cleanlib:
    312 	rm -f a.out [Ee]rrs mklog core *.core ${CLEANFILES}
    313 	rm -f lib${LIB}.a ${OBJS}
    314 	rm -f lib${LIB}_p.a ${POBJS}
    315 	rm -f lib${LIB}_pic.a lib${LIB}.so.* lib${LIB}.so ${SOBJS}
    316 	rm -f llib-l${LIB}.ln ${LOBJS}
    317 
    318 .if defined(SRCS)
    319 afterdepend: .depend
    320 	@(TMP=/tmp/_depend$$$$; \
    321 	    sed -e 's/^\([^\.]*\).o[ ]*:/\1.o \1.po \1.so \1.ln:/' \
    322 	      < .depend > $$TMP; \
    323 	    mv $$TMP .depend)
    324 .endif
    325 
    326 .if !target(libinstall)
    327 # Make sure it gets defined, in case MKPIC==no && MKLINKLIB==no
    328 libinstall::
    329 
    330 .if ${MKLINKLIB} != "no"
    331 libinstall:: ${DESTDIR}${LIBDIR}/lib${LIB}.a
    332 .if !defined(UPDATE)
    333 .PHONY: ${DESTDIR}${LIBDIR}/lib${LIB}.a
    334 .endif
    335 .if !defined(BUILD) && !make(all) && !make(lib${LIB}.a)
    336 ${DESTDIR}${LIBDIR}/lib${LIB}.a: .MADE
    337 .endif
    338 
    339 .PRECIOUS: ${DESTDIR}${LIBDIR}/lib${LIB}.a
    340 ${DESTDIR}${LIBDIR}/lib${LIB}.a: lib${LIB}.a __archiveinstall
    341 .endif
    342 
    343 .if ${MKPROFILE} != "no"
    344 libinstall:: ${DESTDIR}${LIBDIR}/lib${LIB}_p.a
    345 .if !defined(UPDATE)
    346 .PHONY: ${DESTDIR}${LIBDIR}/lib${LIB}_p.a
    347 .endif
    348 .if !defined(BUILD) && !make(all) && !make(lib${LIB}_p.a)
    349 ${DESTDIR}${LIBDIR}/lib${LIB}_p.a: .MADE
    350 .endif
    351 
    352 .PRECIOUS: ${DESTDIR}${LIBDIR}/lib${LIB}_p.a
    353 ${DESTDIR}${LIBDIR}/lib${LIB}_p.a: lib${LIB}_p.a __archiveinstall
    354 .endif
    355 
    356 .if ${MKPIC} != "no" && ${MKPICINSTALL} != "no"
    357 libinstall:: ${DESTDIR}${LIBDIR}/lib${LIB}_pic.a
    358 .if !defined(UPDATE)
    359 .PHONY: ${DESTDIR}${LIBDIR}/lib${LIB}_pic.a
    360 .endif
    361 .if !defined(BUILD) && !make(all) && !make(lib${LIB}_pic.a)
    362 ${DESTDIR}${LIBDIR}/lib${LIB}_pic.a: .MADE
    363 .endif
    364 
    365 .PRECIOUS: ${DESTDIR}${LIBDIR}/lib${LIB}_pic.a
    366 ${DESTDIR}${LIBDIR}/lib${LIB}_pic.a: lib${LIB}_pic.a __archiveinstall
    367 .endif
    368 
    369 .if ${MKPIC} != "no" && defined(SHLIB_MAJOR) && defined(SHLIB_MINOR)
    370 libinstall:: ${DESTDIR}${LIBDIR}/lib${LIB}.so.${SHLIB_MAJOR}.${SHLIB_MINOR}
    371 .if !defined(UPDATE)
    372 .PHONY: ${DESTDIR}${LIBDIR}/lib${LIB}.so.${SHLIB_MAJOR}.${SHLIB_MINOR}
    373 .endif
    374 .if !defined(BUILD) && !make(all) && !make(lib${LIB}.so.${SHLIB_MAJOR}.${SHLIB_MINOR})
    375 ${DESTDIR}${LIBDIR}/lib${LIB}.so.${SHLIB_MAJOR}.${SHLIB_MINOR}: .MADE
    376 .endif
    377 
    378 .PRECIOUS: ${DESTDIR}${LIBDIR}/lib${LIB}.so.${SHLIB_MAJOR}.${SHLIB_MINOR}
    379 ${DESTDIR}${LIBDIR}/lib${LIB}.so.${SHLIB_MAJOR}.${SHLIB_MINOR}: lib${LIB}.so.${SHLIB_MAJOR}.${SHLIB_MINOR}
    380 	${INSTALL} ${RENAME} ${PRESERVE} ${COPY} ${INSTPRIV} -o ${LIBOWN} \
    381 	    -g ${LIBGRP} -m ${LIBMODE} ${.ALLSRC} ${.TARGET}
    382 .if ${OBJECT_FMT} == "a.out" && !defined(DESTDIR)
    383 	/sbin/ldconfig -m ${LIBDIR}
    384 .endif
    385 .if ${OBJECT_FMT} == "ELF"
    386 	rm -f ${DESTDIR}${LIBDIR}/lib${LIB}.so.${SHLIB_MAJOR}
    387 	ln -s lib${LIB}.so.${SHLIB_MAJOR}.${SHLIB_MINOR} \
    388 	    ${DESTDIR}${LIBDIR}/lib${LIB}.so.${SHLIB_MAJOR}
    389 	rm -f ${DESTDIR}${LIBDIR}/lib${LIB}.so
    390 .if ${MKLINKLIB} != "no"
    391 	ln -s lib${LIB}.so.${SHLIB_MAJOR}.${SHLIB_MINOR} \
    392 	    ${DESTDIR}${LIBDIR}/lib${LIB}.so
    393 .endif
    394 .endif
    395 .endif
    396 
    397 .if ${MKLINT} != "no" && ${MKLINKLIB} != "no"
    398 libinstall:: ${DESTDIR}${LINTLIBDIR}/llib-l${LIB}.ln
    399 .if !defined(UPDATE)
    400 .PHONY: ${DESTDIR}${LINTLIBDIR}/llib-l${LIB}.ln
    401 .endif
    402 .if !defined(BUILD) && !make(all) && !make(llib-l${LIB}.ln)
    403 ${DESTDIR}${LINTLIBDIR}/llib-l${LIB}.ln: .MADE
    404 .endif
    405 
    406 .PRECIOUS: ${DESTDIR}${LINTLIBDIR}/llib-l${LIB}.ln
    407 ${DESTDIR}${LINTLIBDIR}/llib-l${LIB}.ln: llib-l${LIB}.ln
    408 	${INSTALL} ${RENAME} ${PRESERVE} ${COPY} ${INSTPRIV} -o ${LIBOWN} \
    409 	    -g ${LIBGRP} -m ${LIBMODE} ${.ALLSRC} ${DESTDIR}${LINTLIBDIR}
    410 .endif
    411 .endif
    412 
    413 .include <bsd.man.mk>
    414 .include <bsd.nls.mk>
    415 .include <bsd.files.mk>
    416 .include <bsd.inc.mk>
    417 .include <bsd.links.mk>
    418 .include <bsd.dep.mk>
    419 .include <bsd.sys.mk>
    420 
    421 # Make sure all of the standard targets are defined, even if they do nothing.
    422 lint regress:
    423