diff options
author | Roy Marples <roy@marples.name> | 2008-01-10 16:35:59 +0000 |
---|---|---|
committer | Roy Marples <roy@marples.name> | 2008-01-10 16:35:59 +0000 |
commit | 43147845209873b0776bd75d363913fe25611f49 (patch) | |
tree | ab3295c30664476d8d05b0fe5fe9ace702ade5ea /mk | |
parent | 2643f2e605f102d2c2fa098d0cf5400d3795ed4a (diff) |
Allow for OS and SUBOS folders so we can introduce NetBSD scripts whilst keeping BSD for all BSD's.
Diffstat (limited to 'mk')
-rw-r--r-- | mk/.mk | 0 | ||||
-rw-r--r-- | mk/cc.mk | 27 | ||||
-rw-r--r-- | mk/depend.mk | 11 | ||||
-rw-r--r-- | mk/lib.mk | 65 | ||||
-rw-r--r-- | mk/ncurses.mk | 3 | ||||
-rw-r--r-- | mk/os.mk | 31 | ||||
-rw-r--r-- | mk/pam.mk | 6 | ||||
-rw-r--r-- | mk/prog.mk | 19 | ||||
-rw-r--r-- | mk/scripts.mk | 34 | ||||
-rw-r--r-- | mk/subdir.mk | 39 | ||||
-rw-r--r-- | mk/termcap.mk | 3 |
11 files changed, 238 insertions, 0 deletions
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 <roy@marples.name> + +# 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 <roy@marples.name> + +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 <roy@marples.name> + +# 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 <roy@marples.name> + +_+_ ?= + +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} |