Skip to content
Permalink
182ae40f8d
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
215 lines (162 sloc) 6.78 KB
NAME=pbackup
VERSION_MAJOR = 0
VERSION_MINOR = 1
VERSION_PATCH = 0
VERSION_EXTRA = "beta"
VERSIONDATE = 2015
PREFIX=/usr
BINDIR=${PREFIX}/bin
SBINDIR=${PREFIX}/sbin
SYSCONFDIR=${PREFIX}/etc
LOCALSTATEDIR=${PREFIX}/var
########################################################################
DESTDIR=
########################################################################
VERSION_GIT := $(shell git describe --long 2>/dev/null)
VERSION = ${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}
ifeq (${VERSION_GIT},)
VERSIONFULL = "${NAME} v${VERSION} (${VERSION_EXTRA})"
else
VERSIONFULL = "${NAME} v${VERSION} (${VERSION_EXTRA}) [${VERSION_GIT}]"
endif
########################################################################
### set sysconfdir /etc if prefix /usr || /usr/local
ifneq (, $(filter /usr /usr/local, ${PREFIX}))
SYSCONFDIR = /etc
LOCALSTATEDIR = /var
SUFFIXDIR = /pbackup
else
SUFFIXDIR =
endif
########################################################################
### strip /${NAME} from SYSCONFDIR if set
ifeq ($(notdir ${SYSCONFDIR}),${NAME})
override SYSCONFDIR := $(patsubst %/,%,$(dir ${SYSCONFDIR}))
endif
### strip /${NAME} from LIBEXECDIR if set
ifeq ($(notdir ${LIBEXECDIR}),${NAME})
override LIBEXECDIR := $(patsubst %/,%,$(dir ${LIBEXECDIR}))
endif
########################################################################
PB_SQLITEDIR=${LOCALSTATEDIR}${SUFFIXDIR}/db
PB_SQLITEDB=${PB_SQLITEDIR}/pbackup.db
PB_VOLUMEDIR=${LOCALSTATEDIR}${SUFFIXDIR}/data
PB_LOGDIR=${LOCALSTATEDIR}/log${SUFFIXDIR}
PB_TMPDIR=${LOCALSTATEDIR}/tmp
PB_SERVERFILE=${SYSCONFDIR}${SUFFIXDIR}/server.dat
PB_JOBSFILE=${SYSCONFDIR}${SUFFIXDIR}/jobs.cfg
PB_EXECLUDESFILE=${SYSCONFDIR}${SUFFIXDIR}/excludes.dat
PB_RSYNCFILTERFILE=${SYSCONFDIR}${SUFFIXDIR}/rsync-filter.dat
PB_SSHPRIVATEKEY=${SYSCONFDIR}${SUFFIXDIR}/ssh/pbackup
########################################################################
quiet-command = $(if ${V},${1},$(if ${2},@echo ${2} && ${1}, @${1}))
quiet-install = $(call quiet-command,install -m ${1} ${2} ${3},"INSTALL ${3} [mode=${1}]")
quiet-installdir = $(call quiet-command,install -m ${1} -d ${2}," MKDIR ${2} [mode=${1}]")
quiet-installforuser = $(call quiet-command,install -m ${1} -o ${2} -g ${3} ${4} ${5},"INSTALL ${5} (user=${2} group=${3}) [mode=${1}]")
########################################################################
sed-rules = -e 's,@PREFIX@,${PREFIX},g' \
-e 's,@EPREFIX@,${EPREFIX},g' \
-e 's,@BINDIR@,${BINDIR},g' \
-e 's,@SBINDIR@,${SBINDIR},g' \
-e 's,@LIBDIR@,${LIBDIR},g' \
-e 's,@SYSCONFDIR@,${SYSCONFDIR},g' \
-e 's,@DEFCONFDIR@,${DEFCONFDIR},g' \
-e 's,@LIBEXECDIR@,${LIBEXECDIR},g' \
-e 's,@LOCALSTATEDIR@,${LOCALSTATEDIR},g' \
-e 's,@DATADIR@,${DATADIR},g' \
-e 's,@VERSION@,${VERSION},g' \
-e 's,@VERSIONFULL@,${VERSIONFULL},g' \
-e 's,@PB_SQLITEDIR@,${PB_SQLITEDIR},g' \
-e 's,@PB_SQLITEDB@,${PB_SQLITEDB},g' \
-e 's,@PB_VOLUMEDIR@,${PB_VOLUMEDIR},g' \
-e 's,@PB_LOGDIR@,${PB_LOGDIR},g' \
-e 's,@PB_SERVERFILE@,${PB_SERVERFILE},g' \
-e 's,@PB_JOBSFILE@,${PB_JOBSFILE},g' \
-e 's,@PB_EXECLUDESFILE@,${PB_EXECLUDESFILE},g' \
-e 's,@PB_RSYNCFILTERFILE@,${PB_RSYNCFILTERFILE},g' \
-e 's,@PB_SSHPRIVATEKEY@,${PB_SSHPRIVATEKEY},g'
########################################################################
%.o: %.c Makefile
$(call quiet-command,${CC} ${CFLAGS} -o $@ -c $<," CC $@")
%: %.c
%: %.o
$(call quiet-command,${CC} -o $@ $^ $(LDFLAGS) $(LDLIBS), " LINK $@")
%: %.in Makefile
$(call quiet-command,sed ${sed-rules} $< >$@, " GEN $@")
########################################################################
.PHONY: all
all: build
########################################################################
.PHONY: clean
clean:
mrproper: clean
mrproper clean:
@for i in $(CLEAN) ; do \
if [ -e "$$i" ] ; then \
if [ "$(V)" = 1 ] ; then \
echo "rm -f $$i" ; \
else \
echo " CLEAN $$i" ; \
fi ; \
rm -f $$i ; \
fi \
done
########################################################################
.PHONY: fix
fix: FIX += */*.pl.in
fix: FIX += */*.pl
fix: FIX += Makefile
fix: FIX += sql/*.sql
fix:
@for i in $(FIX) ; do \
if grep -q -m 1 -E '\s+$$' $$i ; then \
echo "FIX $$i" ; \
sed -i $$i -e 's/\s*$$//g' ; \
fi \
done
########################################################################
.PHONY: install
install:: all
install::
$(call quiet-installdir,0755,${DESTDIR}${BINDIR})
$(call quiet-installdir,0755,${DESTDIR}${SBINDIR})
$(call quiet-installdir,0755,${DESTDIR}${SYSCONFDIR})
$(call quiet-installdir,0755,${DESTDIR}${LOCALSTATEDIR})
install::
$(call quiet-installdir,0750,${DESTDIR}${SYSCONFDIR}${SUFFIXDIR})
$(call quiet-installdir,0750,${DESTDIR}${LOCALSTATEDIR}${SUFFIXDIR})
$(call quiet-installdir,0700,${DESTDIR}${SYSCONFDIR}${SUFFIXDIR}/ssh)
$(call quiet-installdir,0700,${DESTDIR}${PB_SQLITEDIR})
$(call quiet-installdir,0700,${DESTDIR}${PB_VOLUMEDIR})
$(call quiet-installdir,0750,${DESTDIR}${PB_LOGDIR})
########################################################################
build: bin/pbackup.pl
clean: CLEAN += bin/pbackup.pl
install:: bin/pbackup.pl
$(call quiet-install,0755,$<,${DESTDIR}${BINDIR}/$(basename $(notdir $<)))
build: bin/iview.pl
clean: CLEAN += bin/iview.pl
install:: bin/iview.pl
$(call quiet-install,0755,$<,${DESTDIR}${BINDIR}/$(basename $(notdir $<)))
build: extra/pbackup_remote.pl
clean: CLEAN += extra/pbackup_remote.pl
install:: extra/pbackup_remote.pl
$(call quiet-install,0755,$<,${DESTDIR}${SBINDIR}/$(basename $(notdir $<)))
install:: etc/jobs.cfg.sample
$(call quiet-installdir,0750,${DESTDIR}$(dir ${PB_JOBSFILE}))
$(call quiet-install,0644,$<,${DESTDIR}${PB_JOBSFILE}.sample)
install:: etc/rsync-filter.dat.sample
$(call quiet-installdir,0750,${DESTDIR}$(dir ${PB_RSYNCFILTERFILE}))
$(call quiet-install,0644,$<,${DESTDIR}${PB_RSYNCFILTERFILE}.sample)
install:: etc/excludes.dat.sample
$(call quiet-installdir,0750,${DESTDIR}$(dir ${PB_EXECLUDESFILE}))
$(call quiet-install,0644,$<,${DESTDIR}${PB_EXECLUDESFILE}.sample)
install:: etc/server.dat.sample
$(call quiet-installdir,0750,${DESTDIR}$(dir ${PB_SERVERFILE}))
$(call quiet-install,0644,$<,${DESTDIR}${PB_SERVERFILE}.sample)
pbackup.empty.db: sql/schema.sql
$(call quiet-command,sqlite3 $@ < $<, "SQLITE3 $@")
build: pbackup.empty.db
clean: CLEAN += pbackup.empty.db
install:: pbackup.empty.db
$(call quiet-install,0644,$<,${DESTDIR}${PB_SQLITEDB}.empty)