include ../nessus.tmpl

GTKLIBS= $(GTKCONFIG_LIBS)
INCLUDE = ${include} $(GTKCONFIG_CFLAGS) $(GLIB_CFLAGS) -I../src/gui -I../src/openvas-lib -I../src/util
LIBS = $(X_LIBS) $(X_CFLAGS) $(GTKLIBS) $(GLIB_LIBS) $(GDC_LIB) \
	$(RUN_LIBS) $(C_R_LIB) -lm  -L../libnessus -lnessus-client -lssl -lcrypto $(DL_LIB) -lz $(SOCKET_LIB) 

OPENVAS_INCLUDE=`sh ./cflags`	
CFLAGS+=-Wall

# The name of the executable:
NESSUSCLIENT=OpenVAS-Client$(EXEEXT)

# Add some specific Windows compile options for Cygwin
SYSTEM:=$(shell uname -o)
ifeq ($(SYSTEM), Cygwin)
CFLAGS+=-mms-bitfields
LDFLAGS+=-mwindows
NESSUSCLIENT=OpenVAS-Client.exe
endif

OBJS = auth.o \
       nessus_plugin.o \
       comm.o \
       sighand.o \
       cli.o \
       parser.o \
       plugin_infos.o \
       plugin_cache.o \
       context.o \
       preferences.o \
       attack.o \
       report.o \
       report_save.o \
       report_utils.o \
       nbe_output.o \
       html_output.o \
       latex_output.o \
       text_output.o \
       xml_output_ng.o \
       html_graph_output.o \
       monitor_dialog.o \
       error_dlg.o \
       backend.o \
       data_mining.o \
       prefs_dialog.o \
       prefs_scope_tree.o \
       prefs_dialog_scan_opt.o \
       prefs_dialog_user.o \
       prefs_dialog_auth.o \
       prefs_dialog_plugins_prefs.o \
       prefs_plugins.o \
       prefs_plugins_tree.o \
       prefs_target.o \
       prefs_kb.o \
       listnotebook.o \
       read_target_file.o \
       regex.o \
       filter.o \
       openvas_certificates.o \
       openvas_certificate_file.o \
       openvas_ssh_login.o \
       openvas_ssh_key_create.o \
       sslui.o \
       subset.o \
       nessus.o

GTK_OBJS = prefs_comment.o prefs_context.o prefs_options.o prefs_report.o \
           prefs_dialog_prefs.o prefs_scan_assistant.o pdf_output.o readonly.o

GUI_OBJS = ../src/gui/about_dlg.o ../src/gui/severityfiltermngr_dlg.o \
           ../src/gui/slad_install.o ../src/gui/ssh_keys_dialog.o \
           ../src/gui/treeview_support.o \
           ../src/gui/ssh_key_info_form.o ../src/gui/nvt_pref_sshlogin.o \
           ../src/gui/severity_override_form.o

UTIL_OBJS = ../src/util/parseutils.o \
            ../src/util/file_utils.o \
            ../src/util/severity_filter.o \
            ../src/openvas-lib/hash_table_file.o \
            ../src/util/openvas_lsc_user_makensis.o\
            ../src/util/openvas_lsc_user_deb.o\
            ../src/util/openvas_lsc_user_rpm.o \
            ../src/util/openvas_lsc_target_prep.o


all : cflags ${make_bindir}/$(NESSUSCLIENT)


${make_bindir}/$(NESSUSCLIENT) : cflags $(NESSUSCLIENT)
	test -d ${make_bindir} || mkdir ${make_bindir}
	cp $(NESSUSCLIENT) ${make_bindir}

cflags :
	@echo "$(NESSUS_CFLAGS) $(NESSUS_DEFS) -DPACKAGE=\"OpenVAS-Client\" $(INCLUDE)"  | sed 's/\"/\\\"/g' > cflags.tmp
	@echo "echo \"`cat cflags.tmp`\"" > cflags
	@rm cflags.tmp
	@chmod +x cflags

$(NESSUSCLIENT) : cflags $(OBJS) $(if $(USE_GTK),$(GTK_OBJS) gui) \
   libnessus-client util
	$(CC) $(LDFLAGS) $(OBJS) $(if $(USE_GTK),$(GTK_OBJS) $(GUI_OBJS)) $(UTIL_OBJS) -o $(NESSUSCLIENT) $(LIBS)

libnessus-client :
	$(MAKE) -C ../libnessus

context.o : cflags context.c context.h ../src/gui/error_dlg.h comm.h plugin_cache.h
	$(CC) $(CFLAGS) $(OPENVAS_INCLUDE) -c context.c 

preferences.o : cflags preferences.c preferences.h ../src/gui/error_dlg.h globals.h
	$(CC) $(CFLAGS) $(OPENVAS_INCLUDE) -c preferences.c 

