]>
Commit | Line | Data |
---|---|---|
b2898c45 VM |
1 | from waflib.Context import Context |
2 | from waflib.Build import BuildContext, CleanContext, \ | |
3 | InstallContext, UninstallContext | |
4 | ||
9ace34c8 | 5 | # Unix flags |
405ac511 | 6 | CFLAGS_UNIX = ["-O2", "-Wall", "-Wextra"] |
ba84cad3 | 7 | CFLAGS_UNIX_DBG = ['-g', '-O0'] |
9ace34c8 AB |
8 | |
9 | # Windows MSVC flags | |
f73b09cd | 10 | CFLAGS_WIN32_COMMON = ['/TC', '/W4', '/WX', '/nologo', '/Zi'] |
9ace34c8 AB |
11 | CFLAGS_WIN32_RELEASE = ['/O2', '/MD'] |
12 | ||
13 | # Note: /RTC* cannot be used with optimization on. | |
14 | CFLAGS_WIN32_DBG = ['/Od', '/RTC1', '/RTCc', '/DEBUG', '/MDd'] | |
15 | CFLAGS_WIN32_L = ['/RELEASE'] # used for /both/ debug and release builds. | |
16 | # sets the module's checksum in the header. | |
405ac511 | 17 | CFLAGS_WIN32_L_DBG = ['/DEBUG'] |
5dc2bee1 | 18 | |
8a64bc29 | 19 | ALL_LIBS = ['crypto', 'pthread', 'sqlite3', 'hiredis'] |
357547fa VM |
20 | |
21 | def options(opt): | |
2cd6d686 VM |
22 | opt.load('compiler_c') |
23 | opt.add_option('--sha1', action='store', default='builtin', | |
24 | help="Use the builtin SHA1 routines (builtin), the \ | |
e06551e5 | 25 | PPC optimized version (ppc) or the SHA1 functions from OpenSSL (openssl)") |
2cd6d686 VM |
26 | opt.add_option('--debug', action='store_true', default=False, |
27 | help='Compile with debug symbols') | |
28 | opt.add_option('--msvc', action='store', default=None, | |
29 | help='Force a specific MSVC++ version (7.1, 8.0, 9.0, 10.0), if more than one is installed') | |
30 | opt.add_option('--arch', action='store', default='x86', | |
31 | help='Select target architecture (ia64, x64, x86, x86_amd64, x86_ia64)') | |
bb3de0c4 | 32 | opt.add_option('--with-sqlite', action='store_true', default=False, |
a796d24c | 33 | dest='use_sqlite', help='Enable sqlite support') |
8a64bc29 DK |
34 | opt.add_option('--with-hiredis', action='store_true', default=False, |
35 | dest='use_hiredis', help='Enable redis support using hiredis') | |
bb3de0c4 VM |
36 | opt.add_option('--threadsafe', action='store_true', default=False, |
37 | help='Make libgit2 thread-safe (requires pthreads)') | |
357547fa VM |
38 | |
39 | def configure(conf): | |
f73b09cd | 40 | |
2cd6d686 VM |
41 | # load the MSVC configuration flags |
42 | if conf.options.msvc: | |
43 | conf.env['MSVC_VERSIONS'] = ['msvc ' + conf.options.msvc] | |
8507ab12 | 44 | |
2cd6d686 | 45 | conf.env['MSVC_TARGETS'] = [conf.options.arch] |
8507ab12 | 46 | |
2cd6d686 VM |
47 | # default configuration for C programs |
48 | conf.load('compiler_c') | |
357547fa | 49 | |
f73b09cd VM |
50 | dbg = conf.options.debug |
51 | ||
52 | conf.env.CFLAGS = CFLAGS_UNIX + (CFLAGS_UNIX_DBG if dbg else []) | |
53 | ||
2cd6d686 VM |
54 | if conf.env.DEST_OS == 'win32': |
55 | conf.env.PLATFORM = 'win32' | |
5dc2bee1 | 56 | |
f73b09cd VM |
57 | if conf.env.CC_NAME == 'msvc': |
58 | conf.env.CFLAGS = CFLAGS_WIN32_COMMON + \ | |
59 | (CFLAGS_WIN32_DBG if dbg else CFLAGS_WIN32_RELEASE) | |
60 | conf.env.LINKFLAGS += CFLAGS_WIN32_L + \ | |
61 | (CFLAGS_WIN32_L_DBG if dbg else []) | |
62 | conf.env.DEFINES += ['WIN32', '_DEBUG', '_LIB'] | |
63 | ||
2cd6d686 VM |
64 | else: |
65 | conf.env.PLATFORM = 'unix' | |
bb3de0c4 VM |
66 | |
67 | if conf.options.threadsafe: | |
68 | if conf.env.PLATFORM == 'unix': | |
69 | conf.check_cc(lib='pthread', uselib_store='pthread') | |
70 | conf.env.DEFINES += ['GIT_THREADS'] | |
5dc2bee1 | 71 | |
c041af95 | 72 | # check for sqlite3 |
af774b01 OR |
73 | if conf.options.use_sqlite and conf.check_cc( |
74 | lib='sqlite3', uselib_store='sqlite3', install_path=None, mandatory=False): | |
c041af95 | 75 | conf.env.DEFINES += ['GIT2_SQLITE_BACKEND'] |
e06551e5 | 76 | |
8a64bc29 DK |
77 | # check for hiredis |
78 | if conf.options.use_hiredis and conf.check_cc( | |
79 | lib='hiredis', uselib_store='hiredis', install_path=None, mandatory=False): | |
80 | conf.env.DEFINES += ['GIT2_HIREDIS_BACKEND'] | |
81 | ||
82 | ||
2cd6d686 | 83 | if conf.options.sha1 not in ['openssl', 'ppc', 'builtin']: |
83403e99 | 84 | conf.fatal('Invalid SHA1 option') |
357547fa | 85 | |
2cd6d686 VM |
86 | # check for libcrypto (openssl) if we are using its SHA1 functions |
87 | if conf.options.sha1 == 'openssl': | |
88 | conf.check_cfg(package='libcrypto', args=['--cflags', '--libs'], uselib_store='crypto') | |
89 | conf.env.DEFINES += ['OPENSSL_SHA1'] | |
5dc2bee1 | 90 | |
2cd6d686 VM |
91 | elif conf.options.sha1 == 'ppc': |
92 | conf.env.DEFINES += ['PPC_SHA1'] | |
e06551e5 | 93 | |
2cd6d686 | 94 | conf.env.sha1 = conf.options.sha1 |
357547fa | 95 | |
357547fa | 96 | def build(bld): |
b2898c45 | 97 | |
2cd6d686 VM |
98 | # command '[build|clean|install|uninstall]-static' |
99 | if bld.variant == 'static': | |
e7379f33 | 100 | build_library(bld, 'static') |
d910be21 | 101 | |
2cd6d686 VM |
102 | # command '[build|clean|install|uninstall]-shared' |
103 | elif bld.variant == 'shared': | |
e7379f33 | 104 | build_library(bld, 'shared') |
d910be21 | 105 | |
2cd6d686 | 106 | # command '[build|clean]-tests' |
2a1732b4 | 107 | elif bld.variant == 'test': |
e7379f33 | 108 | build_library(bld, 'objects') |
2a1732b4 | 109 | build_test(bld) |
357547fa | 110 | |
2cd6d686 VM |
111 | # command 'build|clean|install|uninstall': by default, run |
112 | # the same command for both the static and the shared lib | |
113 | else: | |
114 | from waflib import Options | |
115 | Options.commands = [bld.cmd + '-shared', bld.cmd + '-static'] + Options.commands | |
d910be21 | 116 | |
9d1dcca2 VM |
117 | def get_libgit2_version(git2_h): |
118 | import re | |
119 | line = None | |
120 | ||
121 | with open(git2_h) as f: | |
7064938b | 122 | line = re.search(r'^#define LIBGIT2_VERSION "(\d+\.\d+\.\d+)"$', f.read(), re.MULTILINE) |
9d1dcca2 VM |
123 | |
124 | if line is None: | |
7064938b | 125 | raise Exception("Failed to detect libgit2 version") |
9d1dcca2 VM |
126 | |
127 | return line.group(1) | |
128 | ||
129 | ||
e7379f33 VM |
130 | def build_library(bld, build_type): |
131 | ||
132 | BUILD = { | |
133 | 'shared' : bld.shlib, | |
134 | 'static' : bld.stlib, | |
135 | 'objects' : bld.objects | |
136 | } | |
2cd6d686 | 137 | |
e7379f33 | 138 | directory = bld.path |
2cd6d686 VM |
139 | sources = directory.ant_glob('src/*.c') |
140 | ||
9d1dcca2 | 141 | # Find the version of the library, from our header file |
71d33382 | 142 | version = get_libgit2_version(directory.find_node("include/git2.h").abspath()) |
9d1dcca2 | 143 | |
2cd6d686 VM |
144 | # Compile platform-dependant code |
145 | # E.g. src/unix/*.c | |
146 | # src/win32/*.c | |
147 | sources = sources + directory.ant_glob('src/%s/*.c' % bld.env.PLATFORM) | |
c041af95 | 148 | sources = sources + directory.ant_glob('src/backends/*.c') |
ab6a3d3d | 149 | sources = sources + directory.ant_glob('deps/zlib/*.c') |
2cd6d686 VM |
150 | |
151 | # SHA1 methods source | |
152 | if bld.env.sha1 == "ppc": | |
153 | sources.append('src/ppc/sha1.c') | |
154 | else: | |
155 | sources.append('src/block-sha1/sha1.c') | |
2cd6d686 VM |
156 | #------------------------------ |
157 | # Build the main library | |
158 | #------------------------------ | |
159 | ||
160 | # either as static or shared; | |
e7379f33 | 161 | BUILD[build_type]( |
2cd6d686 VM |
162 | source=sources, |
163 | target='git2', | |
ab6a3d3d | 164 | includes=['src', 'include', 'deps/zlib'], |
2cd6d686 | 165 | install_path='${LIBDIR}', |
9d1dcca2 VM |
166 | use=ALL_LIBS, |
167 | vnum=version, | |
2cd6d686 VM |
168 | ) |
169 | ||
170 | # On Unix systems, build the Pkg-config entry file | |
e7379f33 | 171 | if bld.env.PLATFORM == 'unix' and bld.is_install: |
9d1dcca2 | 172 | bld(rule="""sed -e 's#@prefix@#${PREFIX}#' -e 's#@libdir@#${LIBDIR}#' -e 's#@version@#%s#' < ${SRC} > ${TGT}""" % version, |
2cd6d686 VM |
173 | source='libgit2.pc.in', |
174 | target='libgit2.pc', | |
175 | install_path='${LIBDIR}/pkgconfig', | |
176 | ) | |
177 | ||
178 | # Install headers | |
71d33382 VM |
179 | bld.install_files('${PREFIX}/include', directory.find_node('include/git2.h')) |
180 | bld.install_files('${PREFIX}/include/git2', directory.ant_glob('include/git2/*.h')) | |
b2898c45 | 181 | |
a58e6a5f | 182 | # On Unix systems, let them know about installation |
2645053b | 183 | if bld.env.PLATFORM == 'unix' and bld.cmd == 'install-shared': |
a58e6a5f MV |
184 | bld.add_post_fun(call_ldconfig) |
185 | ||
186 | def call_ldconfig(bld): | |
2645053b VM |
187 | import distutils.spawn as s |
188 | ldconf = s.find_executable('ldconfig') | |
189 | if ldconf: | |
190 | bld.exec_command(ldconf) | |
a58e6a5f | 191 | |
2a1732b4 | 192 | def build_test(bld): |
2cd6d686 | 193 | directory = bld.path |
0847dff5 | 194 | resources_path = directory.find_node('tests/resources/').abspath().replace('\\', '/') |
2cd6d686 | 195 | |
2a1732b4 VM |
196 | sources = ['tests/test_lib.c', 'tests/test_helpers.c', 'tests/test_main.c'] |
197 | sources = sources + directory.ant_glob('tests/t??-*.c') | |
b2898c45 | 198 | |
2a1732b4 VM |
199 | bld.program( |
200 | source=sources, | |
201 | target='libgit2_test', | |
71d33382 | 202 | includes=['src', 'tests', 'include'], |
2a1732b4 VM |
203 | defines=['TEST_RESOURCES="%s"' % resources_path], |
204 | use=['git2'] + ALL_LIBS | |
205 | ) | |
d910be21 VM |
206 | |
207 | class _test(BuildContext): | |
2cd6d686 VM |
208 | cmd = 'test' |
209 | fun = 'test' | |
d910be21 VM |
210 | |
211 | def test(bld): | |
2cd6d686 | 212 | from waflib import Options |
2a1732b4 | 213 | Options.commands = ['build-test', 'run-test'] + Options.commands |
d910be21 | 214 | |
9de351b2 VM |
215 | class _build_doc(Context): |
216 | cmd = 'doxygen' | |
217 | fun = 'build_docs' | |
218 | ||
219 | def build_docs(ctx): | |
220 | ctx.exec_command("doxygen api.doxygen") | |
221 | ctx.exec_command("git stash") | |
222 | ctx.exec_command("git checkout gh-pages") | |
223 | ctx.exec_command("cp -Rf apidocs/html/* .") | |
224 | ctx.exec_command("git add .") | |
225 | ctx.exec_command("git commit -am 'generated docs'") | |
226 | ctx.exec_command("git push origin gh-pages") | |
227 | ctx.exec_command("git checkout master") | |
d910be21 | 228 | |
2a1732b4 VM |
229 | class _run_test(Context): |
230 | cmd = 'run-test' | |
231 | fun = 'run_test' | |
b2898c45 | 232 | |
2a1732b4 | 233 | def run_test(ctx): |
51035184 | 234 | import shutil, tempfile, sys |
b2898c45 | 235 | |
2cd6d686 | 236 | failed = False |
0ef70b4a | 237 | |
2a1732b4 | 238 | test_path = 'build/test/libgit2_test' |
51035184 | 239 | if sys.platform == 'win32': |
2a1732b4 VM |
240 | test_path += '.exe' |
241 | ||
242 | test_folder = tempfile.mkdtemp() | |
243 | test = ctx.path.find_node(test_path) | |
51035184 | 244 | |
2a1732b4 VM |
245 | if not test or ctx.exec_command(test.abspath(), cwd=test_folder) != 0: |
246 | failed = True | |
b2898c45 | 247 | |
2cd6d686 | 248 | shutil.rmtree(test_folder) |
5dc2bee1 | 249 | |
2cd6d686 VM |
250 | if failed: |
251 | ctx.fatal('Test run failed') | |
357547fa | 252 | |
d910be21 VM |
253 | |
254 | CONTEXTS = { | |
2cd6d686 VM |
255 | 'build' : BuildContext, |
256 | 'clean' : CleanContext, | |
257 | 'install' : InstallContext, | |
258 | 'uninstall' : UninstallContext | |
d910be21 VM |
259 | } |
260 | ||
261 | def build_command(command): | |
2cd6d686 VM |
262 | ctx, var = command.split('-') |
263 | class _gen_command(CONTEXTS[ctx]): | |
264 | cmd = command | |
265 | variant = var | |
d910be21 VM |
266 | |
267 | build_command('build-static') | |
268 | build_command('build-shared') | |
2a1732b4 | 269 | build_command('build-test') |
d910be21 VM |
270 | |
271 | build_command('clean-static') | |
272 | build_command('clean-shared') | |
2a1732b4 | 273 | build_command('clean-test') |
d910be21 VM |
274 | |
275 | build_command('install-static') | |
276 | build_command('install-shared') | |
277 | ||
278 | build_command('uninstall-static') | |
279 | build_command('uninstall-shared') | |
357547fa | 280 |