Home | History | Annotate | Line # | Download | only in mk
bsd.lib.mk revision 1.90
      1  1.90  christos #	$NetBSD: bsd.lib.mk,v 1.90 1997/03/24 23:19:12 christos Exp $
      2  1.50       cgd #	@(#)bsd.lib.mk	5.26 (Berkeley) 5/2/91
      3   1.1       cgd 
      4   1.1       cgd .if exists(${.CURDIR}/../Makefile.inc)
      5   1.1       cgd .include "${.CURDIR}/../Makefile.inc"
      6   1.1       cgd .endif
      7  1.54       cgd 
      8  1.54       cgd .include <bsd.own.mk>				# for 'NOPIC' definition
      9   1.1       cgd 
     10  1.35        pk .if exists(${.CURDIR}/shlib_version)
     11  1.37       cgd SHLIB_MAJOR != . ${.CURDIR}/shlib_version ; echo $$major
     12  1.37       cgd SHLIB_MINOR != . ${.CURDIR}/shlib_version ; echo $$minor
     13  1.35        pk .endif
     14  1.35        pk 
     15   1.1       cgd .MAIN: all
     16   1.1       cgd 
     17  1.58       cgd # prefer .S to a .c, add .po, remove stuff not used in the BSD libraries.
     18  1.58       cgd # .so used for PIC object files.  .ln used for lint output files.
     19   1.1       cgd .SUFFIXES:
     20  1.58       cgd .SUFFIXES: .out .o .po .so .S .s .c .cc .C .f .y .l .ln .m4
     21  1.82     mikel 
     22  1.86  jonathan 
     23  1.86  jonathan # Set PICFLAGS to cc flags for producing position-independent code,
     24  1.86  jonathan # if not already set.  Includes -DPIC, if required.
     25  1.86  jonathan 
     26  1.86  jonathan # Data-driven table using make variables to control  how shared libraries
     27  1.86  jonathan # are built for different platforms and object formats.
     28  1.86  jonathan # SHLIB_TYPE:		currently either "ELF" or "a.out".
     29  1.86  jonathan # SHLIB_SOVERSION:  	version number to be compiled into a shared library
     30  1.86  jonathan #                    	via -soname. Usualy ${SHLIB_MAJOR} on ELF.
     31  1.86  jonathan #   			NetBSD/pmax used to use ${SHLIB_MAJOR}.{SHLIB-MINOR}.
     32  1.86  jonathan # SHLIB_LDSTARTFILE:	???
     33  1.86  jonathan # SHLIB_LDENDTILE:	??
     34  1.86  jonathan # CPICFLAGS:	flags to compile .c files for .so objects.
     35  1.86  jonathan # APICFLAGS:	flags to assemble .S files for .so objects.
     36  1.86  jonathan 
     37  1.86  jonathan .if (${MACHINE_ARCH} == "alpha")
     38  1.86  jonathan 
     39  1.86  jonathan SHLIB_TYPE=ELF
     40  1.86  jonathan SHLIB_LDSTARTFILE= ${DESTDIR}/usr/lib/crtbeginS.o
     41  1.86  jonathan SHLIB_LDENDFILE= ${DESTDIR}/usr/lib/crtendS.o
     42  1.86  jonathan SHLIB_SOVERSION=${SHLIB_MAJOR}
     43  1.86  jonathan CPICFLAGS ?= -fpic -DPIC
     44  1.86  jonathan APICFLAGS ?= -DPIC
     45  1.86  jonathan 
     46  1.86  jonathan .elif (${MACHINE_ARCH} == "mips")
     47  1.86  jonathan 
     48  1.86  jonathan SHLIB_TYPE=ELF
     49  1.86  jonathan # still use gnu-derived ld.so on pmax; don't have or need lib<>.so support.
     50  1.86  jonathan SHLIB_LDSTARTFILE=
     51  1.86  jonathan SHLIB_LDENDFILE=
     52  1.86  jonathan SHLIB_SOVERSION=${SHLIB_MAJOR}
     53  1.86  jonathan 
     54  1.86  jonathan # On mips, all libs need to be compiled with ABIcalls, not just sharedlibs.
     55  1.86  jonathan CPICFLAGS?=
     56  1.86  jonathan APICFLAGS?=
     57  1.86  jonathan #CPICFLAGS?= -fpic -DPIC
     58  1.86  jonathan #APICFLAGS?= -DPIC
     59  1.86  jonathan 
     60  1.86  jonathan # so turn shlib PIC flags on for ${CPP}, ${CC}, and ${AS} as follows:
     61  1.86  jonathan AINC+=-DPIC -DABICALLS
     62  1.86  jonathan COPTS+=	-fPIC ${AINC}
     63  1.86  jonathan AFLAGS+= -fPIC
     64  1.86  jonathan AS+=	-KPIC
     65  1.86  jonathan 
     66  1.86  jonathan .else
     67  1.86  jonathan 
     68  1.86  jonathan SHLIB_TYPE=a.out
     69  1.88       cgd SHLIB_LDSTARTFILE=
     70  1.88       cgd SHLIB_LDENDFILE=
     71  1.86  jonathan SHLIB_SOVERSION=${SHLIB_MAJOR}.${SHLIB_MINOR}
     72  1.86  jonathan CPICFLAGS?= -fpic -DPIC
     73  1.86  jonathan APICFLAGS?= -fpic -DPIC
     74  1.86  jonathan 
     75  1.86  jonathan .endif
     76  1.86  jonathan 
     77  1.86  jonathan 
     78  1.82     mikel CFLAGS+=	${COPTS}
     79   1.1       cgd 
     80   1.1       cgd .c.o:
     81  1.80  christos 	@echo ${COMPILE.c:Q} ${.IMPSRC}
     82  1.62  christos 	@${COMPILE.c} ${.IMPSRC}  -o ${.TARGET}.o
     83  1.62  christos 	@${LD} -x -r ${.TARGET}.o -o ${.TARGET}
     84  1.62  christos 	@rm -f ${.TARGET}.o
     85   1.1       cgd 
     86   1.1       cgd .c.po:
     87  1.80  christos 	@echo ${COMPILE.c:Q} -pg ${.IMPSRC} -o ${.TARGET}
     88  1.68       cgd 	@${COMPILE.c} -pg ${.IMPSRC} -o ${.TARGET}.o
     89  1.62  christos 	@${LD} -X -r ${.TARGET}.o -o ${.TARGET}
     90  1.62  christos 	@rm -f ${.TARGET}.o
     91  1.17   mycroft 
     92  1.27        pk .c.so:
     93  1.86  jonathan 	@echo ${COMPILE.c:Q} ${CPICFLAGS} ${.IMPSRC} -o ${.TARGET}
     94  1.86  jonathan 	@${COMPILE.c} ${CPICFLAGS} ${.IMPSRC} -o ${.TARGET}.o
     95  1.62  christos 	@${LD} -x -r ${.TARGET}.o -o ${.TARGET}
     96  1.62  christos 	@rm -f ${.TARGET}.o
     97  1.27        pk 
     98  1.58       cgd .c.ln:
     99  1.58       cgd 	${LINT} ${LINTFLAGS} ${CFLAGS:M-[IDU]*} -i ${.IMPSRC}
    100  1.58       cgd 
    101  1.18   mycroft .cc.o .C.o:
    102  1.80  christos 	@echo ${COMPILE.cc:Q} ${.IMPSRC}
    103  1.62  christos 	@${COMPILE.cc} ${.IMPSRC} -o ${.TARGET}.o
    104  1.63       jtc 	@${LD} -x -r ${.TARGET}.o -o ${.TARGET}
    105  1.62  christos 	@rm -f ${.TARGET}.o
    106  1.17   mycroft 
    107  1.18   mycroft .cc.po .C.po:
    108  1.80  christos 	@echo ${COMPILE.cc:Q} -pg ${.IMPSRC} -o ${.TARGET}
    109  1.68       cgd 	@${COMPILE.cc} -pg ${.IMPSRC} -o ${.TARGET}.o
    110  1.62  christos 	@${LD} -X -r ${.TARGET}.o -o ${.TARGET}
    111  1.62  christos 	@rm -f ${.TARGET}.o
    112  1.28       cgd 
    113  1.28       cgd .cc.so .C.so:
    114  1.86  jonathan 	@echo ${COMPILE.cc:Q} ${CPICFLAGS} ${.IMPSRC} -o ${.TARGET}
    115  1.86  jonathan 	@${COMPILE.cc} ${CPICFLAGS} ${.IMPSRC} -o ${.TARGET}.o
    116  1.62  christos 	@${LD} -x -r ${.TARGET}.o -o ${.TARGET}
    117  1.62  christos 	@rm -f ${.TARGET}.o
    118   1.1       cgd 
    119  1.40       cgd .S.o .s.o:
    120  1.80  christos 	@echo ${COMPILE.S:Q} ${CFLAGS:M-[ID]*} ${AINC} ${.IMPSRC}
    121  1.69       jtc 	@${COMPILE.S} ${CFLAGS:M-[ID]*} ${AINC} ${.IMPSRC} -o ${.TARGET}.o
    122  1.62  christos 	@${LD} -x -r ${.TARGET}.o -o ${.TARGET}
    123  1.62  christos 	@rm -f ${.TARGET}.o
    124   1.1       cgd 
    125  1.40       cgd .S.po .s.po:
    126  1.80  christos 	@echo ${COMPILE.S:Q} -DGPROF -DPROF ${CFLAGS:M-[ID]*} ${AINC} ${.IMPSRC} -o ${.TARGET}
    127  1.75       jtc 	@${COMPILE.S} -DGPROF -DPROF ${CFLAGS:M-[ID]*} ${AINC} ${.IMPSRC} -o ${.TARGET}.o
    128  1.62  christos 	@${LD} -X -r ${.TARGET}.o -o ${.TARGET}
    129  1.62  christos 	@rm -f ${.TARGET}.o
    130   1.1       cgd 
    131  1.40       cgd .S.so .s.so:
    132  1.86  jonathan 	@echo ${COMPILE.S:Q} ${APICFLAGS} ${CFLAGS:M-[ID]*} ${AINC} ${.IMPSRC} -o ${.TARGET}
    133  1.86  jonathan 	@${COMPILE.S} ${APICFLAGS} ${CFLAGS:M-[ID]*} ${AINC} ${.IMPSRC} -o ${.TARGET}.o
    134  1.62  christos 	@${LD} -x -r ${.TARGET}.o -o ${.TARGET}
    135  1.62  christos 	@rm -f ${.TARGET}.o
    136  1.27        pk 
    137  1.58       cgd 
    138   1.1       cgd .if !defined(NOPROFILE)
    139   1.1       cgd _LIBS=lib${LIB}.a lib${LIB}_p.a
    140   1.1       cgd .else
    141   1.1       cgd _LIBS=lib${LIB}.a
    142   1.1       cgd .endif
    143   1.1       cgd 
    144  1.27        pk .if !defined(NOPIC)
    145  1.27        pk _LIBS+=lib${LIB}_pic.a
    146  1.37       cgd .if defined(SHLIB_MAJOR) && defined(SHLIB_MINOR)
    147  1.37       cgd _LIBS+=lib${LIB}.so.${SHLIB_MAJOR}.${SHLIB_MINOR}
    148  1.27        pk .endif
    149  1.35        pk .endif
    150  1.27        pk 
    151  1.58       cgd .if !defined(NOLINT)
    152  1.58       cgd _LIBS+=llib-l${LIB}.ln
    153  1.27        pk .endif
    154  1.27        pk 
    155  1.58       cgd all: ${_LIBS} _SUBDIRUSE
    156   1.1       cgd 
    157  1.21   mycroft OBJS+=	${SRCS:N*.h:R:S/$/.o/g}
    158   1.1       cgd 
    159  1.90  christos __archivebuild: .USE
    160  1.89  christos 	@rm -f ${.TARGET}
    161  1.89  christos 	@${AR} cq ${.TARGET} `lorder ${.ALLSRC} | tsort -q`
    162  1.89  christos 	${RANLIB} ${.TARGET}
    163  1.89  christos 
    164  1.89  christos __archiveinstall: .USE
    165  1.89  christos 	${INSTALL} ${COPY} -o ${LIBOWN} -g ${LIBGRP} -m 600 ${.ALLSRC} \
    166  1.89  christos 		${.TARGET}
    167  1.89  christos 	${RANLIB} -t ${.TARGET}
    168  1.89  christos 	chmod ${LIBMODE} ${.TARGET}
    169  1.89  christos 
    170  1.89  christos lib${LIB}.a:: ${OBJS} __archivebuild
    171   1.1       cgd 	@echo building standard ${LIB} library
    172   1.1       cgd 
    173   1.1       cgd POBJS+=	${OBJS:.o=.po}
    174  1.89  christos lib${LIB}_p.a:: ${POBJS} __archivebuild
    175   1.1       cgd 	@echo building profiled ${LIB} library
    176   1.1       cgd 
    177  1.27        pk SOBJS+=	${OBJS:.o=.so}
    178  1.89  christos lib${LIB}_pic.a:: ${SOBJS} __archivebuild
    179  1.27        pk 	@echo building shared object ${LIB} library
    180  1.27        pk 
    181  1.88       cgd lib${LIB}.so.${SHLIB_MAJOR}.${SHLIB_MINOR}: lib${LIB}_pic.a ${DPADD} \
    182  1.88       cgd     ${SHLIB_LDSTARTFILE} ${SHLIB_LDENDFILE}
    183  1.38       cgd 	@echo building shared ${LIB} library \(version ${SHLIB_MAJOR}.${SHLIB_MINOR}\)
    184  1.37       cgd 	@rm -f lib${LIB}.so.${SHLIB_MAJOR}.${SHLIB_MINOR}
    185  1.86  jonathan .if (${SHLIB_TYPE} == "a.out")
    186  1.53        pk 	$(LD) -x -Bshareable -Bforcearchive \
    187  1.89  christos 	    -o ${.TARGET} lib${LIB}_pic.a ${LDADD}
    188  1.86  jonathan .elif (${SHLIB_TYPE} == "ELF")
    189  1.89  christos 	$(LD) -x -shared -o ${.TARGET} \
    190  1.86  jonathan 	    -soname lib${LIB}.so.${SHLIB_SOVERSION}  ${SHLIB_LDSTARTFILE} \
    191  1.77       cgd 	    --whole-archive lib${LIB}_pic.a --no-whole-archive ${LDADD} \
    192  1.86  jonathan 	    ${SHLIB_LDENDFILE}
    193  1.72       cgd .endif
    194  1.35        pk 
    195  1.58       cgd LOBJS+=	${LSRCS:.c=.ln} ${SRCS:M*.c:.c=.ln}
    196  1.58       cgd LLIBS?=	-lc
    197  1.58       cgd llib-l${LIB}.ln: ${LOBJS}
    198  1.58       cgd 	@echo building llib-l${LIB}.ln
    199  1.58       cgd 	@rm -f llib-l${LIB}.ln
    200  1.58       cgd 	@${LINT} -C${LIB} ${LOBJS} ${LLIBS}
    201   1.1       cgd 
    202   1.1       cgd .if !target(clean)
    203  1.81       cgd cleanlib:
    204  1.48   mycroft 	rm -f a.out [Ee]rrs mklog core *.core ${CLEANFILES}
    205  1.59       cgd 	rm -f lib${LIB}.a ${OBJS}
    206  1.59       cgd 	rm -f lib${LIB}_p.a ${POBJS}
    207  1.61       cgd 	rm -f lib${LIB}_pic.a lib${LIB}.so.*.* ${SOBJS}
    208  1.59       cgd 	rm -f llib-l${LIB}.ln ${LOBJS}
    209   1.1       cgd 
    210  1.81       cgd clean: _SUBDIRUSE cleanlib
    211  1.81       cgd cleandir: _SUBDIRUSE cleanlib
    212  1.81       cgd .else
    213  1.49       cgd cleandir: _SUBDIRUSE clean
    214  1.81       cgd .endif
    215  1.25   mycroft 
    216  1.26   mycroft .if defined(SRCS)
    217  1.64  christos afterdepend: .depend
    218   1.1       cgd 	@(TMP=/tmp/_depend$$$$; \
    219  1.79       cgd 	    sed -e 's/^\([^\.]*\).o[ ]*:/\1.o \1.po \1.so \1.ln:/' \
    220  1.58       cgd 	      < .depend > $$TMP; \
    221   1.1       cgd 	    mv $$TMP .depend)
    222  1.26   mycroft .endif
    223   1.1       cgd 
    224   1.1       cgd .if !target(install)
    225   1.1       cgd .if !target(beforeinstall)
    226   1.1       cgd beforeinstall:
    227   1.1       cgd .endif
    228   1.1       cgd 
    229  1.89  christos libinstall:: ${DESTDIR}${LIBDIR}/lib${LIB}.a
    230  1.89  christos .if !defined(UPDATE)
    231  1.89  christos .PHONY: ${DESTDIR}${LIBDIR}/lib${LIB}.a
    232  1.89  christos .endif
    233  1.89  christos .if !defined(BUILD)
    234  1.89  christos ${DESTDIR}${LIBDIR}/lib${LIB}.a: .MADE
    235  1.89  christos .endif
    236  1.89  christos 
    237  1.89  christos ${DESTDIR}${LIBDIR}/lib${LIB}.a: lib${LIB}.a __archiveinstall
    238  1.89  christos 
    239  1.12       cgd .if !defined(NOPROFILE)
    240  1.89  christos libinstall:: ${DESTDIR}${LIBDIR}/lib${LIB}_p.a
    241  1.89  christos .if !defined(UPDATE)
    242  1.89  christos .PHONY: ${DESTDIR}${LIBDIR}/lib${LIB}_p.a
    243  1.32        pk .endif
    244  1.89  christos .if !defined(BUILD)
    245  1.89  christos ${DESTDIR}${LIBDIR}/lib${LIB}_p.a: .MADE
    246  1.89  christos .endif
    247  1.89  christos 
    248  1.89  christos ${DESTDIR}${LIBDIR}/lib${LIB}_p.a: lib${LIB}_p.a __archiveinstall
    249  1.89  christos .endif
    250  1.89  christos 
    251  1.39        pk .if !defined(NOPIC)
    252  1.89  christos libinstall:: ${DESTDIR}${LIBDIR}/lib${LIB}_pic.a
    253  1.89  christos .if !defined(UPDATE)
    254  1.89  christos .PHONY: ${DESTDIR}${LIBDIR}/lib${LIB}_pic.a
    255  1.89  christos .endif
    256  1.89  christos .if !defined(BUILD)
    257  1.89  christos ${DESTDIR}${LIBDIR}/lib${LIB}_pic.a: .MADE
    258  1.33        pk .endif
    259  1.89  christos 
    260  1.89  christos ${DESTDIR}${LIBDIR}/lib${LIB}_pic.a: lib${LIB}_pic.a __archiveinstall
    261  1.89  christos .endif
    262  1.89  christos 
    263  1.37       cgd .if !defined(NOPIC) && defined(SHLIB_MAJOR) && defined(SHLIB_MINOR)
    264  1.89  christos libinstall:: ${DESTDIR}${LIBDIR}/lib${LIB}.so.${SHLIB_MAJOR}.${SHLIB_MINOR}
    265  1.89  christos .if !defined(UPDATE)
    266  1.89  christos .PHONY: ${DESTDIR}${LIBDIR}/lib${LIB}.so.${SHLIB_MAJOR}.${SHLIB_MINOR}
    267  1.89  christos .endif
    268  1.89  christos .if !defined(BUILD)
    269  1.89  christos ${DESTDIR}${LIBDIR}/lib${LIB}.so.${SHLIB_MAJOR}.${SHLIB_MINOR}: .MADE
    270  1.89  christos .endif
    271  1.89  christos  
    272  1.89  christos ${DESTDIR}${LIBDIR}/lib${LIB}.so.${SHLIB_MAJOR}.${SHLIB_MINOR}: lib${LIB}.so.${SHLIB_MAJOR}.${SHLIB_MINOR}
    273  1.89  christos 	${INSTALL} ${COPY} -o ${LIBOWN} -g ${LIBGRP} -m ${LIBMODE} ${.ALLSRC} \
    274  1.89  christos 		${.TARGET}
    275  1.86  jonathan .if (${SHLIB_TYPE} == "ELF")
    276  1.83       cgd 	rm -f ${DESTDIR}${LIBDIR}/lib${LIB}.so.${SHLIB_MAJOR}
    277  1.83       cgd 	ln -s lib${LIB}.so.${SHLIB_MAJOR}.${SHLIB_MINOR} \
    278  1.83       cgd 	    ${DESTDIR}${LIBDIR}/lib${LIB}.so.${SHLIB_MAJOR}
    279  1.83       cgd 	rm -f ${DESTDIR}${LIBDIR}/lib${LIB}.so
    280  1.83       cgd 	ln -s lib${LIB}.so.${SHLIB_MAJOR}.${SHLIB_MINOR} \
    281  1.83       cgd 	    ${DESTDIR}${LIBDIR}/lib${LIB}.so
    282  1.83       cgd .endif
    283  1.12       cgd .endif
    284  1.89  christos 
    285  1.58       cgd .if !defined(NOLINT)
    286  1.89  christos libinstall:: ${DESTDIR}${LINTLIBDIR}/llib-l${LIB}.ln
    287  1.89  christos .if !defined(UPDATE)
    288  1.89  christos .PHONY: ${DESTDIR}${LINTLIBDIR}/llib-l${LIB}.ln
    289  1.89  christos .endif
    290  1.89  christos .if !defined(BUILD)
    291  1.89  christos ${DESTDIR}${LINTLIBDIR}/llib-l${LIB}.ln: .MADE
    292  1.89  christos .endif
    293  1.89  christos 
    294  1.89  christos ${DESTDIR}${LINTLIBDIR}/llib-l${LIB}.ln llib-l${LIB}.ln
    295  1.73   thorpej 	${INSTALL} ${COPY} -o ${LIBOWN} -g ${LIBGRP} -m ${LIBMODE} \
    296  1.58       cgd 	    llib-l${LIB}.ln ${DESTDIR}${LINTLIBDIR}
    297  1.58       cgd .endif
    298   1.1       cgd 
    299  1.89  christos libinstall:: linksinstall
    300  1.89  christos realinstall: libinstall
    301  1.89  christos 
    302  1.89  christos install: ${MANINSTALL} _SUBDIRUSE
    303  1.89  christos ${MANINSTALL}: afterinstall
    304  1.11   mycroft afterinstall: realinstall
    305  1.11   mycroft realinstall: beforeinstall
    306   1.1       cgd .endif
    307   1.1       cgd 
    308  1.10   mycroft .if !defined(NOMAN)
    309   1.1       cgd .include <bsd.man.mk>
    310  1.57       jtc .endif
    311  1.57       jtc 
    312  1.57       jtc .if !defined(NONLS)
    313  1.57       jtc .include <bsd.nls.mk>
    314  1.10   mycroft .endif
    315  1.10   mycroft 
    316  1.22   mycroft .include <bsd.obj.mk>
    317  1.89  christos .include <bsd.links.mk>
    318  1.89  christos .include <bsd.inc.mk>
    319  1.24   mycroft .include <bsd.dep.mk>
    320  1.49       cgd .include <bsd.subdir.mk>
    321  1.66  christos .include <bsd.sys.mk>
    322