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