From 43147845209873b0776bd75d363913fe25611f49 Mon Sep 17 00:00:00 2001 From: Roy Marples Date: Thu, 10 Jan 2008 16:35:59 +0000 Subject: Allow for OS and SUBOS folders so we can introduce NetBSD scripts whilst keeping BSD for all BSD's. --- Makefile | 40 ++++-------- README | 3 +- conf.d.BSD/Makefile | 8 +-- conf.d.Linux/Makefile | 10 +-- conf.d/Makefile | 8 +-- default.mk | 65 -------------------- doc.BSD/Makefile | 8 +-- doc.Linux/Makefile | 8 +-- etc.BSD/Makefile | 10 +-- etc.Linux/Makefile | 8 +-- etc/Makefile | 8 +-- init.d.BSD/Makefile | 8 +-- init.d.Linux/Makefile | 8 +-- init.d/Makefile | 8 +-- man/Makefile | 61 +++++++++--------- mk/.mk | 0 mk/cc.mk | 27 ++++++++ mk/depend.mk | 11 ++++ mk/lib.mk | 65 ++++++++++++++++++++ mk/ncurses.mk | 3 + mk/os.mk | 31 ++++++++++ mk/pam.mk | 6 ++ mk/prog.mk | 19 ++++++ mk/scripts.mk | 34 +++++++++++ mk/subdir.mk | 39 ++++++++++++ mk/termcap.mk | 3 + net.BSD/Makefile | 8 +-- net.Linux/Makefile | 8 +-- net/Makefile | 8 +-- runlevels.BSD/Makefile | 10 ++- runlevels.Linux/Makefile | 10 ++- runlevels.mk | 23 ------- runlevels/Makefile | 17 +++--- sh.BSD/Makefile | 8 +-- sh.Linux/Makefile | 8 +-- sh/Makefile | 33 +++++----- src/.mk | 0 src/Makefile | 4 +- src/cc.mk | 27 -------- src/depend.mk | 11 ---- src/hidden-visibility.h | 26 -------- src/includes/hidden-visibility.h | 26 ++++++++ src/includes/rc-misc.h | 129 +++++++++++++++++++++++++++++++++++++++ src/includes/strlist.h | 48 +++++++++++++++ src/lib.mk | 65 -------------------- src/libeinfo/Makefile | 16 ++--- src/librc/Makefile | 10 +-- src/ncurses.mk | 3 - src/os.mk | 24 -------- src/pam.mk | 6 -- src/prog.mk | 19 ------ src/rc-misc.h | 129 --------------------------------------- src/rc/Makefile | 21 +++---- src/strlist.h | 48 --------------- src/termcap.mk | 3 - subdir.mk | 27 -------- 56 files changed, 612 insertions(+), 662 deletions(-) delete mode 100644 default.mk create mode 100644 mk/.mk create mode 100644 mk/cc.mk create mode 100644 mk/depend.mk create mode 100644 mk/lib.mk create mode 100644 mk/ncurses.mk create mode 100644 mk/os.mk create mode 100644 mk/pam.mk create mode 100644 mk/prog.mk create mode 100644 mk/scripts.mk create mode 100644 mk/subdir.mk create mode 100644 mk/termcap.mk delete mode 100644 runlevels.mk delete mode 100644 src/.mk delete mode 100644 src/cc.mk delete mode 100644 src/depend.mk delete mode 100644 src/hidden-visibility.h create mode 100644 src/includes/hidden-visibility.h create mode 100644 src/includes/rc-misc.h create mode 100644 src/includes/strlist.h delete mode 100644 src/lib.mk delete mode 100644 src/ncurses.mk delete mode 100644 src/os.mk delete mode 100644 src/pam.mk delete mode 100644 src/prog.mk delete mode 100644 src/rc-misc.h delete mode 100644 src/strlist.h delete mode 100644 src/termcap.mk delete mode 100644 subdir.mk diff --git a/Makefile b/Makefile index 55d8c6aa..f02c97ea 100644 --- a/Makefile +++ b/Makefile @@ -1,33 +1,19 @@ # OpenRC Makefile -# Copyright 2007 Roy Marples +# Copyright 2007-2008 Roy Marples # Distributed under the terms of the GNU General Public License v2 -NAME = openrc -VERSION = 0.1 -PKG = $(NAME)-$(VERSION) +NAME= openrc +VERSION= 0.1 +PKG= ${NAME}-${VERSION} -SUBDIR = conf.d doc etc init.d man net runlevels sh src +SUBDIR= conf.d doc etc init.d man net runlevels sh src -TOPDIR = . -include $(TOPDIR)/default.mk +MK= mk +include ${MK}/os.mk +include ${MK}/subdir.mk +include ${MK}/dist.mk -install:: - $(INSTALL) -d $(DESTDIR)$(RC_LIB)/init.d - $(INSTALL) -d $(DESTDIR)$(RC_LIB)/tmp - -clean:: - rm -f *.bz2 - -dist: - $(INSTALL) -d /tmp/$(PKG) - cp -RPp . /tmp/$(PKG) - (cd /tmp/$(PKG); git clean; $(MAKE) clean) - rm -rf /tmp/$(PKG)/*.bz2 /tmp/$(PKG)/.git /tmp/$(PKG)/test - rm -rf /tmp/$(PKG)/.gitignore /tmp/$(PKG)/src/.gitignore - sed -i.bak -e '/LDFLAGS += -Wl,-rpath ./ s/^/#/' /tmp/$(PKG)/src/Makefile - rm -f /tmp/$(PKG)/src/Makefile.bak - tar cvjpf $(PKG).tar.bz2 -C /tmp $(PKG) - rm -rf /tmp/$(PKG) - ls -l $(PKG).tar.bz2 - -# vim: set ts=4 : +INSTALLAFTER= _installafter +_installafter: + ${INSTALL} -d ${DESTDIR}${RC_LIB}/init.d + ${INSTALL} -d ${DESTDIR}${RC_LIB}/tmp diff --git a/README b/README index 056971bb..935ae5fd 100644 --- a/README +++ b/README @@ -4,8 +4,7 @@ OpenRC README Installation ------------ make install -Yup, that simple. Works with GNU make, FreeBSD make and pmake. Should work -with every other make too. +Yup, that simple. Works with GNU make and BSD make. You may wish to tweak the installation with the below arguments PROGLDFLAGS=-static diff --git a/conf.d.BSD/Makefile b/conf.d.BSD/Makefile index dd2e315b..c48abbfa 100644 --- a/conf.d.BSD/Makefile +++ b/conf.d.BSD/Makefile @@ -1,5 +1,5 @@ -DIR = /etc/conf.d -CONF = $(CONTENTS) +DIR= /etc/conf.d +CONF= ${CONTENTS} -TOPDIR = .. -include $(TOPDIR)/default.mk +MK= ../mk +include ${MK}/scripts.mk diff --git a/conf.d.Linux/Makefile b/conf.d.Linux/Makefile index 169a7e4f..b8a5bf79 100644 --- a/conf.d.Linux/Makefile +++ b/conf.d.Linux/Makefile @@ -1,6 +1,6 @@ -DIR = /etc/conf.d -CONF = consolefont keymaps modules -CONF_APPEND = clock +DIR= /etc/conf.d +CONF= consolefont keymaps modules +CONF_APPEND= clock -TOPDIR = .. -include $(TOPDIR)/default.mk +MK= ../mk +include ${MK}/scripts.mk diff --git a/conf.d/Makefile b/conf.d/Makefile index f26da996..c48e551a 100644 --- a/conf.d/Makefile +++ b/conf.d/Makefile @@ -1,5 +1,5 @@ -DIR = /etc/conf.d -CONF = $(CONTENTS) +DIR= /etc/conf.d +CONF= ${CONTENTS} -TOPDIR = .. -include $(TOPDIR)/default.mk +MK= ../mk +include ${MK}/scripts.mk diff --git a/default.mk b/default.mk deleted file mode 100644 index 65f2443e..00000000 --- a/default.mk +++ /dev/null @@ -1,65 +0,0 @@ -# Common makefile settings -# We shouldn't use PREFIX as we need to install into / - -_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= /${LIBNAME}/rc - -INSTALL?= install - -_OS_SH= u=`uname -s`; case "$${u}" in *BSD|DragonFly) echo "BSD";; *) echo "$${u}";; esac -_OS!= ${_OS_SH} -OS?= ${_OS}$(shell ${_OS_SH}) - -# We store the contents of the directory for ease of use in Makefiles -_CONTENTS_SH= ls -1 | grep -v Makefile | xargs -_CONTENTS!= ${_CONTENTS_SH} -CONTENTS= ${_CONTENTS}$(shell ${_CONTENTS_SH}) - -# Recursive rules -# Adapted from FreeBSDs bsd.subdir.mk -_+_ ?= + -ECHODIR ?= echo -_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} -depend:: - ${_SUBDIR} -install:: - ${_SUBDIR} - -install:: ${BIN} ${CONF} ${CONF_APPEND} - if test -n "${DIR}"; then ${INSTALL} -d ${DESTDIR}${DIR} || exit $$?; fi - if test -n "${BIN}"; then ${INSTALL} ${BIN} ${DESTDIR}${DIR} || exit $$?; fi - if test -n "${INC}"; then ${INSTALL} -m 0644 ${INC} ${DESTDIR}${DIR} || exit $$?; fi - for x in ${CONF}; do \ - if ! test -e ${DESTDIR}${DIR}/$$x; then \ - ${INSTALL} -m 0644 $$x ${DESTDIR}${DIR} || exit $$?; \ - fi; \ - done - for x in ${CONF_APPEND}; do \ - if test -e ${DESTDIR}${DIR}/$$x; then \ - cat $$x >> ${DESTDIR}${DIR}/$$x || exit $$?; \ - else \ - ${INSTALL} -m 0644 $$x ${DESTDIR}${DIR} || exit $$?; \ - fi; \ - done - -# vim: set ts=4 : diff --git a/doc.BSD/Makefile b/doc.BSD/Makefile index 41ba09f9..029dfa7a 100644 --- a/doc.BSD/Makefile +++ b/doc.BSD/Makefile @@ -1,5 +1,5 @@ -DIR = /usr/share/doc/openrc -INC = $(CONTENTS) +DIR= /usr/share/doc/openrc +INC= ${CONTENTS} -TOPDIR = .. -include $(TOPDIR)/default.mk +MK= ../mk +include ${MK}/scripts.mk diff --git a/doc.Linux/Makefile b/doc.Linux/Makefile index 41ba09f9..029dfa7a 100644 --- a/doc.Linux/Makefile +++ b/doc.Linux/Makefile @@ -1,5 +1,5 @@ -DIR = /usr/share/doc/openrc -INC = $(CONTENTS) +DIR= /usr/share/doc/openrc +INC= ${CONTENTS} -TOPDIR = .. -include $(TOPDIR)/default.mk +MK= ../mk +include ${MK}/scripts.mk diff --git a/etc.BSD/Makefile b/etc.BSD/Makefile index 1e5b056e..639b927c 100644 --- a/etc.BSD/Makefile +++ b/etc.BSD/Makefile @@ -1,6 +1,6 @@ -DIR = /etc -CONF = devd.conf rc rc.shutdown -BIN = rc.devd +DIR= /etc +CONF= devd.conf rc rc.shutdown +BIN= rc.devd -TOPDIR = .. -include $(TOPDIR)/default.mk +MK= ../mk +include ${MK}/scripts.mk diff --git a/etc.Linux/Makefile b/etc.Linux/Makefile index ad04fec9..77a782ab 100644 --- a/etc.Linux/Makefile +++ b/etc.Linux/Makefile @@ -1,5 +1,5 @@ -DIR = /etc -CONF_APPEND = rc.conf +DIR= /etc +CONF_APPEND= rc.conf -TOPDIR = .. -include $(TOPDIR)/default.mk +MK= ../mk +include ${MK}/scripts.mk diff --git a/etc/Makefile b/etc/Makefile index 0b889a9c..869430f8 100644 --- a/etc/Makefile +++ b/etc/Makefile @@ -1,5 +1,5 @@ -DIR = /etc -CONF = rc.conf +DIR= /etc +CONF= rc.conf -TOPDIR = .. -include $(TOPDIR)/default.mk +MK= ../mk +include ${MK}/scripts.mk diff --git a/init.d.BSD/Makefile b/init.d.BSD/Makefile index c50e550a..da0be63d 100644 --- a/init.d.BSD/Makefile +++ b/init.d.BSD/Makefile @@ -1,5 +1,5 @@ -DIR = /etc/init.d -BIN = $(CONTENTS) +DIR= /etc/init.d +BIN= ${CONTENTS} -TOPDIR = .. -include $(TOPDIR)/default.mk +MK= ../mk +include ${MK}/scripts.mk diff --git a/init.d.Linux/Makefile b/init.d.Linux/Makefile index c50e550a..da0be63d 100644 --- a/init.d.Linux/Makefile +++ b/init.d.Linux/Makefile @@ -1,5 +1,5 @@ -DIR = /etc/init.d -BIN = $(CONTENTS) +DIR= /etc/init.d +BIN= ${CONTENTS} -TOPDIR = .. -include $(TOPDIR)/default.mk +MK= ../mk +include ${MK}/scripts.mk diff --git a/init.d/Makefile b/init.d/Makefile index 3b4e1a27..88a2f284 100644 --- a/init.d/Makefile +++ b/init.d/Makefile @@ -1,5 +1,5 @@ -DIR = /etc/init.d -BIN = $(CONTENTS) +DIR= /etc/init.d +BIN= ${CONTENTS} -TOPDIR = .. -include $(TOPDIR)/default.mk +MK= ../mk +include ${MK}/scripts.mk diff --git a/man/Makefile b/man/Makefile index 5375ce90..eaae253f 100644 --- a/man/Makefile +++ b/man/Makefile @@ -1,34 +1,37 @@ -DIR = /usr/share/man -_MAN3_SH = ls -1 *.3 -_MAN3 != $(_MAN3_SH) -MAN3 = $(_MAN3)$(shell $(_MAN3_SH)) -_MAN8_SH = ls -1 *.8 -_MAN8 != $(_MAN8_SH) -MAN8 = $(_MAN8)$(shell $(_MAN8_SH)) - -TOPDIR = .. -include $(TOPDIR)/default.mk +DIR= /usr/share/man +_MAN3_SH= ls -1 *.3 +_MAN3!= ${_MAN3_SH} +MAN3= ${_MAN3}$(shell ${_MAN3_SH}) +_MAN8_SH= ls -1 *.8 +_MAN8!= ${_MAN8_SH} +MAN8= ${_MAN8}$(shell ${_MAN8_SH}) # Handy macro to create symlinks # This does rely on correctly formatting our manpages! -MAKE_LINKS = suffix=$${man\#*.}; \ - prefix=$${man%%.*}; \ - for link in `sed -e 's/ ,//g' \ - -n -e '/^\.Sh NAME$$/,/\.Sh/ s/\.Nm //p' $${man}`; do \ - if test "$${link}" != "$${prefix}" ; then \ - ln -sf $${man} \ - $(DESTDIR)/$(DIR)/man$${suffix}/$${link}.$${suffix} ; \ - fi; \ - done; +MAKE_LINKS= suffix=$${man\#*.}; \ + prefix=$${man%%.*}; \ + for link in `sed -e 's/ ,//g' \ + -n -e '/^\.Sh NAME$$/,/\.Sh/ s/\.Nm //p' $${man}`; do \ + if test "$${link}" != "$${prefix}" ; then \ + ln -sf $${man} \ + ${DESTDIR}/${DIR}/man$${suffix}/$${link}.$${suffix} ; \ + fi; \ + done; -install:: - $(INSTALL) -d $(DESTDIR)/$(DIR)/man3 - for man in $(MAN3); do \ - $(INSTALL) -m 0644 "$$man" $(DESTDIR)/$(DIR)/man3 || exit $$?; \ - $(MAKE_LINKS) \ - done - $(INSTALL) -d $(DESTDIR)/$(DIR)/man8 - for man in $(MAN8); do \ - $(INSTALL) -m 0644 "$$man" $(DESTDIR)/$(DIR)/man8 || exit $$?; \ - $(MAKE_LINKS) \ +INSTALL?= install + +all: + +install: + ${INSTALL} -d ${DESTDIR}/${DIR}/man3 + for man in ${MAN3}; do \ + ${INSTALL} -m 0644 "$$man" ${DESTDIR}/${DIR}/man3 || exit $$?; \ + ${MAKE_LINKS} \ done + ${INSTALL} -d ${DESTDIR}/${DIR}/man8 + for man in ${MAN8}; do \ + ${INSTALL} -m 0644 "$$man" ${DESTDIR}/${DIR}/man8 || exit $$?; \ + ${MAKE_LINKS} \ + done + +clean: diff --git a/mk/.mk b/mk/.mk new file mode 100644 index 00000000..e69de29b diff --git a/mk/cc.mk b/mk/cc.mk new file mode 100644 index 00000000..18eae7ee --- /dev/null +++ b/mk/cc.mk @@ -0,0 +1,27 @@ +# Copyright 2008 Roy Marples + +# Setup some good default CFLAGS + +CFLAGS?= -O2 -pipe +CSTD?= c99 + +# 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=${CSTD} \ + -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/mk/depend.mk b/mk/depend.mk new file mode 100644 index 00000000..a4d717ae --- /dev/null +++ b/mk/depend.mk @@ -0,0 +1,11 @@ +# This only works for make implementations that always include a .depend if +# it exists. Only GNU make does not do this. + +# Copyright 2008 Roy Marples + +CLEANFILES+= .depend + +.depend: ${SRCS} + ${CC} ${CFLAGS} -MM ${SRCS} > .depend + +depend: .depend diff --git a/mk/lib.mk b/mk/lib.mk new file mode 100644 index 00000000..7a570ebe --- /dev/null +++ b/mk/lib.mk @@ -0,0 +1,65 @@ +# rules to build a library +# based on FreeBSD's bsd.lib.mk + +# Copyright 2008 Roy Marples + +LIBNAME?= lib + +SHLIB_NAME= lib${LIB}.so.${SHLIB_MAJOR} +SHLIB_LINK= lib${LIB}.so +SHLIBDIR?= /${LIBNAME} +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 + +PICFLAG?= -fPIC + +INCDIR?= /usr/include +INCMODE?= 0444 + +LIBDIR?= /usr/${LIBNAME} +LIBMODE?= 0444 + +.SUFFIXES: .So + +.c.So: + ${CC} ${PICFLAG} -DPIC ${CFLAGS} -c $< -o $@ + +all: depend ${_LIBS} + +lib${LIB}.a: ${OBJS} ${STATICOBJS} + @${ECHO} building static library $@ + ${AR} rc $@ $^ + ${RANLIB} $@ + +${SHLIB_NAME}: ${VERSION_MAP} +LDFLAGS+= -Wl,--version-script=${VERSION_MAP} + +${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: all + ${INSTALL} -d ${DESTDIR}${LIBDIR} + ${INSTALL} -m ${LIBMODE} lib${LIB}.a ${DESTDIR}${LIBDIR} + ${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} ${CLEANFILES} + +include ${MK}/depend.mk diff --git a/mk/ncurses.mk b/mk/ncurses.mk new file mode 100644 index 00000000..66573d61 --- /dev/null +++ b/mk/ncurses.mk @@ -0,0 +1,3 @@ +LIBTERMCAP?= -lncurses +CFLAGS+= -DHAVE_TERMCAP +LDADD+= ${LIBTERMCAP} diff --git a/mk/os.mk b/mk/os.mk new file mode 100644 index 00000000..aca062c7 --- /dev/null +++ b/mk/os.mk @@ -0,0 +1,31 @@ +# Copyright 2008 Roy Marples + +# Generic definitions + +_OS_SH_= uname -s +_OS!= ${_OS_SH} +OS?= ${_OS}$(shell ${_OS_SH}) + +_SUBOS_SH= case `uname -s` in \ + *BSD|DragonFly) echo "BSD";; \ + *) echo "";; \ + esac +_SUBOS!= ${_SUBOS_SH} +SUBOS?= ${_SUBOS}$(shell ${_SUBOS_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= /$(LIBNAME)/rc + +_DEF_SH= case `uname -s` in Linux) echo "-D_XOPEN_SOURCE=600 -D_BSD_SOURCE";; *) echo;; esac +_DEF!= ${_DEF_SH} +CFLAGS+= ${_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/mk/pam.mk b/mk/pam.mk new file mode 100644 index 00000000..7d0f2ca0 --- /dev/null +++ b/mk/pam.mk @@ -0,0 +1,6 @@ +LIBPAM?= -lpam +CFLAGS+= -DHAVE_PAM +LDADD+= ${LIBPAM} + +PAMDIR?= /etc/pam.d +PAMMODE?= 0644 diff --git a/mk/prog.mk b/mk/prog.mk new file mode 100644 index 00000000..716707c6 --- /dev/null +++ b/mk/prog.mk @@ -0,0 +1,19 @@ +# 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: depend ${PROG} + +${PROG}: ${SCRIPTS} ${OBJS} + ${CC} ${CFLAGS} ${LDFLAGS} ${PROGLDFLAGS} -o $@ ${OBJS} ${LDADD} + +clean: + rm -f ${OBJS} ${PROG} ${CLEANFILES} + +include ${MK}/depend.mk diff --git a/mk/scripts.mk b/mk/scripts.mk new file mode 100644 index 00000000..806a5453 --- /dev/null +++ b/mk/scripts.mk @@ -0,0 +1,34 @@ +# Install rules for our scripts +# Copyright 2007-2008 Roy Marples + +# We store the contents of the directory for ease of use in Makefiles +_CONTENTS_SH= ls -1 | grep -v Makefile | xargs +_CONTENTS!= ${_CONTENTS_SH} +CONTENTS= ${_CONTENTS}$(shell ${_CONTENTS_SH}) + +INSTALL?= install + +include ${MK}/os.mk + +all: + +realinstall: ${BIN} ${CONF} ${CONF_APPEND} + if test -n "${DIR}"; then ${INSTALL} -d ${DESTDIR}${DIR} || exit $$?; fi + if test -n "${BIN}"; then ${INSTALL} ${BIN} ${DESTDIR}${DIR} || exit $$?; fi + if test -n "${INC}"; then ${INSTALL} -m 0644 ${INC} ${DESTDIR}${DIR} || exit $$?; fi + for x in ${CONF}; do \ + if ! test -e ${DESTDIR}${DIR}/$$x; then \ + ${INSTALL} -m 0644 $$x ${DESTDIR}${DIR} || exit $$?; \ + fi; \ + done + for x in ${CONF_APPEND}; do \ + if test -e ${DESTDIR}${DIR}/$$x; then \ + cat $$x >> ${DESTDIR}${DIR}/$$x || exit $$?; \ + else \ + ${INSTALL} -m 0644 $$x ${DESTDIR}${DIR} || exit $$?; \ + fi; \ + done + +install: realinstall ${INSTALLAFTER} + +clean: diff --git a/mk/subdir.mk b/mk/subdir.mk new file mode 100644 index 00000000..97502353 --- /dev/null +++ b/mk/subdir.mk @@ -0,0 +1,39 @@ +# Recursive rules +# Adapted from FreeBSDs bsd.subdir.mk +# Copyright 2007-2008 Roy Marples + +_+_ ?= + +ECHODIR ?= echo +_SUBDIR = @${_+_}for x in ${SUBDIR}; do \ + if test -d $$x; then \ + ${ECHODIR} "===> ${DIRPRFX}$$x (${@:realinstall=install})"; \ + cd $$x; \ + ${MAKE} ${@:realinstall=install} \ + DIRPRFX=${DIRPRFX}$$x/ || exit $$?; \ + cd ..; \ + fi; \ + if test -d $$x.${OS}; then \ + ${ECHODIR} "===> ${DIRPRFX}$$x.${OS} (${@:realinstall=install})"; \ + cd $$x.${OS}; \ + ${MAKE} ${@:realinstall=install} \ + DIRPRFX=${DIRPRFX}$$x.${OS}/ || exit $$?; \ + cd ..; \ + fi; \ + if test -d $$x.${SUBOS}; then \ + ${ECHODIR} "===> ${DIRPRFX}$$x.${SUBOS} (${@:realinstall=install})"; \ + cd $$x.${SUBOS}; \ + ${MAKE} ${@:realinstall=install} \ + DIRPRFX=${DIRPRFX}$$x.${SUBOS}/ || exit $$?; \ + cd ..; \ + fi; \ +done + +all: + ${_SUBDIR} +clean: + ${_SUBDIR} +realinstall: + ${_SUBDIR} +install: realinstall ${INSTALLAFTER} +depend: + ${_SUBDIR} diff --git a/mk/termcap.mk b/mk/termcap.mk new file mode 100644 index 00000000..62a251ac --- /dev/null +++ b/mk/termcap.mk @@ -0,0 +1,3 @@ +LIBTERMCAP?= -ltermcap +CFLAGS+= -DHAVE_TERMCAP +LDADD+= ${LIBTERMCAP} diff --git a/net.BSD/Makefile b/net.BSD/Makefile index 62462763..b2becc4e 100644 --- a/net.BSD/Makefile +++ b/net.BSD/Makefile @@ -1,5 +1,5 @@ -DIR = $(RC_LIB)/net -INC = $(CONTENTS) +DIR = ${RC_LIB}/net +INC = ${CONTENTS} -TOPDIR = .. -include $(TOPDIR)/default.mk +MK= ../mk +include ${MK}/scripts.mk diff --git a/net.Linux/Makefile b/net.Linux/Makefile index 62462763..b2becc4e 100644 --- a/net.Linux/Makefile +++ b/net.Linux/Makefile @@ -1,5 +1,5 @@ -DIR = $(RC_LIB)/net -INC = $(CONTENTS) +DIR = ${RC_LIB}/net +INC = ${CONTENTS} -TOPDIR = .. -include $(TOPDIR)/default.mk +MK= ../mk +include ${MK}/scripts.mk diff --git a/net/Makefile b/net/Makefile index 62462763..5ea18a1e 100644 --- a/net/Makefile +++ b/net/Makefile @@ -1,5 +1,5 @@ -DIR = $(RC_LIB)/net -INC = $(CONTENTS) +DIR= ${RC_LIB}/net +INC= ${CONTENTS} -TOPDIR = .. -include $(TOPDIR)/default.mk +MK= ../mk +include ${MK}/scripts.mk diff --git a/runlevels.BSD/Makefile b/runlevels.BSD/Makefile index 5a0e6b52..0abbb19e 100644 --- a/runlevels.BSD/Makefile +++ b/runlevels.BSD/Makefile @@ -1,7 +1,5 @@ -BOOT = dumpon hostid net.lo0 newsyslog savecore syscons syslogd -DEFAULT = local.rc mixer powerd +BOOT= dumpon hostid net.lo0 newsyslog savecore syscons syslogd +DEFAULT= local.rc mixer powerd -TOPDIR = .. -include $(TOPDIR)/runlevels.mk - -# vim: set ts=4 : +MK= ../mk +include ${MK}/runlevels.mk diff --git a/runlevels.Linux/Makefile b/runlevels.Linux/Makefile index 73a0acbe..8271bb56 100644 --- a/runlevels.Linux/Makefile +++ b/runlevels.Linux/Makefile @@ -1,7 +1,5 @@ -BOOT = consolefont keymaps modules net.lo procfs -DEFAULT = hdparm +BOOT= consolefont keymaps modules net.lo procfs +DEFAULT= hdparm -TOPDIR = .. -include $(TOPDIR)/runlevels.mk - -# vim: set ts=4 : +MK= ../mk +include ${MK}/runlevels.mk diff --git a/runlevels.mk b/runlevels.mk deleted file mode 100644 index 9794c480..00000000 --- a/runlevels.mk +++ /dev/null @@ -1,23 +0,0 @@ -# Handy runlevel stuff - -LEVELDIR = $(DESTDIR)/etc/runlevels -BOOTDIR = $(LEVELDIR)/boot -DEFAULTDIR = $(LEVELDIR)/default - -INSTALL ?= install - -install: - if ! test -d "$(BOOTDIR)"; then \ - $(INSTALL) -d $(BOOTDIR) || exit $$?; \ - for x in $(BOOT); do ln -snf /etc/init.d/"$$x" $(BOOTDIR)/"$$x" || exit $$?; done \ - fi - if ! test -d "$(DEFAULTDIR)"; then \ - $(INSTALL) -d $(DEFAULTDIR) || exit $$?; \ - for x in $(DEFAULT); do ln -snf /etc/init.d/"$$x" $(DEFAULTDIR)/"$$x" || exit $$?; done \ - fi - -all: -clean: -depend: - -# vim: set ts=4 : diff --git a/runlevels/Makefile b/runlevels/Makefile index 400e0003..5fe03721 100644 --- a/runlevels/Makefile +++ b/runlevels/Makefile @@ -1,11 +1,10 @@ -BOOT = bootmisc checkroot checkfs clock hostname localmount swap sysctl urandom -DEFAULT = local netmount +BOOT= bootmisc checkroot checkfs clock hostname localmount \ + swap sysctl urandom +DEFAULT= local netmount -LEVELDIR = $(DESTDIR)/etc/runlevels -BOOTDIR = $(LEVELDIR)/boot -DEFAULTDIR = $(LEVELDIR)/default +LEVELDIR= ${DESTDIR}/etc/runlevels +BOOTDIR= ${LEVELDIR}/boot +DEFAULTDIR= ${LEVELDIR}/default -TOPDIR = .. -include $(TOPDIR)/runlevels.mk - -# vim: set ts=4 : +MK= ../mk +include ${MK}/runlevels.mk diff --git a/sh.BSD/Makefile b/sh.BSD/Makefile index 19b68f36..3e5a37c1 100644 --- a/sh.BSD/Makefile +++ b/sh.BSD/Makefile @@ -1,5 +1,5 @@ -DIR = $(RC_LIB)/sh -BIN = $(CONTENTS) +DIR= ${RC_LIB}/sh +BIN= ${CONTENTS} -TOPDIR = .. -include $(TOPDIR)/default.mk +MK= ../mk +include ${MK}/scripts.mk diff --git a/sh.Linux/Makefile b/sh.Linux/Makefile index 19b68f36..3e5a37c1 100644 --- a/sh.Linux/Makefile +++ b/sh.Linux/Makefile @@ -1,5 +1,5 @@ -DIR = $(RC_LIB)/sh -BIN = $(CONTENTS) +DIR= ${RC_LIB}/sh +BIN= ${CONTENTS} -TOPDIR = .. -include $(TOPDIR)/default.mk +MK= ../mk +include ${MK}/scripts.mk diff --git a/sh/Makefile b/sh/Makefile index 225d9f15..ff4d31b2 100644 --- a/sh/Makefile +++ b/sh/Makefile @@ -1,23 +1,26 @@ -DIR = $(RC_LIB)/sh -INC = functions.sh init-common-post.sh rc-functions.sh rc-mount.sh -BIN = gendepends.sh net.sh runscript.sh +DIR= ${RC_LIB}/sh +INC= functions.sh init-common-post.sh rc-functions.sh rc-mount.sh +BIN= gendepends.sh net.sh runscript.sh -TOPDIR = .. -include $(TOPDIR)/default.mk +MK= ../mk # To get NET_LO -include Makefile.$(OS) +include ${MK}/os.mk +include Makefile.${SUBOS} -install:: +INSTALLAFTER= _installafter +_installafter: @# Handle lib correctly - if test $(LIBNAME) != "lib"; then \ - sed -i'.bak' -e 's,/lib/,/$(LIBNAME)/,g' $(DESTDIR)/$(RC_LIB)/sh/functions.sh || exit $$?; \ - rm -f $(DESTDIR)/$(RC_LIB)/sh/functions.sh.bak; \ - sed -i'.bak' -e 's,/lib/,/$(LIBNAME)/,g' $(DESTDIR)/$(RC_LIB)/sh/rc-functions.sh || exit $$?; \ - rm -f $(DESTDIR)/$(RC_LIB)/sh/rc-functions.sh.bak; \ + if test ${LIBNAME} != "lib"; then \ + sed -i'.bak' -e 's,/lib/,/${LIBNAME}/,g' ${DESTDIR}/${RC_LIB}/sh/functions.sh || exit $$?; \ + rm -f ${DESTDIR}/${RC_LIB}/sh/functions.sh.bak; \ + sed -i'.bak' -e 's,/lib/,/${LIBNAME}/,g' ${DESTDIR}/${RC_LIB}/sh/rc-functions.sh || exit $$?; \ + rm -f ${DESTDIR}/${RC_LIB}/sh/rc-functions.sh.bak; \ fi @# Provide an init script for the loopback interface - ln -snf $(RC_LIB)/sh/net.sh $(DESTDIR)/etc/init.d/$(NET_LO) || exit $$? - @# Put functions.sh into the init.d dir so 3rd part apps don't have to + ln -snf ${RC_LIB}/sh/net.sh ${DESTDIR}/etc/init.d/${NET_LO} || exit $$? + @# Put functions.sh into the init.d dir so 3rd party apps don't have to @# be multilib aware - ln -snf $(RC_LIB)/sh/functions.sh $(DESTDIR)/etc/init.d || exit $$? + ln -snf ${RC_LIB}/sh/functions.sh ${DESTDIR}/etc/init.d || exit $$? + +include ${MK}/scripts.mk diff --git a/src/.mk b/src/.mk deleted file mode 100644 index e69de29b..00000000 diff --git a/src/Makefile b/src/Makefile index 19922620..36a3b8e1 100644 --- a/src/Makefile +++ b/src/Makefile @@ -2,5 +2,5 @@ SUBDIR= libeinfo librc rc -TOPDIR= .. -include ${TOPDIR}/subdir.mk +MK= ../mk +include ${MK}/subdir.mk diff --git a/src/cc.mk b/src/cc.mk deleted file mode 100644 index 18eae7ee..00000000 --- a/src/cc.mk +++ /dev/null @@ -1,27 +0,0 @@ -# Copyright 2008 Roy Marples - -# Setup some good default CFLAGS - -CFLAGS?= -O2 -pipe -CSTD?= c99 - -# 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=${CSTD} \ - -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/depend.mk b/src/depend.mk deleted file mode 100644 index a4d717ae..00000000 --- a/src/depend.mk +++ /dev/null @@ -1,11 +0,0 @@ -# This only works for make implementations that always include a .depend if -# it exists. Only GNU make does not do this. - -# Copyright 2008 Roy Marples - -CLEANFILES+= .depend - -.depend: ${SRCS} - ${CC} ${CFLAGS} -MM ${SRCS} > .depend - -depend: .depend diff --git a/src/hidden-visibility.h b/src/hidden-visibility.h deleted file mode 100644 index bc7e338a..00000000 --- a/src/hidden-visibility.h +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Written by Mike Frysinger - * Placed in the Public Domain - */ - -#ifndef _HIDDEN_VISIBILITY_H_ -#define _HIDDEN_VISIBILITY_H_ - -#if defined(__ELF__) && defined(__GNUC__) -# define __hidden_asmname(name) __hidden_asmname1 (__USER_LABEL_PREFIX__, name) -# define __hidden_asmname1(prefix, name) __hidden_asmname2(prefix, name) -# define __hidden_asmname2(prefix, name) #prefix name -# define __hidden_proto(name, internal) \ - extern __typeof (name) name __asm__ (__hidden_asmname (#internal)) \ - __attribute__ ((visibility ("hidden"))); -# define __hidden_ver(local, internal, name) \ - extern __typeof (name) __EI_##name __asm__(__hidden_asmname (#internal)); \ - extern __typeof (name) __EI_##name __attribute__((alias (__hidden_asmname1 (,#local)))) -# define hidden_proto(name) __hidden_proto(name, __RC_##name) -# define hidden_def(name) __hidden_ver(__RC_##name, name, name); -#else -# define hidden_proto(name) -# define hidden_def(name) -#endif - -#endif diff --git a/src/includes/hidden-visibility.h b/src/includes/hidden-visibility.h new file mode 100644 index 00000000..bc7e338a --- /dev/null +++ b/src/includes/hidden-visibility.h @@ -0,0 +1,26 @@ +/* + * Written by Mike Frysinger + * Placed in the Public Domain + */ + +#ifndef _HIDDEN_VISIBILITY_H_ +#define _HIDDEN_VISIBILITY_H_ + +#if defined(__ELF__) && defined(__GNUC__) +# define __hidden_asmname(name) __hidden_asmname1 (__USER_LABEL_PREFIX__, name) +# define __hidden_asmname1(prefix, name) __hidden_asmname2(prefix, name) +# define __hidden_asmname2(prefix, name) #prefix name +# define __hidden_proto(name, internal) \ + extern __typeof (name) name __asm__ (__hidden_asmname (#internal)) \ + __attribute__ ((visibility ("hidden"))); +# define __hidden_ver(local, internal, name) \ + extern __typeof (name) __EI_##name __asm__(__hidden_asmname (#internal)); \ + extern __typeof (name) __EI_##name __attribute__((alias (__hidden_asmname1 (,#local)))) +# define hidden_proto(name) __hidden_proto(name, __RC_##name) +# define hidden_def(name) __hidden_ver(__RC_##name, name, name); +#else +# define hidden_proto(name) +# define hidden_def(name) +#endif + +#endif diff --git a/src/includes/rc-misc.h b/src/includes/rc-misc.h new file mode 100644 index 00000000..b7208e67 --- /dev/null +++ b/src/includes/rc-misc.h @@ -0,0 +1,129 @@ +/* + rc-misc.h + This is private to us and not for user consumption + */ + +/* + * Copyright 2007 Roy Marples + * All rights reserved + + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#ifndef __RC_MISC_H__ +#define __RC_MISC_H__ + +#include +#include +#include +#include + +#ifndef LIB +# define LIB "lib" +#endif + +#define RC_LEVEL_BOOT "boot" +#define RC_LEVEL_DEFAULT "default" + +#define RC_LIBDIR "/" LIB "/rc" +#define RC_SVCDIR RC_LIBDIR "/init.d" +#define RC_DEPTREE RC_SVCDIR "/deptree" +#define RC_RUNLEVELDIR "/etc/runlevels" +#define RC_INITDIR "/etc/init.d" +#define RC_CONFDIR "/etc/conf.d" + +#define RC_INITDIR_LOCAL "/usr/local/etc/init.d" +#define RC_CONFDIR_LOCAL "/usr/local/etc/conf.d" + +#define RC_KSOFTLEVEL RC_SVCDIR "/ksoftlevel" +#define RC_STARTING RC_SVCDIR "/rc.starting" +#define RC_STOPPING RC_SVCDIR "/rc.stopping" + +#define RC_SVCDIR_STARTING RC_SVCDIR "/starting" +#define RC_SVCDIR_INACTIVE RC_SVCDIR "/inactive" +#define RC_SVCDIR_STARTED RC_SVCDIR "/started" +#define RC_SVCDIR_COLDPLUGGED RC_SVCDIR "/coldplugged" + +#define RC_PLUGINDIR RC_LIBDIR "/plugins" + +#define ERRX fprintf (stderr, "out of memory\n"); exit (1) + +static inline void *xmalloc (size_t size) +{ + void *value = malloc (size); + + if (value) + return (value); + + ERRX; +} + +static inline void *xrealloc (void *ptr, size_t size) +{ + void *value = realloc (ptr, size); + + if (value) + return (value); + + ERRX; +} + +static inline char *xstrdup (const char *str) +{ + char *value; + + if (! str) + return (NULL); + + value = strdup (str); + + if (value) + return (value); + + ERRX; +} + +#undef ERRX + +static inline bool exists (const char *pathname) +{ + struct stat buf; + + return (stat (pathname, &buf) == 0); +} + +char *rc_conf_value (const char *var); +bool rc_conf_yesno (const char *var); +char **env_filter (void); +char **env_config (void); + +/* basename_c never modifies the argument. As such, if there is a trailing + * slash then an empty string is returned. */ +static inline const char *basename_c (const char *path) { + const char *slash = strrchr (path, '/'); + + if (slash) + return (++slash); + return (path); +} + +#endif diff --git a/src/includes/strlist.h b/src/includes/strlist.h new file mode 100644 index 00000000..3abe44ff --- /dev/null +++ b/src/includes/strlist.h @@ -0,0 +1,48 @@ +/* + strlist.h + String list macros for making char ** arrays + Based on a previous implementation by Martin Schlemmer + */ + +/* + * Copyright 2007 Roy Marples + * All rights reserved + + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#ifndef __STRLIST_H__ +#define __STRLIST_H__ + +/* FIXME: We should replace the macro with an rc_strlist_foreach + function, but I'm unsure how to go about this. */ + +/* Step through each entry in the string list, setting '_pos' to the + beginning of the entry. '_counter' is used by the macro as index, + but should not be used by code as index (or if really needed, then + it should usually by +1 from what you expect, and should only be + used in the scope of the macro) */ +#define STRLIST_FOREACH(_list, _pos, _counter) \ + if ((_list) && _list[0] && ! (_counter = 0)) \ + while ((_pos = _list[_counter++])) + +#endif /* __STRLIST_H__ */ diff --git a/src/lib.mk b/src/lib.mk deleted file mode 100644 index e7759173..00000000 --- a/src/lib.mk +++ /dev/null @@ -1,65 +0,0 @@ -# rules to build a library -# based on FreeBSD's bsd.lib.mk - -# Copyright 2008 Roy Marples - -LIBNAME?= lib - -SHLIB_NAME= lib${LIB}.so.${SHLIB_MAJOR} -SHLIB_LINK= lib${LIB}.so -SHLIBDIR?= /${LIBNAME} -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 - -PICFLAG?= -fPIC - -INCDIR?= /usr/include -INCMODE?= 0444 - -LIBDIR?= /usr/${LIBNAME} -LIBMODE?= 0444 - -.SUFFIXES: .So - -.c.So: - ${CC} ${PICFLAG} -DPIC ${CFLAGS} -c $< -o $@ - -all: depend ${_LIBS} - -lib${LIB}.a: ${OBJS} ${STATICOBJS} - @${ECHO} building static library $@ - ${AR} rc $@ $^ - ${RANLIB} $@ - -${SHLIB_NAME}: ${VERSION_MAP} -LDFLAGS+= -Wl,--version-script=${VERSION_MAP} - -${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: all - ${INSTALL} -d ${DESTDIR}${LIBDIR} - ${INSTALL} -m ${LIBMODE} lib${LIB}.a ${DESTDIR}${LIBDIR} - ${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} ${CLEANFILES} - -include ${TOPDIR}/depend.mk diff --git a/src/libeinfo/Makefile b/src/libeinfo/Makefile index da12ef78..7ef84abb 100644 --- a/src/libeinfo/Makefile +++ b/src/libeinfo/Makefile @@ -1,16 +1,16 @@ -TOPDIR= .. -include ${TOPDIR}/os.mk +MK= ../../mk +include ${MK}/os.mk LIB= einfo -SHLIB_MAJOR= 1 +SHLIB_MAJOR= 1 SRCS= libeinfo.c INCS= einfo.h -VERSION_MAP= einfo.map +VERSION_MAP= einfo.map SHLIBDIR= /${LIBNAME} -CFLAGS+= -I${TOPDIR} +CFLAGS+= -I../includes -include ${TOPDIR}/cc.mk -include ${TOPDIR}/lib.mk -include ${TOPDIR}/${TERMCAP}.mk +include ${MK}/cc.mk +include ${MK}/lib.mk +include ${MK}/${TERMCAP}.mk diff --git a/src/librc/Makefile b/src/librc/Makefile index 095988b8..888155b8 100644 --- a/src/librc/Makefile +++ b/src/librc/Makefile @@ -1,5 +1,5 @@ -TOPDIR= .. -include ${TOPDIR}/os.mk +MK= ../../mk +include ${MK}/os.mk LIB= rc SHLIB_MAJOR= 1 @@ -11,9 +11,9 @@ VERSION_MAP= rc.map CFLAGS+= -DLIB=\"${LIBNAME}\" LDADD+= ${LIBKVM} -CFLAGS+= -I${TOPDIR} +CFLAGS+= -I../includes SHLIBDIR= /${LIBNAME} -include ${TOPDIR}/cc.mk -include ${TOPDIR}/lib.mk +include ${MK}/cc.mk +include ${MK}/lib.mk diff --git a/src/ncurses.mk b/src/ncurses.mk deleted file mode 100644 index 66573d61..00000000 --- a/src/ncurses.mk +++ /dev/null @@ -1,3 +0,0 @@ -LIBTERMCAP?= -lncurses -CFLAGS+= -DHAVE_TERMCAP -LDADD+= ${LIBTERMCAP} diff --git a/src/os.mk b/src/os.mk deleted file mode 100644 index a4bef109..00000000 --- a/src/os.mk +++ /dev/null @@ -1,24 +0,0 @@ -# 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} -CFLAGS+= ${_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 deleted file mode 100644 index 7d0f2ca0..00000000 --- a/src/pam.mk +++ /dev/null @@ -1,6 +0,0 @@ -LIBPAM?= -lpam -CFLAGS+= -DHAVE_PAM -LDADD+= ${LIBPAM} - -PAMDIR?= /etc/pam.d -PAMMODE?= 0644 diff --git a/src/prog.mk b/src/prog.mk deleted file mode 100644 index 5da7e75f..00000000 --- a/src/prog.mk +++ /dev/null @@ -1,19 +0,0 @@ -# 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: depend ${PROG} - -${PROG}: ${SCRIPTS} ${OBJS} - ${CC} ${CFLAGS} ${LDFLAGS} ${PROGLDFLAGS} -o $@ ${OBJS} ${LDADD} - -clean: - rm -f ${OBJS} ${PROG} ${CLEANFILES} - -include ${TOPDIR}/depend.mk diff --git a/src/rc-misc.h b/src/rc-misc.h deleted file mode 100644 index b7208e67..00000000 --- a/src/rc-misc.h +++ /dev/null @@ -1,129 +0,0 @@ -/* - rc-misc.h - This is private to us and not for user consumption - */ - -/* - * Copyright 2007 Roy Marples - * All rights reserved - - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#ifndef __RC_MISC_H__ -#define __RC_MISC_H__ - -#include -#include -#include -#include - -#ifndef LIB -# define LIB "lib" -#endif - -#define RC_LEVEL_BOOT "boot" -#define RC_LEVEL_DEFAULT "default" - -#define RC_LIBDIR "/" LIB "/rc" -#define RC_SVCDIR RC_LIBDIR "/init.d" -#define RC_DEPTREE RC_SVCDIR "/deptree" -#define RC_RUNLEVELDIR "/etc/runlevels" -#define RC_INITDIR "/etc/init.d" -#define RC_CONFDIR "/etc/conf.d" - -#define RC_INITDIR_LOCAL "/usr/local/etc/init.d" -#define RC_CONFDIR_LOCAL "/usr/local/etc/conf.d" - -#define RC_KSOFTLEVEL RC_SVCDIR "/ksoftlevel" -#define RC_STARTING RC_SVCDIR "/rc.starting" -#define RC_STOPPING RC_SVCDIR "/rc.stopping" - -#define RC_SVCDIR_STARTING RC_SVCDIR "/starting" -#define RC_SVCDIR_INACTIVE RC_SVCDIR "/inactive" -#define RC_SVCDIR_STARTED RC_SVCDIR "/started" -#define RC_SVCDIR_COLDPLUGGED RC_SVCDIR "/coldplugged" - -#define RC_PLUGINDIR RC_LIBDIR "/plugins" - -#define ERRX fprintf (stderr, "out of memory\n"); exit (1) - -static inline void *xmalloc (size_t size) -{ - void *value = malloc (size); - - if (value) - return (value); - - ERRX; -} - -static inline void *xrealloc (void *ptr, size_t size) -{ - void *value = realloc (ptr, size); - - if (value) - return (value); - - ERRX; -} - -static inline char *xstrdup (const char *str) -{ - char *value; - - if (! str) - return (NULL); - - value = strdup (str); - - if (value) - return (value); - - ERRX; -} - -#undef ERRX - -static inline bool exists (const char *pathname) -{ - struct stat buf; - - return (stat (pathname, &buf) == 0); -} - -char *rc_conf_value (const char *var); -bool rc_conf_yesno (const char *var); -char **env_filter (void); -char **env_config (void); - -/* basename_c never modifies the argument. As such, if there is a trailing - * slash then an empty string is returned. */ -static inline const char *basename_c (const char *path) { - const char *slash = strrchr (path, '/'); - - if (slash) - return (++slash); - return (path); -} - -#endif diff --git a/src/rc/Makefile b/src/rc/Makefile index b6ae45a2..e804ec98 100644 --- a/src/rc/Makefile +++ b/src/rc/Makefile @@ -5,11 +5,9 @@ SRCS= checkpath.c fstabinfo.c mountinfo.c rc.c rc-depend.c \ CLEANFILES= version.h -TOPDIR= .. - -LDFLAGS+= -L${TOPDIR}/librc -L${TOPDIR}/libeinfo +LDFLAGS+= -L../librc -L../libeinfo LDADD+= -lutil -lrc -leinfo -CFLAGS+= -I${TOPDIR} -I${TOPDIR}/librc -I${TOPDIR}/libeinfo +CFLAGS+= -I../includes -I../librc -I../libeinfo BINDIR?= /sbin @@ -32,18 +30,19 @@ RC_SBINLINKS= mark_service_starting mark_service_started \ mark_service_coldplugged mark_service_failed \ rc-abort -include ${TOPDIR}/os.mk +MK= ../../mk +include ${MK}/os.mk CFLAGS+= -DLIB=\"${LIBNAME}\" -include ${TOPDIR}/cc.mk -include ${TOPDIR}/prog.mk +include ${MK}/cc.mk +include ${MK}/prog.mk -include ${TOPDIR}/${TERMCAP}.mk +include ${MK}/${TERMCAP}.mk LDADD+= ${LIBDL} ${LIBKVM} -include ${TOPDIR}/${PAM}.mk +include ${MK}/${PAM}.mk ${SRCS}: version.h version.h: - sed -n -e 's/^VERSION =[[:space:]]*\([^[:space:]]*\).*/#define VERSION "\1\"/p' ../../Makefile > version.h + sed -n -e 's/^VERSION=[[:space:]]*\([^[:space:]]*\).*/#define VERSION "\1\"/p' ../../Makefile > version.h if test -n "${BRANDING}"; then \ echo "#define BRANDING \"${BRANDING}\"" >> version.h; \ fi @@ -54,7 +53,7 @@ install: all ${INSTALL} -d ${DESTDIR}/bin for x in ${BINLINKS}; do ln -fs ${BINDIR}/${PROG} ${DESTDIR}/bin/$$x; done ${INSTALL} -d ${DESTDIR}/bin - for x in ${SBINLINKS}; do ln -fs ${BINDIR}/${PROG} ${DESTDIR}${BINDIR}/$$x; done + for x in ${SBINLINKS}; do ln -fs ${PROG} ${DESTDIR}${BINDIR}/$$x; done ${INSTALL} -d ${DESTDIR}/${LIBNAME}/${PROG}/bin for x in $(RC_BINLINKS); do ln -fs ${BINDIR}/${PROG} $(DESTDIR)/${LIBNAME}/${PROG}/bin/$$x; done ${INSTALL} -d ${DESTDIR}/${LIBNAME}/${PROG}/sbin diff --git a/src/strlist.h b/src/strlist.h deleted file mode 100644 index 3abe44ff..00000000 --- a/src/strlist.h +++ /dev/null @@ -1,48 +0,0 @@ -/* - strlist.h - String list macros for making char ** arrays - Based on a previous implementation by Martin Schlemmer - */ - -/* - * Copyright 2007 Roy Marples - * All rights reserved - - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#ifndef __STRLIST_H__ -#define __STRLIST_H__ - -/* FIXME: We should replace the macro with an rc_strlist_foreach - function, but I'm unsure how to go about this. */ - -/* Step through each entry in the string list, setting '_pos' to the - beginning of the entry. '_counter' is used by the macro as index, - but should not be used by code as index (or if really needed, then - it should usually by +1 from what you expect, and should only be - used in the scope of the macro) */ -#define STRLIST_FOREACH(_list, _pos, _counter) \ - if ((_list) && _list[0] && ! (_counter = 0)) \ - while ((_pos = _list[_counter++])) - -#endif /* __STRLIST_H__ */ diff --git a/src/termcap.mk b/src/termcap.mk deleted file mode 100644 index 62a251ac..00000000 --- a/src/termcap.mk +++ /dev/null @@ -1,3 +0,0 @@ -LIBTERMCAP?= -ltermcap -CFLAGS+= -DHAVE_TERMCAP -LDADD+= ${LIBTERMCAP} diff --git a/subdir.mk b/subdir.mk deleted file mode 100644 index 86efca04..00000000 --- a/subdir.mk +++ /dev/null @@ -1,27 +0,0 @@ -# Recursive rules -# Adapted from FreeBSDs bsd.subdir.mk -_+_ ?= + -ECHODIR ?= echo -_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} -depend: - ${_SUBDIR} -- cgit v1.2.3