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