#    Copyright (C)  2005  Daniele Zelante
#
#    This file is part of copyblock.
#
#    This file 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.
#
#    copyblock 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 copyblock; if not, write to the Free Software
#    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA


#begin productinfo
PRODUCT := copyblock
RELEASE := 0.0.7
#end 


MKDIR := mkdir -p
CPLN := cp -l
MV := mv
RMRF := rm -rf

PREFIX ?= /usr/local

TIMESTAMP := $(strip $(shell date -u +%Y_%m_%d_%H_%M_%S_%N))

CPPFLAGS += -DPRODUCT=\"$(PRODUCT)\" 
CPPFLAGS += -DRELEASE=\"$(RELEASE)\"
CPPFLAGS += -DTIMESTAMP="\"$(TIMESTAMP)\""
CPPFLAGS += -D_FILE_OFFSET_BITS=64

CFLAGS += -Wall -W -O2

PRODVER := $(PRODUCT)-$(RELEASE)
BINARY := $(PRODVER)

BINDIR := $(PREFIX)/bin
TBFS := $(shell find . -maxdepth 1 -type f -name '*' ! -name '*-*.*.*' -printf '%f ')


all: $(BINARY)

$(BINARY): copyblock.c
	$(CC) $(CPPFLAGS) $(CFLAGS) -o $@ $^


install: all
	install -s $(BINARY) $(BINDIR)
	cd $(BINDIR); ln -sf $(BINARY) $(PRODUCT)
	install isoread.sh $(BINDIR)
	install floppyread.sh $(BINDIR)
	install floppywrite.sh $(BINDIR)
	install hdread.sh $(BINDIR)

clean:
	$(RM) $(BINARY)


tarball:
	$(MKDIR) .tmp/$(PRODVER)
	$(CPLN) $(TBFS) .tmp/$(PRODVER)
	cd .tmp; tar --owner root --group root -jcf $(PRODVER)-$(TIMESTAMP).tar.bz2 $(PRODVER)
	$(MV) .tmp/*.tar.bz2 ..
	$(RMRF) .tmp


