1 # vi:filetype=python:expandtab:tabstop=2:shiftwidth=2
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 #----------------------------------------------------------
15 #----------------------------------------------------------
17 # some global settings
19 dirs_common
= ['include/hkl', 'src', 'test', 'Documentation']
21 #----------------------------------------------------------
22 # platform dependent settings
23 #----------------------------------------------------------
26 platform_name
= 'win32'
28 elif os
.name
== 'posix' and sys
.platform
!= 'cygwin':
29 platform_name
= sys
.platform
32 #---------------------------------------------------------
34 #----------------------------------------------------------
35 option_file
= 'config-' + platform_name
+ '.py'
37 opts
= Options(option_file
)
39 # debug or release build
40 EnumOption('mode', 'Building method', 'debug', allowed_values
= ('debug', 'release')),
42 BoolOption('test', 'Build and run the unit test', True),
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),
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
70 if platform_name
== 'linux2':
71 cflags
+= ['-Wall', '-std=gnu99']
73 elif platform_name
== 'win32':
74 cflags
+= ['/GX', '/MD', '/GR']
75 cxxflags
+= ['/GX', '/MD', '/GR']
77 #add the debug flag if needed
79 if env
.has_key('mode'):
82 if platform_name
== 'win32':
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':
93 elif platform_name
== 'win32':
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
)
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")
112 bld
= Builder(action
= builder_unit_test
)
113 env
.Append(BUILDERS
= {'Test' : bld
})
114 opts
.Save(option_file
, env
)
116 #----------------------------------------------------------
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
126 dirs
= dirs_common
+ dirs_platform
128 file = os
.path
.join(dir, 'SConscript')
129 env
.SConscript(file, variant_dir
= os
.path
.join(build_dir
, dir), duplicate
= 0, exports
= 'env')
131 #----------------------------------------------------------
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',
141 PACKAGETYPE
= ['src_tarbz2'],
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']