Compile Script


(=>ETK<=Elite) #1

Ok, I have created a new script for compiling both windows and linux builds on a linux machine. It runs more like a console application than a script that just performs one job. I will continue to work on this and add features/fixes if/when needed.

This script depends on Jaybird’s comment on naming dll’s properly.

Anyhow, here it is, just let me know if If anything needs to be added (or comments if I am doing this wrong, thanks).
Instructions on use:

  • Copy to file of your choice (ie: compile.sh)
  • Place file in a location in yur PATH for easier access (ie: /usr/local/bin)
  • Be sure to replace the paths near the top of the script to what fits you. The server and client paths are not important unless you run a server for testing purposes locally.
  • Open terminal and type 'sh ’
# Enemy Territory Compilation Script v1.2.2
# Written by =>ETK<=Elite

BASE_PATH="/usr/local/games/etkmod-1.0.0"
BUILD_PATH=$BASE_PATH/src
BIN_PATH=$BASE_PATH/bin
PAK_PATH=$BASE_PATH/pak
PAK_FILE="etkmod-1.0.0"
SERVER_OS="linux"
SERVER_PATH="/usr/local/games/enemy-territory/27960/etkmod"
CLIENT_PATH="/home/*****/.etwolf/etkmod"

title()
{
	echo ""
	echo "Enemy Territory Compilation Script v1.2.2 by =>ETK<= Elite"
}

check_root()
{
	if [ "$UID" != "0" ]; then
		echo "Must be root"
		exit
	fi
}

check_paths()
{
	if [ ! -d $BASE_PATH ]; then
		echo "ERROR: $BASE_PATH does not exist"
		exit
	fi

	if [ ! -d $BUILD_PATH ]; then
		echo "ERROR: $BUILD_PATH does not exist"
		exit
	fi
}

general_actions()
{
	echo ""
	echo "Please select an action to perform:"
	echo "   1 - clean old builds"
	echo "   2 - build linux module(s)"
	echo "   3 - build win32 module(s)"
	echo "   4 - build all modules for release"
	echo "   5 - create pak file"
	echo "   6 - install files on server"
	echo "   7 - install files on client"
	echo "   8 - list files in $BIN_PATH"
	echo "   9 - list files in $PAK_PATH"
	echo "   0 - exit"

	read ga_answer
	
	case $ga_answer in
		"0") exit;;
		"1") clean;;
		"2") linux_actions;;
		"3") win32_actions;;
		"4") build_all_release;;
		"5") create_pak;;
		"6") install_server;;
		"7") install_client;;
		"8") list_bin;;
		"9") list_pak;;
		*) general_actions;;
	esac
}

clean()
{
	echo ""
	echo "Cleaning old builds..."

	cd $BUILD_PATH
	scons -c

	general_actions
}

linux_actions()
{
	echo ""
	echo "Which linux module(s) would you like to build?"
	echo "   1 - build all modules for release"
	echo "   2 - build qagame module for release"
	echo "   3 - build cgame module for release"
	echo "   4 - build ui module for release"
	echo "   5 - return to previous screen"

	read la_answer

	case $la_answer in
		"1") linux_build_all_final;;
		"2") linux_build_qagame_final;;
		"3") linux_build_cgame_final;;
		"4") linux_build_ui_final;;
		"5") general_actions;;
		*) linux_actions;;
	esac

	general_actions
}

win32_actions()
{
	echo ""
	echo "Which win32 module(s) would you like to build?"
	echo "   1 - build all modules for release"
	echo "   2 - build qagame module for release"
	echo "   3 - build cgame module for release"
	echo "   4 - build ui module for release"
	echo "   5 - return to previous screen"

	read la_answer

	case $la_answer in
		"1") win32_build_all_final;;
		"2") win32_build_qagame_final;;
		"3") win32_build_cgame_final;;
		"4") win32_build_ui_final;;
		"5") general_actions;;
		*) win32_actions;;
	esac

	general_actions
}

