source: SConstruct @ 226

Last change on this file since 226 was 226, checked in by tim, 14 years ago

several fixes for pyregfi Windows portability
better error handling within pyregfi

File size: 5.6 KB
RevLine 
[226]1cflags = '-std=gnu99 -pedantic -Wall -D_FILE_OFFSET_BITS=64 -DREGFI_WIN32'
[189]2
[191]3libiconv_path='win32/libiconv/'
4libpthreads_path='win32/libpthreads/'
5libpthread_name='pthreadGC2'
[195]6libtalloc_path='win32/libtalloc/'
[191]7
[209]8source_targets=('reglookup-src-trunk.tar.gz',)
9win32_targets=('reglookup-win32-trunk.zip',)
10doc_targets=('reglookup-doc-trunk.tar.gz',)
[222]11all_targets = source_targets+win32_targets+doc_targets
[191]12
13def target2version(target):
[222]14    chunks = target.split('-')
15    if len(chunks) != 3:
16        return None
17    return chunks[2].split('.')[0]
[191]18
19def version2input(version):
20    if version == 'trunk':
21        return 'trunk/'
22    else:
23        return 'releases/%s/' % version
24
25
26source_cmds='''
[187]27rm -rf .release;
[189]28svn export svn+ssh://sentinelchicken.org/home/projects/subversion/reglookup/$SOURCE .release/%s;
29cd .release/%s && scons doc
30cd .release && tar cf %s.tar %s && gzip -9 %s.tar;
31mv .release/%s.tar.gz . && rm -rf .release
[187]32'''
33
[191]34win32_cmds='''
[225]35rm -rf .release && mkdir -p .release/%s/python/pyregfi
[191]36cp %s/src/*.exe .release/%s
[225]37
38cp %s/pyregfi-distutils.py .release/%s/setup.py
39cp %s/python/pyregfi/*.py .release/%s/python/pyregfi
40
[222]41cp win32/libiconv/bin/*.dll win32/libpthreads/bin/*.dll win32/libtalloc/bin/*.dll trunk/lib/*.dll .release/%s
[191]42cd .release && zip -r %s.zip %s
43mv .release/%s.zip . && rm -rf .release
44'''
[187]45
[209]46doc_cmds='''
47rm -rf .release;
48svn export svn+ssh://sentinelchicken.org/home/projects/subversion/reglookup/ .release;
49cd .release && doxygen Doxyfile.regfi
[221]50cd .release && doxygen Doxyfile.pyregfi
[209]51mv .release/doc .release/%s
52cd .release && tar cf %s.tar %s && gzip -9 %s.tar;
53mv .release/%s.tar.gz . && rm -rf .release
54'''
55
[189]56def generate_cmds(source, target, env, for_signature):
57    ret_val = ''
58    for t in target:
[191]59        t = str(t)
60        t_base = t.split('.tar.gz')[0].split('.zip')[0]
61        if t in source_targets:
62            ret_val += source_cmds % (t_base,t_base,t_base,
63                                      t_base,t_base,t_base)
64        elif t in win32_targets:
65            version = target2version(t)
66            input_prefix = version2input(version)
67
68            env['platform']='cygwin'
69            env['CC']='i586-mingw32msvc-cc'
70            env['AR']='i586-mingw32msvc-ar'
71            env['RANLIB']='i586-mingw32msvc-ranlib'
72           
73            env['CFLAGS']=cflags
74            env['CPPPATH']=[input_prefix+'include',
75                            libiconv_path+'include',
[195]76                            libpthreads_path+'include',
77                            libtalloc_path+'include']
[191]78            env['LIBPATH']=[input_prefix+'lib',
79                            libiconv_path+'lib',
[195]80                            libpthreads_path+'lib',
81                            libtalloc_path+'lib']
82            env['LIBS']=['m', libpthread_name, 'iconv', 'regfi', 'talloc']
[222]83           
84            # Third-party dependencies
85            extra_obj=['%s/lib/lib%s.a' % (libpthreads_path, libpthread_name),
86                       libiconv_path+'/lib/libiconv.dll.a',
87                       libtalloc_path+'/lib/libtalloc.dll.a']
[191]88
[222]89            # Build libregfi.dll
90            #   Core regfi source
[191]91            lib_src = [input_prefix+'lib/regfi.c',
92                       input_prefix+'lib/winsec.c',
93                       input_prefix+'lib/range_list.c',
94                       input_prefix+'lib/lru_cache.c',
95                       input_prefix+'lib/void_stack.c']
[222]96            regfi_o = env.Object(lib_src)
[191]97
[222]98            regfi_obj = []
99            for s in lib_src:
100                regfi_obj.append(s[0:-1]+'o')
[191]101
[226]102            # XXX: Several options here may not be necessary. 
103            #      Need to investigate why stdcall interfaces don't seem to be
104            #      working on Windows.
[222]105            env.Command(input_prefix+'lib/libregfi.o', regfi_o+extra_obj,
106                        'i586-mingw32msvc-dlltool --export-all-symbols'
[226]107                        +' --add-stdcall-alias  --dllname libregfi.dll -e $TARGET'
[222]108                        +' -l %slib/libregfi.dll.a %s'
109                        % (input_prefix, ' '.join(regfi_obj)))
110
111            env.Command(input_prefix+'lib/libregfi.dll',
112                        input_prefix+'lib/libregfi.o',
[226]113                        'i586-mingw32msvc-gcc ' + cflags
114                        + ' --shared -Wl,--out-implib -add-stdcall-alias -o $TARGET $SOURCE %s'
[222]115                        % ' '.join(regfi_obj+extra_obj))
116
[191]117            # Executables
118            reglookup = env.Program(input_prefix+'src/reglookup.exe',
119                                    [input_prefix+'src/reglookup.c']+extra_obj)
120            reglookup_recover = env.Program(input_prefix+'src/reglookup-recover.exe',
121                                            [input_prefix+'src/reglookup-recover.c']+extra_obj)
122
[225]123            ret_val += win32_cmds % (t_base,input_prefix,t_base,input_prefix,
124                                     t_base,input_prefix,
[191]125                                     t_base,t_base,t_base,t_base,t_base)
126
[209]127        elif t in doc_targets:
128            ret_val += doc_cmds % (t_base,t_base,t_base,t_base,t_base)
[191]129       
[189]130    return ret_val
[187]131
[188]132
[191]133
[189]134release_builder = Builder(generator = generate_cmds,
135                          suffix = '.tar.gz',
136                          src_suffix = '',
137                          prefix='reglookup-')
[188]138
[191]139
[189]140env = Environment()
141env['BUILDERS']['Release'] = release_builder
[188]142
[222]143if len(COMMAND_LINE_TARGETS) == 0:
144    print('Acceptable targets: %s' % repr(all_targets))
[189]145
[195]146for target in COMMAND_LINE_TARGETS:
[222]147    AlwaysBuild(target)
148    if target not in all_targets:
149        print('ERROR: cannot build "%s".  Acceptable targets: %s'
150              % (target, repr(all_targets)))
151        break
[191]152    env.Release(target, Dir(version2input(target2version(target))))
[189]153
[187]154Default(None)
Note: See TracBrowser for help on using the repository browser.