prefs_dialog.o : cflags prefs_dialog/prefs_dialog.c prefs_dialog/prefs_dialog.h\
 prefs_dialog/prefs_help.h globals.h context.h prefs_dialog/prefs_context.h\
 ../src/gui/error_dlg.h prefs_dialog/prefs_comment.h \
 xpm/connect_16.xpm xpm/connected.xpm xpm/connect_24.xpm xpm/disconnect_16.xpm\
 xpm/access_rules.xpm xpm/credentials.xpm xpm/general_prefs.xpm \
 xpm/knowledgebase.xpm xpm/plugins.xpm xpm/properties.xpm \
 xpm/target_selection.xpm
	$(CC) $(CFLAGS) $(OPENVAS_INCLUDE) -c prefs_dialog/prefs_dialog.c 

prefs_scope_tree.o : cflags prefs_dialog/prefs_scope_tree.c ../src/gui/error_dlg.h \
  globals.h preferences.h context.h prefs_dialog/prefs_context.h \
  prefs_dialog/prefs_dialog_auth.h xpm/connected.xpm
	$(CC) $(CFLAGS) $(OPENVAS_INCLUDE) -c prefs_dialog/prefs_scope_tree.c 

prefs_dialog_scan_opt.o : cflags prefs_dialog/prefs_dialog_scan_opt.c\
 prefs_dialog/prefs_dialog_scan_opt.h ../src/gui/error_dlg.h prefs_dialog/readonly.h \
 globals.h
	$(CC) $(CFLAGS) $(OPENVAS_INCLUDE) -c prefs_dialog/prefs_dialog_scan_opt.c 

prefs_target.o : cflags prefs_dialog/prefs_target.c\
 prefs_dialog/prefs_target.h read_target_file.h
	$(CC) $(CFLAGS) $(OPENVAS_INCLUDE) -c prefs_dialog/prefs_target.c 

prefs_dialog_user.o : cflags prefs_dialog/prefs_dialog_user.c globals.h \
 prefs_dialog/readonly.h
	$(CC) $(CFLAGS) $(OPENVAS_INCLUDE) -c prefs_dialog/prefs_dialog_user.c 

prefs_dialog_auth.o : cflags prefs_dialog/prefs_dialog_auth.c \
 prefs_dialog/prefs_help.h globals.h context.h ../src/gui/error_dlg.h
	$(CC) $(CFLAGS) $(OPENVAS_INCLUDE) -c prefs_dialog/prefs_dialog_auth.c 

nessus_plugin.o : cflags nessus_plugin.c
	$(CC) $(CFLAGS) $(OPENVAS_INCLUDE) -c nessus_plugin.c

prefs_plugins.o : cflags prefs_dialog/prefs_plugins.c ../src/gui/error_dlg.h\
                  prefs_dialog/prefs_help.h prefs_dialog/prefs_plugins_tree.h\
		  prefs_dialog/readonly.h globals.h
	$(CC) $(CFLAGS) $(OPENVAS_INCLUDE) -c prefs_dialog/prefs_plugins.c 

prefs_plugins_tree.o : cflags prefs_dialog/prefs_plugins_tree.c \
	prefs_dialog/prefs_plugins_tree.h filter.h \
	../src/gui/error_dlg.h prefs_dialog/prefs_help.h globals.h \
	plugin_infos.h xpm/warning_small.xpm
	$(CC) $(CFLAGS) $(OPENVAS_INCLUDE) -c prefs_dialog/prefs_plugins_tree.c 

openvas_certificates.o : cflags ../src/openvas-lib/openvas_certificates.c \
	../src/openvas-lib/openvas_certificates.h
	$(CC) $(CFLAGS) $(OPENVAS_INCLUDE) -c ../src/openvas-lib/openvas_certificates.c

openvas_certificate_file.o : cflags ../src/openvas-lib/openvas_certificate_file.c \
	../src/openvas-lib/openvas_certificate_file.c \
	../src/openvas-lib/openvas_certificates.h \
	../src/openvas-lib/openvas_certificates.c
	$(CC) $(CFLAGS) $(OPENVAS_INCLUDE) -c ../src/openvas-lib/openvas_certificate_file.c
	
openvas_ssh_login.o : cflags ../src/openvas-lib/openvas_ssh_login.c \
	../src/openvas-lib/openvas_ssh_login.h
	$(CC) $(CFLAGS) $(OPENVAS_INCLUDE) -c ../src/openvas-lib/openvas_ssh_login.c

openvas_ssh_key_create.o : cflags ../src/util/openvas_ssh_key_create.c \
	../src/util/openvas_ssh_key_create.h
	$(CC) $(CFLAGS) $(OPENVAS_INCLUDE) -c ../src/util/openvas_ssh_key_create.c

