Home | History | Annotate | Line # | Download | only in mk
bsd.lib.mk revision 1.109
      1 #	$NetBSD: bsd.lib.mk,v 1.109 1997/05/27 17:45:57 cjs Exp $
      2 #	@(#)bsd.lib.mk	8.3 (Berkeley) 4/22/94
      3 
      4 .if exists(${.CURDIR}/../Makefile.inc)
      5 .include "${.CURDIR}/../Makefile.inc"
      6 .endif
      7 
      8 .include <bsd.own.mk>
      9 
     10 .MAIN:		all
     11 .PHONY:		cleanlib libinstall
     12 realinstall:	libinstall
     13 clean cleandir:	cleanlib
     14 
     15 .if exists(${.CURDIR}/shlib_version)
     16 SHLIB_MAJOR != . ${.CURDIR}/shlib_version ; echo $$major
     17 SHLIB_MINOR != . ${.CURDIR}/shlib_version ; echo $$minor
     18 .endif
     19 
     20 # add additional suffixes not exported.
     21 # .po is used for profiling object files.
     22 # .so is used for PIC object files.
     23 .SUFFIXES: .out .a .ln .so .po .o .s .S .c .cc .C .F .f .r .y .l .cl .p .h .sh .m4
     24 
     25 
     26 # Set PICFLAGS to cc flags for producing position-independent code,
     27 # if not already set.  Includes -DPIC, if required.
     28 
     29 # Data-driven table using make variables to control  how shared libraries
     30 # are built for different platforms and object formats.
     31 # SHLIB_TYPE:		currently either "ELF" or "a.out".
     32 # SHLIB_SOVERSION:  	version number to be compiled into a shared library
     33 #                    	via -soname. Usualy ${SHLIB_MAJOR} on ELF.
     34 #   			NetBSD/pmax used to use ${SHLIB_MAJOR}.{SHLIB-MINOR}.
     35 # SHLIB_LDSTARTFILE:	???
     36 # SHLIB_LDENDTILE:	??
     37 # CPPICFLAGS:	flags for ${CPP} to preprocess  .[sS]  files for ${AS}
     38 # CPICFLAGS:	flags for ${CC} to compile  .[cC] files to .so objects.
     39 # CAPICFLAGS	flags for {$CC} to compiling .[Ss] files
     40 #		 	(usually just ${CPPPICFLAGS} ${CPICFLAGS})
     41 # APICFLAGS:	flags for ${AS} to assemble .[sS]  to .so objects.
     42 
     43 .if (${MACHINE_ARCH} == "alpha")
     44 
     45 SHLIB_TYPE=ELF
     46 SHLIB_LDSTARTFILE= ${BUILDDIR}${LIBDIR}/crtbeginS.o
     47 SHLIB_LDENDFILE= ${BUILDDIR}${LIBDIR}/crtendS.o
     48 SHLIB_SOVERSION=${SHLIB_MAJOR}
     49 CPICFLAGS ?= -fpic -DPIC
     50 CPPPICFLAGS?= -DPIC 
     51 CAPICFLAGS?= ${CPPPICFLAGS} ${CPICFLAGS}
     52 APICFLAGS ?=
     53 
     54 .elif (${MACHINE_ARCH} == "mips")
     55 
     56 SHLIB_TYPE=ELF
     57 # still use gnu-derived ld.so on pmax; don't have or need lib<>.so support.
     58 SHLIB_LDSTARTFILE=
     59 SHLIB_LDENDFILE=
     60 SHLIB_SOVERSION=${SHLIB_MAJOR}
     61 
     62 # On mips, all libs need to be compiled with ABIcalls, not just sharedlibs.
     63 CPICFLAGS?=
     64 APICFLAGS?=
     65 #CPICFLAGS?= -fpic -DPIC
     66 #APICFLAGS?= -DPIC
     67 
     68 # so turn shlib PIC flags on for ${CPP}, ${CC}, and ${AS} as follows:
     69 AINC+=-DPIC -DABICALLS
     70 COPTS+=	-fPIC ${AINC}
     71 AFLAGS+= -fPIC
     72 AS+=	-KPIC
     73 
     74 .else
     75 
     76 SHLIB_TYPE=a.out
     77 SHLIB_LDSTARTFILE=
     78 SHLIB_LDENDFILE=
     79 SHLIB_SOVERSION=${SHLIB_MAJOR}.${SHLIB_MINOR}
     80 CPICFLAGS?= -fpic
     81 CPPPICFLAGS?= -DPIC 
     82 CAPICFLAGS?= ${CPPPICFLAGS} ${CPICFLAGS}
     83 APICFLAGS?= -k
     84 
     85 .endif
     86 
     87 
     88 CFLAGS+=	${COPTS}
     89 
     90 .c.o:
     91 	@echo ${COMPILE.c:Q} ${.IMPSRC}
     92 	@${COMPILE.c} ${.IMPSRC}  -o ${.TARGET}.o
     93 	@${LD} -x -r ${.TARGET}.o -o ${.TARGET}
     94 	@rm -f ${.TARGET}.o
     95 
     96 .c.po:
     97 	@echo ${COMPILE.c:Q} -pg ${.IMPSRC} -o ${.TARGET}
     98 	@${COMPILE.c} -pg ${.IMPSRC} -o ${.TARGET}.o
     99 	@${LD} -X -r ${.TARGET}.o -o ${.TARGET}
    100 	@rm -f ${.TARGET}.o
    101 
    102 .c.so:
    103 	@echo ${COMPILE.c:Q} ${CPICFLAGS} ${.IMPSRC} -o ${.TARGET}
    104 	@${COMPILE.c} ${CPICFLAGS} ${.IMPSRC} -o ${.TARGET}.o
    105 	@${LD} -x -r ${.TARGET}.o -o ${.TARGET}
    106 	@rm -f ${.TARGET}.o
    107 
    108 .c.ln:
    109 	${LINT} ${LINTFLAGS} ${CFLAGS:M-[IDU]*} -i ${.IMPSRC}
    110 
    111 .cc.o .C.o:
    112 	@echo ${COMPILE.cc:Q} ${.IMPSRC}
    113 	@${COMPILE.cc} ${.IMPSRC} -o ${.TARGET}.o
    114 	@${LD} -x -r ${.TARGET}.o -o ${.TARGET}
    115 	@rm -f ${.TARGET}.o
    116 
    117 .cc.po .C.po:
    118 	@echo ${COMPILE.cc:Q} -pg ${.IMPSRC} -o ${.TARGET}
    119 	@${COMPILE.cc} -pg ${.IMPSRC} -o ${.TARGET}.o
    120 	@${LD} -X -r ${.TARGET}.o -o ${.TARGET}
    121 	@rm -f ${.TARGET}.o
    122 
    123 .cc.so .C.so:
    124 	@echo ${COMPILE.cc:Q} ${CPICFLAGS} ${.IMPSRC} -o ${.TARGET}
    125 	@${COMPILE.cc} ${CPICFLAGS} ${.IMPSRC} -o ${.TARGET}.o
    126 	@${LD} -x -r ${.TARGET}.o -o ${.TARGET}
    127 	@rm -f ${.TARGET}.o
    128 
    129 .S.o .s.o:
    130 	@echo ${COMPILE.S:Q} ${CFLAGS:M-[ID]*} ${AINC} ${.IMPSRC}
    131 	@${COMPILE.S} ${CFLAGS:M-[ID]*} ${AINC} ${.IMPSRC} -o ${.TARGET}.o
    132 	@${LD} -x -r ${.TARGET}.o -o ${.TARGET}
    133 	@rm -f ${.TARGET}.o
    134 
    135 .S.po .s.po:
    136 	@echo ${COMPILE.S:Q} -DGPROF -DPROF ${CFLAGS:M-[ID]*} ${AINC} ${.IMPSRC} -o ${.TARGET}
    137 	@${COMPILE.S} -DGPROF -DPROF ${CFLAGS:M-[ID]*} ${AINC} ${.IMPSRC} -o ${.TARGET}.o
    138 	@${LD} -X -r ${.TARGET}.o -o ${.TARGET}
    139 	@rm -f ${.TARGET}.o
    140 
    141 .S.so .s.so:
    142 	@echo ${COMPILE.S:Q} ${CAPICFLAGS} ${CFLAGS:M-[ID]*} ${AINC} ${.IMPSRC} -o ${.TARGET}
    143 	@${COMPILE.S} ${CAPICFLAGS} ${CFLAGS:M-[ID]*} ${AINC} ${.IMPSRC} -o ${.TARGET}.o
    144 	@${LD} -x -r ${.TARGET}.o -o ${.TARGET}
    145 	@rm -f ${.TARGET}.o
    146 
    147 
    148 .if !defined(NOPROFILE)
    149 _LIBS=lib${LIB}.a lib${LIB}_p.a
    150 .else
    151 _LIBS=lib${LIB}.a
    152 .endif
    153 
    154 .if !defined(NOPIC)
    155 _LIBS+=lib${LIB}_pic.a
    156 .if defined(SHLIB_MAJOR) && defined(SHLIB_MINOR)
    157 _LIBS+=lib${LIB}.so.${SHLIB_MAJOR}.${SHLIB_MINOR}
    158 .endif
    159 .endif
    160 
    161 .if !defined(NOLINT)
    162 _LIBS+=llib-l${LIB}.ln
    163 .endif
    164 
    165 all: ${SRCS} ${_LIBS}
    166 
    167 __archivebuild: .USE
    168 	@rm -f ${.TARGET}
    169 	@${AR} cq ${.TARGET} `NM=${NM} lorder ${.ALLSRC} | tsort -q`
    170 	${RANLIB} ${.TARGET}
    171 
    172 __archiveinstall: .USE
    173 	${INSTALL} ${COPY} -o ${LIBOWN} -g ${LIBGRP} -m 600 ${.ALLSRC} \
    174 		${.TARGET}
    175 	${RANLIB} -t ${.TARGET}
    176 	chmod ${LIBMODE} ${.TARGET}
    177 
    178 DPSRCS+=	${SRCS:M*.l:.l=.c} ${SRCS:M*.y:.y=.c}
    179 CLEANFILES+=	${DPSRCS}
    180 
    181 OBJS+=		${SRCS:N*.h:N*.sh:R:S/$/.o/g}
    182 lib${LIB}.a:: ${OBJS} __archivebuild
    183 	@echo building standard ${LIB} library
    184 .if defined(OBJDIR)
    185 	@echo install -d ${BUILDDIR}${LIBDIR}
    186 	@install -d ${BUILDDIR}${LIBDIR}
    187 	@echo ${BUILDDIR}${LIBDIR}/${.TARGET} '->' `pwd`/${.TARGET};
    188 	@rm -f ${BUILDDIR}${LIBDIR}/${.TARGET};
    189 	@ln -s `pwd`/${.TARGET} ${BUILDDIR}${LIBDIR}/${.TARGET};
    190 .endif
    191 
    192 POBJS+=		${OBJS:.o=.po}
    193 lib${LIB}_p.a:: ${POBJS} __archivebuild
    194 	@echo building profiled ${LIB} library
    195 .if defined(OBJDIR)
    196 	@echo install -d ${BUILDDIR}${LIBDIR}
    197 	@install -d ${BUILDDIR}${LIBDIR}
    198 	@echo ${BUILDDIR}${LIBDIR}/${.TARGET} '->' `pwd`/${.TARGET};
    199 	@rm -f ${BUILDDIR}${LIBDIR}/${.TARGET};
    200 	@ln -s `pwd`/${.TARGET} ${BUILDDIR}${LIBDIR}/${.TARGET};
    201 .endif
    202 
    203 SOBJS+=		${OBJS:.o=.so}
    204 lib${LIB}_pic.a:: ${SOBJS} __archivebuild
    205 	@echo building shared object ${LIB} library
    206 .if defined(OBJDIR)
    207 	@echo install -d ${BUILDDIR}${LIBDIR}
    208 	@install -d ${BUILDDIR}${LIBDIR}
    209 	@echo ${BUILDDIR}${LIBDIR}/${.TARGET} '->' `pwd`/${.TARGET};
    210 	@rm -f ${BUILDDIR}${LIBDIR}/${.TARGET};
    211 	@ln -s `pwd`/${.TARGET} ${BUILDDIR}${LIBDIR}/${.TARGET};
    212 .endif
    213 
    214 lib${LIB}.so.${SHLIB_MAJOR}.${SHLIB_MINOR}: lib${LIB}_pic.a ${DPADD} \
    215     ${SHLIB_LDSTARTFILE} ${SHLIB_LDENDFILE}
    216 	@echo building shared ${LIB} library \(version ${SHLIB_MAJOR}.${SHLIB_MINOR}\)
    217 	@rm -f lib${LIB}.so.${SHLIB_MAJOR}.${SHLIB_MINOR}
    218 .if (${SHLIB_TYPE} == "a.out")
    219 	$(LD) -x -Bshareable -Bforcearchive \
    220 	    -o ${.TARGET} lib${LIB}_pic.a ${LDADD}
    221 .elif (${SHLIB_TYPE} == "ELF")
    222 	$(LD) -x -shared -o ${.TARGET} \
    223 	    -soname lib${LIB}.so.${SHLIB_SOVERSION}  ${SHLIB_LDSTARTFILE} \
    224 	    --whole-archive lib${LIB}_pic.a --no-whole-archive ${LDADD} \
    225 	    ${SHLIB_LDENDFILE}
    226 .endif
    227 .if defined(OBJDIR)
    228 	@echo install -d ${BUILDDIR}${LIBDIR}
    229 	@install -d ${BUILDDIR}${LIBDIR}
    230 	@echo ${BUILDDIR}${LIBDIR}/${.TARGET} '->' `pwd`/${.TARGET};
    231 	@rm -f ${BUILDDIR}${LIBDIR}/${.TARGET};
    232 	@ln -s `pwd`/${.TARGET} ${BUILDDIR}${LIBDIR}/${.TARGET};
    233 .if (${SHLIB_TYPE} == "ELF")
    234 	rm -f ${BUILDDIR}${LIBDIR}/lib${LIB}.so.${SHLIB_MAJOR}
    235 	ln -s lib${LIB}.so.${SHLIB_MAJOR}.${SHLIB_MINOR} \
    236 	    ${BUILDDIR}${LIBDIR}/lib${LIB}.so.${SHLIB_MAJOR}
    237 	rm -f ${BUILDDIR}${LIBDIR}/lib${LIB}.so
    238 	ln -s lib${LIB}.so.${SHLIB_MAJOR}.${SHLIB_MINOR} \
    239 	    ${BUILDDIR}${LIBDIR}/lib${LIB}.so
    240 .endif	# SHLIB_TYPE == ELF
    241 .endif	# defined(OBJDIR)
    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.*.* ${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 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 
    277 .if !defined(NOPROFILE)
    278 libinstall:: ${DESTDIR}${LIBDIR}/lib${LIB}_p.a
    279 .if !defined(UPDATE)
    280 .PHONY: ${DESTDIR}${LIBDIR}/lib${LIB}_p.a
    281 .endif
    282 .if !defined(BUILD)
    283 ${DESTDIR}${LIBDIR}/lib${LIB}_p.a: .MADE
    284 .endif
    285 
    286 .PRECIOUS: ${DESTDIR}${LIBDIR}/lib${LIB}_p.a
    287 ${DESTDIR}${LIBDIR}/lib${LIB}_p.a: lib${LIB}_p.a __archiveinstall
    288 .endif
    289 
    290 .if !defined(NOPIC)
    291 libinstall:: ${DESTDIR}${LIBDIR}/lib${LIB}_pic.a
    292 .if !defined(UPDATE)
    293 .PHONY: ${DESTDIR}${LIBDIR}/lib${LIB}_pic.a
    294 .endif
    295 .if !defined(BUILD)
    296 ${DESTDIR}${LIBDIR}/lib${LIB}_pic.a: .MADE
    297 .endif
    298 
    299 .PRECIOUS: ${DESTDIR}${LIBDIR}/lib${LIB}_pic.a
    300 ${DESTDIR}${LIBDIR}/lib${LIB}_pic.a: lib${LIB}_pic.a __archiveinstall
    301 .endif
    302 
    303 .if !defined(NOPIC) && defined(SHLIB_MAJOR) && defined(SHLIB_MINOR)
    304 libinstall:: ${DESTDIR}${LIBDIR}/lib${LIB}.so.${SHLIB_MAJOR}.${SHLIB_MINOR}
    305 .if !defined(UPDATE)
    306 .PHONY: ${DESTDIR}${LIBDIR}/lib${LIB}.so.${SHLIB_MAJOR}.${SHLIB_MINOR}
    307 .endif
    308 .if !defined(BUILD)
    309 ${DESTDIR}${LIBDIR}/lib${LIB}.so.${SHLIB_MAJOR}.${SHLIB_MINOR}: .MADE
    310 .endif
    311 
    312 .PRECIOUS: ${DESTDIR}${LIBDIR}/lib${LIB}.so.${SHLIB_MAJOR}.${SHLIB_MINOR}
    313 ${DESTDIR}${LIBDIR}/lib${LIB}.so.${SHLIB_MAJOR}.${SHLIB_MINOR}: lib${LIB}.so.${SHLIB_MAJOR}.${SHLIB_MINOR}
    314 	${INSTALL} ${COPY} -o ${LIBOWN} -g ${LIBGRP} -m ${LIBMODE} ${.ALLSRC} \
    315 		${.TARGET}
    316 .if (${SHLIB_TYPE} == "ELF")
    317 	rm -f ${DESTDIR}${LIBDIR}/lib${LIB}.so.${SHLIB_MAJOR}
    318 	ln -s lib${LIB}.so.${SHLIB_MAJOR}.${SHLIB_MINOR} \
    319 	    ${DESTDIR}${LIBDIR}/lib${LIB}.so.${SHLIB_MAJOR}
    320 	rm -f ${DESTDIR}${LIBDIR}/lib${LIB}.so
    321 	ln -s lib${LIB}.so.${SHLIB_MAJOR}.${SHLIB_MINOR} \
    322 	    ${DESTDIR}${LIBDIR}/lib${LIB}.so
    323 .endif
    324 .endif
    325 
    326 .if !defined(NOLINT)
    327 libinstall:: ${DESTDIR}${LINTLIBDIR}/llib-l${LIB}.ln
    328 .if !defined(UPDATE)
    329 .PHONY: ${DESTDIR}${LINTLIBDIR}/llib-l${LIB}.ln
    330 .endif
    331 .if !defined(BUILD)
    332 ${DESTDIR}${LINTLIBDIR}/llib-l${LIB}.ln: .MADE
    333 .endif
    334 
    335 .PRECIOUS: ${DESTDIR}${LINTLIBDIR}/llib-l${LIB}.ln
    336 ${DESTDIR}${LINTLIBDIR}/llib-l${LIB}.ln: llib-l${LIB}.ln
    337 	${INSTALL} ${COPY} -o ${LIBOWN} -g ${LIBGRP} -m ${LIBMODE} \
    338 	    llib-l${LIB}.ln ${DESTDIR}${LINTLIBDIR}
    339 .endif
    340 .endif
    341 
    342 .if !defined(NOMAN)
    343 .include <bsd.man.mk>
    344 .endif
    345 
    346 .if !defined(NONLS)
    347 .include <bsd.nls.mk>
    348 .endif
    349 
    350 .include <bsd.obj.mk>
    351 .include <bsd.files.mk>
    352 .include <bsd.inc.mk>
    353 .include <bsd.links.mk>
    354 .include <bsd.dep.mk>
    355 .include <bsd.subdir.mk>
    356 .include <bsd.sys.mk>
    357