# Sconstruct for FCollada Library and Test executable for Linux
import os
import glob
import shutil
import string
execfile("../SconsCommon.py")

# Parse the arguments.
ifdebug = ARGUMENTS.get('debug', "0") #Default is Retail.
ifnumber = ARGUMENTS.get('target', "0") #Default is help.
ifunicode = ARGUMENTS.get('unicode', "0") #Default is non-unicode.
ifshared = ARGUMENTS.get('shared', "0") #Default is static library.

cdebug = int(ifdebug)
cnumber = int(ifnumber)
cunicode = int(ifunicode)
cshared = int(ifshared)

# This is the name of the build.
buildName = BuildName(ifdebug, ifunicode, cshared)

# Specific Help text.
Help("""
==========================USER HELP=======================================
Type 'scons debug=x unicode=x target=1' to compile files for Linux.
    If debug=0, version of code compiled is release.
       debug=1, version of code compiled is debug.
    If unicode=0, the FCollada library built doesn't support unicode. 
       unicode=1, the FCollada library built supports unicode.
    If shared=0, a static library (a) is build.
       shared=1, a dynamic library (so) is built.
    If target=1, all related libraries are built.
Add '-c' at the end of the command line with target 2 or 3 to clean 
	up object files.
==========================================================================""")

if cnumber == 0:
    print "=====================ATTENTION================================="
    print "Please type 'scons -h' to see what to type in the command line."
    print "==============================================================="    

# Build all.
elif cnumber == 1:
    buildString = "scons debug=" + ifdebug + " unicode=" + ifunicode + " shared=" + ifshared + " target=" 
    os.chdir("../FColladaPlugins")
    os.system(buildString + "2")
    os.chdir("../FCollada")
    os.system(buildString + "2")
    os.system(buildString + "3")

# FCollada Library.
elif cnumber == 2:
    print "Building: '%s' version of FCollada." % buildName

    # If necesary, create the output folder.
    outputFolder = "Output/" + buildName + "/Intermediate"
    if not os.path.exists(outputFolder):
        os.makedirs(outputFolder)

    SConscript('Sconscript', build_dir=outputFolder, duplicate=0)

# FColladaTest executable
elif cnumber == 3:
    if cdebug == 1 and cunicode == 1 and cshared == 0:
        outputFolder = "FColladaTest/Output/" + buildName + "/Intermediate"
        if not os.path.exists(outputFolder):
            os.makedirs(outputFolder)
        SConscript('FColladaTest/Sconscript', build_dir=outputFolder, duplicate=0)

    else:
	print 'WARNING: FColladaTest only works with debug, unicode version of the FCollada library.'

# In case target number is not in this list.
else:
    print "Target number un-recognized. Type 'scons -h' to know which targets are available."