Home | History | Annotate | Line # | Download | only in mk
bsd.lib.mk revision 1.101
      1 #	$NetBSD: bsd.lib.mk,v 1.101 1997/05/09 06:19:55 mycroft 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 install:	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 .c .cc .C .F .f .r .y .l .s .S .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 # CPICFLAGS:	flags to compile .c files for .so objects.
     38 # APICFLAGS:	flags to assemble .S files for .so objects.
     39 
     40 .if (${MACHINE_ARCH} == "alpha")
     41 
     42 SHLIB_TYPE=ELF
     43 SHLIB_LDSTARTFILE= ${DESTDIR}/usr/lib/crtbeginS.o
     44 SHLIB_LDENDFILE= ${DESTDIR}/usr/lib/crtendS.o
     45 SHLIB_SOVERSION=${SHLIB_MAJOR}
     46 CPICFLAGS ?= -fpic -DPIC
     47 APICFLAGS ?= -DPIC
     48 
     49 .elif (${MACHINE_ARCH} == "mips")
     50 
     51 SHLIB_TYPE=ELF
     52 # still use gnu-derived ld.so on pmax; don't have or need lib<>.so support.
     53 SHLIB_LDSTARTFILE=
     54 SHLIB_LDENDFILE=
     55 SHLIB_SOVERSION=${SHLIB_MAJOR}
     56 
     57 # On mips, all libs need to be compiled with ABIcalls, not just sharedlibs.
     58 CPICFLAGS?=
     59 APICFLAGS?=
     60 #CPICFLAGS?= -fpic -DPIC
     61 #APICFLAGS?= -DPIC
     62 
     63 # so turn shlib PIC flags on for ${CPP}, ${CC}, and ${AS} as follows:
     64 AINC+=-DPIC -DABICALLS
     65 COPTS+=	-fPIC ${AINC}
     66 AFLAGS+= -fPIC
     67 AS+=	-KPIC
     68 
     69 .else
     70 
     71 SHLIB_TYPE=a.out
     72 SHLIB_LDSTARTFILE=
     73 SHLIB_LDENDFILE=
     74 SHLIB_SOVERSION=${SHLIB_MAJOR}.${SHLIB_MINOR}
     75 CPICFLAGS?= -fpic -DPIC
     76 APICFLAGS?= -fpic -DPIC
     77 
     78 .endif
     79 
     80 
     81 CFLAGS+=	${COPTS}
     82 
     83 .c.o:
     84 	@echo ${COMPILE.c:Q} ${.IMPSRC}
     85 	@${COMPILE.c} ${.IMPSRC}  -o ${.TARGET}.o
     86 	@${LD} -x -r ${.TARGET}.o -o ${.TARGET}
     87 	@rm -f ${.TARGET}.o
     88 
     89 .c.po:
     90 	@echo ${COMPILE.c:Q} -pg ${.IMPSRC} -o ${.TARGET}
     91 	@${COMPILE.c} -pg ${.IMPSRC} -o ${.TARGET}.o
     92 	@${LD} -X -r ${.TARGET}.o -o ${.TARGET}
     93 	@rm -f ${.TARGET}.o
     94 
     95 .c.so:
     96 	@echo ${COMPILE.c:Q} ${CPICFLAGS} ${.IMPSRC} -o ${.TARGET}
     97 	@${COMPILE.c} ${CPICFLAGS} ${.IMPSRC} -o ${.TARGET}.o
     98 	@${LD} -x -r ${.TARGET}.o -o ${.TARGET}
     99 	@rm -f ${.TARGET}.o
    100 
    101 .c.ln:
    102 	${LINT} ${LINTFLAGS} ${CFLAGS:M-[IDU]*} -i ${.IMPSRC}
    103 
    104 .cc.o .C.o:
    105 	@echo ${COMPILE.cc:Q} ${.IMPSRC}
    106 	@${COMPILE.cc} ${.IMPSRC} -o ${.TARGET}.o
    107 	@${LD} -x -r ${.TARGET}.o -o ${.TARGET}
    108 	@rm -f ${.TARGET}.o
    109 
    110 .cc.po .C.po:
    111 	@echo ${COMPILE.cc:Q} -pg ${.IMPSRC} -o ${.TARGET}
    112 	@${COMPILE.cc} -pg ${.IMPSRC} -o ${.TARGET}.o
    113 	@${LD} -X -r ${.TARGET}.o -o ${.TARGET}
    114 	@rm -f ${.TARGET}.o
    115 
    116 .cc.so .C.so:
    117 	@echo ${COMPILE.cc:Q} ${CPICFLAGS} ${.IMPSRC} -o ${.TARGET}
    118 	@${COMPILE.cc} ${CPICFLAGS} ${.IMPSRC} -o ${.TARGET}.o
    119 	@${LD} -x -r ${.TARGET}.o -o ${.TARGET}
    120 	@rm -f ${.TARGET}.o
    121 
    122 .S.o .s.o:
    123 	@echo ${COMPILE.S:Q} ${CFLAGS:M-[ID]*} ${AINC} ${.IMPSRC}
    124 	@${COMPILE.S} ${CFLAGS:M-[ID]*} ${AINC} ${.IMPSRC} -o ${.TARGET}.o
    125 	@${LD} -x -r ${.TARGET}.o -o ${.TARGET}
    126 	@rm -f ${.TARGET}.o
    127 
    128 .S.po .s.po:
    129 	@echo ${COMPILE.S:Q} -DGPROF -DPROF ${CFLAGS:M-[ID]*} ${AINC} ${.IMPSRC} -o ${.TARGET}
    130 	@${COMPILE.S} -DGPROF -DPROF ${CFLAGS:M-[ID]*} ${AINC} ${.IMPSRC} -o ${.TARGET}.o
    131 	@${LD} -X -r ${.TARGET}.o -o ${.TARGET}
    132 	@rm -f ${.TARGET}.o
    133 
    134 .S.so .s.so:
    135 	@echo ${COMPILE.S:Q} ${APICFLAGS} ${CFLAGS:M-[ID]*} ${AINC} ${.IMPSRC} -o ${.TARGET}
    136 	@${COMPILE.S} ${APICFLAGS} ${CFLAGS:M-[ID]*} ${AINC} ${.IMPSRC} -o ${.TARGET}.o
    137 	@${LD} -x -r ${.TARGET}.o -o ${.TARGET}
    138 	@rm -f ${.TARGET}.o
    139 
    140 
    141 .if !defined(NOPROFILE)
    142 _LIBS=lib${LIB}.a lib${LIB}_p.a
    143 .else
    144 _LIBS=lib${LIB}.a
    145 .endif
    146 
    147 .if !defined(NOPIC)
    148 _LIBS+=lib${LIB}_pic.a
    149 .if defined(SHLIB_MAJOR) && defined(SHLIB_MINOR)
    150 _LIBS+=lib${LIB}.so.${SHLIB_MAJOR}.${SHLIB_MINOR}
    151 .endif
    152 .endif
    153 
    154 .if !defined(NOLINT)
    155 _LIBS+=llib-l${LIB}.ln
    156 .endif
    157 
    158 all depend: ${SRCS}
    159 all: ${_LIBS}
    160 
    161 OBJS+=	${SRCS:N*.h:R:S/$/.o/g}
    162 
    163 __archivebuild: .USE
    164 	@rm -f ${.TARGET}
    165 	@${AR} cq ${.TARGET} `NM=${NM} lorder ${.ALLSRC} | tsort -q`
    166 	${RANLIB} ${.TARGET}
    167 
    168 __archiveinstall: .USE
    169 	${INSTALL} ${COPY} -o ${LIBOWN} -g ${LIBGRP} -m 600 ${.ALLSRC} \
    170 		${.TARGET}
    171 	${RANLIB} -t ${.TARGET}
    172 	chmod ${LIBMODE} ${.TARGET}
    173 
    174 lib${LIB}.a:: ${OBJS} __archivebuild
    175 	@echo building standard ${LIB} library
    176 
    177 POBJS+=	${OBJS:.o=.po}
    178 lib${LIB}_p.a:: ${POBJS} __archivebuild
    179 	@echo building profiled ${LIB} library
    180 
    181 SOBJS+=	${OBJS:.o=.so}
    182 lib${LIB}_pic.a:: ${SOBJS} __archivebuild
    183 	@echo building shared object ${LIB} library
    184 
    185 lib${LIB}.so.${SHLIB_MAJOR}.${SHLIB_MINOR}: lib${LIB}_pic.a ${DPADD} \
    186     ${SHLIB_LDSTARTFILE} ${SHLIB_LDENDFILE}
    187 	@echo building shared ${LIB} library \(version ${SHLIB_MAJOR}.${SHLIB_MINOR}\)
    188 	@rm -f lib${LIB}.so.${SHLIB_MAJOR}.${SHLIB_MINOR}
    189 .if (${SHLIB_TYPE} == "a.out")
    190 	$(LD) -x -Bshareable -Bforcearchive \
    191 	    -o ${.TARGET} lib${LIB}_pic.a ${LDADD}
    192 .elif (${SHLIB_TYPE} == "ELF")
    193 	$(LD) -x -shared -o ${.TARGET} \
    194 	    -soname lib${LIB}.so.${SHLIB_SOVERSION}  ${SHLIB_LDSTARTFILE} \
    195 	    --whole-archive lib${LIB}_pic.a --no-whole-archive ${LDADD} \
    196 	    ${SHLIB_LDENDFILE}
    197 .endif
    198 
    199 LOBJS+=	${LSRCS:.c=.ln} ${SRCS:M*.c:.c=.ln}
    200 LLIBS?=	-lc
    201 llib-l${LIB}.ln: ${LOBJS}
    202 	@echo building llib-l${LIB}.ln
    203 	@rm -f llib-l${LIB}.ln
    204 	@${LINT} -C${LIB} ${LOBJS} ${LLIBS}
    205 
    206 cleanlib:
    207 	rm -f a.out [Ee]rrs mklog core *.core ${CLEANFILES}
    208 	rm -f lib${LIB}.a ${OBJS}
    209 	rm -f lib${LIB}_p.a ${POBJS}
    210 	rm -f lib${LIB}_pic.a lib${LIB}.so.*.* ${SOBJS}
    211 	rm -f llib-l${LIB}.ln ${LOBJS}
    212 
    213 .if defined(SRCS)
    214 afterdepend: .depend
    215 	@(TMP=/tmp/_depend$$$$; \
    216 	    sed -e 's/^\([^\.]*\).o[ ]*:/\1.o \1.po \1.so \1.ln:/' \
    217 	      < .depend > $$TMP; \
    218 	    mv $$TMP .depend)
    219 .endif
    220 
    221 .if !target(libinstall)
    222 libinstall:: ${DESTDIR}${LIBDIR}/lib${LIB}.a
    223 .if !defined(UPDATE)
    224 .PHONY: ${DESTDIR}${LIBDIR}/lib${LIB}.a
    225 .endif
    226 .if !defined(BUILD)
    227 ${DESTDIR}${LIBDIR}/lib${LIB}.a: .MADE
    228 .endif
    229 
    230 .PRECIOUS: ${DESTDIR}${LIBDIR}/lib${LIB}.a
    231 ${DESTDIR}${LIBDIR}/lib${LIB}.a: lib${LIB}.a __archiveinstall
    232 
    233 .if !defined(NOPROFILE)
    234 libinstall:: ${DESTDIR}${LIBDIR}/lib${LIB}_p.a
    235 .if !defined(UPDATE)
    236 .PHONY: ${DESTDIR}${LIBDIR}/lib${LIB}_p.a
    237 .endif
    238 .if !defined(BUILD)
    239 ${DESTDIR}${LIBDIR}/lib${LIB}_p.a: .MADE
    240 .endif
    241 
    242 .PRECIOUS: ${DESTDIR}${LIBDIR}/lib${LIB}_p.a
    243 ${DESTDIR}${LIBDIR}/lib${LIB}_p.a: lib${LIB}_p.a __archiveinstall
    244 .endif
    245 
    246 .if !defined(NOPIC)
    247 libinstall:: ${DESTDIR}${LIBDIR}/lib${LIB}_pic.a
    248 .if !defined(UPDATE)
    249 .PHONY: ${DESTDIR}${LIBDIR}/lib${LIB}_pic.a
    250 .endif
    251 .if !defined(BUILD)
    252 ${DESTDIR}${LIBDIR}/lib${LIB}_pic.a: .MADE
    253 .endif
    254 
    255 .PRECIOUS: ${DESTDIR}${LIBDIR}/lib${LIB}_pic.a
    256 ${DESTDIR}${LIBDIR}/lib${LIB}_pic.a: lib${LIB}_pic.a __archiveinstall
    257 .endif
    258 
    259 .if !defined(NOPIC) && defined(SHLIB_MAJOR) && defined(SHLIB_MINOR)
    260 libinstall:: ${DESTDIR}${LIBDIR}/lib${LIB}.so.${SHLIB_MAJOR}.${SHLIB_MINOR}
    261 .if !defined(UPDATE)
    262 .PHONY: ${DESTDIR}${LIBDIR}/lib${LIB}.so.${SHLIB_MAJOR}.${SHLIB_MINOR}
    263 .endif
    264 .if !defined(BUILD)
    265 ${DESTDIR}${LIBDIR}/lib${LIB}.so.${SHLIB_MAJOR}.${SHLIB_MINOR}: .MADE
    266 .endif
    267 
    268 .PRECIOUS: ${DESTDIR}${LIBDIR}/lib${LIB}.so.${SHLIB_MAJOR}.${SHLIB_MINOR}
    269 ${DESTDIR}${LIBDIR}/lib${LIB}.so.${SHLIB_MAJOR}.${SHLIB_MINOR}: lib${LIB}.so.${SHLIB_MAJOR}.${SHLIB_MINOR}
    270 	${INSTALL} ${COPY} -o ${LIBOWN} -g ${LIBGRP} -m ${LIBMODE} ${.ALLSRC} \
    271 		${.TARGET}
    272 .if (${SHLIB_TYPE} == "ELF")
    273 	rm -f ${DESTDIR}${LIBDIR}/lib${LIB}.so.${SHLIB_MAJOR}
    274 	ln -s lib${LIB}.so.${SHLIB_MAJOR}.${SHLIB_MINOR} \
    275 	    ${DESTDIR}${LIBDIR}/lib${LIB}.so.${SHLIB_MAJOR}
    276 	rm -f ${DESTDIR}${LIBDIR}/lib${LIB}.so
    277 	ln -s lib${LIB}.so.${SHLIB_MAJOR}.${SHLIB_MINOR} \
    278 	    ${DESTDIR}${LIBDIR}/lib${LIB}.so
    279 .endif
    280 .endif
    281 
    282 .if !defined(NOLINT)
    283 libinstall:: ${DESTDIR}${LINTLIBDIR}/llib-l${LIB}.ln
    284 .if !defined(UPDATE)
    285 .PHONY: ${DESTDIR}${LINTLIBDIR}/llib-l${LIB}.ln
    286 .endif
    287 .if !defined(BUILD)
    288 ${DESTDIR}${LINTLIBDIR}/llib-l${LIB}.ln: .MADE
    289 .endif
    290 
    291 .PRECIOUS: ${DESTDIR}${LINTLIBDIR}/llib-l${LIB}.ln
    292 ${DESTDIR}${LINTLIBDIR}/llib-l${LIB}.ln: llib-l${LIB}.ln
    293 	${INSTALL} ${COPY} -o ${LIBOWN} -g ${LIBGRP} -m ${LIBMODE} \
    294 	    llib-l${LIB}.ln ${DESTDIR}${LINTLIBDIR}
    295 .endif
    296 .endif
    297 
    298 .if !defined(NOMAN)
    299 .include <bsd.man.mk>
    300 .endif
    301 
    302 .if !defined(NONLS)
    303 .include <bsd.nls.mk>
    304 .endif
    305 
    306 .include <bsd.obj.mk>
    307 .include <bsd.links.mk>
    308 .include <bsd.files.mk>
    309 .include <bsd.inc.mk>
    310 .include <bsd.dep.mk>
    311 .include <bsd.subdir.mk>
    312 .include <bsd.sys.mk>
    313