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