linux_build_qagame_final()
{
	echo ""
	echo "Cleaning old linux qagame modules..."

	if [ ! -d $BIN_PATH ]; then
		mkdir $BIN_PATH
	fi

	cd $BIN_PATH

	if [ -f qagame.mp.i386.so ]; then
		rm qagame.mp.i386.so
	fi

	cd $BUILD_PATH
	scons -c

	echo "Building qagame.mp.i386.so..."
	scons CC=gcc CXX=g++ BUILD=release DEDICATED=1 TARGET_GAME=1 TARGET_CGAME=0 TARGET_UI=0 COPYBINS=1
}

linux_build_cgame_final()
{
	echo ""
	echo "Cleaning old linux cgame modules..."

	if [ ! -d $BIN_PATH ]; then
		mkdir $BIN_PATH
	fi

	cd $BIN_PATH

	if [ -f cgame.mp.i386.so ]; then
		rm cgame.mp.i386.so
	fi

	cd $BUILD_PATH
	scons -c

	echo "Building cgame.mp.i386.so..."
	scons CC=gcc CXX=g++ BUILD=release DEDICATED=0 TARGET_GAME=0 TARGET_CGAME=1 TARGET_UI=0 COPYBINS=1
}

linux_build_ui_final()
{
	echo ""
	echo "Cleaning old linux ui modules..."

	if [ ! -d $BIN_PATH ]; then
		mkdir $BIN_PATH
	fi

	cd $BIN_PATH

	if [ -f ui.mp.i386.so ]; then
		rm ui.mp.i386.so
	fi

	cd $BUILD_PATH
	scons -c

	echo "Building ui.mp.i386.so..."
	scons CC=gcc CXX=g++ BUILD=release DEDICATED=0 TARGET_GAME=0 TARGET_CGAME=0 TARGET_UI=1 COPYBINS=1
}

linux_build_all_final()
{
	linux_build_qagame_final
	linux_build_cgame_final
	linux_build_ui_final

	general_actions
}

win32_build_qagame_final()
{
	echo ""
	echo "Cleaning old win32 qagame modules..."

	if [ ! -d $BIN_PATH ]; then
		mkdir $BIN_PATH
	fi

	cd $BIN_PATH

	if [ -f qagame_mp_x86.dll ]; then
		rm qagame_mp_x86.dll
	fi
	
	cd $BUILD_PATH
	scons -c

	echo "Building qagame_mp_x86.dll..."
	scons CC=i586-mingw32msvc-gcc CXX=i586-mingw32msvc-g++ BUILD=release DEDICATED=1 TARGET_GAME=1 TARGET_CGAME=0 TARGET_UI=0 COPYBINS=1
}

win32_build_cgame_final()
{
	echo ""
	echo "Cleaning old win32 cgame modules..."

	if [ ! -d $BIN_PATH ]; then
		mkdir $BIN_PATH
	fi

	cd $BIN_PATH
	
	if [ -f cgame_mp_x86.dll ]; then
		rm cgame_mp_x86.dll
	fi

	cd $BUILD_PATH
	scons -c

	echo "Building cgame_mp_x86.dll..."
	scons CC=i586-mingw32msvc-gcc CXX=i586-mingw32msvc-g++ BUILD=release DEDICATED=0 TARGET_GAME=0 TARGET_CGAME=1 TARGET_UI=0 COPYBINS=1
}

win32_build_ui_final()
{
	echo ""
	echo "Cleaning old win32 ui modules..."

	if [ ! -d $BIN_PATH ]; then
		mkdir $BIN_PATH
	fi

	cd $BIN_PATH

	if [ -f ui_mp_x86.dll ]; then
		rm ui_mp_x86.dll
	fi

	cd $BUILD_PATH
	scons -c

	echo "Building ui_mp_x86.dll..."
	scons CC=i586-mingw32msvc-gcc CXX=i586-mingw32msvc-g++ BUILD=release DEDICATED=0 TARGET_GAME=0 TARGET_CGAME=0 TARGET_UI=1 COPYBINS=1
}

win32_build_all_final()
{
	win32_build_qagame_final
	win32_build_cgame_final
	win32_build_ui_final

	general_actions
}

build_all_release()
{
	linux_build_qagame_final
	linux_build_cgame_final
	linux_build_ui_final

	win32_build_qagame_final
	win32_build_cgame_final
	win32_build_ui_final

	general_actions
}

