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