error_dlg.o : cflags ../src/gui/error_dlg.c ../src/gui/error_dlg.h globals.h   
	$(CC) $(CFLAGS) $(OPENVAS_INCLUDE) -c ../src/gui/error_dlg.c

ssh_key_info_form.o : cflags ../src/gui/ssh_key_info_form.c ../src/gui/ssh_key_info_form.h globals.h   
	$(CC) $(CFLAGS) $(OPENVAS_INCLUDE) -c ../src/gui/ssh_key_info_form.c

prefs_dialog_plugins_prefs.o : cflags prefs_dialog/prefs_dialog_plugins_prefs.c context.h \
	prefs_dialog/listnotebook.h prefs_dialog/readonly.h
	$(CC) $(CFLAGS) $(OPENVAS_INCLUDE) -c prefs_dialog/prefs_dialog_plugins_prefs.c 

prefs_kb.o : cflags prefs_dialog/prefs_kb.c prefs_dialog/prefs_help.h \
 context.h
	$(CC) $(CFLAGS) $(OPENVAS_INCLUDE) -c prefs_dialog/prefs_kb.c

prefs_context.o : cflags prefs_dialog/prefs_context.c globals.h context.h \
 preferences.h ../src/gui/error_dlg.h prefs_dialog/prefs_comment.h
	$(CC) $(CFLAGS) $(OPENVAS_INCLUDE) -c prefs_dialog/prefs_context.c

prefs_comment.o : cflags prefs_dialog/prefs_comment.c \
                  prefs_dialog/prefs_comment.h globals.h
	$(CC) $(CFLAGS) $(OPENVAS_INCLUDE) -c prefs_dialog/prefs_comment.c

prefs_options.o : cflags prefs_dialog/prefs_options.c \
                  prefs_dialog/prefs_options.h prefs_dialog/listnotebook.h \
		  globals.h
	$(CC) $(CFLAGS) $(OPENVAS_INCLUDE) -c prefs_dialog/prefs_options.c

prefs_report.o : cflags prefs_dialog/prefs_report.c \
 prefs_dialog/prefs_report.h globals.h xpm/computer.xpm xpm/network.xpm \
 xpm/warning_small.xpm xpm/info_small.xpm xpm/error_small.xpm xpm/nothing.xpm
	$(CC) $(CFLAGS) $(OPENVAS_INCLUDE) -c prefs_dialog/prefs_report.c

prefs_dialog_prefs.o : cflags prefs_dialog/prefs_dialog_prefs.c \
                  prefs_dialog/prefs_dialog_prefs.h globals.h
	$(CC) $(CFLAGS) $(OPENVAS_INCLUDE) -c prefs_dialog/prefs_dialog_prefs.c

prefs_scan_assistant.o : cflags prefs_dialog/prefs_scan_assistant.c \
 ../src/gui/error_dlg.h context.h prefs_dialog/prefs_context.h \
 prefs_dialog/prefs_scope_tree.h prefs_dialog/prefs_dialog.h \
 prefs_dialog/prefs_dialog_auth.h
	$(CC) $(CFLAGS) $(OPENVAS_INCLUDE) -c prefs_dialog/prefs_scan_assistant.c

listnotebook.o : cflags prefs_dialog/listnotebook.c \
		  prefs_dialog/listnotebook.h prefs_dialog/readonly.h
	$(CC) $(CFLAGS) $(OPENVAS_INCLUDE) -c prefs_dialog/listnotebook.c

readonly.o : cflags prefs_dialog/readonly.c \
		  prefs_dialog/readonly.h
	$(CC) $(CFLAGS) $(OPENVAS_INCLUDE) -c prefs_dialog/readonly.c

plugin_infos.o : cflags plugin_infos.c plugin_infos.h globals.h context.h
	$(CC) $(CFLAGS) $(OPENVAS_INCLUDE) -c plugin_infos.c 

plugin_cache.o : cflags plugin_cache.c plugin_cache.h nessus_plugin.h \
 ../src/gui/error_dlg.h context.h preferences.h globals.h
	$(CC) $(CFLAGS) $(OPENVAS_INCLUDE) -c plugin_cache.c 

main_window.o : cflags main_window.c main_window.h
	$(CC) $(CFLAGS) $(OPENVAS_INCLUDE) -c main_window.c 

nbe_output.o : cflags nbe_output.c nbe_output.h ../src/gui/error_dlg.h
	$(CC) $(CFLAGS) $(OPENVAS_INCLUDE) -c nbe_output.c 

html_output.o : cflags html_output.c html_output.h ../src/gui/error_dlg.h globals.h
	$(CC) $(CFLAGS) $(OPENVAS_INCLUDE) -c html_output.c 

