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