##
##  OSSP asgui - Accounting system graphical user interface
##  Copyright (c) 2002-2009 The OSSP Project (http://www.ossp.org/)
##  Copyright (c) 2002-2009 Ralf S. Engelschall <rse@engelschall.com>
##  Copyright (c) 2002-2009 Michael Schloh von Bennewitz <michael@schloh.com>
##  Copyright (c) 2002-2009 Cable & Wireless Telecommunications Services GmbH
##
##  This file is part of OSSP asgui, an accounting system graphical user
##  interface which can be found at http://asgui.europalab.com/.
##
##  Permission to use, copy, modify, and distribute this software for
##  any purpose with or without fee is hereby granted, provided that
##  the above copyright notice and this permission notice appear in all
##  copies.
##
##  THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
##  WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
##  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
##  IN NO EVENT SHALL THE AUTHORS AND COPYRIGHT HOLDERS AND THEIR
##  CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
##  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
##  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
##  USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
##  ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
##  OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
##  OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
##  SUCH DAMAGE.
##
##  Makefile.in: Autoconf Makefile template
##

@SET_MAKE@

DESTDIR         =
prefix          = @prefix@
exec_prefix     = @exec_prefix@
bindir          = @bindir@
sbindir         = @sbindir@
libdir          = @libdir@
datadir         = @datadir@
includedir      = @includedir@
mandir          = @mandir@

CC              = @CC@
CXX             = @CXX@
CFLAGS          = @CFLAGS@ @DEFS@
CXXFLAGS        = @CXXFLAGS@ @DEFS@
#CFLAGS          = @CFLAGS@ @DEFS@ -Wl,-Bstatic
#CXXFLAGS        = @CXXFLAGS@ @DEFS@ -Wl,-Bstatic
CPPFLAGS        = @CPPFLAGS@
CXXCPP          = @CXXCPP@
LDFLAGS         = @LDFLAGS@
LIBS            = @LIBS@

# CORBA-specific variables
CORBABASE       = @CORBABASE@
IDL             = $(CORBABASE)/bin/idl

# Qt-specific variables
QTCFLAGS        = @QT_CFLAGS@
QTLIBS          = @QT_LIBS@
QTBASE          = @QTBASE@
UIC             = @UIC@
MOC             = @MOC@

RM              = rm -f
STRIP           = strip
CHMOD           = chmod
RMDIR           = rmdir
SHTOOL          = ./shtool
POD2MAN         = pod2man
TRUE            = true

PROG_NAME       = as-gui
TARGET_PROGS    = as-gui
TARGET_MANS     = as-gui.1 as-gui.conf.5

SRCS            = as_main.cpp as_gui.cpp as_assist.cpp as_slot.cpp as_dataop.cpp as_except.cpp as_generic.cpp as_amount.cpp as_table.cpp as_panel.cpp as_reportpanel.cpp as_helpanel.cpp as_numdial.cpp as_sfile.cpp as_pref.cpp as_user.cpp as_rand.cpp as_crc.cpp as_uuid.cpp as_version.cpp

OBJS            = as_main.o as_gui.o as_assist.o as_slot.o as_dataop.o as_except.o as_generic.o as_amount.o as_table.o as_panel.o as_sfile.o as_pref.o as_reportpanel.o as_helpanel.o as_numdial.o as_user.o as_rand.o as_crc.o as_uuid.o as_version.o

GRAFX           = gfx/ossplogo.xpm

# IDL compiler generated
IDL_SRC         = as_stub.idl
IDL_OUT         = as_stub.cpp as_stub.h
IDL_OBJ         = as_stub.o

# Qt meta object compiler (MOC) generated
MOC_OUT         = moc_as_gui.cpp moc_as_table.cpp moc_as_panel.cpp moc_as_reportpanel.cpp moc_as_helpanel.cpp moc_as_numdial.cpp
MOC_OBJ         = moc_as_gui.o moc_as_table.o moc_as_panel.o moc_as_reportpanel.o moc_as_helpanel.o moc_as_numdial.o

