#!/bin/sh

########################################################
## This file is part of CodeLite project and 
## it is released under the terms of GPLv2 or later
## Copyrights Eran Ifrah (c) 2008
########################################################
	
createRevisionFile()
{
	file_exist=`test -f LiteEditor/svninfo.cpp`
	file_exist=$?

	cur_rev=`svn info | grep Revision | awk '{print $2;}'`
	if [ $file_exist -eq 1 ] 
	then
		## file does not exist, create an empty file
		touch LiteEditor/svninfo.cpp
	fi
	src_rev=`cat LiteEditor/svninfo.cpp | awk '{print $4;}' | sed s/\"//g | sed s/\;//g`

	if [ "$src_rev" != "$cur_rev" ]; then
		## generate the svninfo file again
		\cp /dev/null LiteEditor/svninfo.cpp
		echo "char *SvnRevision = \"${cur_rev}\";" >> LiteEditor/svninfo.cpp
		echo "" >> LiteEditor/svninfo.cpp
		echo "Generating svninfo file..."
	fi
	chmod +x ./le_makerevision.sh
}

createVariables()
{
	## set the compiler name 
	compiler_name="g++ "
	c_compiler_name="gcc "
	exe_name="Runtime/CodeLite"
	exe_name1="CodeLite"
	is_plugin=$1
	if [ "$arch" = "x86_64" ]; then
		compiler_name=${compiler_name}" -fPIC "
		c_compiler_name=${c_compiler_name}" -fPIC "
	fi

	## set the executable name
	if [ "$enable_debug" = "yes" ]; then
		exe_name=${exe_name}"UD"
		exe_name1=${exe_name1}"UD"
		objects_dir="Debug_gcc_unicode"
		configuration="Debug_gcc_unicode"
		debug_flag=" -g "
		ext=ud
		optimization=" -DREGEXP_UNICODE "
		wxcfg="--unicode=yes --debug=yes"
	else
		exe_name=${exe_name}"UR"
		exe_name1=${exe_name1}"UR"
		objects_dir="Release_gcc_unicode"
		configuration="Release_gcc_unicode"
		ext=u
		debug_flag=""
		optimization=" -O3 -DREGEXP_UNICODE "
		wxcfg="\"--unicode=yes --debug=no\""
	fi

	echo "OPT=${optimization}" >> Makefile
	echo "DEBUG=${debug_flag}" >> Makefile
	echo "CMP=${compiler_name} \$(DEBUG) \$(OPT) " >> Makefile
	echo "GCC=${c_compiler_name}" >> Makefile
	echo "EXE_NAME=${exe_name}" >> Makefile
	echo "EXE_NAME_NO_PATH=${exe_name1}" >> Makefile
	echo "OBJ_DIR=${objects_dir}" >> Makefile
	echo "EXT=${ext}" >> Makefile
	echo "OUTPUT_DIR=lib" >> Makefile
	echo "WXCFG=${wxcfg}" >> Makefile
	echo "" >> Makefile
	echo "CCFLAGS= -Wall \$(shell wx-config --cxxflags \$(WXCFG)) -fno-strict-aliasing -DASTYLE_LIB -DYY_NEVER_INTERACTIVE=1 -DGTK -DSCI_LEXER -DLINK_LEXERS -D__WX__ " >> Makefile
	echo "LINK_FLAGS =  -L${base_dir}/\$(OUTPUT_DIR) -lcurl -lplugin\$(EXT) -lcodelite\$(EXT) -lwxsqlite3\$(EXT) \\" >> Makefile
	echo "	-lwxscintilla\$(EXT) -L${base_dir}/sdk/sqlite3/lib \$(shell wx-config --libs \$(WXCFG))" >> Makefile
	

	if [ "$is_plugin" = "no" ]; then
		echo "INCLUDES := \$(INCLUDES) -ILiteEditor " >> Makefile 
	fi
	echo "" >> Makefile
	if [ "$os_name" != "Darwin" ] ; then
		echo "INCLUDES := \$(INCLUDES) \$(shell pkg-config --cflags gtk+-2.0)" >> Makefile
		echo "LINK_FLAGS := \$(LINK_FLAGS) \$(shell pkg-config --libs gtk+-2.0)" >> Makefile
	fi
	echo "INCLUDES := \$(INCLUDES) -I. -I${base_dir}/sdk/wxsqlite3/include -I${base_dir}/sdk/wxsqlite3/sqlite3/include -I${base_dir}/sdk/wxscintilla/include -I${base_dir}/sdk/wxscintilla/src/scintilla/include	 -I${base_dir}/sdk/wxscintilla/src/scintilla/src -I${base_dir}/Interfaces -I${base_dir}/Debugger -I${base_dir}/Plugin -I${base_dir}/CodeLite " >> Makefile 
	echo "" >> Makefile
	echo "" >> Makefile
}

