CC=gcc

bin=theftdeterrent

PIXMAPS = pixmaps
DOC = doc
CONF = conf

datadir = /usr/share

pkgdatadir = $(datadir)/theftdeterrent
pkgpixmapsdir = /usr/local/pixmaps/theftdeterrent/
pkgdocdir = /etc/theftdeterrent
pkgconfdir = /etc/theftdeterrent
pkginitdir = /etc/init.d
pkgtssdir = /etc/ntru
pkgstudentdir = /home/student
pkgiconsdir = /etc/intel/icons

SHELL = /bin/sh
mkinstalldirs = $(SHELL) ./mkinstalldirs
INSTALL = /usr/bin/install -c

INSTALL_DATA = ${INSTALL} -m 644
INSTALL_PROGRAM = ${INSTALL}
INSTALL_SCRIPT = ${INSTALL}
INSTALL_STRIP_PROGRAM = ${SHELL} $(install_sh) -c -s


bindir=/usr/bin
libdir=/usr/lib


src_dir = ./src

Model_ConnMgmt = $(src_dir)/ConnMgmt
Model_Engine = $(src_dir)/Engine
Model_GUI = $(src_dir)/GUI/src
Model_InfoMgmt = $(src_dir)/InfoMgmt
Model_Provision = $(src_dir)/Provision
Model_TPMCtrl = $(src_dir)/TPMCtrl

Model_GUI = $(src_dir)/GUI/src

CFLAGS_ConnMgmt=-I./lib/GSoap/gsoap-linux-2.7/ -I./include/ -I$(Model_ConnMgmt) -g -DDEBUG
CFLAGS_Engine=-I./include -I$(Model_Engine) -I./include/TPMCtrl
CFLAGS_InfoMgmt=-I./include -I$(Model_InfoMgmt) 
CFLAGS_TPMCtrl=-I./include -I$(Model_TPMCtrl) -I./include/TPMCtrl
CFLAGS_GUI=-I./include `pkg-config gtk+-2.0 --cflags`

theftcontrol_OBJECTS= DeviceInfo.o OtherInfo.o PromptInfo.o ProxyInfo.o ServerInfo.o IniFile.o ConnMgmt.o  soapC.o  soapClient.o stdsoap2.o ListenBroadcast.o  ParseHttpPacket.o CurrentState.o TCEngine.o TPMInterface.o TPMCtrl.o Provision.o main.o support.o interface.o callbacks.o FormTCAgent.o resmgmt.o errormap.o tray.o

Link_lib = -lgtk-x11-2.0 -lgdk-x11-2.0 -latk-1.0 -lgdk_pixbuf-2.0 -lm -lpangocairo-1.0 -lfontconfig -lXext -lXrender -lXinerama -lXi -lXrandr -lXcursor -lXfixes -lpango-1.0 -lcairo -lX11 -lgobject-2.0 -lgmodule-2.0 -ldl -lglib-2.0  -lpthread  -lssl -lcrypto -ltsp -llowlevel_tray

all:
	$(CC) $(CFLAGS_ConnMgmt) -DConnMgmt_DEBUG -DWITH_OPENSSL -c -o ConnMgmt.o $(Model_ConnMgmt)/ConnMgmt.c 
	$(CC) $(CFLAGS_ConnMgmt) -DWITH_OPENSSL -c -o soapC.o $(Model_ConnMgmt)/soapC.c
	$(CC) $(CFLAGS_ConnMgmt) -DWITH_OPENSSL -c -o soapClient.o $(Model_ConnMgmt)/soapClient.c
	$(CC) $(CFLAGS_ConnMgmt) -DWITH_OPENSSL -c -o stdsoap2.o $(Model_ConnMgmt)/stdsoap2.c
	$(CC) $(CFLAGS_ConnMgmt) -DWITH_OPENSSL -c -o ListenBroadcast.o $(Model_ConnMgmt)/ListenBroadcast.c
	$(CC) $(CFLAGS_ConnMgmt) -DWITH_OPENSSL -c -o ParseHttpPacket.o $(Model_ConnMgmt)/ParseHttpPacket.c
	$(CC) $(CFLAGS_Engine) -c -o CurrentState.o $(Model_Engine)/CurrentState.c
	$(CC) $(CFLAGS_Engine) -c -o TCEngine.o $(Model_Engine)/TCEngine.c
	$(CC) $(CFLAGS_InfoMgmt) -c -o DeviceInfo.o $(Model_InfoMgmt)/DeviceInfo.c
	$(CC) $(CFLAGS_InfoMgmt) -c -o OtherInfo.o $(Model_InfoMgmt)/OtherInfo.c
	$(CC) $(CFLAGS_InfoMgmt) -c -o PromptInfo.o $(Model_InfoMgmt)/PromptInfo.c
	$(CC) $(CFLAGS_InfoMgmt) -c -o ProxyInfo.o $(Model_InfoMgmt)/ProxyInfo.c
	$(CC) $(CFLAGS_InfoMgmt) -c -o ServerInfo.o $(Model_InfoMgmt)/ServerInfo.c
	$(CC) $(CFLAGS_InfoMgmt) -c -o IniFile.o $(Model_InfoMgmt)/IniFile.c
	$(CC) $(CFLAGS_TPMCtrl) -c -o TPMCtrl.o $(Model_TPMCtrl)/TPMCtrl.c
	$(CC) $(CFLAGS_TPMCtrl) -c -o TPMInterface.o $(Model_TPMCtrl)/TPMInterface.c
	$(CC) $(CFLAGS_TPMCtrl) -c -o Provision.o $(Model_Provision)/Provision.c
	$(CC) $(CFLAGS_GUI) -c -o FormTCAgent.o $(Model_GUI)/FormTCAgent.c
	$(CC) $(CFLAGS_GUI) -c -o interface.o $(Model_GUI)/interface.c
	$(CC) $(CFLAGS_GUI) -c -o main.o $(Model_GUI)/main.c
	$(CC) $(CFLAGS_GUI) -c -o resmgmt.o $(Model_GUI)/resmgmt.c
	$(CC) $(CFLAGS_GUI) -c -o support.o $(Model_GUI)/support.c
	$(CC) $(CFLAGS_GUI) -c -o tray.o $(Model_GUI)/tray.c
	$(CC) $(CFLAGS_GUI) -c -o callbacks.o $(Model_GUI)/callbacks.c
	$(CC) $(CFLAGS_GUI) -c -o errormap.o $(Model_GUI)/errormap.c
	
	$(CC) -o $(bin) $(theftcontrol_OBJECTS) $(Link_lib)