create_pak()
{
	echo ""
	echo "Creating pak..."

	if [ ! -d $PAK_PATH ]; then
		mkdir $PAK_PATH
	fi

	cd $PAK_PATH
	
	if [ -f $PAK_FILE.pk3 ]; then
		rm $PAK_FILE.pk3
	fi

	cd $BIN_PATH

	if [ -f cgame.mp.i386.so ]; then
		cp cgame.mp.i386.so $PAK_PATH
	else
		echo "ERROR: cgame.mp.i386.so does not exist in $BIN_PATH"
		general_actions
	fi
	if [ -f cgame_mp_x86.dll ]; then
		cp cgame_mp_x86.dll $PAK_PATH
	else
		echo "ERROR: cgame_mp_x86.dll does not exist in $BIN_PATH"
		general_actions
	fi
	if [ -f ui.mp.i386.so ]; then
		cp ui.mp.i386.so $PAK_PATH
	else
		echo "ERROR: ui.mp.i386.so does not exist in $BIN_PATH"
		general_actions
	fi
	if [ -f ui_mp_x86.dll ]; then
		cp ui_mp_x86.dll $PAK_PATH
	else
		echo "ERROR: ui_mp_x86.dll does not exist in $BIN_PATH"
		general_actions
	fi

	cd $PAK_PATH
	zip -r $PAK_FILE.zip *
	mv $PAK_FILE.zip $PAK_FILE.pk3

	general_actions
}

install_server()
{
	echo ""
	echo "Installing files on server..."

	if [ $SERVER_OS = "linux" ]; then
		cd $SERVER_PATH
		if [ -f qagame.mp.i386.so ]; then
			rm -f qagame.mp.i386.so
		fi

		cd $BIN_PATH
		if [ -f qagame.mp.i386.so ]; then
			cp qagame.mp.i386.so $SERVER_PATH
		else
			echo "ERROR: qagame.mp.i386.so does not exist in $BIN_PATH"
			general_actions
		fi
	else
		cd $SERVER_PATH
		if [ -f qagame_mp_x86.dll ]; then
			rm -f qagame_mp_x86.dll
		fi

		cd $BIN_PATH
		if [ -f qagame_mp_x86.dll ]; then
			cp qagame_mp_x86.dll $SERVER_PATH
		else
			echo "ERROR: qagame_mp_x86.dll does not exist in $BIN_PATH"
			general_actions
		fi
	fi

	if [ -d $PAK_PATH ]; then
		cd $PAK_PATH
		if [ -f $PAK_FILE.pk3 ]; then
			cp $PAK_FILE.pk3 $SERVER_PATH
		else
			echo "ERROR: $PAK_FILE.pk3 does not exist"
		fi
	else
		echo "ERROR: $PAK_FILE.pk3 does not exist"
	fi

	general_actions
}

install_client()
{
	echo ""
	echo "Installing files on client..."

	if [ -d $PAK_PATH ]; then
		cd $PAK_PATH
		if [ -f $PAK_FILE.pk3 ]; then
			cp $PAK_FILE.pk3 $CLIENT_PATH
		else
			echo "ERROR: $PAK_FILE.pk3 does not exist"
		fi
	else
		echo "ERROR: $PAK_FILE.pk3 does not exist"
	fi

	general_actions
}

list_bin()
{
	echo ""
	echo "Contents of $BIN_PATH:"
	dir $BIN_PATH

	general_actions
}

list_pak()
{
	echo ""
	echo "Contents of $PAK_PATH:"
	dir $PAK_PATH

	general_actions
}

title
check_root
check_paths
general_actions

(=>ETK<=Elite) #2

Updated to v1.2.1


(kamikazee) #3

Not only is this a quite long, and probably rarely used script, there are a few suspicious things. Especially: taken from win32_build_ui_final()

if [ -f cgame.mp.i386.so ]; then
      rm ui_mp_x86.dll
   fi

So this removes the dll only when the cgame so exists? What’s the use in that?


(=>ETK<=Elite) #4

To make sure it’s cleaned. If I compile it, I want it new obviously. So I don’t need the old one anyhow. If for example I am not in the mood to go through the output, I can just take a quick glance at the files in the directory and see if it was compiled or not.