createMainTargets()
{
	echo "## build tagrets" >> Makefile
	
	## default
	target_all="all :  pre_build CodeLite Scintilla SQLite SDK LiteEditor ctags Plugins "
	
	## if we are on Linux, print the post message
	if [ "$os_name" = "Linux" ]; then
		target_all="all :  pre_build CodeLite Scintilla SQLite SDK LiteEditor ctags Plugins post_build_msg"
	fi
	
	if [ "$os_name" = "Darwin" ]; then
		target_all="all :  pre_build CodeLite Scintilla SQLite SDK LiteEditor ctags Plugins mac_bundle"
	fi
	
	## add the "all" target to the makefile
	echo "${target_all}" >> Makefile
	echo "" >> Makefile

	echo "ctags: sdk/ctags/Makefile" >> Makefile
	echo "	cd sdk/ctags/ && \$(MAKE)" >> Makefile
	echo "" >> Makefile

	echo "sdk/ctags/Makefile:" >> Makefile
	echo "	@chmod +x sdk/ctags/configure" >> Makefile
	echo "	cd sdk/ctags && ./configure" >> Makefile 
	echo "" >> Makefile

	echo "pre_build:" >> Makefile
	echo "	./le_makerevision.sh" >> Makefile
	echo "	test -d  \$(OBJ_DIR) || mkdir \$(OBJ_DIR)" >> Makefile
	echo "	test -d  \$(OUTPUT_DIR) || mkdir \$(OUTPUT_DIR)" >> Makefile
	echo "" >> Makefile

	echo "clean: clean_plugins" >> Makefile
	echo "	\$(RM) \$(OUTPUT_DIR)/*.a \$(OUTPUT_DIR)/*.so" >> Makefile
	echo "	\$(RM) -fr \$(OBJ_DIR)" >> Makefile
	echo "" >> Makefile

	if [ "$os_name" = "Darwin" ]; then
		echo "mac_bundle: " >> Makefile
		echo "	@echo Creating Mac bundle..." >> Makefile
		echo "	@cd Runtime && ./make_mac_bundle.sh" >> Makefile
		echo "	@echo done" >> Makefile
		echo "" >> Makefile
	fi
}

createObjectList ()
{
	files_list=$1
	object_list_name=$2
	
	echo "${object_list_name} = \\"  >> Makefile
	for a_file in $files_list
	do
		a_file_no_ext=`basename $a_file .cxx`
		a_file_no_ext=`basename $a_file_no_ext .cpp`
		a_file_no_ext=`basename $a_file_no_ext .c`
		echo "	${configuration}/${a_file_no_ext}.o\\" >> Makefile
	done
	echo >> Makefile
}

