#   FauBackup - Backup System, using a Filesystem for Storage
#   Copyright (C) 2000-2002 Martin Waitz, Dr. Volkmar Sieh
#   $Id: Makefile,v 1.11 2001/03/10 16:03:41 mnwaitz Exp $
#
#   This program is free software; you can redistribute it and/or modify
#   it under the terms of the GNU General Public License as published by
#   the Free Software Foundation; either version 2 of the License, or
#   (at your option) any later version.
#
#   This program is distributed in the hope that it will be useful,
#   but WITHOUT ANY WARRANTY; without even the implied warranty of
#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#   GNU General Public License for more details.
#
#   You should have received a copy of the GNU General Public License
#   along with this program; if not, write to the Free Software
#   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA


prefix=/usr/local

 #       #
###########
VERSION=0.5
###########
 #       #

BUILD=./=build
CC=gcc
CFLAGS+=-Wall

PROGS=$(BUILD)/faubackup $(BUILD)/faubackup-find $(BUILD)/faubackup-gather $(BUILD)/faubackup-scatter

all: build



#
# Building
#

build: $(BUILD) $(PROGS)

$(BUILD):
	mkdir $@


#
# Installation
#

install: build
	mkdir -p $(DESTDIR)/etc
	mkdir -p $(DESTDIR)$(prefix)/sbin
	mkdir -p $(DESTDIR)$(prefix)/share/man/man5
	mkdir -p $(DESTDIR)$(prefix)/share/man/man8
	for f in $(PROGS) ; do \
		install -m 755 $$f $(DESTDIR)$(prefix)/sbin/ ;\
	done
	cp -p faubackup.8 $(DESTDIR)$(prefix)/share/man/man8/
	cp -p faubackup-find.8 $(DESTDIR)$(prefix)/share/man/man8/
	cp -p faubackup-gather.8 $(DESTDIR)$(prefix)/share/man/man8/
	ln -s faubackup-gather.8 $(DESTDIR)$(prefix)/share/man/man8/faubackup-scatter.8
	cp -p faubackup.conf $(DESTDIR)/etc/
	cp -p faubackup.conf.5 $(DESTDIR)$(prefix)/share/man/man5/
uninstall:
	rm -f $(DESTDIR)/etc/faubackup.conf
	rm -f $(DESTDIR)$(prefix)/sbin/faubackup
	rm -f $(DESTDIR)$(prefix)/sbin/faubackup-find
	rm -f $(DESTDIR)$(prefix)/sbin/faubackup-gather
	rm -f $(DESTDIR)$(prefix)/sbin/faubackup-scatter
	rm -f $(DESTDIR)$(prefix)/share/man/man5/faubackup.conf.5
	rm -f $(DESTDIR)$(prefix)/share/man/man8/faubackup.8
	rm -f $(DESTDIR)$(prefix)/share/man/man8/faubackup-gather.8
	rm -f $(DESTDIR)$(prefix)/share/man/man8/faubackup-scatter.8


#############################################################################
#
# Rules:
#


clean:
	rm -rf $(BUILD)/

# Build Perl scripts
$(BUILD)/% : %.pl
	perl -c $<
	echo "#!`which perl` -w" > $@
	sed -e 's/@VERSION@/$(VERSION)/g' $< >> $@
	chmod +x $@

# Build C programs
$(BUILD)/%.o : %.c faubackup.h
	$(CC) -o $@ $(CFLAGS) $<
$(BUILD)/% : $(BUILD)/%.o
	$(LD) -o $@ $(LDFLAGS) $<

.PHONY: all clean dist-clean
