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