]>
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"] |
405ac511 | 7 | CFLAGS_UNIX_DBG = ['-g'] |
9ace34c8 AB |
8 | |
9 | # Windows MSVC flags | |
10 | CFLAGS_WIN32_COMMON = ['/TC', '/W4', '/WX', '/nologo', '/Zi'] | |
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 | |
c041af95 | 19 | ALL_LIBS = ['z', 'crypto', 'pthread', 'sqlite3'] |
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)') | |
357547fa VM |
32 | |
33 | def configure(conf): | |
8507ab12 | 34 | |
2cd6d686 VM |
35 | # load the MSVC configuration flags |
36 | if conf.options.msvc: | |
37 | conf.env['MSVC_VERSIONS'] = ['msvc ' + conf.options.msvc] | |
8507ab12 | 38 | |
2cd6d686 | 39 | conf.env['MSVC_TARGETS'] = [conf.options.arch] |
8507ab12 | 40 | |
2cd6d686 VM |
41 | # default configuration for C programs |
42 | conf.load('compiler_c') | |
357547fa | 43 | |
2cd6d686 VM |
44 | dbg = conf.options.debug |
45 | zlib_name = 'z' | |
5dc2bee1 | 46 | |
2cd6d686 | 47 | conf.env.CFLAGS = CFLAGS_UNIX + (CFLAGS_UNIX_DBG if dbg else []) |
5dc2bee1 | 48 | |
2cd6d686 VM |
49 | if conf.env.DEST_OS == 'win32': |
50 | conf.env.PLATFORM = 'win32' | |
5dc2bee1 | 51 | |
2cd6d686 | 52 | if conf.env.CC_NAME == 'msvc': |
9ace34c8 AB |
53 | conf.env.CFLAGS = CFLAGS_WIN32_COMMON + \ |
54 | (CFLAGS_WIN32_DBG if dbg else CFLAGS_WIN32_RELEASE) | |
55 | conf.env.LINKFLAGS += CFLAGS_WIN32_L + \ | |
56 | (CFLAGS_WIN32_L_DBG if dbg else []) | |
2cd6d686 VM |
57 | conf.env.DEFINES += ['WIN32', '_DEBUG', '_LIB', 'ZLIB_WINAPI'] |
58 | zlib_name = 'zlibwapi' | |
5dc2bee1 | 59 | |
2cd6d686 | 60 | elif conf.env.CC_NAME == 'gcc': |
c041af95 | 61 | conf.check_cc(lib='pthread', uselib_store='pthread') |
5dc2bee1 | 62 | |
2cd6d686 VM |
63 | else: |
64 | conf.env.PLATFORM = 'unix' | |
5dc2bee1 | 65 | |
2cd6d686 | 66 | # check for Z lib |
c041af95 VM |
67 | conf.check_cc(lib=zlib_name, uselib_store='z', install_path=None) |
68 | ||
69 | # check for sqlite3 | |
70 | if conf.check_cc(lib='sqlite3', uselib_store='sqlite3', install_path=None, mandatory=False): | |
71 | conf.env.DEFINES += ['GIT2_SQLITE_BACKEND'] | |
e06551e5 | 72 | |
2cd6d686 VM |
73 | if conf.options.sha1 not in ['openssl', 'ppc', 'builtin']: |
74 | ctx.fatal('Invalid SHA1 option') | |
357547fa | 75 | |
2cd6d686 VM |
76 | # check for libcrypto (openssl) if we are using its SHA1 functions |
77 | if conf.options.sha1 == 'openssl': | |
78 | conf.check_cfg(package='libcrypto', args=['--cflags', '--libs'], uselib_store='crypto') | |
79 | conf.env.DEFINES += ['OPENSSL_SHA1'] | |
5dc2bee1 | 80 | |
2cd6d686 VM |
81 | elif conf.options.sha1 == 'ppc': |
82 | conf.env.DEFINES += ['PPC_SHA1'] | |
e06551e5 | 83 | |
2cd6d686 | 84 | conf.env.sha1 = conf.options.sha1 |
357547fa | 85 | |
357547fa | 86 | def build(bld): |
b2898c45 | 87 | |
2cd6d686 VM |
88 | # command '[build|clean|install|uninstall]-static' |
89 | if bld.variant == 'static': | |
e7379f33 | 90 | build_library(bld, 'static') |
d910be21 | 91 | |
2cd6d686 VM |
92 | # command '[build|clean|install|uninstall]-shared' |
93 | elif bld.variant == 'shared': | |
e7379f33 | 94 | build_library(bld, 'shared') |
d910be21 | 95 | |
2cd6d686 | 96 | # command '[build|clean]-tests' |
2a1732b4 | 97 | elif bld.variant == 'test': |
e7379f33 | 98 | build_library(bld, 'objects') |
2a1732b4 | 99 | build_test(bld) |
357547fa | 100 | |
2cd6d686 VM |
101 | # command 'build|clean|install|uninstall': by default, run |
102 | # the same command for both the static and the shared lib | |
103 | else: | |
104 | from waflib import Options | |
105 | Options.commands = [bld.cmd + '-shared', bld.cmd + '-static'] + Options.commands | |
d910be21 | 106 | |
e7379f33 VM |
107 | def build_library(bld, build_type): |
108 | ||
109 | BUILD = { | |
110 | 'shared' : bld.shlib, | |
111 | 'static' : bld.stlib, | |
112 | 'objects' : bld.objects | |
113 | } | |
2cd6d686 | 114 | |
e7379f33 | 115 | directory = bld.path |
2cd6d686 VM |
116 | sources = directory.ant_glob('src/*.c') |
117 | ||
118 | # Compile platform-dependant code | |
119 | # E.g. src/unix/*.c | |
120 | # src/win32/*.c | |
121 | sources = sources + directory.ant_glob('src/%s/*.c' % bld.env.PLATFORM) | |
c041af95 | 122 | sources = sources + directory.ant_glob('src/backends/*.c') |
2cd6d686 VM |
123 | |
124 | # SHA1 methods source | |
125 | if bld.env.sha1 == "ppc": | |
126 | sources.append('src/ppc/sha1.c') | |
127 | else: | |
128 | sources.append('src/block-sha1/sha1.c') | |
2cd6d686 VM |
129 | #------------------------------ |
130 | # Build the main library | |
131 | #------------------------------ | |
132 | ||
133 | # either as static or shared; | |
e7379f33 | 134 | BUILD[build_type]( |
2cd6d686 VM |
135 | source=sources, |
136 | target='git2', | |
137 | includes='src', | |
138 | install_path='${LIBDIR}', | |
139 | use=ALL_LIBS | |
140 | ) | |
141 | ||
142 | # On Unix systems, build the Pkg-config entry file | |
e7379f33 | 143 | if bld.env.PLATFORM == 'unix' and bld.is_install: |
bd6eb230 | 144 | bld(rule="""sed -e 's#@prefix@#${PREFIX}#' -e 's#@libdir@#${LIBDIR}#' < ${SRC} > ${TGT}""", |
2cd6d686 VM |
145 | source='libgit2.pc.in', |
146 | target='libgit2.pc', | |
147 | install_path='${LIBDIR}/pkgconfig', | |
148 | ) | |
149 | ||
150 | # Install headers | |
151 | bld.install_files('${PREFIX}/include', directory.find_node('src/git2.h')) | |
152 | bld.install_files('${PREFIX}/include/git2', directory.ant_glob('src/git2/*.h')) | |
b2898c45 | 153 | |
a58e6a5f | 154 | # On Unix systems, let them know about installation |
2645053b | 155 | if bld.env.PLATFORM == 'unix' and bld.cmd == 'install-shared': |
a58e6a5f MV |
156 | bld.add_post_fun(call_ldconfig) |
157 | ||
158 | def call_ldconfig(bld): | |
2645053b VM |
159 | import distutils.spawn as s |
160 | ldconf = s.find_executable('ldconfig') | |
161 | if ldconf: | |
162 | bld.exec_command(ldconf) | |
a58e6a5f | 163 | |
2a1732b4 | 164 | def build_test(bld): |
2cd6d686 | 165 | directory = bld.path |
0847dff5 | 166 | resources_path = directory.find_node('tests/resources/').abspath().replace('\\', '/') |
2cd6d686 | 167 | |
2a1732b4 VM |
168 | sources = ['tests/test_lib.c', 'tests/test_helpers.c', 'tests/test_main.c'] |
169 | sources = sources + directory.ant_glob('tests/t??-*.c') | |
b2898c45 | 170 | |
2a1732b4 VM |
171 | bld.program( |
172 | source=sources, | |
173 | target='libgit2_test', | |
174 | includes=['src', 'tests'], | |
175 | defines=['TEST_RESOURCES="%s"' % resources_path], | |
176 | use=['git2'] + ALL_LIBS | |
177 | ) | |
d910be21 VM |
178 | |
179 | class _test(BuildContext): | |
2cd6d686 VM |
180 | cmd = 'test' |
181 | fun = 'test' | |
d910be21 VM |
182 | |
183 | def test(bld): | |
2cd6d686 | 184 | from waflib import Options |
2a1732b4 | 185 | Options.commands = ['build-test', 'run-test'] + Options.commands |
d910be21 | 186 | |
9de351b2 VM |
187 | class _build_doc(Context): |
188 | cmd = 'doxygen' | |
189 | fun = 'build_docs' | |
190 | ||
191 | def build_docs(ctx): | |
192 | ctx.exec_command("doxygen api.doxygen") | |
193 | ctx.exec_command("git stash") | |
194 | ctx.exec_command("git checkout gh-pages") | |
195 | ctx.exec_command("cp -Rf apidocs/html/* .") | |
196 | ctx.exec_command("git add .") | |
197 | ctx.exec_command("git commit -am 'generated docs'") | |
198 | ctx.exec_command("git push origin gh-pages") | |
199 | ctx.exec_command("git checkout master") | |
d910be21 | 200 | |
2a1732b4 VM |
201 | class _run_test(Context): |
202 | cmd = 'run-test' | |
203 | fun = 'run_test' | |
b2898c45 | 204 | |
2a1732b4 | 205 | def run_test(ctx): |
51035184 | 206 | import shutil, tempfile, sys |
b2898c45 | 207 | |
2cd6d686 | 208 | failed = False |
0ef70b4a | 209 | |
2a1732b4 | 210 | test_path = 'build/test/libgit2_test' |
51035184 | 211 | if sys.platform == 'win32': |
2a1732b4 VM |
212 | test_path += '.exe' |
213 | ||
214 | test_folder = tempfile.mkdtemp() | |
215 | test = ctx.path.find_node(test_path) | |
51035184 | 216 | |
2a1732b4 VM |
217 | if not test or ctx.exec_command(test.abspath(), cwd=test_folder) != 0: |
218 | failed = True | |
b2898c45 | 219 | |
2cd6d686 | 220 | shutil.rmtree(test_folder) |
5dc2bee1 | 221 | |
2cd6d686 VM |
222 | if failed: |
223 | ctx.fatal('Test run failed') | |
357547fa | 224 | |
d910be21 VM |
225 | |
226 | CONTEXTS = { | |
2cd6d686 VM |
227 | 'build' : BuildContext, |
228 | 'clean' : CleanContext, | |
229 | 'install' : InstallContext, | |
230 | 'uninstall' : UninstallContext | |
d910be21 VM |
231 | } |
232 | ||
233 | def build_command(command): | |
2cd6d686 VM |
234 | ctx, var = command.split('-') |
235 | class _gen_command(CONTEXTS[ctx]): | |
236 | cmd = command | |
237 | variant = var | |
d910be21 VM |
238 | |
239 | build_command('build-static') | |
240 | build_command('build-shared') | |
2a1732b4 | 241 | build_command('build-test') |
d910be21 VM |
242 | |
243 | build_command('clean-static') | |
244 | build_command('clean-shared') | |
2a1732b4 | 245 | build_command('clean-test') |
d910be21 VM |
246 | |
247 | build_command('install-static') | |
248 | build_command('install-shared') | |
249 | ||
250 | build_command('uninstall-static') | |
251 | build_command('uninstall-shared') | |
357547fa | 252 |