source: SConstruct @ 232

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

added a convenience openHive function in pyregfi
standardized static function names
improvements to scons release script and library versioning

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