]> git.proxmox.com Git - libgit2.git/blob - wscript
Revert changes in wscript file
[libgit2.git] / wscript
1 from waflib.Context import Context
2 from waflib.Build import BuildContext, CleanContext, \
3 InstallContext, UninstallContext
4
5 # Unix flags
6 CFLAGS_UNIX = ["-O2", "-Wall", "-Wextra"]
7 CFLAGS_UNIX_DBG = ['-g']
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.
17 CFLAGS_WIN32_L_DBG = ['/DEBUG']
18
19 ALL_LIBS = ['crypto', 'pthread', 'sqlite3']
20
21 def options(opt):
22 opt.load('compiler_c')
23 opt.add_option('--sha1', action='store', default='builtin',
24 help="Use the builtin SHA1 routines (builtin), the \
25 PPC optimized version (ppc) or the SHA1 functions from OpenSSL (openssl)")
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)')
32 opt.add_option('--without-sqlite', action='store_false', default=True,
33 dest='use_sqlite', help='Disable sqlite support')
34
35 def configure(conf):
36
37 # load the MSVC configuration flags
38 if conf.options.msvc:
39 conf.env['MSVC_VERSIONS'] = ['msvc ' + conf.options.msvc]
40
41 conf.env['MSVC_TARGETS'] = [conf.options.arch]
42
43 # default configuration for C programs
44 conf.load('compiler_c')
45
46 dbg = conf.options.debug
47
48 conf.env.CFLAGS = CFLAGS_UNIX + (CFLAGS_UNIX_DBG if dbg else [])
49
50 if conf.env.DEST_OS == 'win32':
51 conf.env.PLATFORM = 'win32'
52
53 if conf.env.CC_NAME == 'msvc':
54 conf.env.CFLAGS = CFLAGS_WIN32_COMMON + \
55 (CFLAGS_WIN32_DBG if dbg else CFLAGS_WIN32_RELEASE)
56 conf.env.LINKFLAGS += CFLAGS_WIN32_L + \
57 (CFLAGS_WIN32_L_DBG if dbg else [])
58 conf.env.DEFINES += ['WIN32', '_DEBUG', '_LIB']
59
60 else:
61 conf.env.PLATFORM = 'unix'
62 conf.check_cc(lib='pthread', uselib_store='pthread')
63
64 # Do not build ZLib with GZIP support
65 conf.env.DEFINES += ['NO_GZIP']
66
67 # check for sqlite3
68 if conf.options.use_sqlite and conf.check_cc(
69 lib='sqlite3', uselib_store='sqlite3', install_path=None, mandatory=False):
70 conf.env.DEFINES += ['GIT2_SQLITE_BACKEND']
71
72 if conf.options.sha1 not in ['openssl', 'ppc', 'builtin']:
73 conf.fatal('Invalid SHA1 option')
74
75 # check for libcrypto (openssl) if we are using its SHA1 functions
76 if conf.options.sha1 == 'openssl':
77 conf.check_cfg(package='libcrypto', args=['--cflags', '--libs'], uselib_store='crypto')
78 conf.env.DEFINES += ['OPENSSL_SHA1']
79
80 elif conf.options.sha1 == 'ppc':
81 conf.env.DEFINES += ['PPC_SHA1']
82
83 conf.env.sha1 = conf.options.sha1
84
85 def build(bld):
86
87 # command '[build|clean|install|uninstall]-static'
88 if bld.variant == 'static':
89 build_library(bld, 'static')
90
91 # command '[build|clean|install|uninstall]-shared'
92 elif bld.variant == 'shared':
93 build_library(bld, 'shared')
94
95 # command '[build|clean]-tests'
96 elif bld.variant == 'test':
97 build_library(bld, 'objects')
98 build_test(bld)
99
100 # command 'build|clean|install|uninstall': by default, run
101 # the same command for both the static and the shared lib
102 else:
103 from waflib import Options
104 Options.commands = [bld.cmd + '-shared', bld.cmd + '-static'] + Options.commands
105
106 def get_libgit2_version(git2_h):
107 import re
108 line = None
109
110 with open(git2_h) as f:
111 line = re.search(r'^#define LIBGIT2_VERSION "(\d+\.\d+\.\d+)"$', f.read(), re.MULTILINE)
112
113 if line is None:
114 raise Exception("Failed to detect libgit2 version")
115
116 return line.group(1)
117
118
119 def build_library(bld, build_type):
120
121 BUILD = {
122 'shared' : bld.shlib,
123 'static' : bld.stlib,
124 'objects' : bld.objects
125 }
126
127 directory = bld.path
128 sources = directory.ant_glob('src/*.c')
129
130 # Find the version of the library, from our header file
131 version = get_libgit2_version(directory.find_node("include/git2.h").abspath())
132
133 # Compile platform-dependant code
134 # E.g. src/unix/*.c
135 # src/win32/*.c
136 sources = sources + directory.ant_glob('src/%s/*.c' % bld.env.PLATFORM)
137 sources = sources + directory.ant_glob('src/backends/*.c')
138 sources = sources + directory.ant_glob('deps/zlib/*.c')
139
140 # SHA1 methods source
141 if bld.env.sha1 == "ppc":
142 sources.append('src/ppc/sha1.c')
143 else:
144 sources.append('src/block-sha1/sha1.c')
145 #------------------------------
146 # Build the main library
147 #------------------------------
148
149 # either as static or shared;
150 BUILD[build_type](
151 source=sources,
152 target='git2',
153 includes=['src', 'include', 'deps/zlib'],
154 install_path='${LIBDIR}',
155 use=ALL_LIBS,
156 vnum=version,
157 )
158
159 # On Unix systems, build the Pkg-config entry file
160 if bld.env.PLATFORM == 'unix' and bld.is_install:
161 bld(rule="""sed -e 's#@prefix@#${PREFIX}#' -e 's#@libdir@#${LIBDIR}#' -e 's#@version@#%s#' < ${SRC} > ${TGT}""" % version,
162 source='libgit2.pc.in',
163 target='libgit2.pc',
164 install_path='${LIBDIR}/pkgconfig',
165 )
166
167 # Install headers
168 bld.install_files('${PREFIX}/include', directory.find_node('include/git2.h'))
169 bld.install_files('${PREFIX}/include/git2', directory.ant_glob('include/git2/*.h'))
170
171 # On Unix systems, let them know about installation
172 if bld.env.PLATFORM == 'unix' and bld.cmd == 'install-shared':
173 bld.add_post_fun(call_ldconfig)
174
175 def call_ldconfig(bld):
176 import distutils.spawn as s
177 ldconf = s.find_executable('ldconfig')
178 if ldconf:
179 bld.exec_command(ldconf)
180
181 def build_test(bld):
182 directory = bld.path
183 resources_path = directory.find_node('tests/resources/').abspath().replace('\\', '/')
184
185 sources = ['tests/test_lib.c', 'tests/test_helpers.c', 'tests/test_main.c']
186 sources = sources + directory.ant_glob('tests/t??-*.c')
187
188 bld.program(
189 source=sources,
190 target='libgit2_test',
191 includes=['src', 'tests', 'include'],
192 defines=['TEST_RESOURCES="%s"' % resources_path],
193 use=['git2'] + ALL_LIBS
194 )
195
196 class _test(BuildContext):
197 cmd = 'test'
198 fun = 'test'
199
200 def test(bld):
201 from waflib import Options
202 Options.commands = ['build-test', 'run-test'] + Options.commands
203
204 class _build_doc(Context):
205 cmd = 'doxygen'
206 fun = 'build_docs'
207
208 def build_docs(ctx):
209 ctx.exec_command("doxygen api.doxygen")
210 ctx.exec_command("git stash")
211 ctx.exec_command("git checkout gh-pages")
212 ctx.exec_command("cp -Rf apidocs/html/* .")
213 ctx.exec_command("git add .")
214 ctx.exec_command("git commit -am 'generated docs'")
215 ctx.exec_command("git push origin gh-pages")
216 ctx.exec_command("git checkout master")
217
218 class _run_test(Context):
219 cmd = 'run-test'
220 fun = 'run_test'
221
222 def run_test(ctx):
223 import shutil, tempfile, sys
224
225 failed = False
226
227 test_path = 'build/test/libgit2_test'
228 if sys.platform == 'win32':
229 test_path += '.exe'
230
231 test_folder = tempfile.mkdtemp()
232 test = ctx.path.find_node(test_path)
233
234 if not test or ctx.exec_command(test.abspath(), cwd=test_folder) != 0:
235 failed = True
236
237 shutil.rmtree(test_folder)
238
239 if failed:
240 ctx.fatal('Test run failed')
241
242
243 CONTEXTS = {
244 'build' : BuildContext,
245 'clean' : CleanContext,
246 'install' : InstallContext,
247 'uninstall' : UninstallContext
248 }
249
250 def build_command(command):
251 ctx, var = command.split('-')
252 class _gen_command(CONTEXTS[ctx]):
253 cmd = command
254 variant = var
255
256 build_command('build-static')
257 build_command('build-shared')
258 build_command('build-test')
259
260 build_command('clean-static')
261 build_command('clean-shared')
262 build_command('clean-test')
263
264 build_command('install-static')
265 build_command('install-shared')
266
267 build_command('uninstall-static')
268 build_command('uninstall-shared')
269