diff --git a/src/.mk b/src/.mk new file mode 100644 index 00000000..e69de29b diff --git a/src/Makefile. b/src/Makefile. deleted file mode 100644 index baa0cf1c..00000000 --- a/src/Makefile. +++ /dev/null @@ -1,4 +0,0 @@ -# Empty Makefile so that we can do this -#include Makefile.$(FOO) -# where FOO is unset. -# This is needed as not all make implementations can optionally include a Makefile diff --git a/src/Makefile.BSD b/src/Makefile.BSD deleted file mode 100644 index a9ef9791..00000000 --- a/src/Makefile.BSD +++ /dev/null @@ -1,2 +0,0 @@ -LDLIBS_LIBRC += -lkvm -LDLIBS_RC += -lkvm diff --git a/src/Makefile.Linux b/src/Makefile.Linux deleted file mode 100644 index 96a80ab9..00000000 --- a/src/Makefile.Linux +++ /dev/null @@ -1,2 +0,0 @@ -LDLIBS_RC += -Wl,-Bdynamic -ldl -CPPFLAGS += -D_BSD_SOURCE -D_XOPEN_SOURCE=500 diff --git a/src/Makefile.ncurses b/src/Makefile.ncurses deleted file mode 100644 index 204325dd..00000000 --- a/src/Makefile.ncurses +++ /dev/null @@ -1,2 +0,0 @@ -LIBTERMCAP = -lncurses -include Makefile.termcap diff --git a/src/Makefile.pam b/src/Makefile.pam deleted file mode 100644 index 5f8ff569..00000000 --- a/src/Makefile.pam +++ /dev/null @@ -1,2 +0,0 @@ -CPPFLAGS_SSD = -DHAVE_PAM -LDLIBS_RC += -lpam diff --git a/src/Makefile.termcap b/src/Makefile.termcap deleted file mode 100644 index 10f19865..00000000 --- a/src/Makefile.termcap +++ /dev/null @@ -1,4 +0,0 @@ -LIBTERMCAP ?= -ltermcap -CPPFLAGS_LIBEINFO = -DHAVE_TERMCAP -LDLIBS_LIBEINFO += $(LIBTERMCAP) -LDLIBS_RC += $(LIBTERMCAP) diff --git a/src/cc.mk b/src/cc.mk new file mode 100644 index 00000000..d3c96a65 --- /dev/null +++ b/src/cc.mk @@ -0,0 +1,25 @@ +# Copyright 2008 Roy Marples + +# Setup some good default CFLAGS + +CFLAGS ?= -O2 -pipe + +# GNU Make way of detecting gcc flags we can use +check_gcc=$(shell if $(CC) $(1) -S -o /dev/null -xc /dev/null >/dev/null 2>&1; \ + then echo "$(1)"; else echo "$(2)"; fi) + +# pmake check for extra cflags +WEXTRA != for x in -Wdeclaration-after-statement -Wsequence-point -Wextra; do \ + if $(CC) $$x -S -o /dev/null -xc /dev/null >/dev/null 2>&1; \ + then echo -n "$$x "; fi \ + done + +# Loads of nice flags to ensure our code is good +CFLAGS += -pedantic -std=c99 \ + -Wall -Wunused -Wimplicit -Wshadow -Wformat=2 \ + -Wmissing-declarations -Wno-missing-prototypes -Wwrite-strings \ + -Wbad-function-cast -Wnested-externs -Wcomment -Winline \ + -Wchar-subscripts -Wcast-align -Wno-format-nonliteral \ + $(call check_gcc, -Wdeclaration-after-statement) \ + $(call check_gcc, -Wsequence-point) \ + $(call check_gcc, -Wextra) $(WEXTRA) diff --git a/src/default.mk b/src/default.mk new file mode 100644 index 00000000..10f4fcb2 --- /dev/null +++ b/src/default.mk @@ -0,0 +1,34 @@ +# Copyright 2007-2008 Roy Marples + +CC ?= gcc +AR ?= ar +RANLIB ?= ranlib +CFLAGS += -O2 -pipe +LDFLAGS += -L. +PICFLAG = -fPIC + +# GNU Make way of detecting gcc flags we can use +check_gcc=$(shell if $(CC) $(1) -S -o /dev/null -xc /dev/null >/dev/null 2>&1; \ + then echo "$(1)"; else echo "$(2)"; fi) + +# pmake check for extra cflags +WEXTRA != for x in -Wdeclaration-after-statement -Wsequence-point -Wextra; do \ + if $(CC) $$x -S -o /dev/null -xc /dev/null >/dev/null 2>&1; \ + then echo -n "$$x "; fi \ + done + +# Loads of nice flags to ensure our code is good +CFLAGS += -pedantic -std=c99 \ + -Wall -Wunused -Wimplicit -Wshadow -Wformat=2 \ + -Wmissing-declarations -Wno-missing-prototypes -Wwrite-strings \ + -Wbad-function-cast -Wnested-externs -Wcomment -Winline \ + -Wchar-subscripts -Wcast-align -Wno-format-nonliteral \ + $(call check_gcc, -Wdeclaration-after-statement) \ + $(call check_gcc, -Wsequence-point) \ + $(call check_gcc, -Wextra) $(WEXTRA) + +# For debugging. -Werror is pointless due to ISO C issues with dlsym +#CFLAGS += -ggdb + +TOPDIR = .. +include $(TOPDIR)/default.mk diff --git a/src/lib.mk b/src/lib.mk new file mode 100644 index 00000000..947492c1 --- /dev/null +++ b/src/lib.mk @@ -0,0 +1,55 @@ +# rules to build a library +# based on FreeBSD's bsd.lib.mk + +# Copyright 2008 Roy Marples + +SHLIB_NAME= lib${LIB}.so.${SHLIB_MAJOR} +SHLIB_LINK= lib${LIB}.so +SHLIBDIR?= /lib +SONAME?= ${SHLIB_NAME} + +OBJS+= ${SRCS:.c=.o} +SOBJS+= ${OBJS:.o=.So} +_LIBS= lib${LIB}.a ${SHLIB_NAME} + +ECHO?= echo +AR?= ar +RANLIB?= ranlib +INSTALL?= install +LIBMODE?= 0444 + +PICFLAG?= -fPIC + +INCDIR?= /usr/include +INCMODE?= 0444 + +.SUFFIXES: .So + +.c.So: + ${CC} ${PICFLAG} -DPIC ${CFLAGS} ${CPPFLAGS} -c $< -o $@ + +all: ${_LIBS} + +lib${LIB}.a: ${OBJS} ${STATICOBJS} + @${ECHO} building static library $@ + ${AR} rc $@ $^ + ${RANLIB} $@ + + +${SHLIB_NAME}: ${SOBJS} + @${ECHO} building shared library $@ + @rm -f $@ ${SHLIB_LINK} + @ln -fs $@ ${SHLIB_LINK} + ${CC} ${LDFLAGS} -shared -Wl,-x \ + -o $@ -Wl,-soname,${SONAME} \ + ${SOBJS} ${LDADD} + +install: + ${INSTALL} -d ${DESTDIR}${SHLIBDIR} + ${INSTALL} -m ${LIBMODE} ${SHLIB_NAME} ${DESTDIR}${SHLIBDIR} + ln -fs ${SHLIB_NAME} ${DESTDIR}${SHLIBDIR}/${SHLIB_LINK} + ${INSTALL} -d ${DESTDIR}${INCDIR} + for x in ${INCS}; do ${INSTALL} -m ${INCMODE} $$x ${DESTDIR}${INCDIR}; done + +clean: + rm -f ${OBJS} ${SOBJS} ${_LIBS} ${SHLIB_LINK} diff --git a/src/libeinfo/Makefile b/src/libeinfo/Makefile new file mode 100644 index 00000000..b6826340 --- /dev/null +++ b/src/libeinfo/Makefile @@ -0,0 +1,14 @@ +TOPDIR= .. +include $(TOPDIR)/os.mk + +LIB= einfo +SHLIB_MAJOR= 1 +SRCS= libeinfo.c +INCS= einfo.h + +SHLIBDIR= /${LIBNAME} + +include $(TOPDIR)/cc.mk +include $(TOPDIR)/lib.mk +include $(TOPDIR)/$(TERMCAP).mk + diff --git a/src/einfo.h b/src/libeinfo/einfo.h similarity index 100% rename from src/einfo.h rename to src/libeinfo/einfo.h diff --git a/src/einfo.map b/src/libeinfo/einfo.map similarity index 100% rename from src/einfo.map rename to src/libeinfo/einfo.map diff --git a/src/libeinfo.c b/src/libeinfo/libeinfo.c similarity index 100% rename from src/libeinfo.c rename to src/libeinfo/libeinfo.c diff --git a/src/librc/Makefile b/src/librc/Makefile new file mode 100644 index 00000000..27ea942c --- /dev/null +++ b/src/librc/Makefile @@ -0,0 +1,14 @@ +TOPDIR= .. +include $(TOPDIR)/os.mk + +LIB= rc +SHLIB_MAJOR= 1 +SRCS= librc.c librc-daemon.c librc-depend.c librc-misc.c librc-strlist.c +INCS= rc.h + +CPPFLAGS+= -DLIB=\"${LIBNAME}\" + +SHLIBDIR= /${LIBNAME} + +include $(TOPDIR)/cc.mk +include $(TOPDIR)/lib.mk diff --git a/src/librc-daemon.c b/src/librc/librc-daemon.c similarity index 100% rename from src/librc-daemon.c rename to src/librc/librc-daemon.c diff --git a/src/librc-depend.c b/src/librc/librc-depend.c similarity index 100% rename from src/librc-depend.c rename to src/librc/librc-depend.c diff --git a/src/librc-depend.h b/src/librc/librc-depend.h similarity index 100% rename from src/librc-depend.h rename to src/librc/librc-depend.h diff --git a/src/librc-misc.c b/src/librc/librc-misc.c similarity index 100% rename from src/librc-misc.c rename to src/librc/librc-misc.c diff --git a/src/librc-strlist.c b/src/librc/librc-strlist.c similarity index 100% rename from src/librc-strlist.c rename to src/librc/librc-strlist.c diff --git a/src/librc.c b/src/librc/librc.c similarity index 100% rename from src/librc.c rename to src/librc/librc.c diff --git a/src/librc.h b/src/librc/librc.h similarity index 100% rename from src/librc.h rename to src/librc/librc.h diff --git a/src/rc.h b/src/librc/rc.h similarity index 100% rename from src/rc.h rename to src/librc/rc.h diff --git a/src/ncurses.mk b/src/ncurses.mk new file mode 100644 index 00000000..f1df47f0 --- /dev/null +++ b/src/ncurses.mk @@ -0,0 +1,3 @@ +LIBTERMCAP?= -lncurses +CPPFLAGS+= -DHAVE_TERMCAP +LDADD+= ${LIBTERMCAP} diff --git a/src/os.mk b/src/os.mk new file mode 100644 index 00000000..6b8b56d9 --- /dev/null +++ b/src/os.mk @@ -0,0 +1,24 @@ +# Copyright 2008 Roy Marples + +# Generic definitions + +_OS_SH= u=`uname -s`; case "$${u}" in *BSD|DragonFly) echo "BSD";; *) echo "$${u}";; esac +_OS!= $(_OS_SH) +OS?= $(_OS)$(shell $(_OS_SH)) + +_LIBNAME_SH= l=`readlink /lib`; case "$$l" in /lib64|lib64) echo "lib64";; *) echo "lib";; esac +_LIBNAME!= $(_LIBNAME_SH) +LIBNAME?= $(_LIBNAME)$(shell $(_LIBNAME_SH)) +RC_LIB= /$(LIB)/rc + +_DEF_SH= case `uname -s` in Linux) echo "-D_XOPEN_SOURCE=600 -D_BSD_SOURCE";; *) echo;; esac +_DEF!= $(_DEF_SH) +CPPFLAGS+= $(_DEF)$(shell $(_DEF_SH)) + +_LIBDL_SH= case `uname -s` in Linux) echo "-Wl,-Bdynamic -ldl";; *) echo;; esac +_LIBDL!= $(_LIBDL_SH) +LIBDL?= $(_LIBDL)$(shell $(_LIBDL_SH)) + +_LIBKVM_SH= case `uname -s` in *BSD) echo "-lkvm";; *) echo;; esac +_LIBKVM!= $(_LIBKVM_SH) +LIBKVM?= $(_LIBKVM)$(shell $(_LIBKVM_SH)) diff --git a/src/pam.mk b/src/pam.mk new file mode 100644 index 00000000..a9c961ed --- /dev/null +++ b/src/pam.mk @@ -0,0 +1,6 @@ +LIBPAM?= -lpam +CPPFLAGS+= -DHAVE_PAM +LDADD+= ${LIBPAM} + +PAMDIR?= /etc/pam.d +PAMMODE?= 0644 diff --git a/src/prog.mk b/src/prog.mk new file mode 100644 index 00000000..1d0f013f --- /dev/null +++ b/src/prog.mk @@ -0,0 +1,18 @@ +# rules to build a library +# based on FreeBSD's bsd.prog.mk + +# Copyright 2008 Roy Marples + +BINDIR?= /sbin + +OBJS+= ${SRCS:.c=.o} + +INSTALL?= install + +all: ${PROG} + +${PROG}: ${SCRIPTS} ${OBJS} + ${CC} ${CFLAGS} ${LDFLAGS} ${PROGLDFLAGS} ${CPPFLAGS} -o $@ ${OBJS} ${LDADD} + +clean: + rm -f ${OBJS} ${PROG} ${CLEANFILES} diff --git a/src/_usage.c b/src/rc/_usage.c similarity index 100% rename from src/_usage.c rename to src/rc/_usage.c diff --git a/src/_usage.h b/src/rc/_usage.h similarity index 100% rename from src/_usage.h rename to src/rc/_usage.h diff --git a/src/builtins.h b/src/rc/builtins.h similarity index 100% rename from src/builtins.h rename to src/rc/builtins.h diff --git a/src/checkpath.c b/src/rc/checkpath.c similarity index 100% rename from src/checkpath.c rename to src/rc/checkpath.c diff --git a/src/fstabinfo.c b/src/rc/fstabinfo.c similarity index 100% rename from src/fstabinfo.c rename to src/rc/fstabinfo.c diff --git a/src/mountinfo.c b/src/rc/mountinfo.c similarity index 100% rename from src/mountinfo.c rename to src/rc/mountinfo.c diff --git a/src/rc-depend.c b/src/rc/rc-depend.c similarity index 100% rename from src/rc-depend.c rename to src/rc/rc-depend.c diff --git a/src/rc-logger.c b/src/rc/rc-logger.c similarity index 100% rename from src/rc-logger.c rename to src/rc/rc-logger.c diff --git a/src/rc-logger.h b/src/rc/rc-logger.h similarity index 100% rename from src/rc-logger.h rename to src/rc/rc-logger.h diff --git a/src/rc-misc.c b/src/rc/rc-misc.c similarity index 100% rename from src/rc-misc.c rename to src/rc/rc-misc.c diff --git a/src/rc-plugin.c b/src/rc/rc-plugin.c similarity index 100% rename from src/rc-plugin.c rename to src/rc/rc-plugin.c diff --git a/src/rc-plugin.h b/src/rc/rc-plugin.h similarity index 100% rename from src/rc-plugin.h rename to src/rc/rc-plugin.h diff --git a/src/rc-status.c b/src/rc/rc-status.c similarity index 100% rename from src/rc-status.c rename to src/rc/rc-status.c diff --git a/src/rc-update.c b/src/rc/rc-update.c similarity index 100% rename from src/rc-update.c rename to src/rc/rc-update.c diff --git a/src/rc.c b/src/rc/rc.c similarity index 100% rename from src/rc.c rename to src/rc/rc.c diff --git a/src/rc.map b/src/rc/rc.map similarity index 100% rename from src/rc.map rename to src/rc/rc.map diff --git a/src/runscript.c b/src/rc/runscript.c similarity index 100% rename from src/runscript.c rename to src/rc/runscript.c diff --git a/src/start-stop-daemon.c b/src/rc/start-stop-daemon.c similarity index 100% rename from src/start-stop-daemon.c rename to src/rc/start-stop-daemon.c diff --git a/src/start-stop-daemon.pam b/src/rc/start-stop-daemon.pam similarity index 100% rename from src/start-stop-daemon.pam rename to src/rc/start-stop-daemon.pam diff --git a/src/termcap.mk b/src/termcap.mk new file mode 100644 index 00000000..7b5058db --- /dev/null +++ b/src/termcap.mk @@ -0,0 +1,3 @@ +LIBTERMCAP?= -ltermcap +CPPFLAGS+= -DHAVE_TERMCAP +LDADD+= ${LIBTERMCAP} diff --git a/subdir.mk b/subdir.mk new file mode 100644 index 00000000..03bec8c3 --- /dev/null +++ b/subdir.mk @@ -0,0 +1,25 @@ +# Recursive rules +# Adapted from FreeBSDs bsd.subdir.mk +_+_ ?= + +ECHODIR ?= true +_SUBDIR = @${_+_}for x in ${SUBDIR}; do \ + if test -d $$x; then \ + ${ECHODIR} "===> ${DIRPRFX}$$x ($@)"; \ + cd $$x; \ + ${MAKE} $@ DIRPRFX=${DIRPRFX}$$x/ || exit $$?; \ + cd ..; \ + fi; \ + if test -d $$x.${OS}; then \ + ${ECHODIR} "===> ${DIRPRFX}$$x.${OS} ($@)"; \ + cd $$x.${OS}; \ + ${MAKE} $@ DIRPRFX=${DIRPRFX}$$x/ || exit $$?; \ + cd ..; \ + fi; \ +done + +all: + $(_SUBDIR) +clean: + $(_SUBDIR) +install: + $(_SUBDIR)