anchor.diff:  	
   	
   	IF [%1] == [package] (
  +		
  +		REM Force driver to be built
  +		IF NOT EXIST %root%/luaw.exe (
  +			echo Please build the driver first.
  +			exit /b 1
  +		)
  +		
  +		echo Cleaning workspace...
  +		REM Resets dll
  +		del %dlldir%\*.dll
  +		
   		IF [%2] == [luajit] (
  -			echo Building luajit...
  -			
  -			pushd luajit-2.0\src
  -				IF NOT EXIST "lua51.dll" (
  -					%MAKE% -j%NUMBER_OF_PROCESSORS%
  -				) ELSE (
  -					IF [%force_build%] == [1] (
  -						%MAKE% -j%NUMBER_OF_PROCESSORS%
  -					)
  -				)
  -				echo Installing...
  -				xcopy /Y lua.h		..\..\include
  -				xcopy /Y luaconf.h	..\..\include
  -				xcopy /Y lualib.h	..\..\include
  -				xcopy /Y lauxlib.h	..\..\include
  -				xcopy /Y luajit.h	..\..\include
  -				xcopy /Y lua51.dll	..\..\dll
  -			popd
  -			
  -			echo Finished building and linking luajit.
  +			call :build_luajit
   		) ELSE (
  -			echo Building %2...
  -			
  -			pushd lua-all\%2
  -				IF NOT EXIST "*.dll" (
  -					echo Compiling...
  -					%GCC% -std=%GCC_VER% -g0 -O2 -Wall -Wextra %lua_cflags% -DLUA_BUILD_AS_DLL -c *.c
  -					
  -					del lua.o
  -					del luac.o
  -					
  -					echo Linking...
  -					%GCC% -std=%GCC_VER% -g0 -O2 -Wall -Wextra -shared -o %2.dll *.o
  -					
  -					echo Archiving...
  -					%AR% rcu lib%2.a *.o
  -				) ELSE (
  -					IF [%force_build%] == [1] (
  -						echo Compiling...
  -						%GCC% -std=%GCC_VER% -g0 -O2 -Wall -Wextra %lua_cflags% -DLUA_BUILD_AS_DLL -c *.c
  -						
  -						del lua.o
  -						del luac.o
  -						
  -						echo Linking...
  -						%GCC% -std=%GCC_VER% -g0 -O2 -Wall -Wextra -shared -o %2.dll *.o
  -						
  -						echo Archiving...
  -						%AR% rcu lib%2.a *.o
  -					)
  -				)
  -				
  -				echo Installing...
  -				xcopy /Y lua.h			..\..\include
  -				xcopy /Y luaconf.h		..\..\include
  -				xcopy /Y lualib.h		..\..\include
  -				xcopy /Y lauxlib.h		..\..\include
  -				xcopy /Y %2.dll			..\..\dll
  -				xcopy /Y lib%2.a		..\..\lib
  -			popd
  -			
  -			echo Finished building and linking %2.
  -		)
  -		
  -		echo Creating local luaw package as %2...
  -		
  -		if [%2] == [luajit] (
  -			echo Compiling luaw package %2...
  -			%GCC% %attrib% %dirs% %luaverdef% -D__USE_MINGW_ANSI_STDIO=1 -DLC_LD_DLL -DLUA_JIT_51 -c %srcdir%\ldata.c %srcdir%\jitsupport.c %srcdir%\darr.c
  -			
  -			echo Linking luaw package %2...
  -			%GCC% %attrib% %dirs% -shared -o lc%2.dll ldata.o jitsupport.o darr.o %dlldir%\lua51.dll
  -		) ELSE (
  -			echo Compiling luaw package %2...
  -			%GCC% %attrib% %dirs% %luaverdef% -D__USE_MINGW_ANSI_STDIO=1 -DLC_LD_DLL -c %srcdir%\ldata.c %srcdir%\jitsupport.c %srcdir%\darr.c
  -			
  -			echo Linking luaw package %2...
  -			%GCC% %attrib% %dirs% -shared -o lc%2.dll ldata.o jitsupport.o darr.o %dlldir%\%2.dll
  -		)
  -		
  -		echo Finished building and linking %2.
  -		
  -		REM Migrate binaries
  -		echo Migrating binaries...
  -		move /Y *.dll		%root%
  -		move /Y *.o			%objdir%
  -		move /Y *.a			%libdir%
  -		copy /Y %resdir%\*	%root%\res
  -		copy /Y %dlldir%\*	%root%
  -		copy /Y %rootdir%\*	%root%
  +			IF NOT EXIST "lua-all/%2" (
  +				echo Not a valid lua version!
  +				goto failure
  +			)
  +			call :build_lua %2
  +		)
  +		
  +		call :build_package %2
  +		call :build_install %2
   		
   		echo Finished.
   		exit /b 0
   	)
   	
  +	
  +	REM --------------------------------------------------------------------
  +	
  +	
  +	:build_luajit
  +	setlocal
  +		echo Building luajit...
  +			
  +		pushd luajit-2.0\src
  +			IF NOT EXIST "lua51.dll" (
  +				%MAKE% -j%NUMBER_OF_PROCESSORS%
  +			) ELSE (
  +				echo luajit already cached.
  +			)
  +			
  +			echo Installing...
  +			xcopy /Y lua.h		..\..\include
  +			xcopy /Y luaconf.h	..\..\include
  +			xcopy /Y lualib.h	..\..\include
  +			xcopy /Y lauxlib.h	..\..\include
  +			xcopy /Y luajit.h	..\..\include
  +			xcopy /Y lua51.dll	..\..\dll
  +		popd
  +		
  +		echo Finished installing luajit.
  +		goto :EOF
  +	endlocal
  +	
  +	:build_lua
  +	setlocal
  +		echo "Building %1..."
  +		
  +		pushd lua-all\%1
  +			IF NOT EXIST "*.dll" (
  +				echo Compiling %1...
  +				%GCC% -std=%GCC_VER% -g0 -O2 -Wall %luaverdef% -c *.c
  +				
  +				del lua.o
  +				del luac.o
  +				
  +				echo Linking %1...
  +				%GCC% -std=%GCC_VER% -g0 -O2 -Wall -shared -o %1.dll *.o
  +				
  +				echo Archiving %1...
  +				%AR% rcu lib%1.a *.o
  +			) ELSE (
  +				echo %1 already cached.
  +			)
  +			
  +			echo Installing...
  +			xcopy /Y lua.h			..\..\include
  +			xcopy /Y luaconf.h		..\..\include
  +			xcopy /Y lualib.h		..\..\include
  +			xcopy /Y lauxlib.h		..\..\include
  +			xcopy /Y %1.dll			..\..\dll
  +		popd
  +		
  +		echo Finished installing %1.
  +		goto :EOF
  +	endlocal
  +	
  +	:build_install
  +	setlocal
  +		move /Y *.o %objdir%
  +		IF [%1] == [luajit] (
  +			echo wrap 2
  +			copy /Y %dlldir%\lua51.dll %root%
  +			echo wrap 2 eof
  +		) ELSE (
  +			echo wrap 3
  +			copy /Y %dlldir%\%1.dll %root%
  +			echo wrap 3 eof
  +		)
  +		echo wrap 4
  +		move lc%1.dll %root%
  +		echo wrap 4 eof
  +		
  +		echo Finished installing %1.
  +		goto :EOF
  +	endlocal
  +	
  +	:build_package
  +	setlocal
  +		IF [%1] == [luajit] (
  +			set luaverdef=-DLUA_JIT_51
  +			set luaverout=%dlldir%/lua51.dll
  +		) ELSE (
  +			set luaverout=%dlldir%/%1.dll
  +		)
  +		
  +		echo Compiling luaw driver package %1...
  +		%gcc% %attrib% %dirs% %luaverdef% -D__USE_MINGW_ANSI_STDIO=1 -DLC_LD_DLL -c %srcdir%\ldata.c %srcdir%\jitsupport.c %srcdir%\darr.c
  +		
  +		echo Linking luaw driver package %1...
  +		%GCC% %attrib% %dirs% -shared -o lc%1.dll ldata.o jitsupport.o darr.o %luaverout%
  +		
  +		goto :EOF
  +	endlocal
  +	
  +	:build_driver
  +	setlocal
  +		echo Compiling luaw driver...
  +		%GCC% %attrib% %dirs% -D__USE_MINGW_ANSI_STDIO=1 -DDEFAULT_LUA=\"lc%1.dll\" -c %srcdir%\darr.c %srcdir%\luadriver.c
  +		
  +		echo Linking luaw driver...
  +		%GCC% %attrib% %dirs% -o luaw.exe luadriver.o darr.o
  +		
  +		call :build_package %1
  +		
  +		IF %debug% EQU 0 (
  +			echo Stripping...
  +			strip --strip-all luaw.exe
  +		)
  +		
  +		echo Finished building driver %1.
  +		goto :EOF
  +	endlocal
   	
   endlocal
   
  
