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