install:
	if test -d ./pixmaps; then \
	  $(mkinstalldirs) $(DESTDIR)$(pkgpixmapsdir); \
	  for pixmap in ./pixmaps/*; do \
	    if test -f $$pixmap; then \
	      $(INSTALL_DATA) $$pixmap $(DESTDIR)$(pkgpixmapsdir); \
	    fi \
	  done \
	fi; \
	if test -d ./doc; then \
	  $(mkinstalldirs) $(DESTDIR)$(pkgdocdir); \
	  for docs in ./doc/*; do \
	    if test -f $$docs; then \
	      $(INSTALL_DATA) $$docs $(DESTDIR)$(pkgdocdir); \
	    fi \
	  done \
	fi; \
	if test -d ./doc/agent_files; then \
	  $(mkinstalldirs) $(DESTDIR)$(pkgdocdir)/agent_files; \
	  for docs in ./doc/agent_files/*; do \
	    if test -f $$docs; then \
	      $(INSTALL_DATA) $$docs $(DESTDIR)$(pkgdocdir)/agent_files; \
	    fi \
	  done \
	fi; \
	if test -d ./conf; then \
	  $(mkinstalldirs) $(DESTDIR)$(pkgconfdir); \
	  for confs in ./conf/*; do \
	    if test -f $$confs; then \
	      $(INSTALL_DATA) $$confs $(DESTDIR)$(pkgconfdir); \
	    fi \
	  done \
	fi; \
	if test -d ./student; then \
	$(mkinstalldirs) $(DESTDIR)$(pkgstudentdir); \
	fi; \
	if test -d ./icons; then \
	$(mkinstalldirs) $(DESTDIR)$(pkgiconsdir); \
	$(INSTALL_PROGRAM) ./icons/theftdeterrent.png $(DESTDIR)$(pkgiconsdir); \
	fi; \
	$(mkinstalldirs) $(DESTDIR)$(bindir); \
	$(INSTALL_PROGRAM) $(bin) $(DESTDIR)$(bindir); \
	$(INSTALL_PROGRAM) ./tools/tcsd $(DESTDIR)$(bindir); \
	$(INSTALL_PROGRAM) ./tools/theftdeterrent.sh $(DESTDIR)$(bindir); \
	$(INSTALL_PROGRAM) ./tools/set_tdagent_file  $(DESTDIR)$(pkgconfdir); \
	$(mkinstalldirs) $(DESTDIR)$(pkginitdir); \
	$(INSTALL_PROGRAM) ./init/tcsd  $(DESTDIR)$(pkginitdir); \
	$(mkinstalldirs) $(DESTDIR)$(pkgtssdir); \
	$(INSTALL_DATA) ./tss1_license.txt $(DESTDIR)$(pkgtssdir); \
	$(mkinstalldirs) $(DESTDIR)/usr/share/applications; \
	$(mkinstalldirs) $(DESTDIR)/etc/xdg/autostart; \
	$(INSTALL_DATA) ./theftdeterrent.desktop $(DESTDIR)/etc/xdg/autostart;
clean:
	rm  *.o
	rm theftdeterrent

	
