Home | History | Annotate | Line # | Download | only in mk
bsd.lib.mk revision 1.84
      1 #	$NetBSD: bsd.lib.mk,v 1.84 1997/03/13 02:46:00 perry Exp $
      2 #	@(#)bsd.lib.mk	5.26 (Berkeley) 5/2/91
      3 
      4 .if exists(${.CURDIR}/../Makefile.inc)
      5 .include "${.CURDIR}/../Makefile.inc"
      6 .endif
      7 
      8 .include <bsd.own.mk>				# for 'NOPIC' definition
      9 
     10 .if exists(${.CURDIR}/shlib_version)
     11 SHLIB_MAJOR != . ${.CURDIR}/shlib_version ; echo $$major
     12 SHLIB_MINOR != . ${.CURDIR}/shlib_version ; echo $$minor
     13 .endif
     14 
     15 .MAIN: all
     16 
     17 # prefer .S to a .c, add .po, remove stuff not used in the BSD libraries.
     18 # .so used for PIC object files.  .ln used for lint output files.
     19 .SUFFIXES:
     20 .SUFFIXES: .out .o .po .so .S .s .c .cc .C .f .y .l .ln .m4
     21 
     22 CFLAGS+=	${COPTS}
     23 
     24 .c.o:
     25 	@echo ${COMPILE.c:Q} ${.IMPSRC}
     26 	@${COMPILE.c} ${.IMPSRC}  -o ${.TARGET}.o
     27 	@${LD} -x -r ${.TARGET}.o -o ${.TARGET}
     28 	@rm -f ${.TARGET}.o
     29 
     30 .c.po:
     31 	@echo ${COMPILE.c:Q} -pg ${.IMPSRC} -o ${.TARGET}
     32 	@${COMPILE.c} -pg ${.IMPSRC} -o ${.TARGET}.o
     33 	@${LD} -X -r ${.TARGET}.o -o ${.TARGET}
     34 	@rm -f ${.TARGET}.o
     35 
     36 .c.so:
     37 	@echo ${COMPILE.c:Q} ${PICFLAG} -DPIC ${.IMPSRC} -o ${.TARGET}
     38 	@${COMPILE.c} ${PICFLAG} -DPIC ${.IMPSRC} -o ${.TARGET}.o
     39 	@${LD} -x -r ${.TARGET}.o -o ${.TARGET}
     40 	@rm -f ${.TARGET}.o
     41 
     42 .c.ln:
     43 	${LINT} ${LINTFLAGS} ${CFLAGS:M-[IDU]*} -i ${.IMPSRC}
     44 
     45 .cc.o .C.o:
     46 	@echo ${COMPILE.cc:Q} ${.IMPSRC}
     47 	@${COMPILE.cc} ${.IMPSRC} -o ${.TARGET}.o
     48 	@${LD} -x -r ${.TARGET}.o -o ${.TARGET}
     49 	@rm -f ${.TARGET}.o
     50 
     51 .cc.po .C.po:
     52 	@echo ${COMPILE.cc:Q} -pg ${.IMPSRC} -o ${.TARGET}
     53 	@${COMPILE.cc} -pg ${.IMPSRC} -o ${.TARGET}.o
     54 	@${LD} -X -r ${.TARGET}.o -o ${.TARGET}
     55 	@rm -f ${.TARGET}.o
     56 
     57 .cc.so .C.so:
     58 	@echo ${COMPILE.cc:Q} ${PICFLAG} -DPIC ${.IMPSRC} -o ${.TARGET}
     59 	@${COMPILE.cc} ${PICFLAG} -DPIC ${.IMPSRC} -o ${.TARGET}.o
     60 	@${LD} -x -r ${.TARGET}.o -o ${.TARGET}
     61 	@rm -f ${.TARGET}.o
     62 
     63 .S.o .s.o:
     64 	@echo ${COMPILE.S:Q} ${CFLAGS:M-[ID]*} ${AINC} ${.IMPSRC}
     65 	@${COMPILE.S} ${CFLAGS:M-[ID]*} ${AINC} ${.IMPSRC} -o ${.TARGET}.o
     66 	@${LD} -x -r ${.TARGET}.o -o ${.TARGET}
     67 	@rm -f ${.TARGET}.o
     68 
     69 .S.po .s.po:
     70 	@echo ${COMPILE.S:Q} -DGPROF -DPROF ${CFLAGS:M-[ID]*} ${AINC} ${.IMPSRC} -o ${.TARGET}
     71 	@${COMPILE.S} -DGPROF -DPROF ${CFLAGS:M-[ID]*} ${AINC} ${.IMPSRC} -o ${.TARGET}.o
     72 	@${LD} -X -r ${.TARGET}.o -o ${.TARGET}
     73 	@rm -f ${.TARGET}.o
     74 
     75 .S.so .s.so:
     76 	@echo ${COMPILE.S:Q} ${PICFLAG} -DPIC ${CFLAGS:M-[ID]*} ${AINC} ${.IMPSRC} -o ${.TARGET}
     77 	@${COMPILE.S} ${PICFLAG} -DPIC ${CFLAGS:M-[ID]*} ${AINC} ${.IMPSRC} -o ${.TARGET}.o
     78 	@${LD} -x -r ${.TARGET}.o -o ${.TARGET}
     79 	@rm -f ${.TARGET}.o
     80 
     81 .if !defined(PICFLAG)
     82 PICFLAG=-fpic
     83 .endif
     84 
     85 .if !defined(NOPROFILE)
     86 _LIBS=lib${LIB}.a lib${LIB}_p.a
     87 .else
     88 _LIBS=lib${LIB}.a
     89 .endif
     90 
     91 .if !defined(NOPIC)
     92 _LIBS+=lib${LIB}_pic.a
     93 .if defined(SHLIB_MAJOR) && defined(SHLIB_MINOR)
     94 _LIBS+=lib${LIB}.so.${SHLIB_MAJOR}.${SHLIB_MINOR}
     95 .endif
     96 .endif
     97 
     98 .if !defined(NOLINT)
     99 _LIBS+=llib-l${LIB}.ln
    100 .endif
    101 
    102 all: ${_LIBS} _SUBDIRUSE
    103 
    104 OBJS+=	${SRCS:N*.h:R:S/$/.o/g}
    105 
    106 lib${LIB}.a:: ${OBJS}
    107 	@echo building standard ${LIB} library
    108 	@rm -f lib${LIB}.a
    109 	@${AR} cq lib${LIB}.a `lorder ${OBJS} | tsort -q`
    110 	${RANLIB} lib${LIB}.a
    111 
    112 POBJS+=	${OBJS:.o=.po}
    113 lib${LIB}_p.a:: ${POBJS}
    114 	@echo building profiled ${LIB} library
    115 	@rm -f lib${LIB}_p.a
    116 	@${AR} cq lib${LIB}_p.a `lorder ${POBJS} | tsort -q`
    117 	${RANLIB} lib${LIB}_p.a
    118 
    119 SOBJS+=	${OBJS:.o=.so}
    120 lib${LIB}_pic.a:: ${SOBJS}
    121 	@echo building shared object ${LIB} library
    122 	@rm -f lib${LIB}_pic.a
    123 	@${AR} cq lib${LIB}_pic.a `lorder ${SOBJS} | tsort -q`
    124 	${RANLIB} lib${LIB}_pic.a
    125 
    126 lib${LIB}.so.${SHLIB_MAJOR}.${SHLIB_MINOR}: lib${LIB}_pic.a ${DPADD}
    127 	@echo building shared ${LIB} library \(version ${SHLIB_MAJOR}.${SHLIB_MINOR}\)
    128 	@rm -f lib${LIB}.so.${SHLIB_MAJOR}.${SHLIB_MINOR}
    129 .if (${MACHINE_ARCH} != "alpha")
    130 	$(LD) -x -Bshareable -Bforcearchive \
    131 	    -o lib${LIB}.so.${SHLIB_MAJOR}.${SHLIB_MINOR} lib${LIB}_pic.a ${LDADD}
    132 .else
    133 	$(LD) -shared -o lib${LIB}.so.${SHLIB_MAJOR}.${SHLIB_MINOR} \
    134 	    -soname lib${LIB}.so.${SHLIB_MAJOR} /usr/lib/crtbeginS.o \
    135 	    --whole-archive lib${LIB}_pic.a --no-whole-archive ${LDADD} \
    136 	    /usr/lib/crtendS.o
    137 .endif
    138 
    139 LOBJS+=	${LSRCS:.c=.ln} ${SRCS:M*.c:.c=.ln}
    140 LLIBS?=	-lc
    141 llib-l${LIB}.ln: ${LOBJS}
    142 	@echo building llib-l${LIB}.ln
    143 	@rm -f llib-l${LIB}.ln
    144 	@${LINT} -C${LIB} ${LOBJS} ${LLIBS}
    145 
    146 .if !target(clean)
    147 cleanlib:
    148 	rm -f a.out [Ee]rrs mklog core *.core ${CLEANFILES}
    149 	rm -f lib${LIB}.a ${OBJS}
    150 	rm -f lib${LIB}_p.a ${POBJS}
    151 	rm -f lib${LIB}_pic.a lib${LIB}.so.*.* ${SOBJS}
    152 	rm -f llib-l${LIB}.ln ${LOBJS}
    153 
    154 clean: _SUBDIRUSE cleanlib
    155 cleandir: _SUBDIRUSE cleanlib
    156 .else
    157 cleandir: _SUBDIRUSE clean
    158 .endif
    159 
    160 .if defined(SRCS)
    161 afterdepend: .depend
    162 	@(TMP=/tmp/_depend$$$$; \
    163 	    sed -e 's/^\([^\.]*\).o[ ]*:/\1.o \1.po \1.so \1.ln:/' \
    164 	      < .depend > $$TMP; \
    165 	    mv $$TMP .depend)
    166 .endif
    167 
    168 .if !target(install)
    169 .if !target(beforeinstall)
    170 beforeinstall:
    171 .endif
    172 
    173 realinstall:
    174 #	ranlib lib${LIB}.a
    175 	${INSTALL} ${COPY} -o ${LIBOWN} -g ${LIBGRP} -m 600 lib${LIB}.a \
    176 	    ${DESTDIR}${LIBDIR}
    177 	${RANLIB} -t ${DESTDIR}${LIBDIR}/lib${LIB}.a
    178 	chmod ${LIBMODE} ${DESTDIR}${LIBDIR}/lib${LIB}.a
    179 .if !defined(NOPROFILE)
    180 #	ranlib lib${LIB}_p.a
    181 	${INSTALL} ${COPY} -o ${LIBOWN} -g ${LIBGRP} -m 600 \
    182 	    lib${LIB}_p.a ${DESTDIR}${LIBDIR}
    183 	${RANLIB} -t ${DESTDIR}${LIBDIR}/lib${LIB}_p.a
    184 	chmod ${LIBMODE} ${DESTDIR}${LIBDIR}/lib${LIB}_p.a
    185 .endif
    186 .if !defined(NOPIC)
    187 #	ranlib lib${LIB}_pic.a
    188 	${INSTALL} ${COPY} -o ${LIBOWN} -g ${LIBGRP} -m 600 \
    189 	    lib${LIB}_pic.a ${DESTDIR}${LIBDIR}
    190 	${RANLIB} -t ${DESTDIR}${LIBDIR}/lib${LIB}_pic.a
    191 	chmod ${LIBMODE} ${DESTDIR}${LIBDIR}/lib${LIB}_pic.a
    192 .endif
    193 .if !defined(NOPIC) && defined(SHLIB_MAJOR) && defined(SHLIB_MINOR)
    194 	${INSTALL} ${COPY} -o ${LIBOWN} -g ${LIBGRP} -m ${LIBMODE} \
    195 	    lib${LIB}.so.${SHLIB_MAJOR}.${SHLIB_MINOR} ${DESTDIR}${LIBDIR}
    196 .if (${MACHINE_ARCH} == "alpha")
    197 	rm -f ${DESTDIR}${LIBDIR}/lib${LIB}.so.${SHLIB_MAJOR}
    198 	ln -s lib${LIB}.so.${SHLIB_MAJOR}.${SHLIB_MINOR} \
    199 	    ${DESTDIR}${LIBDIR}/lib${LIB}.so.${SHLIB_MAJOR}
    200 	rm -f ${DESTDIR}${LIBDIR}/lib${LIB}.so
    201 	ln -s lib${LIB}.so.${SHLIB_MAJOR}.${SHLIB_MINOR} \
    202 	    ${DESTDIR}${LIBDIR}/lib${LIB}.so
    203 .endif
    204 .endif
    205 .if !defined(NOLINT)
    206 	${INSTALL} ${COPY} -o ${LIBOWN} -g ${LIBGRP} -m ${LIBMODE} \
    207 	    llib-l${LIB}.ln ${DESTDIR}${LINTLIBDIR}
    208 .endif
    209 .if defined(LINKS) && !empty(LINKS)
    210 	@set ${LINKS}; \
    211 	while test $$# -ge 2; do \
    212 		l=${DESTDIR}$$1; \
    213 		shift; \
    214 		t=${DESTDIR}$$1; \
    215 		shift; \
    216 		echo $$t -\> $$l; \
    217 		rm -f $$t; \
    218 		ln $$l $$t; \
    219 	done; true
    220 .endif
    221 .if defined(SYMLINKS) && !empty(SYMLINKS)
    222 	@set ${SYMLINKS}; \
    223 	while test $$# -ge 2; do \
    224 		l=${DESTDIR}$$1; \
    225 		shift; \
    226 		t=${DESTDIR}$$1; \
    227 		shift; \
    228 		echo $$t -\> $$l; \
    229 		rm -f $$t; \
    230 		ln -s $$l $$t; \
    231 	done; true
    232 .endif
    233 
    234 install: maninstall _SUBDIRUSE
    235 maninstall: afterinstall
    236 afterinstall: realinstall
    237 realinstall: beforeinstall
    238 .endif
    239 
    240 .if !defined(NOMAN)
    241 .include <bsd.man.mk>
    242 .endif
    243 
    244 .if !defined(NONLS)
    245 .include <bsd.nls.mk>
    246 .endif
    247 
    248 .include <bsd.obj.mk>
    249 .include <bsd.dep.mk>
    250 .include <bsd.subdir.mk>
    251 .include <bsd.sys.mk>
    252