* fprintf of a pseudoAxes also return the restricted symm angle
[hkl.git] / SConstruct
blob002faf5af9352a3edce7e5e247f5d88127f0d390
1 # vi:filetype=python:expandtab:tabstop=2:shiftwidth=2
2 import os, sys
4 #sys.path.append('tool')
6 #----------------------------------------------------------
7 # Required runtime environment
8 #----------------------------------------------------------
10 # Please use at least 0.98.0
11 EnsureSConsVersion(0, 98, 0)
13 #----------------------------------------------------------
14 # Global definitions
15 #----------------------------------------------------------
17 # some global settings
19 dirs_common = ['include/hkl', 'src', 'test', 'Documentation']
21 #----------------------------------------------------------
22 # platform dependent settings
23 #----------------------------------------------------------
24 print os.name
25 if os.name == 'nt':
26 platform_name = 'win32'
27 dirs_platform = []
28 elif os.name == 'posix' and sys.platform != 'cygwin':
29 platform_name = sys.platform
30 dirs_platform = []
32 #---------------------------------------------------------
33 # Handling options
34 #----------------------------------------------------------
35 option_file = 'config-' + platform_name + '.py'
37 opts = Options(option_file)
38 opts.AddOptions(
39 # debug or release build
40 EnumOption('mode', 'Building method', 'debug', allowed_values = ('debug', 'release')),
41 # test
42 BoolOption('test', 'Build and run the unit test', True),
43 # gsl
44 PathOption('gsl_inc_path', 'where we can find the gsl/*.h files', None),
45 PathOption('gsl_lib_path', 'where we can find the gsl library files', None),
46 # packaging
47 PathOption('DESTDIR', 'Where to install the package', '/'),
48 PathOption('prefix', 'the package is build for this path', '/usr')
51 #---------------------------------------------------------
52 # Setting up environment
53 #---------------------------------------------------------
54 env = Environment(tools = ['default', 'packaging'], options = opts)
56 # create the build directory
57 build_dir = os.path.join(env['mode'], platform_name)
58 if not os.path.isdir(build_dir):
59 os.makedirs(build_dir)
61 # -h will print out help info
62 Help(opts.GenerateHelpText(env))
64 #add the default cxxflags and ldflags depending on the platform
65 cflags = []
66 cxxflags = []
67 cppdefines = []
68 linkflags = []
70 if platform_name == 'linux2':
71 cflags += ['-Wall', '-std=gnu99']
72 cxxflags += ['-Wall']
73 elif platform_name == 'win32':
74 cflags += ['/GX', '/MD', '/GR']
75 cxxflags += ['/GX', '/MD', '/GR']
77 #add the debug flag if needed
78 mode = None
79 if env.has_key('mode'):
80 mode = env['mode']
81 if mode == 'debug':
82 if platform_name == 'win32':
83 cflags += ['/ZI']
84 cxxflags += ['/ZI']
85 elif platform_name == 'linux2':
86 cflags += ['-g', '-O0']
87 cxxflags += ['-g', '-O0']
88 elif mode == 'release':
89 cppdefines += ['NDEBUG']
90 if platform_name == 'linux2':
91 cflags += ['-O2']
92 cxxflags += ['-O2']
93 elif platform_name == 'win32':
94 cflags += ['/Op']
95 cxxflags += ['/Op']
97 env.AppendUnique(CFLAGS = cflags)
98 env.AppendUnique(CXXFLAGS = cxxflags)
99 env.AppendUnique(CPPDEFINES = cppdefines)
100 env.AppendUnique(LINKFLAGS = linkflags)
102 # Create a builder for tests
103 def builder_unit_test(target, source, env):
104 app = str(source[0].abspath)
105 lenv = os.environ
106 lenv['LD_LIBRARY_PATH'] = os.path.join(build_dir, 'src')
107 if os.spawnle(os.P_WAIT, app, app, lenv) == 0:
108 open(str(target[0]),'w').write("PASSED\n")
109 else:
110 return -1
112 bld = Builder(action = builder_unit_test)
113 env.Append(BUILDERS = {'Test' : bld})
114 opts.Save(option_file, env)
116 #----------------------------------------------------------
117 # Building
118 #----------------------------------------------------------
120 #put the SConsignFile in one place
121 sconsign_file = os.path.join(build_dir, '.sconsign')
122 env.SConsignFile(sconsign_file)
124 #no default target add manually
125 Default(None)
126 dirs = dirs_common + dirs_platform
127 for dir in dirs:
128 file = os.path.join(dir, 'SConscript')
129 env.SConscript(file, variant_dir = os.path.join(build_dir, dir), duplicate = 0, exports = 'env')
131 #----------------------------------------------------------
132 # Packaging
133 #----------------------------------------------------------
135 #trick to put the right sources in the package at the right place
136 sources = [ s.path.replace(os.path.join(build_dir, ''), '') for s in env.FindSourceFiles()]
138 env.Package(NAME = 'hkl',
139 VERSION = '3.0.0',
140 PACKAGEVERSION = 0,
141 PACKAGETYPE = ['src_tarbz2'],
142 LICENSE = 'gpl',
143 SUMMARY = 'Diffractometer computation library',
144 DESCRIPTION = 'Diffractometer computation library',
145 SOURCE_URL = 'http://foo.org/foo-1.2.3.tar.gz',
146 source = sources + ['README']