Home | History | Annotate | Line # | Download | only in mk
bsd.lib.mk revision 1.149
      1 #	$NetBSD: bsd.lib.mk,v 1.149 1999/02/12 12:38:45 lukem 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} == "mips"
     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 .else
     83 
     84 # Platform-independent flags for NetBSD a.out shared libraries (and PowerPC)
     85 SHLIB_LDSTARTFILE=
     86 SHLIB_LDENDFILE=
     87 SHLIB_SHFLAGS=
     88 SHLIB_SOVERSION=${SHLIB_MAJOR}.${SHLIB_MINOR}
     89 CPICFLAGS?= -fpic -DPIC
     90 CPPPICFLAGS?= -DPIC 
     91 CAPICFLAGS?= ${CPPPICFLAGS} ${CPICFLAGS}
     92 APICFLAGS?= -k
     93 
     94 .endif
     95 
     96 # Platform-independent linker flags for ELF shared libraries
     97 .if ${OBJECT_FMT} == "ELF"
     98 SHLIB_SOVERSION=${SHLIB_MAJOR}
     99 SHLIB_SHFLAGS=-soname lib${LIB}.so.${SHLIB_SOVERSION}
    100 SHLIB_LDSTARTFILE= ${DESTDIR}/usr/lib/crtbeginS.o
    101 SHLIB_LDENDFILE= ${DESTDIR}/usr/lib/crtendS.o
    102 .endif
    103 
    104 CFLAGS+=	${COPTS}
    105 
    106 .c.o:
    107 	@echo ${COMPILE.c:Q} ${.IMPSRC}
    108 	@${COMPILE.c} ${.IMPSRC} -o ${.TARGET}.o
    109 	@${LD} -x -r ${.TARGET}.o -o ${.TARGET}
    110 	@rm -f ${.TARGET}.o
    111 
    112 .c.po:
    113 	@echo ${COMPILE.c:Q} -pg ${.IMPSRC} -o ${.TARGET}
    114 	@${COMPILE.c} -pg ${.IMPSRC} -o ${.TARGET}.o
    115 	@${LD} -X -r ${.TARGET}.o -o ${.TARGET}
    116 	@rm -f ${.TARGET}.o
    117 
    118 .c.so:
    119 	@echo ${COMPILE.c:Q} ${CPICFLAGS} ${.IMPSRC} -o ${.TARGET}
    120 	@${COMPILE.c} ${CPICFLAGS} ${.IMPSRC} -o ${.TARGET}.o
    121 	@${LD} -x -r ${.TARGET}.o -o ${.TARGET}
    122 	@rm -f ${.TARGET}.o
    123 
    124 .c.ln:
    125 	${LINT} ${LINTFLAGS} ${CPPFLAGS:M-[IDU]*} -i ${.IMPSRC}
    126 
    127 .cc.o .C.o:
    128 	@echo ${COMPILE.cc:Q} ${.IMPSRC}
    129 	@${COMPILE.cc} ${.IMPSRC} -o ${.TARGET}.o
    130 	@${LD} -x -r ${.TARGET}.o -o ${.TARGET}
    131 	@rm -f ${.TARGET}.o
    132 
    133 .cc.po .C.po:
    134 	@echo ${COMPILE.cc:Q} -pg ${.IMPSRC} -o ${.TARGET}
    135 	@${COMPILE.cc} -pg ${.IMPSRC} -o ${.TARGET}.o
    136 	@${LD} -X -r ${.TARGET}.o -o ${.TARGET}
    137 	@rm -f ${.TARGET}.o
    138 
    139 .cc.so .C.so:
    140 	@echo ${COMPILE.cc:Q} ${CPICFLAGS} ${.IMPSRC} -o ${.TARGET}
    141 	@${COMPILE.cc} ${CPICFLAGS} ${.IMPSRC} -o ${.TARGET}.o
    142 	@${LD} -x -r ${.TARGET}.o -o ${.TARGET}
    143 	@rm -f ${.TARGET}.o
    144 
    145 .m.o:
    146 	@echo ${COMPILE.m:Q} ${.IMPSRC}
    147 	@${COMPILE.m} ${.IMPSRC} -o ${.TARGET}.o
    148 	@${LD} -x -r ${.TARGET}.o -o ${.TARGET}
    149 	@rm -f ${.TARGET}.o
    150 
    151 .m.po:
    152 	@echo ${COMPILE.m:Q} -pg ${.IMPSRC} -o ${.TARGET}
    153 	@${COMPILE.m} -pg ${.IMPSRC} -o ${.TARGET}.o
    154 	@${LD} -X -r ${.TARGET}.o -o ${.TARGET}
    155 	@rm -f ${.TARGET}.o
    156 
    157 .m.so:
    158 	@echo ${COMPILE.m:Q} ${CPICFLAGS} ${.IMPSRC} -o ${.TARGET}
    159 	@${COMPILE.m} ${CPICFLAGS} ${.IMPSRC} -o ${.TARGET}.o
    160 	@${LD} -x -r ${.TARGET}.o -o ${.TARGET}
    161 	@rm -f ${.TARGET}.o
    162 
    163 .S.o .s.o:
    164 	@echo ${COMPILE.S:Q} ${CFLAGS:M-[ID]*} ${AINC} ${.IMPSRC}
    165 	@${COMPILE.S} ${CFLAGS:M-[ID]*} ${AINC} ${.IMPSRC} -o ${.TARGET}.o
    166 	@${LD} -x -r ${.TARGET}.o -o ${.TARGET}
    167 	@rm -f ${.TARGET}.o
    168 
    169 .S.po .s.po:
    170 	@echo ${COMPILE.S:Q} -DGPROF -DPROF ${CFLAGS:M-[ID]*} ${AINC} ${.IMPSRC} -o ${.TARGET}
    171 	@${COMPILE.S} -DGPROF -DPROF ${CFLAGS:M-[ID]*} ${AINC} ${.IMPSRC} -o ${.TARGET}.o
    172 	@${LD} -X -r ${.TARGET}.o -o ${.TARGET}
    173 	@rm -f ${.TARGET}.o
    174 
    175 .S.so .s.so:
    176 	@echo ${COMPILE.S:Q} ${CAPICFLAGS} ${CFLAGS:M-[ID]*} ${AINC} ${.IMPSRC} -o ${.TARGET}
    177 	@${COMPILE.S} ${CAPICFLAGS} ${CFLAGS:M-[ID]*} ${AINC} ${.IMPSRC} -o ${.TARGET}.o
    178 	@${LD} -x -r ${.TARGET}.o -o ${.TARGET}
    179 	@rm -f ${.TARGET}.o
    180 
    181 .if ${MKPIC} == "no" || (defined(LDSTATIC) && ${LDSTATIC} != "") \
    182 	|| ${MKLINKLIB} != "no"
    183 _LIBS=lib${LIB}.a
    184 .else
    185 _LIBS=
    186 .endif
    187 
    188 .if ${MKPROFILE} != "no"
    189 _LIBS+=lib${LIB}_p.a
    190 .endif
    191 
    192 .if ${MKPIC} != "no"
    193 _LIBS+=lib${LIB}_pic.a
    194 .if defined(SHLIB_MAJOR) && defined(SHLIB_MINOR)
    195 _LIBS+=lib${LIB}.so.${SHLIB_MAJOR}.${SHLIB_MINOR}
    196 .endif
    197 .endif
    198 
    199 .if ${MKLINT} != "no" && ${MKLINKLIB} != "no"
    200 _LIBS+=llib-l${LIB}.ln
    201 .endif
    202 
    203 all: ${SRCS} ${_LIBS}
    204 
    205 __archivebuild: .USE
    206 	@rm -f ${.TARGET}
    207 	@${AR} cq ${.TARGET} `NM=${NM} ${LORDER} ${.ALLSRC:M*o} | ${TSORT}`
    208 	${RANLIB} ${.TARGET}
    209 
    210 __archiveinstall: .USE
    211 	${INSTALL} ${RENAME} ${PRESERVE} ${COPY} -o ${LIBOWN} -g ${LIBGRP} \
    212 		-m 600 ${.ALLSRC} ${.TARGET}
    213 	${RANLIB} -t ${.TARGET}
    214 	chmod ${LIBMODE} ${.TARGET}
    215 
    216 DPSRCS+=	${SRCS:M*.l:.l=.c} ${SRCS:M*.y:.y=.c}
    217 CLEANFILES+=	${DPSRCS}
    218 .if defined(YHEADER)
    219 CLEANFILES+=	${SRCS:M*.y:.y=.h}
    220 .endif
    221 
    222 OBJS+=		${SRCS:N*.h:N*.sh:R:S/$/.o/g}
    223 lib${LIB}.a:: ${OBJS} __archivebuild
    224 	@echo building standard ${LIB} library
    225 
    226 POBJS+=		${OBJS:.o=.po}
    227 lib${LIB}_p.a:: ${POBJS} __archivebuild
    228 	@echo building profiled ${LIB} library
    229 
    230 SOBJS+=		${OBJS:.o=.so}
    231 lib${LIB}_pic.a:: ${SOBJS} __archivebuild
    232 	@echo building shared object ${LIB} library
    233 
    234 lib${LIB}.so.${SHLIB_MAJOR}.${SHLIB_MINOR}: lib${LIB}_pic.a ${DPADD} \
    235     ${SHLIB_LDSTARTFILE} ${SHLIB_LDENDFILE}
    236 	@echo building shared ${LIB} library \(version ${SHLIB_MAJOR}.${SHLIB_MINOR}\)
    237 	@rm -f lib${LIB}.so.${SHLIB_MAJOR}.${SHLIB_MINOR}
    238 	$(LD) -x -shared ${SHLIB_SHFLAGS} -o ${.TARGET} \
    239 	    ${SHLIB_LDSTARTFILE} \
    240 	    --whole-archive lib${LIB}_pic.a --no-whole-archive ${LDADD} \
    241 	    ${SHLIB_LDENDFILE}
    242 .if ${OBJECT_FMT} == "ELF"
    243 	rm -f lib${LIB}.so.${SHLIB_MAJOR}
    244 	ln -s lib${LIB}.so.${SHLIB_MAJOR}.${SHLIB_MINOR} \
    245 	    lib${LIB}.so.${SHLIB_MAJOR}
    246 	rm -f lib${LIB}.so
    247 	ln -s lib${LIB}.so.${SHLIB_MAJOR}.${SHLIB_MINOR} \
    248 	    lib${LIB}.so
    249 .endif
    250 
    251 LOBJS+=		${LSRCS:.c=.ln} ${SRCS:M*.c:.c=.ln}
    252 LLIBS?=		-lc
    253 llib-l${LIB}.ln: ${LOBJS}
    254 	@echo building llib-l${LIB}.ln
    255 	@rm -f llib-l${LIB}.ln
    256 	@${LINT} -C${LIB} ${.ALLSRC} ${LLIBS}
    257 
    258 cleanlib:
    259 	rm -f a.out [Ee]rrs mklog core *.core ${CLEANFILES}
    260 	rm -f lib${LIB}.a ${OBJS}
    261 	rm -f lib${LIB}_p.a ${POBJS}
    262 	rm -f lib${LIB}_pic.a lib${LIB}.so.* lib${LIB}.so ${SOBJS}
    263 	rm -f llib-l${LIB}.ln ${LOBJS}
    264 
    265 .if defined(SRCS)
    266 afterdepend: .depend
    267 	@(TMP=/tmp/_depend$$$$; \
    268 	    sed -e 's/^\([^\.]*\).o[ ]*:/\1.o \1.po \1.so \1.ln:/' \
    269 	      < .depend > $$TMP; \
    270 	    mv $$TMP .depend)
    271 .endif
    272 
    273 .if !target(libinstall)
    274 # Make sure it gets defined, in case MKPIC==no && MKLINKLIB==no
    275 libinstall::
    276 
    277 .if ${MKLINKLIB} != "no"
    278 libinstall:: ${DESTDIR}${LIBDIR}/lib${LIB}.a
    279 .if !defined(UPDATE)
    280 .PHONY: ${DESTDIR}${LIBDIR}/lib${LIB}.a
    281 .endif
    282 .if !defined(BUILD)
    283 ${DESTDIR}${LIBDIR}/lib${LIB}.a: .MADE
    284 .endif
    285 
    286 .PRECIOUS: ${DESTDIR}${LIBDIR}/lib${LIB}.a
    287 ${DESTDIR}${LIBDIR}/lib${LIB}.a: lib${LIB}.a __archiveinstall
    288 .endif
    289 
    290 .if ${MKPROFILE} != "no"
    291 libinstall:: ${DESTDIR}${LIBDIR}/lib${LIB}_p.a
    292 .if !defined(UPDATE)
    293 .PHONY: ${DESTDIR}${LIBDIR}/lib${LIB}_p.a
    294 .endif
    295 .if !defined(BUILD)
    296 ${DESTDIR}${LIBDIR}/lib${LIB}_p.a: .MADE
    297 .endif
    298 
    299 .PRECIOUS: ${DESTDIR}${LIBDIR}/lib${LIB}_p.a
    300 ${DESTDIR}${LIBDIR}/lib${LIB}_p.a: lib${LIB}_p.a __archiveinstall
    301 .endif
    302 
    303 .if ${MKPIC} != "no" && ${MKPICINSTALL} != "no"
    304 libinstall:: ${DESTDIR}${LIBDIR}/lib${LIB}_pic.a
    305 .if !defined(UPDATE)
    306 .PHONY: ${DESTDIR}${LIBDIR}/lib${LIB}_pic.a
    307 .endif
    308 .if !defined(BUILD)
    309 ${DESTDIR}${LIBDIR}/lib${LIB}_pic.a: .MADE
    310 .endif
    311 
    312 .PRECIOUS: ${DESTDIR}${LIBDIR}/lib${LIB}_pic.a
    313 ${DESTDIR}${LIBDIR}/lib${LIB}_pic.a: lib${LIB}_pic.a __archiveinstall
    314 .endif
    315 
    316 .if ${MKPIC} != "no" && defined(SHLIB_MAJOR) && defined(SHLIB_MINOR)
    317 libinstall:: ${DESTDIR}${LIBDIR}/lib${LIB}.so.${SHLIB_MAJOR}.${SHLIB_MINOR}
    318 .if !defined(UPDATE)
    319 .PHONY: ${DESTDIR}${LIBDIR}/lib${LIB}.so.${SHLIB_MAJOR}.${SHLIB_MINOR}
    320 .endif
    321 .if !defined(BUILD)
    322 ${DESTDIR}${LIBDIR}/lib${LIB}.so.${SHLIB_MAJOR}.${SHLIB_MINOR}: .MADE
    323 .endif
    324 
    325 .PRECIOUS: ${DESTDIR}${LIBDIR}/lib${LIB}.so.${SHLIB_MAJOR}.${SHLIB_MINOR}
    326 ${DESTDIR}${LIBDIR}/lib${LIB}.so.${SHLIB_MAJOR}.${SHLIB_MINOR}: lib${LIB}.so.${SHLIB_MAJOR}.${SHLIB_MINOR}
    327 	${INSTALL} ${RENAME} ${PRESERVE} ${COPY} -o ${LIBOWN} -g ${LIBGRP} \
    328 		-m ${LIBMODE} ${.ALLSRC} ${.TARGET}
    329 .if ${OBJECT_FMT} == "a.out" && !defined(DESTDIR)
    330 	/sbin/ldconfig -m ${LIBDIR}
    331 .endif
    332 .if ${OBJECT_FMT} == "ELF"
    333 	rm -f ${DESTDIR}${LIBDIR}/lib${LIB}.so.${SHLIB_MAJOR}
    334 	ln -s lib${LIB}.so.${SHLIB_MAJOR}.${SHLIB_MINOR} \
    335 	    ${DESTDIR}${LIBDIR}/lib${LIB}.so.${SHLIB_MAJOR}
    336 	rm -f ${DESTDIR}${LIBDIR}/lib${LIB}.so
    337 .if ${MKLINKLIB} != "no"
    338 	ln -s lib${LIB}.so.${SHLIB_MAJOR}.${SHLIB_MINOR} \
    339 	    ${DESTDIR}${LIBDIR}/lib${LIB}.so
    340 .endif
    341 .endif
    342 .endif
    343 
    344 .if ${MKLINT} != "no" && ${MKLINKLIB} != "no"
    345 libinstall:: ${DESTDIR}${LINTLIBDIR}/llib-l${LIB}.ln
    346 .if !defined(UPDATE)
    347 .PHONY: ${DESTDIR}${LINTLIBDIR}/llib-l${LIB}.ln
    348 .endif
    349 .if !defined(BUILD)
    350 ${DESTDIR}${LINTLIBDIR}/llib-l${LIB}.ln: .MADE
    351 .endif
    352 
    353 .PRECIOUS: ${DESTDIR}${LINTLIBDIR}/llib-l${LIB}.ln
    354 ${DESTDIR}${LINTLIBDIR}/llib-l${LIB}.ln: llib-l${LIB}.ln
    355 	${INSTALL} ${RENAME} ${PRESERVE} ${COPY} -o ${LIBOWN} -g ${LIBGRP} \
    356 		-m ${LIBMODE} ${.ALLSRC} ${DESTDIR}${LINTLIBDIR}
    357 .endif
    358 .endif
    359 
    360 .include <bsd.man.mk>
    361 .include <bsd.nls.mk>
    362 .include <bsd.files.mk>
    363 .include <bsd.inc.mk>
    364 .include <bsd.links.mk>
    365 .include <bsd.dep.mk>
    366 .include <bsd.sys.mk>
    367 
    368 # Make sure all of the standard targets are defined, even if they do nothing.
    369 lint regress:
    370