Add some .mk stubs to impersonate bsk .mk files to make writing our Makefiles easier. libeinfo, librc and rc now have their own seperate directories. More work is needed to tidy this up though.

This commit is contained in:
Roy Marples 2008-01-05 19:25:55 +00:00
parent 112fbde453
commit ac21d75300
48 changed files with 221 additions and 16 deletions

0
src/.mk Normal file
View File

View File

@ -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

View File

@ -1,2 +0,0 @@
LDLIBS_LIBRC += -lkvm
LDLIBS_RC += -lkvm

View File

@ -1,2 +0,0 @@
LDLIBS_RC += -Wl,-Bdynamic -ldl
CPPFLAGS += -D_BSD_SOURCE -D_XOPEN_SOURCE=500

View File

@ -1,2 +0,0 @@
LIBTERMCAP = -lncurses
include Makefile.termcap

View File

@ -1,2 +0,0 @@
CPPFLAGS_SSD = -DHAVE_PAM
LDLIBS_RC += -lpam

View File

@ -1,4 +0,0 @@
LIBTERMCAP ?= -ltermcap
CPPFLAGS_LIBEINFO = -DHAVE_TERMCAP
LDLIBS_LIBEINFO += $(LIBTERMCAP)
LDLIBS_RC += $(LIBTERMCAP)

25
src/cc.mk Normal file
View File

@ -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)

34
src/default.mk Normal file
View File

@ -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

55
src/lib.mk Normal file
View File

@ -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}

14
src/libeinfo/Makefile Normal file
View File

@ -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

14
src/librc/Makefile Normal file
View File

@ -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

3
src/ncurses.mk Normal file
View File

@ -0,0 +1,3 @@
LIBTERMCAP?= -lncurses
CPPFLAGS+= -DHAVE_TERMCAP
LDADD+= ${LIBTERMCAP}

24
src/os.mk Normal file
View File

@ -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))

6
src/pam.mk Normal file
View File

@ -0,0 +1,6 @@
LIBPAM?= -lpam
CPPFLAGS+= -DHAVE_PAM
LDADD+= ${LIBPAM}
PAMDIR?= /etc/pam.d
PAMMODE?= 0644

18
src/prog.mk Normal file
View File

@ -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}

3
src/termcap.mk Normal file
View File

@ -0,0 +1,3 @@
LIBTERMCAP?= -ltermcap
CPPFLAGS+= -DHAVE_TERMCAP
LDADD+= ${LIBTERMCAP}

25
subdir.mk Normal file
View File

@ -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)