# create list of files for scintilla
createRules_archive ()
{
	files_list=$1
	object_list_name=$2
	rule_name=$3
	libname=$4
	for a_file in $files_list
	do 

		a_file_with_ext=`basename $a_file`
		a_file_no_ext=`basename $a_file .cxx`
		a_file_no_ext=`basename $a_file_no_ext .cpp`
		a_file_no_ext=`basename $a_file_no_ext .c`
		file_extension=`basename $a_file | cut -d. -f2`
		
		if [ "$file_extension" = "c" ]; then
			echo ${configuration}/${a_file_no_ext}.o: ${a_file} ${configuration}/${a_file_no_ext}.o.d >> Makefile
			echo "	\$(GCC) \$(CCFLAGS) \$(INCLUDES) -c ${a_file} -o ${configuration}/${a_file_no_ext}.o" >> Makefile
			echo ${configuration}/${a_file_no_ext}.o.d:  >> Makefile
			echo "	\$(GCC) \$(CCFLAGS) \$(INCLUDES) -MT${configuration}/${a_file_no_ext}.o -MF${configuration}/${a_file_no_ext}.o.d  -MM ${a_file}" >> Makefile
		else
			echo ${configuration}/${a_file_no_ext}.o: ${a_file} ${configuration}/${a_file_no_ext}.o.d >> Makefile
			echo "	\$(CMP) \$(CCFLAGS) \$(INCLUDES) -c ${a_file} -o ${configuration}/${a_file_no_ext}.o" >> Makefile
			echo ${configuration}/${a_file_no_ext}.o.d:  >> Makefile
			echo "	\$(CMP) \$(CCFLAGS) \$(INCLUDES) -MT${configuration}/${a_file_no_ext}.o -MF${configuration}/${a_file_no_ext}.o.d  -MM ${a_file}" >> Makefile
		fi
	done
	echo >> Makefile
	
	echo "${rule_name}: \$(${object_list_name})" >> Makefile
	echo "	ar rcu \$(OUTPUT_DIR)/lib${libname}\$(EXT).a \$(${object_list_name})" >> Makefile
	echo "	ranlib \$(OUTPUT_DIR)/lib${libname}\$(EXT).a " >> Makefile
	echo >> Makefile
}

createRules_sharedObject ()
{
	files_list=$1
	object_list_name=$2
	rule_name=$3
	libname=$4
	for a_file in $files_list
	do 

		a_file_with_ext=`basename $a_file`
		a_file_no_ext=`basename $a_file .cxx`
		a_file_no_ext=`basename $a_file_no_ext .cpp`
		a_file_no_ext=`basename $a_file_no_ext .c`
		file_extension=`basename $a_file | cut -d. -f2`
		
		if [ "$file_extension" = "c" ]; then
			echo ${configuration}/${a_file_no_ext}.o: ${a_file} ${configuration}/${a_file_no_ext}.o.d >> Makefile
			echo "	\$(GCC) \$(CCFLAGS) \$(INCLUDES) -c ${a_file} -o ${configuration}/${a_file_no_ext}.o" >> Makefile
			echo ${configuration}/${a_file_no_ext}.o.d:  >> Makefile
			echo "	\$(GCC) \$(CCFLAGS) \$(INCLUDES) -MT${configuration}/${a_file_no_ext}.o -MF${configuration}/${a_file_no_ext}.o.d  -MM ${a_file}" >> Makefile
		else
			echo ${configuration}/${a_file_no_ext}.o: ${a_file} ${configuration}/${a_file_no_ext}.o.d >> Makefile
			echo "	\$(CMP) \$(CCFLAGS) \$(INCLUDES) -c ${a_file} -o ${configuration}/${a_file_no_ext}.o" >> Makefile
			echo ${configuration}/${a_file_no_ext}.o.d:  >> Makefile
			echo "	\$(CMP) \$(CCFLAGS) \$(INCLUDES) -MT${configuration}/${a_file_no_ext}.o -MF${configuration}/${a_file_no_ext}.o.d  -MM ${a_file}" >> Makefile
		fi
	done
	echo >> Makefile
	
	shared_obj_switch=" -shared "
	if [ "$os_name" = "Darwin" ]; then
		shared_obj_switch=" -dynamiclib "
	fi
	
	echo "${rule_name}: \$(${object_list_name})" >> Makefile
	echo "	\$(CMP) ${shared_obj_switch} -o ${base_dir}/\$(OUTPUT_DIR)/${libname}.so \$(${object_list_name}) \$(LINK_FLAGS)" >> Makefile
	echo >> Makefile
}