Here’s my logic at a glance:
-> if file doesn’t exist, create it, that’s what I want
-> if file exists, make sure it is going to be 100% clean and rebuilt. I don’t want to look in the directory and see a file there when I was expecting a newer version.

Have you tried it? It’s more of a small program than a simple script. It basically is a front end to scons for compiling mods for et. A large part of the script comes from the menu system (probably 95% atleast). I don’t know about most people, but for myself I know cutting and pasting words whether it is 100 words or 500 words is just as easy.

As far as it being rarely used, I beg to differ. I compile after every change I make to see if I broke something. If I made 50 changes then compiled it would take me a heck of alot longer to debug and see where all the problems were, rather than just making one change, if it’s broke I immediately know where the problem is.

I am a windows programmer, not a linux programmer so I am sure there are better ways to do this, and I already know it can be improved speedwise if the checks were removed in some places, but this was a personal preference. But there is nobody who can say it will be rarely used unless your not ever gonna finish a mod.

win32_build_ui_final()
{
echo “”
echo “Cleaning old win32 ui modules…”

if [ ! -d $BIN_PATH ]; then
mkdir $BIN_PATH
fi

cd $BIN_PATH

if [ -f cgame.mp.i386.so ]; then
rm ui_mp_x86.dll
fi

cd $BUILD_PATH
scons -c

echo “Building ui_mp_x86.dll…”
scons CC=i586-mingw32msvc-gcc CXX=i586-mingw32msvc-g++ BUILD=release DEDICATED=0 TARGET_GAME=0 TARGET_CGAME=0 TARGET_UI=1 COPYBINS=1
}

Ok, about this beign suspicious, here’s the breakdown on what it does because I don’t think you looked good enough.

  • display message
  • make bin directory if it doesn’t exist
  • enter bin directory and remove old ui_mp_x86.dll
  • remove old builds from build directory
  • build new ui_mp_x86.dll
    I don’t know what is suspicious about it.

I would rather have this script to just myself…I didn’t think I would like it as much as I do until I used it, but I just want to contribute something. People here have helped me when I needed it, and it’s nice to help others. I just figured this really simpliflies the compiling and would help out alot of people, or atleast speed up the process.


(kamikazee) #5

My point was that it checks for a completely different file then the one it removes. It would be far more obvious to write

if [ -f ui_mp_x86.dll ]; then
rm ui_mp_x86.dll
fi 

And besides, scons updates the libraries any time they’re rebuilt…


(=>ETK<=Elite) #6

Hey, thanks, bug in the script that you pointed out. I will fix that up straight away.

I am not that familiar with the workings of linux progs. All I know is I use scons to compile the mod, and I know what I want to accomplish. it is just a personal preference, and anyone is free to use the script and change it as they like.

Anyone who uses this script is going to like it…and now they will like it more that the bug you pointed out will be fixed., lol.

Again, it is not a script in the traditional script sense. You don’t simply type sh <script> and run it and have it perform one simple task. Obviously to start it, you need to sh it, but when it is running it is more of a small program, with menus. It offers many options as to build all or a specific part of the mod with builds optimized builds (again, I don’t know alot about linux, so I am sure they are better tools for optimsation other than what’s already in sconstruct). Other features include creating your pak file and installing everything on a local client and server.

I submitted an earlier script for compiling both windows and linux builds at the same time, and had someone compliment it. Jaybird pointed out that there was a more proper way to name the dll’s at the time, I took his advice, and decided to completely rewrite a new, more advanced, and user friendly script.

It is a supposed to be more of a one-stop shop so to speak for compiling, packaging, and testing a mod.

=====================
Updated : v1.2.2


(jaybird) #7

Just an off-topic note, a script isn’t considered traditional because it does one thing. Take into account the scons scripts. Those do a lot of things, and they’re still scripts. SysV start scripts do a variety of things, such as start, stop, restart a program, and require input to operate. In fact, most scripts you will find on a unix box either require or take input.


(=>ETK<=Elite) #8

I know, I was just comparing in that it runs moreso as a program than most scripts do.

I do programming for a living so I know the differences. Simply put, a script just gives a program some args/actions to work with.

(Programmer Analyst and Internet Solutions Developer)