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