createRules_exe ()
{
	files_list=$1
	object_list_name=$2
	rule_name=$3
	exename=$4
	for a_file in $files_list
	do 

		a_file_with_ext=`basename $a_file`
		a_file_no_ext=`basename $a_file .cxx`
		a_file_no_ext=`basename $a_file_no_ext .cpp`
		a_file_no_ext=`basename $a_file_no_ext .c`
		file_extension=`basename $a_file | cut -d. -f2`
		
		if [ "$file_extension" = "c" ]; then
			echo ${configuration}/${a_file_no_ext}.o: ${a_file} ${configuration}/${a_file_no_ext}.o.d >> Makefile
			echo "	\$(GCC) \$(CCFLAGS) \$(INCLUDES) -c ${a_file} -o ${configuration}/${a_file_no_ext}.o" >> Makefile
			echo ${configuration}/${a_file_no_ext}.o.d:  >> Makefile
			echo "	\$(GCC) \$(CCFLAGS) \$(INCLUDES) -MT${configuration}/${a_file_no_ext}.o -MF${configuration}/${a_file_no_ext}.o.d  -MM ${a_file}" >> Makefile
		else
			echo ${configuration}/${a_file_no_ext}.o: ${a_file} ${configuration}/${a_file_no_ext}.o.d >> Makefile
			echo "	\$(CMP) \$(CCFLAGS) \$(INCLUDES) -c ${a_file} -o ${configuration}/${a_file_no_ext}.o" >> Makefile
			echo ${configuration}/${a_file_no_ext}.o.d:  >> Makefile
			echo "	\$(CMP) \$(CCFLAGS) \$(INCLUDES) -MT${configuration}/${a_file_no_ext}.o -MF${configuration}/${a_file_no_ext}.o.d  -MM ${a_file}" >> Makefile
		fi
	done
	echo >> Makefile
	
	echo "${rule_name}: \$(${object_list_name})" >> Makefile
	echo "	\$(CMP) -o ${exename} \$(${object_list_name}) \$(LINK_FLAGS)" >> Makefile
	echo >> Makefile
}

createPluginMakefile()
{
	plugin_path=$1
	plugin_name=$2
	install_path=$3
	
	echo "Generating ${plugin_path}/Makefile..."
	current_wd=`pwd`
	cd ${plugin_path}
	
	## remove old Makefile
	rm -fr Makefile
	
	## set the plugin path relative to the main path
	base_dir=".."

	createVariables "yes"
	createObjectList "*.cpp" "${plugin_name}Objects"
	createPluginTargets "${plugin_name}"	
	createRules_sharedObject "*.cpp" "${plugin_name}Objects" "${plugin_name}" "${plugin_name}"

	## restore the path
	cd ${current_wd}
	
	echo ".PHONY: ${plugin_name} ${plugin_name}_clean ${plugin_name}_install" >> Makefile
	echo "${plugin_name}:" >> Makefile
	echo "	cd ${plugin_path} && \$(MAKE) -f Makefile" >> Makefile
	echo "" >> Makefile

	echo "${plugin_name}_clean:" >> Makefile
	echo "	cd ${plugin_path} && \$(MAKE) -f Makefile clean" >> Makefile
	echo "" >> Makefile
	
	echo "${plugin_name}_install:" >> Makefile
	echo "	cp \$(OUTPUT_DIR)/${plugin_name}.so ${install_path}" >> Makefile
	echo "" >> Makefile
}

createPluginTargets()
{
	plugin_name=$1
	echo "## build tagrets" >> Makefile
	echo "all :  pre_build ${plugin_name}" >> Makefile
	echo "" >> Makefile
	echo "pre_build:" >> Makefile
	echo "	@echo =================================================" >> Makefile
	echo "	@echo Building target ${plugin_name}" >> Makefile
	echo "	@echo =================================================" >> Makefile
	echo "	test -d  \$(OBJ_DIR) || mkdir \$(OBJ_DIR)" >> Makefile
	echo "	test -d  ${base_dir}/\$(OUTPUT_DIR) || mkdir ${base_dir}/\$(OUTPUT_DIR)" >> Makefile
	echo "" >> Makefile
	echo "clean:" >> Makefile
	echo "	\$(RM) ${base_dir}/\$(OUTPUT_DIR)/${plugin_name}.so" >> Makefile
	echo "	\$(RM) -fr \$(OBJ_DIR)" >> Makefile
	echo "" >> Makefile

}

