Bring over configure imporvements from dhcpcd.
[dhcpcd-ui] / mk / lib.mk
1 # rules to build a library
2
3 include ${TOPDIR}/iconfig.mk
4
5 SHLIB=                  lib${LIB}.so.${SHLIB_MAJOR}
6 SHLIB_LINK=             lib${LIB}.so
7 LIBNAME=                lib${LIB}.a
8 SONAME?=                ${SHLIB}
9
10 OBJS+=                  ${SRCS:.c=.o}
11 SOBJS+=                 ${OBJS:.o=.So}
12 LIBS?=                  ${LIBNAME} ${SHLIB}
13
14 CLEANFILES+=            ${OBJS} ${SOBJS} ${LIBS} ${SHLIB_LINK}
15
16 LIBINSTALL?=            _libinstall
17
18 .SUFFIXES:              .So
19
20 .c.o:
21         ${CC} ${CFLAGS} ${CPPFLAGS} -c $< -o $@
22
23 .c.So:
24         ${CC} ${PICFLAG} -DPIC ${CPPFLAGS} ${CFLAGS} -c $< -o $@
25
26 all: depend ${LIBS}
27
28 ${LIBNAME}:     ${OBJS} ${STATICOBJS}
29         @${ECHO} building static library $@
30         ${AR} cr $@ ${STATICOBJS} ${OBJS}
31         ${RANLIB} $@
32
33 ${SHLIB}:       ${SOBJS}
34         @${ECHO} building shared library $@
35         @rm -f $@ ${SHLIB_LINK}
36         @ln -fs $@ ${SHLIB_LINK}
37         ${CC} ${LDFLAGS} -shared -Wl,-x -o $@ -Wl,-soname,${SONAME} \
38                 ${SOBJS} ${LDADD}
39
40 _libinstall:    all
41         ${INSTALL} -d ${DESTDIR}${LIBDIR}
42         ${INSTALL} -m ${LIBMODE} ${LIBNAME} ${DESTDIR}${LIBDIR}
43         ${INSTALL} -d ${DESTDIR}${SHLIBDIR}
44         ${INSTALL} -m ${LIBMODE} ${SHLIB} ${DESTDIR}${SHLIBDIR}
45         ln -fs ${SHLIB} ${DESTDIR}${SHLIBDIR}/${SHLIB_LINK}
46         ${INSTALL} -d ${DESTDIR}${INCDIR}
47         for x in ${INCS}; do ${INSTALL} -m ${INCMODE} $$x ${DESTDIR}${INCDIR}; done
48
49 install: ${LIBINSTALL}
50
51 proginstall: install
52
53 clean:
54         rm -f ${OBJS} ${SOBJS} ${LIBS} ${SHLIB_LINK} ${CLEANFILES}
55
56 extra_depend:
57         @TMP=depend.$$$$; \
58         ${SED} -e 's/^\([^\.]*\).o[ ]*:/\1.o \1.So:/' .depend > $${TMP}; \
59         mv $${TMP} .depend
60
61 include ${MKDIR}/sys.mk
62 include ${MKDIR}/depend.mk