text_output.o : cflags text_output.c text_output.h ../src/gui/error_dlg.h globals.h
	$(CC) $(CFLAGS) $(OPENVAS_INCLUDE) -c text_output.c 

xml_output_ng.o : cflags xml_output_ng.c  ../src/gui/error_dlg.h globals.h context.h
	$(CC) $(CFLAGS) $(OPENVAS_INCLUDE) -c xml_output_ng.c

latex_output.o : cflags latex_output.c latex_output.h globals.h
	$(CC) $(CFLAGS) $(OPENVAS_INCLUDE) -c latex_output.c 

html_graph_output.o : cflags html_graph_output.c html_graph_output.h ../src/gui/error_dlg.h globals.h
	$(CC) $(CFLAGS) $(OPENVAS_INCLUDE) -c html_graph_output.c 

pdf_output.o : cflags pdf_output.c pdf_output.h globals.h
	$(CC) $(CFLAGS) $(OPENVAS_INCLUDE) -c pdf_output.c

monitor_dialog.o : cflags monitor_dialog.c monitor_dialog.h globals.h \
 context.h report.h xpm/computer.xpm \
 prefs_dialog/prefs_context.h prefs_dialog/prefs_scope_tree.h
	$(CC) $(CFLAGS) $(OPENVAS_INCLUDE) -c monitor_dialog.c 

backend.o : cflags backend.c backend.h ../src/gui/error_dlg.h
	$(CC) $(CFLAGS) $(OPENVAS_INCLUDE) -c backend.c 	

data_mining.o : cflags data_mining.c data_mining.h subset.c subset.h
	$(CC) $(CFLAGS) $(OPENVAS_INCLUDE) -c data_mining.c 	

report_utils.o : cflags report_utils.h report_utils.c
	$(CC) $(CFLAGS) $(OPENVAS_INCLUDE) -c report_utils.c 

nessus.o : cflags nessus.c globals.h context.h preferences.h nessus.h
	$(CC) $(CFLAGS) $(OPENVAS_INCLUDE) -c nessus.c 

sighand.o : cflags sighand.c sighand.h ../src/gui/error_dlg.h context.h backend.h auth.h
	$(CC) $(CFLAGS) $(OPENVAS_INCLUDE) -c sighand.c 

auth.o : cflags auth.c globals.h
	$(CC) $(CFLAGS) $(OPENVAS_INCLUDE) -c auth.c 

comm.o : cflags comm.c ../src/gui/error_dlg.h globals.h context.h plugin_cache.h
	$(CC) $(CFLAGS) $(OPENVAS_INCLUDE) -c comm.c 

report.o : cflags report.c ../src/gui/error_dlg.h globals.h context.h \
 plugin_cache.h nessus_plugin.h \
 prefs_dialog/prefs_scope_tree.h prefs_dialog/prefs_context.h
	$(CC) $(CFLAGS) $(OPENVAS_INCLUDE) -c report.c 

report_save.o : cflags report_save.c preferences.h context.h ../src/gui/error_dlg.h
	$(CC) $(CFLAGS) $(OPENVAS_INCLUDE) -c report_save.c 	

parser.o : cflags parser.c ../src/gui/error_dlg.h globals.h
	$(CC) $(CFLAGS) $(OPENVAS_INCLUDE) -c parser.c 

attack.o : cflags attack.c globals.h context.h
	$(CC) $(CFLAGS) $(OPENVAS_INCLUDE) -c attack.c 

cli.o : cflags cli.c cli.h globals.h preferences.h
	$(CC) $(CFLAGS) $(OPENVAS_INCLUDE) -c cli.c

read_target_file.o : cflags read_target_file.c ../src/gui/error_dlg.h globals.h
	$(CC) $(CFLAGS) $(OPENVAS_INCLUDE) -c read_target_file.c

subset.o : cflags subset.c subset.h
	$(CC) $(CFLAGS) $(OPENVAS_INCLUDE) -c subset.c

openvas-lib:
	$(MAKE) -C ../src/openvas-lib

util: openvas-lib
	$(MAKE) -C ../src/util

gui: util
	$(MAKE) -C ../src/gui

regex.o : cflags regex.c 
	$(CC) $(CFLAGS) $(OPENVAS_INCLUDE) -c regex.c 

filter.o : cflags filter.c ../src/gui/error_dlg.h
	$(CC) $(CFLAGS) $(OPENVAS_INCLUDE) -c filter.c 

sslui.o : cflags sslui.c globals.h xpm/lock.xpm
	$(CC) $(CFLAGS) $(OPENVAS_INCLUDE) -c sslui.c

clean : 
	rm -f *.o $(NESSUSCLIENT) *~ cflags prefs_dialog/*.o
