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