# !/bin/sh
#  GTKmathplot makefile
#  Copyright (C)  2012, 2013  Ivano Primi  <ivprimi@libero.it>    
#
#   Copying and distribution of this file, with or without modification,
#   are permitted in any medium without royalty provided the copyright
#   notice and this notice are preserved.
#
CC=gcc
MAKE=make
CP= ./shtool install -c -m 644
MKDIR= ./shtool install -d
INSTALL_BIN= ./shtool install -m 755
INSTALL_DOC= ./shtool install -m 644
ECHO= ./shtool echo 
RM= rm -f
RMDIR= rmdir
COMPILER_FLAGS=-c -g -Wall -I.

OBJECTS=gui.o cairo_driver.o callbacks.o controls.o gnuplot.o main.o par2d.o par3d.o gr2d.o gr3d.o utils.o

LDFLAGS=-L./xxcalc-3.2.0
LIBS=-lxxcalc

# Leave the following line uncommented to build GTKmathplot under
# GNU/Linux or Unix(R):
TARGET=gtkmathplot

# Uncomment next line if you are going to build GTKmathplot under
# MinGW/Windows(R):
# TARGET=gtkmathplot.exe

# Root directory of the installation. The binaries will be installed
# in $(PREFIX)/bin, the documentation files in $(PREFIX)/doc/gtkmathplot. 
PREFIX=/usr/local
#PREFIX=/opt
#PREFIX=/usr
#PREFIX=$(HOME)

# BELOW THIS LINE YOU SHOULD NOT CHANGE ANYTHING

# BINDIR defines the (sub)directory of the system where TARGET
# will be installed; you should change
# this value only if you know what you are doing.
# Mind that, if $(PREFIX)/bin is not present in the searching path of
# the executable files (i.e. it is not present in the list 
# specified by the PATH environment variable), then you should
# add $(PREFIX)/bin to the list of directories of PATH.
BINDIR= $(PREFIX)/bin

# DOCDIR defines the (sub)directory where the documentation 
# files will be copied to (text of the license, help files and so on). 
# Also this location can be redefined, but you should do it only
# if you know what you are doing
DOCDIR= $(PREFIX)/doc/gtkmathplot

#Documents
DOCS            = ./LICENSE ./docs/introduction.txt ./docs/overview.txt ./docs/input_page.txt ./docs/output_page.txt ./docs/preferences.txt ./docs/examples.txt ./docs/gdat_files.txt ./docs/mathstuff.txt ./docs/README ./docs/fdl-1.3.txt

CFLAGS=$(COMPILER_FLAGS) -D_DOCDIR="\"$(DOCDIR)\"" -D_DOC1="\"introduction.txt\"" -D_DOC2="\"overview.txt\"" -D_DOC3="\"input_page.txt\"" -D_DOC4="\"output_page.txt\"" -D_DOC5="\"preferences.txt\"" -D_DOC6="\"examples.txt\"" -D_DOC7="\"mathstuff.txt\"" -D_DOC8="\"gdat_files.txt\""

GTK_CFLAGS=`pkg-config --cflags gtk+-2.0`
CAIRO_CFLAGS=`pkg-config --cflags cairo gtk+-2.0`
CAIRO_LIBS=`pkg-config --libs cairo gtk+-2.0`

all: $(TARGET)

gui.o: gui.c cairo_driver.h controls.h gr.h gr2d.h gr3d.h par2d.h par3d.h utils.h callbacks.h
	$(CC) $(CFLAGS) $(GTK_CFLAGS) $< -o $@

cairo_driver.o: cairo_driver.c gr2d.h gr.h gr3d.h utils.h cairo_driver.h controls.h par2d.h par3d.h
	$(CC) $(CFLAGS) $(CAIRO_CFLAGS) $< -o $@

callbacks.o: callbacks.c callbacks.h gr.h gui.h cairo_driver.h controls.h gr2d.h gr3d.h par2d.h par3d.h utils.h gnuplot.h
	$(CC) $(CFLAGS) $(GTK_CFLAGS) $< -o $@

controls.o: controls.c cairo_driver.h controls.h gr.h gr2d.h gr3d.h par2d.h par3d.h utils.h gnuplot.h
	$(CC) $(CFLAGS) $(GTK_CFLAGS) $< -o $@

gnuplot.o: gnuplot.c gr2d.h gr.h gr3d.h controls.h par2d.h par3d.h utils.h gnuplot.h
	$(CC) $(CFLAGS) $(GTK_CFLAGS) $< -o $@

main.o: main.c cairo_driver.h controls.h gr.h gr2d.h gr3d.h par2d.h par3d.h utils.h gui.h gnuplot.h
	$(CC) $(CFLAGS) $(GTK_CFLAGS) $< -o $@

par2d.o: par2d.c par2d.h gr2d.h gr.h gnuplot.h gr3d.h utils.h
	$(CC) $(CFLAGS) $< -o $@

par3d.o: par3d.c par3d.h gr3d.h gr.h gnuplot.h gr2d.h utils.h
	$(CC) $(CFLAGS) $< -o $@

gr2d.o: gr2d.c gr2d.h gr.h utils.h
	$(CC) $(CFLAGS) $< -o $@

gr3d.o: gr3d.c gr3d.h gr.h utils.h
	$(CC) $(CFLAGS) $< -o $@

utils.o: utils.c controls.h gr.h gr2d.h gr3d.h par2d.h par3d.h utils.h
	$(CC) $(CFLAGS) $(GTK_CFLAGS) $< -o $@

$(TARGET): $(OBJECTS)
	$(MAKE) -C ./xxcalc-3.2.0 all
	$(CC) $(OBJECTS) $(LDFLAGS) $(LIBS) $(CAIRO_LIBS) -o $@ 

install : all
	$(MKDIR) $(BINDIR)
	$(MKDIR) $(DOCDIR)
	$(CP) $(DOCS)    $(DOCDIR)
	$(INSTALL_BIN)   $(TARGET) $(BINDIR)

clean:
	$(RM) $(OBJECTS) $(TARGET)
	$(MAKE) -C ./xxcalc-3.2.0 clean

uninstall :
	$(RM)    $(DOCDIR)/*
	$(RM)    $(BINDIR)/$(TARGET)
	$(RMDIR) $(DOCDIR)
	@$(ECHO) "I have not removed the directories $(PREFIX) and $(BINDIR)."
	@$(ECHO) "If you may and want to do it, please do it yourself!"
