# Copyright (C)  2005  Daniele Zelante

# This file is part of copyblock.
# 
# copyblock 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

#@LICENSE
# $Id: GNUmakefile,v 1.1 2005/11/14 22:06:30 zeldan Exp $

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

ARCH := $(shell uname)

ifeq ($(ARCH),Linux)
	GNUNATIVE:=1
	EXESFX:=
	SYMLINK:=cp -l
endif

ifeq ($(ARCH),NetBSD)
	GNUNATIVE:=0
	EXESFX:=
	SYMLINK:=ln -sfh
endif

ifeq ($(ARCH),FreeBSD)
	GNUNATIVE:=0
	EXESFX:=
	SYMLINK:=ln -sfh
endif

ifeq ($(ARCH),CYGWIN_NT-5.0)
	GNUNATIVE:=1
	EXESFX:=.exe
	SYMLINK:=cp -l
endif

ifneq ($(GNUNATIVE),0)
	FIND := find
	TAR := tar
else
	FIND := gfind
	TAR := gtar
endif	


PREFIX ?= /usr/local

MKDIR := mkdir -p
MV := mv
RMRF := rm -rf

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

WARNINGS := \
	-Wall \
	-W \
	-Wpointer-arith \
	-Wcast-qual \
	-Wcast-align \
	-Wwrite-strings \
	-Wconversion \
	-Wsign-compare \
	-Wfloat-equal \
	-Wendif-labels \
	-Wshadow \
	-Wpointer-arith \
	-Woverloaded-virtual \
	-Wabi \
	-Wsynth
	

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

CXXFLAGS += $(WARNINGS) -O2

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

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


.PHONY: clean
.PHONY: tarball

all: $(BINARY)

$(BINARY): copyblock.cxx
	$(CXX) $(CPPFLAGS) $(CXXFLAGS) -o $@ $^


install: all
	$(MKDIR) $(BINDIR)
	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) $(PRODUCT)-*.*.*$(EXESFX)


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


