# Makefile for Excalibur under Linux

#
# x11-devel libs must be installed to compile
#
# libpthread must be installed to compile
#

#
# Static libpcap, libnet, gtk (2.2.x) libs are provided cuz I'm a nice guy :-)
#

#
# If you wonder how to build proper static gtk stuff, check :
#  http://cloud.prohosting.com/patos/download/gtk2/Makefile.static
#
# 1) unpack glib/gtk/atk/pango tar.gz from www.gtk.org into one directory
#
# 2) move to Glib, rebuild
# make clean && ./configure --disable-shared --enable-static --enable-threads=yes && make && make install
#
# 3) move to Pango, rebuild
#  - note that Hangul language support was removed since it relies on newer version of freetype that everyone might not have;
#  - you'll have to hand edit all Makefiles where "hangul" appears and also module-defs.h/module-defs-x.c
# make clean && ./configure --prefix=/var/cache/excalibur --disable-shared --enable-static --with-included-modules && make && make install
# export PKG_CONFIG_PATH=/var/cache/excalibur/lib/pkgconfig
#
# 4) move to Atk, rebuild
# make clean && ./configure --disable-shared --enable-static && make && make install
#
# 5) move to Gtk, rebuild
# make clean && ./configure --prefix=/var/cache/excalibur --enable-static && make && make install
#
# 6) Grok header files to excalibur directory
#  find <gtk_unpack_dir> -name "*.h" -exec cp --parent {} <excalibur_src_dir>/gui/linux/include/ \;
# 7) Grok libs files to excalibur directory
#  find <gtk_unpack_dir> -name "*.a" -exec cp {} <excalibur_src_dir>/gui/linux/lib/ \;
#
# 8) cleanup all the mess : make uninstall and clean for all but pango and gtk, 
#    make clean pango, remove all but /etc and /shared from /var/cache/excalibur
#    remove all .a from <excalibur_src>/gui/linux/lib except those explicitely linked below
#

PROG    =   excalibur

PRGOBJ  =	../globals/globvar.o ../globals/globfunc.o \
	        ../pluggin/addons.o ../pluggin/function_query.o \
                ../packet/packet.o ../packet/script.o \
                ../gui/getopt.o ../gui/gui_support.o \
                ../parse/read_iso_file.o ../parse/write_memory.o ../parse/search_memory.o \
                ../parse/read_write_preference.o ../parse/read_write_packet.o ../parse/read_write_script.o \
		./main_screen/main_screen.o ./main_screen/main_screen_callbacks.o \
		./main_screen/main_screen_support.o ./main_screen/main_screen_open_adapter.o \
		./main_screen/main_screen_directories_option.o ./main_screen/main_screen_script_options.o\
		./main_screen/main_screen_result_options.o ./main_screen/main_screen_query.o \
		./packet_decode/packet_decode.o ./packet_decode/packet_decode_callbacks.o \
		./packet_decode/packet_decode_long_detail_list.o ./packet_decode/packet_decode_last_iso.o \
		./packet_decode/packet_decode_support.o ./packet_decode/packet_decode_options.o \
		./msg_screens/file_selection.o ./msg_screens/popup_message.o ./msg_screens/yesno_message.o \
		./msg_screens/help_message.o \
		guivar.o guifunc.o main.o
		
# if you rather have a dynamically linked program to your installed gtk/glib, reverse comments below
# GTK_LIB = -L/usr/lib -lgtk2 -lgdk2 -lgmodule2 -lglib2 -L/usr/X11R6/lib -lXinerama -lXext -ldl
# GTK_PATH = -I/usr/lib/glib/include -I/usr/include/gtk-2.2 -I/usr/include/glib-2.2

GTK_LIB	=  ../gui/linux/lib/libgtk-x11-2.0.a  \
	   ../gui/linux/lib/libgdk_pixbuf-2.0.a ../gui/linux/lib/libgdk-x11-2.0.a \
	   ../gui/linux/lib/libatk-1.0.a ../gui/linux/lib/libpango-1.0.a \
	   ../gui/linux/lib/libgthread-2.0.a \
	   -L/usr/X11R6/lib -lXinerama -lXext -ldl

GTK_PATH	= -I../gui/linux/include/glib-2.2.0 -I../gui/linux/include/glib-2.2.0/glib \
		  -I../gui/linux/include/gtk+-2.2.0/gdk -I../gui/linux/include/gtk+-2.2.0/gtk \
		  -I../gui/linux/include/gtk+-2.2.0 \
	          -I../gui/linux/include/atk-1.2.0 -I../gui/linux/include/pango-1.2.0

PACKET_LIB	= ../packet/lib/linux/libpcap.a ../packet/lib/linux/libnet.a
PACKET_PATH	= -I../packet/include

THREAD_LIB	= -lm -lpthread

CFLAGS = $(GTK_PATH) $(PACKET_PATH) -c -O3 -funroll-all-loops -mcpu=pentium \
	 -D__EXCALIBUR_STD_PATH
CC = gcc -Wall

all: $(PROG) install clean

$(PROG): $(PRGOBJ)
		$(CC) -o $(PROG) $(PRGOBJ) $(GTK_LIB) $(PACKET_LIB) ${THREAD_LIB} 

install :
	strip $(PROG)
	\rm -f /usr/sbin/excalibur
	\rm -rf /var/cache/excalibur
	cp -f $(PROG) /usr/sbin/
	mkdir -m 755 -p /var/cache/excalibur
	cp -Rf ../binaries/iso /var/cache/excalibur/
	cp -Rf ../binaries/packets /var/cache/excalibur/
	cp -Rf ../binaries/scripts /var/cache/excalibur/
	cp -Rf ../binaries/linux/etc /var/cache/excalibur/
	cp -Rf ../binaries/linux/share /var/cache/excalibur/
	cp -f  ../binaries/_* /var/cache/excalibur/

clean :
	\rm -f *.o
	\rm -f excalibur
	\rm -f ./msg_screens/*.o
	\rm -f ./main_screen/*.o
	\rm -f ./packet_decode/*.o
	\rm -f ../globals/*.o
	\rm -f ../pluggin/*.o
	\rm -f ../gui/*.o
	\rm -f ../packet/*.o
	\rm -f ../parse/*.o