.SUFFIXES:
.SUFFIXES: .c .cc .cpp .cxx .o
.c.o:
	$(CXX) -c $(CPPFLAGS) $(QTCFLAGS) $(CXXFLAGS) $<

.cc.o:
	$(CXX) -c $(CPPFLAGS) $(QTCFLAGS) $(CXXFLAGS) $<

.cpp.o:
	$(CXX) -c $(CPPFLAGS) $(QTCFLAGS) $(CXXFLAGS) $<

.cxx.o:
	$(CXX) -c $(CPPFLAGS) $(QTCFLAGS) $(CXXFLAGS) $<

all: Makefile $(TARGET_PROGS)

# Build the program conditionally including
# RPC stubs and skeleton objects
ifdef CORBABASE
$(PROG_NAME): $(OBJS) $(IDL_OBJ) $(MOC_OBJ)
	$(CXX) $(LDFLAGS) -o $@ $+ $(QTLIBS) $(LIBS)
else
$(PROG_NAME): $(OBJS) $(MOC_OBJ)
	$(CXX) $(LDFLAGS) -o $@ $+ $(QTLIBS) $(LIBS)
endif

moc_%.cpp: %.h
	$(MOC) $< -o $@

# Use the Trolltech uic to compile headers
# and implementation from ui XML
#%.h: %.ui
#	uic $< -o $@
#%.cpp: %.ui
#	uic -impl $*.h $< -o $@

# Run the IDL compiler over IDL source
# but avoid a make deps spaghetti nest
ifdef CORBABASE
$(SRCS):$(IDL_OUT)
$(IDL_OUT): $(IDL_SRC)
	$(IDL) --c++-suffix=cpp $<
endif

# Special treatment for help panel class, which needs the $datadir variable
as_helpanel.o: as_helpanel.cpp
	$(CXX) -c -DTITRAQ_DOCDIR=\"$(datadir)\" $(CPPFLAGS) $(QTCFLAGS) $(CXXFLAGS) $<

doc: as-gui.1 as-gui.conf.5 as-events.5 as-accounts.5

as-gui.1: as-gui.pod
	VS=`$(SHTOOL) version -lc -dshort as_version.cpp`; \
	VL=`$(SHTOOL) version -lc -dlong as_version.cpp`; \
	D=`$(SHTOOL) version -lc -dlong as_version.cpp | sed -e 's;.*(;;' -e 's;).*;;'`; \
	$(POD2MAN) --quotes=none \
               --section=1 --center="AS Accounting System" \
               --release="$$D" --date="as-gui $$VS" as-gui.pod | \
               sed -e "s;ASGUI_VERSION_STR;$$VL;" >as-gui.1

as-gui.conf.5: as-gui.conf.pod
	VS=`$(SHTOOL) version -lc -dshort as_version.cpp`; \
	VL=`$(SHTOOL) version -lc -dlong as_version.cpp`; \
	D=`$(SHTOOL) version -lc -dlong as_version.cpp | sed -e 's;.*(;;' -e 's;).*;;'`; \
	$(POD2MAN) --quotes=none \
               --section=5 --center="AS Preferences File" \
               --release="$$D" --date="as-gui $$VS" as-gui.conf.pod | \
               sed -e "s;ASGUI_VERSION_STR;$$VL;" >as-gui.conf.5

as-events.5: as-events.pod
	VS=`$(SHTOOL) version -lc -dshort as_version.cpp`; \
	VL=`$(SHTOOL) version -lc -dlong as_version.cpp`; \
	D=`$(SHTOOL) version -lc -dlong as_version.cpp | sed -e 's;.*(;;' -e 's;).*;;'`; \
	$(POD2MAN) --quotes=none \
               --section=5 --center="AS Events File" \
               --release="$$D" --date="as-gui $$VS" as-events.pod | \
               sed -e "s;ASGUI_VERSION_STR;$$VL;" >as-events.5