positive.code: 	
  	REM --------------------------------------------------------------------
  	
  	
  	IF [%1] == [driver] (
  		
  		echo Cleaning bin...
  		REM Resets bin\res
  		IF EXIST %root% ( rmdir /S /Q %root% )
  		mkdir %root%\res
  		
  		IF [%2] == [luajit] (
  			echo Building luajit...
  			
  			pushd luajit-2.0\src
  				IF NOT EXIST "lua51.dll" (
  					%MAKE% -j%NUMBER_OF_PROCESSORS%
  				) ELSE (
  					IF [%force_build%] == [1] (
  						%MAKE% -j%NUMBER_OF_PROCESSORS%
  					)
  				)
  				echo Installing...
  				xcopy /Y lua.h		..\..\include
  				xcopy /Y luaconf.h	..\..\include
  				xcopy /Y lualib.h	..\..\include
  				xcopy /Y lauxlib.h	..\..\include
  				xcopy /Y luajit.h	..\..\include
  				xcopy /Y lua51.dll	..\..\dll
  			popd
  			
  			echo Finished building and linking luajit.
  		) ELSE (
  			echo Building %2...
  			
  			pushd lua-all\%2
  				IF NOT EXIST "*.dll" (
  					echo Compiling...
  					%GCC% -std=%GCC_VER% -g0 -O2 -Wall -Wextra %lua_cflags% -DLUA_BUILD_AS_DLL -c *.c
  					
  					del lua.o
  					del luac.o
  					
  					echo Linking...
  					%GCC% -std=%GCC_VER% -g0 -O2 -Wall -Wextra -shared -o %2.dll *.o
  					
  					echo Archiving...
  					%AR% rcu lib%2.a *.o
  				) ELSE (
  					IF [%force_build%] == [1] (
  						echo Compiling...
  						%GCC% -std=%GCC_VER% -g0 -O2 -Wall -Wextra %lua_cflags% -DLUA_BUILD_AS_DLL -c *.c
  						
  						del lua.o
  						del luac.o
  						
  						echo Linking...
  						%GCC% -std=%GCC_VER% -g0 -O2 -Wall -Wextra -shared -o %2.dll *.o
  						
  						echo Archiving...
  						%AR% rcu lib%2.a *.o
  					)
  				)
  				
  				echo Installing...
  				xcopy /Y lua.h			..\..\include
  				xcopy /Y luaconf.h		..\..\include
  				xcopy /Y lualib.h		..\..\include
  				xcopy /Y lauxlib.h		..\..\include
  				xcopy /Y %2.dll			..\..\dll
  				xcopy /Y lib%2.a		..\..\lib
  			popd
  			
  			echo Finished building and linking %2.
  		)
  		
  		if [%2] == [luajit] (
  			echo Compiling luaw driver...
  			%GCC% %attrib% %dirs% -D__USE_MINGW_ANSI_STDIO=1 -DDEFAULT_LUA=\"lc%2.dll\" -c %srcdir%\darr.c %srcdir%\luadriver.c
  			
  			echo Compiling default luaw driver package %2...
  			%GCC% %attrib% %dirs% %luaverdef% -D__USE_MINGW_ANSI_STDIO=1 -DLC_LD_DLL -DLUA_JIT_51 -c %srcdir%\ldata.c %srcdir%\jitsupport.c %srcdir%\darr.c
  			
  			echo Linking luaw driver...
  			%GCC% %attrib% %dirs% -o luaw.exe luadriver.o darr.o
  		
  			echo Linking default luaw driver package %2...
  			%GCC% %attrib% %dirs% -shared -o lc%2.dll ldata.o jitsupport.o darr.o %dlldir%\lua51.dll
  		) ELSE (
  			echo Compiling luaw driver...
  			%GCC% %attrib% %dirs% -D__USE_MINGW_ANSI_STDIO=1 -DDEFAULT_LUA=\"lc%2.dll\" -c %srcdir%\darr.c %srcdir%\luadriver.c
  			
  			echo Compiling default luaw driver package %2...
  			%GCC% %attrib% %dirs% %luaverdef% -D__USE_MINGW_ANSI_STDIO=1 -DLC_LD_DLL -c %srcdir%\ldata.c %srcdir%\jitsupport.c %srcdir%\darr.c
  			
  			echo Linking luaw driver...
  			%GCC% %attrib% %dirs% -o luaw.exe luadriver.o darr.o
  		
  			echo Linking default luaw driver package %2...
  			%GCC% %attrib% %dirs% -shared -o lc%2.dll ldata.o jitsupport.o darr.o %dlldir%\%2.dll
  		)
  		
  		
  		REM Strip luaw driver if not debug
  		echo Stripping...
  		IF %debug% EQU 0 (
  			strip --strip-all luaw.exe
  		)
  		
  		REM Migrate binaries
  		echo Migrating binaries...
  		move /Y *.dll		%root%
  		move /Y *.o			%objdir%
  		move /Y *.a			%libdir%
  		move /Y *.exe		%root%
  		copy /Y %resdir%\*	%root%\res
  		copy /Y %dlldir%\*	%root%
  		copy /Y %rootdir%\*	%root%
  		
  		echo Finished.
  		exit /b 0
  
negative.code: 	echo An error has occured!
  	pause
  	exit /b 1
  
  :end
  