- Timestamp:
- Dec 6, 2017 9:03:34 PM (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
TabularUnified trunk/fsource/SConstruct ¶
r3136 r3178 2 2 # it compiles the Fortran files needed to be used as Python packages for GSAS-II 3 3 # 4 # if the default options need to be overridden for this to work on your system, please let me4 # if the default options need to be overridden for this to work on your system, please let us 5 5 # know the details of what OS, compiler and python you are using as well as the command-line 6 6 # options you need. … … 10 10 import glob 11 11 import subprocess 12 import numpy as np 12 13 #========================================================================================== 13 14 def is_exe(fpath): … … 28 29 return path 29 30 return "" 31 32 def GetBinaryDir(): 33 # format current platform, Python & numpy version 34 if sys.platform == "win32": 35 prefix = 'win' 36 elif sys.platform == "darwin": 37 prefix = 'mac' 38 elif sys.platform.startswith("linux"): 39 prefix = 'linux' 40 else: 41 print(u'Unknown platform: '+sys.platform) 42 raise Exception('Unknown platform') 43 if platform.architecture()[0] == '64bit': 44 bits = '64' 45 else: 46 bits = '32' 47 pyver = 'p{}.{}'.format(*sys.version_info[0:2]) 48 npver = 'n' + np.__version__[:np.__version__.find('.',2)] 49 return '_'.join([prefix,bits,pyver,npver]) 30 50 #========================================================================================== 31 51 # misc initializations … … 74 94 FORTpath = "" 75 95 FORTflags = "" 76 liblist = []77 96 LDFLAGS = '' 78 97 #========================================================================================== … … 84 103 elif GFORTpath != "": 85 104 FCompiler='gfortran' 86 # LDFLAGS = '-static-libgfortran -static-libgcc'87 105 else: 88 106 print ('No Fortran compiler in path') 89 107 sys.exit() 90 108 elif sys.platform == "darwin": 91 LDFLAGS = '-undefined dynamic_lookup -bundle -static-libgfortran -static-libgcc'109 LDFLAGS = '-undefined dynamic_lookup -bundle' 92 110 F2PYsuffix = '.so' 93 elif sys.platform == "linux2":111 elif sys.platform.startswith("linux"): 94 112 #LDFLAGS = '-Wall -shared -static-libgfortran -static-libgcc' # does not work with gfortran 4.4.4 20100726 (Red Hat 4.4.4-13) 95 113 F2PYsuffix = '.so' … … 97 115 print ("Sorry, parameters for platform "+sys.platform+" are not yet defined") 98 116 sys.exit() 117 if FCompiler == 'gfortran': 118 if ARGUMENTS.get('LIBGCC', '').upper().startswith('T'): 119 LDFLAGS += ' -static-libgcc' 120 print('LIBGCC') 121 if ARGUMENTS.get('LIBGFORTRAN', '').upper().startswith('T'): 122 LDFLAGS += ' -static-libgfortran' 123 print('LIBGfortran') 124 99 125 #========================================================================================== 100 126 # help … … 113 139 -n -- causes scons to show but not execute the commands it will perform 114 140 115 -c -- clean: causes scons to delete previously created files ( don't use116 with install)141 -c -- clean: causes scons to delete previously created files (but not from 142 install directory) 117 143 118 144 help -- causes this message to be displayed (no compiling is done) 119 145 120 install -- causes the module files to be placed in an installation directory 121 (../bin<X>NNv.v) rather than ../bin (<X> is mac, win or linux; NN is 64- 122 or blank; v.v is the python version (2.6 or 2.7,...). Normally used only 123 by Brian or Bob for distribution of compiled software. 146 install=T -- causes the module files to be placed in an installation directory 147 (../AllBinaries/<X>_NN_pv.v_nv.v) rather than ../bin, where: 148 <X> is mac, win or linux; 149 NN is 64 or 32; 150 pv.v is the Python version (p2.7 or p3.6,...) and 151 nv.v is the Numpy version (n1.13,...). 152 Normally used only by Brian or Bob for distribution of compiled software. 124 153 125 154 The following options override defaults set in the scons script: … … 144 173 mac/linux: '.so') 145 174 175 LIBGCC=T -- adds the option -static-libgcc as an link option with gfortran. This 176 prevents use of the dynamic libgcc library, which must be then present on each 177 run-time computer. To use this, gfortran must be installed with the static 178 libraries. 179 180 LIBGFORTRAN=T -- adds the option -static-libgfortran as an link option with 181 gfortran. This prevents use of the dynamic libgcc library, which then must be 182 present on each run-time computer. To use this, gfortran must be installed 183 with the static libraries. 184 146 185 LDFLAGS='string' -- string of options to be used for f2py during link step 147 186 … … 188 227 version = str(int(versions[0])) + '.' + str(int(versions[1])) 189 228 PlatformBits = '64bits' 190 if '32' in platform. python_compiler():229 if '32' in platform.architecture()[0]: 191 230 PlatformBits = '32bits' 192 231 #PlatformBits = versions[2][:-1] 193 232 # 194 print (version,PlatformBits) 195 # Install location 196 InstallLoc = '../bin' 197 if len(COMMAND_LINE_TARGETS) == 0: 198 Default(InstallLoc) 199 elif 'install' in COMMAND_LINE_TARGETS: 200 if PlatformBits == '64bit': 201 bits = '64-' 202 else: 203 bits = '' 204 if sys.platform == "win32": 205 prefix = 'binwin' 206 elif sys.platform == "darwin": 207 prefix = 'binmac' 208 elif sys.platform == "linux2": 209 prefix = 'binlinux' 210 InstallLoc = '../' + prefix + bits + version 211 Alias('install',InstallLoc) 233 # Set install location 234 if ARGUMENTS.get('install', '').upper().startswith('T'): 235 InstallLoc = os.path.join('..','AllBinaries', GetBinaryDir()) 236 else: 237 InstallLoc = os.path.join('..','bin') 212 238 #========================================================================================== 213 239 # use the compiler choice to set compiler options, but don't change anything … … 215 241 if FCompiler == 'gfortran': 216 242 if FORTpath == "": FORTpath = GFORTpath 217 if sys.platform == "linux2" and PlatformBits == '64bit':243 if sys.platform.startswith("linux") and "64" in PlatformBits: 218 244 if FORTflags == "": FORTflags = ' -w -O2 -fPIC -m64' 219 245 if F2PYflags == "": F2PYflags = '--fcompiler=gnu95 --f77exec=gfortran --f77flags="-fno-range-check -m64"'# --arch="-arch x86_64"' 220 elif sys.platform == "linux2":246 elif sys.platform.startswith("linux"): 221 247 if FORTflags == "": FORTflags = ' -w -O2 -fPIC -m32' 222 248 if F2PYflags == "": F2PYflags = '--fcompiler=gnu95 --f77exec=gfortran --f77flags="-fno-range-check -m32"' 223 elif sys.platform == "darwin" and PlatformBits == '64bit': 249 elif sys.platform == "darwin": # now 64 bit only 250 #if "64" in PlatformBits: 224 251 LDFLAGS += " -arch x86_64 -m64" 225 252 if FORTflags == "": FORTflags = ' -w -O2 -m64' 226 253 if F2PYflags == "": F2PYflags = '--fcompiler=gnu95 --f77exec=gfortran --f77flags="-fno-range-check -m64"' 227 elif sys.platform == "darwin": 228 if F2PYflags == "": F2PYflags = '--fcompiler=gnu95 --f77exec=gfortran --f77flags="-fno-range-check -m32"' 254 elif sys.platform == "win32" and "64" in PlatformBits: 255 if FORTflags == "": FORTflags = ' -w -O2 -m64' 256 if F2PYflags == "": 257 F2PYflags = '--compiler=mingw32 --fcompiler=gfortran --f77flags="-fno-range-check -m64"' 229 258 elif sys.platform == "win32": 230 if F2PYflags == "": F2PYflags = '--compiler=mingw32 --fcompiler=gfortran --f77flags="-fno-range-check -m64"' 259 #if FORTflags == "": FORTflags = ' -w -O2 -m32' 260 if F2PYflags == "": 261 F2PYflags = '--compiler=mingw32 --fcompiler=gfortran --f77flags="-fno-range-check"' 231 262 elif FCompiler == 'g77': 232 263 if FORTpath == "": FORTpath = G77path … … 252 283 module = module + ' ' + str(lib) 253 284 f2pyprogram = os.path.normpath(os.path.join(F2PYpath,F2PYprog)) 254 if os.path.splitext(F2PYprog)[1] == '.py': 255 return pythonprogram + ' ' + f2pyprogram + ' -c $SOURCE ' + ' -m ' + module + ' ' + F2PYflags 256 else: 257 return f2pyprogram + ' -c $SOURCE' + ' -m ' + module + ' ' + F2PYflags 285 if os.path.splitext(F2PYprog)[1] == '.py': # use f2py.py if no f2py[.exe] 286 f2pycmd = pythonprogram + ' ' + f2pyprogram + ' -c $SOURCE ' + ' -m ' + module + ' ' + F2PYflags 287 else: 288 f2pycmd = f2pyprogram + ' -c $SOURCE' + ' -m ' + module + ' ' + F2PYflags 289 if sys.platform == "win32": 290 installcmd = "copy " + os.path.splitext(str(source[0]))[0] + '*' + F2PYsuffix + ' ' + InstallLoc 291 else: 292 installcmd = "cp " + os.path.splitext(str(source[0]))[0] + '*' + F2PYsuffix + ' ' + InstallLoc 293 return [f2pycmd, installcmd] 258 294 f2py = Builder(generator = generate_f2py) 259 295 env.Append(BUILDERS = {'f2py' : f2py},) … … 282 318 # add other needed environment variables 283 319 var = 'LDFLAGS' 284 if eval(var) != "": env['ENV'][var] = eval(var) 320 if eval(var) != "": 321 env['ENV'][var] = eval(var) 322 print("Setting environment variable {} to {}".format(var,eval(var))) 323 if 'WINDIR' in os.environ: env['ENV']['WINDIR'] = os.environ['WINDIR'] 285 324 286 325 #========================================================================================== 287 326 # finally ready to build something! 288 327 # locate libraries to be built (subdirectories named *subs) 328 liblist = [] 289 329 for sub in glob.glob('*subs'): 290 330 filelist = [] … … 301 341 liblist.append(lib[0].name) 302 342 filename = str(lib[0]) 303 #Install(InstallLoc,filename)304 343 # find modules that need to be built 305 344 modlist = [] … … 307 346 target = os.path.splitext(src)[0] + F2PYsuffix 308 347 out = env.f2py(target,src) 348 Clean(out, Glob(os.path.splitext(src)[0] + "*" + F2PYsuffix)) # this picks up old- & new-style .pyd/.so names 309 349 Depends(target, liblist) # make sure libraries are rebuilt if old 310 350 modlist.append(out[0].name) 311 env.Install(InstallLoc, out[0].name)312 351 #break # bail out early for testing 313 352 #========================================================================================== … … 328 367 #print (env.Dump()) 329 368 if 'help' in COMMAND_LINE_TARGETS: sys.exit() 369 if not os.path.exists(InstallLoc): 370 print('Creating '+InstallLoc) 371 os.makedirs(InstallLoc)
Note: See TracChangeset
for help on using the changeset viewer.