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