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