as-accounts.5: as-accounts.pod
	VS=`$(SHTOOL) version -lc -dshort as_version.cpp`; \
	VL=`$(SHTOOL) version -lc -dlong as_version.cpp`; \
	D=`$(SHTOOL) version -lc -dlong as_version.cpp | sed -e 's;.*(;;' -e 's;).*;;'`; \
	$(POD2MAN) --quotes=none \
               --section=5 --center="AS Accounts File" \
               --release="$$D" --date="as-gui $$VS" as-accounts.pod | \
               sed -e "s;ASGUI_VERSION_STR;$$VL;" >as-accounts.5

install: all
	$(SHTOOL) mkdir -f -p -m 755 $(DESTDIR)$(prefix)
	$(SHTOOL) mkdir -f -p -m 755 $(DESTDIR)$(bindir)
	$(SHTOOL) mkdir -f -p -m 755 $(DESTDIR)$(mandir)/man1
	$(SHTOOL) mkdir -f -p -m 755 $(DESTDIR)$(mandir)/man5
	$(SHTOOL) mkdir -f -p -m 755 $(DESTDIR)$(datadir)
	$(SHTOOL) install -c -s -m 755 as-gui $(DESTDIR)$(bindir)/as-gui
	$(SHTOOL) install -c -m 644 as-gui.1 $(DESTDIR)$(mandir)/man1/as-gui.1
	$(SHTOOL) install -c -m 644 as-gui.conf.5 $(DESTDIR)$(mandir)/man5/as-gui.conf.5
	$(SHTOOL) install -c -m 644 as-events.5 $(DESTDIR)$(mandir)/man5/as-events.5
	$(SHTOOL) install -c -m 644 as-accounts.5 $(DESTDIR)$(mandir)/man5/as-accounts.5
	$(SHTOOL) install -c -m 644 as-gui.html $(DESTDIR)$(datadir)/as-gui.html

uninstall:
	$(RM) $(DESTDIR)$(datadir)/as-gui.html
	$(RM) $(DESTDIR)$(mandir)/man5/as-accounts.5
	$(RM) $(DESTDIR)$(mandir)/man5/as-events.5
	$(RM) $(DESTDIR)$(mandir)/man5/as-gui.conf.5
	$(RM) $(DESTDIR)$(mandir)/man1/as-gui.1
	$(RM) $(DESTDIR)$(bindir)/as-gui
	$(RMDIR) $(DESTDIR)$(datadir) >/dev/null 2>&1 || $(TRUE)
	$(RMDIR) $(DESTDIR)$(mandir)/man5 >/dev/null 2>&1 || $(TRUE)
	$(RMDIR) $(DESTDIR)$(mandir)/man1 >/dev/null 2>&1 || $(TRUE)
	$(RMDIR) $(DESTDIR)$(mandir) >/dev/null 2>&1 || $(TRUE)
	$(RMDIR) $(DESTDIR)$(bindir) >/dev/null 2>&1 || $(TRUE)
	$(RMDIR) $(DESTDIR)$(prefix) >/dev/null 2>&1 || $(TRUE)

clean:
	$(RM) $(TARGET_PROGS) $(OBJS) $(IDL_OBJ) $(MOC_OBJ)
ifdef CORBABASE
	$(RM) $(IDL_OBJ)
endif
	$(RM) as_gui_pcre.tab *.core

distclean: clean
	$(RM) config.log config.status config.cache # Generated by ./configure
	$(RM) Makefile ac_config.h                  # Generated by ./configure
ifdef CORBABASE
	$(RM) $(IDL_OUT)                 # Generated by $(IDL)
endif
	$(RM) $(MOC_OUT)       # Generated by $(MOC)

realclean: distclean
	$(RM) configure ac_config.h.in*             # Generated by Autoconf
	$(RM) configure.lineno                      # Generated by Autoconf
	$(RM) shtool                                # Generated by Devtool

check: test
test: as-gui
	./as_gui_test.sh

.PHONY: doc install uninstall clean distclean realclean check test