createInstallTarget()
{
	echo "install: core_install plugins_install" >> Makefile
	echo "" >> Makefile
	
	echo "core_install:" >> Makefile
	echo "	@echo installing CodeLite" >> Makefile
	echo "	@\$(RM) -fr  /usr/local/bin/CodeLite" >> Makefile
	echo "	@\$(RM) -fr  /usr/local/share/codelite" >> Makefile
	echo "	@mkdir -p /usr/local/bin" >> Makefile
	echo "	@cp \$(EXE_NAME) /usr/local/bin/" >> Makefile
	echo "	@ln -s /usr/local/bin/\$(EXE_NAME_NO_PATH) /usr/local/bin/CodeLite" >> Makefile
	echo "	@cp Runtime/le_dos2unix.sh /usr/local/bin/" >> Makefile
	echo "	@cp Runtime/le_exec.sh /usr/local/bin/" >> Makefile
	echo "	@cp Runtime/le_killproc.sh /usr/local/bin/" >> Makefile
	echo "	@chmod +x /usr/local/bin/le_dos2unix.sh" >> Makefile
	echo "	@chmod +x /usr/local/bin/le_exec.sh" >> Makefile
	echo "	@chmod +x /usr/local/bin/le_killproc.sh" >> Makefile
	echo "	@cp sdk/ctags/ctags-le /usr/local/bin/" >> Makefile
	echo "	@mkdir -p /usr/local/share/codelite" >> Makefile
	echo "	@mkdir -p /usr/local/share/codelite/config" >> Makefile
	echo "	@mkdir -p /usr/local/share/codelite/debuggers" >> Makefile
	echo "	@mkdir -p /usr/local/share/codelite/templates" >> Makefile
	echo "	@mkdir -p /usr/local/share/codelite/plugins" >> Makefile
	echo "	@mkdir -p /usr/local/share/codelite/images" >> Makefile
	echo "	@mkdir -p /usr/local/share/codelite/rc" >> Makefile
	echo "	@mkdir -p /usr/local/share/codelite/lexers" >> Makefile
	echo "	@mkdir -p /usr/local/share/codelite/lexers/Default" >> Makefile
	echo "	@mkdir -p /usr/local/share/codelite/lexers/BlackTheme" >> Makefile
	echo "	@cp -fr Runtime/config/*.xml /usr/local/share/codelite/config/" >> Makefile
	echo "	@cp -fr Runtime/config/debuggers.xml.gtk /usr/local/share/codelite/config/debuggers.xml" >> Makefile
	echo "	@cp -fr Runtime/config/codelite.xml.default /usr/local/share/codelite/config/codelite.xml.default" >> Makefile
	echo "	@cp -fr Runtime/config/codelite.layout.default /usr/local/share/codelite/config/codelite.layout" >> Makefile
	echo "	@cp -fr Runtime/codelite.desktop /usr/share/applications/codelite.desktop" >> Makefile
	echo "	@cp -fpr Runtime/rc/*.xrc /usr/local/share/codelite/rc/" >> Makefile
	echo "	@cp -fpr Runtime/templates/* /usr/local/share/codelite/templates/" >> Makefile
	echo "	@chmod -R +w /usr/local/share/codelite/templates/* " >> Makefile
	echo "	@cp -fpr Runtime/lexers/Default/*.xml /usr/local/share/codelite/lexers/Default/" >> Makefile
	echo "	@cp -fpr Runtime/lexers/BlackTheme/*.xml /usr/local/share/codelite/lexers/BlackTheme/" >> Makefile
	echo "	@cp -fpr lib/Debugger.so /usr/local/share/codelite/debuggers/" >> Makefile
	echo "	@cp -fpr lib/CodeFormatter.so /usr/local/share/codelite/plugins/" >> Makefile
	echo "	@cp -fpr lib/Subversion.so /usr/local/share/codelite/plugins/" >> Makefile
#	echo "	@cp -fpr lib/ReferenceAnalyser.so /usr/local/share/codelite/plugins/" >> Makefile
	echo "	@cp -fpr lib/cscope.so /usr/local/share/codelite/plugins/" >> Makefile
	echo "	@cp -fpr lib/Gizmos.so /usr/local/share/codelite/plugins/" >> Makefile
	echo "	@cp -fpr Runtime/index.html /usr/local/share/codelite/" >> Makefile
	echo "	@cp -fpr Runtime/astyle.sample /usr/local/share/codelite/" >> Makefile
	echo "	@cp -fpr Runtime/svnreport.html /usr/local/share/codelite/" >> Makefile
	echo "	@cp -fpr Runtime/images/*.png /usr/local/share/codelite/images/" >> Makefile
	echo "	@cp -fpr Runtime/config/accelerators.conf.default /usr/local/share/codelite/config/" >> Makefile
	echo "	@cp -fpr Runtime/codelite.desktop /usr/share/applications/" >> Makefile
	echo "	@cp -fpr Runtime/codelite.desktop ~/Desktop/" >> Makefile
	echo "	@mkdir -p /usr/local/include/UnitTest++/" >> Makefile
	echo "	@mkdir -p /usr/local/lib/" >> Makefile
	echo "	@cp -fr Runtime/sdk/lib/unix/*.a /usr/local/lib/" >> Makefile
	echo "	@cp -fr Runtime/sdk/include/UnitTest++/* /usr/local/include/UnitTest++/" >> Makefile
	echo "	@chmod -R 777 /usr/local/share/codelite" >> Makefile
	echo "	@chmod +x /usr/local/bin/CodeLite" >> Makefile
	echo "" >> Makefile
}

