/[ascend]/trunk/SConstruct
ViewVC logotype

Diff of /trunk/SConstruct

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 577 by johnpye, Tue May 9 04:08:53 2006 UTC revision 578 by johnpye, Tue May 9 04:59:03 2006 UTC
# Line 291  opts.Add( Line 291  opts.Add(
291      ,"ascend-"+version      ,"ascend-"+version
292  )  )
293    
294    opts.Add(
295        'WIN_INSTALLER_NAME'
296        ,"Name of the installer .exe to create under Windows (minus the '.exe')"
297        ,"ascend-"+version
298    )
299    
300  if platform.system()!="Windows":  if platform.system()!="Windows":
301      opts.Add(BoolOption(      opts.Add(BoolOption(
302          'WITH_GCCVISIBILITY'          'WITH_GCCVISIBILITY'
# Line 315  if platform.system()=="Windows": Line 321  if platform.system()=="Windows":
321  if os.environ.get('OSTYPE')=='msys':  if os.environ.get('OSTYPE')=='msys':
322      env = Environment(      env = Environment(
323          ENV=os.environ          ENV=os.environ
324          , tools=['mingw','lex','yacc','fortran','swig','disttar']          , tools=['mingw','lex','yacc','fortran','swig','disttar','nsis']
325          , toolpath=['scons']          , toolpath=['scons']
326      )      )
327      env['IS_MINGW']=True      env['IS_MINGW']=True
328  else:  else:
329      env = Environment(      env = Environment(
330          ENV=os.environ          ENV=os.environ
331          ,tools=['default','lex','yacc','fortran','swig','disttar']          ,tools=['default','lex','yacc','fortran','swig','disttar','nsis']
332          , toolpath=['scons']          , toolpath=['scons']
333      )      )
334    
# Line 991  SConsEnvironment.InstallPerm = InstallPe Line 997  SConsEnvironment.InstallPerm = InstallPe
997            
998  # define wrappers      # define wrappers    
999  SConsEnvironment.InstallProgram = lambda env, dest, files: InstallPerm(env, dest, files, 0755)    SConsEnvironment.InstallProgram = lambda env, dest, files: InstallPerm(env, dest, files, 0755)  
1000  SConsEnvironment.InstallHeader = lambda env, dest, files: InstallPerm(env, dest, files, 0644)      SConsEnvironment.InstallHeader = lambda env, dest, files: InstallPerm(env, dest, files, 0644)
   
 #------------------------------------------------------  
 # NSIS Support for SCons  
   
 # Adapted version by John Pye, April 2006.  
 # from http://www.scons.org/cgi-sys/cgiwrap/scons/moin.cgi/NsisSconsTool  
 # Written by Mike Elkins, January 2004.  
   
 #This tool provides SCons support for the Nullsoft Scriptable Install System  
 #a windows installer builder available at http://nsis.sourceforge.net/home  
   
 #In addition, if you set NSISDEFINES to a dictionary, those variables will be passed  
 #to NSIS.  
   
 import SCons.Builder  
 import SCons.Util  
 import SCons.Scanner  
 import SCons.Sig  
 import os.path  
 import glob  
   
 def nsis_parse( sources, keyword, multiple ):  
   """  
   A function that knows how to read a .nsi file and figure  
   out what files are referenced, or find the 'OutFile' line.  
   
   
   sources is a list of nsi files.  
   keyword is the command ('File' or 'OutFile') to look for  
   multiple is true if you want all the args as a list, false if you  
   just want the first one.  
   """  
   stuff = []  
   for s in sources:  
     c = s.get_contents()  
     for l in c.split('\n'):  
       semi = l.find(';')  
       if (semi != -1):  
         l = l[:semi]  
       hash = l.find('#')  
       if (hash != -1):  
         l = l[:hash]  
       # Look for the keyword  
       l = l.strip()  
       spl = l.split(None,1)  
       if len(spl) > 1:  
         if spl[0].capitalize() == keyword.capitalize():  
           arg = spl[1]  
           if arg.startswith('"') and arg.endswith('"'):  
             arg = arg[1:-1]  
           if multiple:  
             stuff += [ arg ]  
           else:  
             return arg  
   return stuff  
   
   
 def nsis_path( filename, nsisdefines, rootdir ):  
   """  
   Do environment replacement, and prepend with the SCons root dir if  
   necessary  
   """  
   # We can't do variables defined by NSIS itself (like $INSTDIR),  
   # only user supplied ones (like ${FOO})  
   varPos = filename.find('${')  
   while varPos != -1:  
     endpos = filename.find('}',varPos)  
     assert endpos != -1  
     if not nsisdefines.has_key(filename[varPos+2:endpos]):  
       raise KeyError ("Could not find %s in NSISDEFINES" % filename[varPos+2:endpos])  
     val = nsisdefines[filename[varPos+2:endpos]]  
     if type(val) == list:  
       if varPos != 0 or endpos+1 != len(filename):  
         raise Exception("Can't use lists on variables that aren't complete filenames")  
       return val  
     filename = filename[0:varPos] + val + filename[endpos+1:]  
     varPos = filename.find('${')  
   return filename  
   
   
 def nsis_scanner( node, env, path ):  
   """  
   The scanner that looks through the source .nsi files and finds all lines  
   that are the 'File' command, fixes the directories etc, and returns them.  
   """  
   nodes = node.rfile()  
   if not node.exists():  
     return []  
   nodes = []  
   source_dir = node.get_dir()  
   for include in nsis_parse([node],'file',1):  
     exp = nsis_path(include,env['NSISDEFINES'],source_dir)  
     if type(exp) != list:  
       exp = [exp]  
     for p in exp:  
       for filename in glob.glob( os.path.abspath(  
         os.path.join(str(source_dir),p))):  
           # Why absolute path?  Cause it breaks mysteriously without it :(  
           nodes.append(filename)  
   return nodes  
   
   
 def nsis_emitter( source, target, env ):  
   """  
   The emitter changes the target name to match what the command actually will  
   output, which is the argument to the OutFile command.  
   """  
   nsp = nsis_parse(source,'outfile',0)  
   if not nsp:  
     return (target,source)  
   x  = (  
     nsis_path(nsp,env['NSISDEFINES'],''),  
     source)  
   return x  
   
 def quoteIfSpaced(text):  
   if ' ' in text:  
     return '"'+text+'"'  
   else:  
     return text  
   
 def toString(item,env):  
   if type(item) == list:  
     ret = ''  
     for i in item:  
       if ret:  
         ret += ' '  
       val = toString(i,env)  
       if ' ' in val:  
         val = "'"+val+"'"  
       ret += val  
     return ret  
   else:  
     # For convienence, handle #s here  
     if str(item).startswith('#'):  
       item = env.File(item).get_abspath()  
     return str(item)  
   
 def runNSIS(source,target,env,for_signature):  
   ret = env['NSIS']+" "  
   if env.has_key('NSISFLAGS'):  
     for flag in env['NSISFLAGS']:  
       ret += flag  
       ret += ' '  
   if env.has_key('NSISDEFINES'):  
     for d in env['NSISDEFINES']:  
       ret += '/D'+d  
       if env['NSISDEFINES'][d]:  
         ret +='='+quoteIfSpaced(toString(env['NSISDEFINES'][d],env))  
       ret += ' '  
   for s in source:  
     ret += quoteIfSpaced(str(s))  
   return ret  
   
 def find_nsis(env):  
   """  
   Try and figure out if NSIS is installed on this machine, and if so,  
   where.  
   """  
   if SCons.Util.can_read_reg:  
     # If we can read the registry, get the NSIS command from it  
     try:  
       k = SCons.Util.RegOpenKeyEx(SCons.Util.hkey_mod.HKEY_LOCAL_MACHINE,  
                                   'SOFTWARE\\NSIS')  
       val, tok = SCons.Util.RegQueryValueEx(k,None)  
       ret = val + os.path.sep + 'makensis.exe'  
       if os.path.exists(ret):  
         return '"' + ret + '"'  
       else:  
         return None  
     except:  
       pass # Couldn't find the key, just act like we can't read the registry  
   # Hope it's on the path  
   return env.WhereIs('makensis.exe')  
   
 def nsis_exists(env):  
   """  
   Is NSIS findable on this machine?  
   """  
   if find_nsis(env) != None:  
     return 1  
   return 0  
   
 env['BUILDERS']['Nsis'] = SCons.Builder.Builder(generator=runNSIS,  
                                  src_suffix='.nsi',  
                                  emitter=nsis_emitter)  
   
 env.Append(SCANNERS = SCons.Scanner.Scanner( function = nsis_scanner,  
              skeys = ['.nsi']))  
   
 if not env.has_key('NSISDEFINES'):  
     env['NSISDEFINES'] = {}  
 env['NSIS'] = find_nsis(env)  
1001    
1002  #------------------------------------------------------  #------------------------------------------------------
1003  # BUILD...  # BUILD...

Legend:
Removed from v.577  
changed lines
  Added in v.578

john.pye@anu.edu.au
ViewVC Help
Powered by ViewVC 1.1.22