createUnInstallTarget()
{
	echo "uninstall: " >> Makefile
	echo "	@echo Uninstalling CodeLite" >> Makefile
	echo "	@\$(RM) -fr  /usr/local/bin/CodeLite" >> Makefile
	echo "	@\$(RM) -fr  /usr/local/bin/le_dos2unix.sh" >> Makefile
	echo "	@\$(RM) -fr  /usr/local/bin/le_exec.sh" >> Makefile
	echo "	@\$(RM) -fr  /usr/local/bin/le_killproc.sh" >> Makefile
	echo "	@\$(RM) -fr  /usr/local/bin/CodeLiteUR" >> Makefile
	echo "	@\$(RM) -fr  /usr/local/bin/CodeLiteUD" >> Makefile
	echo "	@\$(RM) -fr  /usr/local/include/UnitTest++/" >> Makefile
	echo "	@\$(RM) -fr  /usr/local/lib/libUnitTest++.a" >> Makefile
	echo "	@\$(RM) -fr  /usr/local/share/codelite" >> Makefile
	echo "	@\$(RM) -fr /usr/share/applications/codelite.desktop" >> Makefile
	echo "	@\$(RM) -fr ~/Desktop/codelite.desktop" >> Makefile
	echo "" >> Makefile
}

createEndMessage() 
{
	if [ "$os_name" = "Linux" ]; then
		echo "post_build_msg:" >> Makefile
		echo "	@echo ==========================================================" >> Makefile
		echo "	@echo Done, please run \"sudo make install\"." >> Makefile
		echo "	@echo ==========================================================" >> Makefile
	fi
}

checkCURL()
{
	if [ -d "/usr/include/curl/" ] || [ -d "/usr/local/include/curl/" ] ; then
		echo "Found cURL installation"
	else
		echo "ERROR: Please install libcurl development package (under Ubuntu 7.10, the package name is libcurl4-dev)"
		exit 1
	fi
}

generateControlFile() 
{
	rm -fr fakeroot/DEBIAN/control
	echo "Package: CodeLite" >> fakeroot/DEBIAN/control
	echo "Version: 1.0RC02" >> fakeroot/DEBIAN/control
	echo "Section: Development " >> fakeroot/DEBIAN/control
	echo "Architecture: i386 " >> fakeroot/DEBIAN/control
	echo "Essential: no" >> fakeroot/DEBIAN/control
	echo "Depends: libwxgtk2.8-0, libgtk2.0-0, libcurl3" >> fakeroot/DEBIAN/control
	echo "Maintainer: Eran Ifrah [eran.ifrah@gmail.com]" >> fakeroot/DEBIAN/control
	echo "Description: CodeLite is a powerful open-source, cross platform code editor for the C/C++ programming languages (regulary tested on Windows XP sp2, Ubuntu 7.10 Gutsy Gibbon, Fedora Core 6 and Debian lenny/sid). " >> fakeroot/DEBIAN/control
	echo "		 CodeLite is distributed under the terms of the GPL license." >> fakeroot/DEBIAN/control
	echo "		 CodeLite uses a sophisticated, yet intuitive interface which allows user to easly " >> fakeroot/DEBIAN/control
	echo "		 create and build complex projects. " >> fakeroot/DEBIAN/control
	echo ""  >> fakeroot/DEBIAN/control
}

## main
checkCURL

## Create variables needed by the makefile
enable_debug="no"
os_name=`uname -s`
arch=`uname -m`

if [ "$1" = "--enable-debug" ]; then
	enable_debug="yes"
fi

## remove old makefile
makefile_name="Makefile"
base_dir="."
rm -fr ./Makefile

## Create revision file
createRevisionFile
echo "Generating Makefile..."
createVariables "no"

## Create the various object lists
createObjectList "sdk/wxscintilla/src/scintilla/src/*.cxx sdk/wxscintilla/src/*.cpp" "ScintillaObjects"
createObjectList "CodeLite/*.cpp" "CodeLiteObjects"
createObjectList "LiteEditor/*.cpp" "LiteEditorObjects"
createObjectList "sdk/wxsqlite3/src/*.cpp sqlite3/*.c" "wxSqlite3Objects"
createObjectList "Plugin/*.cpp" "SDKObjects"

createMainTargets
echo >> Makefile

## Create the rules
createRules_archive "sdk/wxscintilla/src/scintilla/src/*.cxx sdk/wxscintilla/src/*.cpp" "ScintillaObjects" "Scintilla" "wxscintilla"
createRules_archive "CodeLite/*.cpp" "CodeLiteObjects" "CodeLite" "codelite"
createRules_archive "sdk/wxsqlite3/src/*.cpp sqlite3/*.c" "wxSqlite3Objects" "SQLite" "wxsqlite3"
createRules_archive "Plugin/*.cpp " "SDKObjects" "SDK" "plugin"
createRules_exe "LiteEditor/*.cpp" "LiteEditorObjects" "LiteEditor" ${exe_name}
createInstallTarget
createUnInstallTarget
generateControlFile

echo "-include \$(OBJ_DIR)/*.d" >> Makefile
echo "" >> Makefile

createEndMessage

echo "Plugins:\\" >> Makefile

########################################################
##
## Add any plugin targets you need here
## Append these as dependencie for the main project
##
########################################################
echo "Debugger\\" >> Makefile
echo "Gizmos\\" >> Makefile
echo "cscope\\" >> Makefile
echo "Subversion\\" >> Makefile
echo "CodeFormatter\\" >> Makefile
#echo "ReferenceAnalyser\\" >> Makefile
echo "Copyright\\" >> Makefile
echo "UnitTestCPP\\" >> Makefile
echo "" >> Makefile

echo "plugins_install:\\" >> Makefile
########################################################
##
## For all plugins you add, you can add an entry here for 
## the install target
########################################################
echo "Debugger_install\\" >> Makefile
echo "Gizmos_install\\" >> Makefile
echo "cscope_install\\" >> Makefile
echo "Subversion_install\\" >> Makefile
echo "CodeFormatter_install\\" >> Makefile
#echo "ReferenceAnalyser_install\\" >> Makefile
echo "Copyright_install\\" >> Makefile
echo "UnitTestCPP_install\\" >> Makefile
echo "" >> Makefile

echo "clean_plugins:\\" >> Makefile
########################################################
##
## For all plugins you add, add an entry here for 'clean'
##
########################################################
echo "Debugger_clean\\" >> Makefile
echo "Gizmos_clean\\" >> Makefile
echo "cscope_clean\\" >> Makefile
echo "Subversion_clean\\" >> Makefile
echo "CodeFormatter_clean\\" >> Makefile
#echo "ReferenceAnalyser_clean\\" >> Makefile
echo "Copyright_clean\\" >> Makefile
echo "UnitTestCPP_clean\\" >> Makefile
echo "" >> Makefile

########################################################
##
## add plugins here
## createPluginMakefile <plugin path> <plugin name>
##
########################################################

createPluginMakefile "Debugger" "Debugger" "/usr/local/share/codelite/debuggers/"
createPluginMakefile "Gizmos" "Gizmos"  "/usr/local/share/codelite/plugins/"
createPluginMakefile "cscope" "cscope" "/usr/local/share/codelite/plugins/"
createPluginMakefile "Subversion" "Subversion" "/usr/local/share/codelite/plugins/"
createPluginMakefile "CodeFormatter" "CodeFormatter" "/usr/local/share/codelite/plugins/"
#createPluginMakefile "ReferenceAnalyser" "ReferenceAnalyser" "/usr/local/share/codelite/plugins/"
createPluginMakefile "Copyright" "Copyright" "/usr/local/share/codelite/plugins/"
createPluginMakefile "UnitTestCPP" "UnitTestCPP" "/usr/local/share/codelite/plugins/"


