Skip to content
Newer
Older
100644 268 lines (202 sloc) 8.27 KB
b2898c4 @vmg Add more features to the build system
vmg authored
1 from waflib.Context import Context
2 from waflib.Build import BuildContext, CleanContext, \
3 InstallContext, UninstallContext
4
405ac51 @vmg Add --debug flag to toggle debugging
vmg authored
5 CFLAGS_UNIX = ["-O2", "-Wall", "-Wextra"]
6 CFLAGS_WIN32 = ['/TC', '/W4', '/RTC1', '/nologo']
7
8 CFLAGS_UNIX_DBG = ['-g']
9 CFLAGS_WIN32_DBG = ['/Zi', '/DEBUG']
10 CFLAGS_WIN32_L_DBG = ['/DEBUG']
5dc2bee @vmg Fix compilation in Win32
vmg authored
11
12 ALL_LIBS = ['z', 'crypto', 'pthread']
357547f @vmg Change to waf as the buildsystem
vmg authored
13
14 def options(opt):
2cd6d68 @vmg Tests now run with the resources folder as a hardcoded path
vmg authored
15 opt.load('compiler_c')
16 opt.add_option('--sha1', action='store', default='builtin',
17 help="Use the builtin SHA1 routines (builtin), the \
e06551e @vmg Add library dependencies to the build
vmg authored
18 PPC optimized version (ppc) or the SHA1 functions from OpenSSL (openssl)")
2cd6d68 @vmg Tests now run with the resources folder as a hardcoded path
vmg authored
19 opt.add_option('--debug', action='store_true', default=False,
20 help='Compile with debug symbols')
21 opt.add_option('--msvc', action='store', default=None,
22 help='Force a specific MSVC++ version (7.1, 8.0, 9.0, 10.0), if more than one is installed')
23 opt.add_option('--arch', action='store', default='x86',
24 help='Select target architecture (ia64, x64, x86, x86_amd64, x86_ia64)')
357547f @vmg Change to waf as the buildsystem
vmg authored
25
26 def configure(conf):
8507ab1 @vmg Improve build system for MSVC
vmg authored
27
2cd6d68 @vmg Tests now run with the resources folder as a hardcoded path
vmg authored
28 # load the MSVC configuration flags
29 if conf.options.msvc:
30 conf.env['MSVC_VERSIONS'] = ['msvc ' + conf.options.msvc]
8507ab1 @vmg Improve build system for MSVC
vmg authored
31
2cd6d68 @vmg Tests now run with the resources folder as a hardcoded path
vmg authored
32 conf.env['MSVC_TARGETS'] = [conf.options.arch]
8507ab1 @vmg Improve build system for MSVC
vmg authored
33
2cd6d68 @vmg Tests now run with the resources folder as a hardcoded path
vmg authored
34 # default configuration for C programs
35 conf.load('compiler_c')
357547f @vmg Change to waf as the buildsystem
vmg authored
36
2cd6d68 @vmg Tests now run with the resources folder as a hardcoded path
vmg authored
37 dbg = conf.options.debug
38 zlib_name = 'z'
5dc2bee @vmg Fix compilation in Win32
vmg authored
39
2cd6d68 @vmg Tests now run with the resources folder as a hardcoded path
vmg authored
40 conf.env.CFLAGS = CFLAGS_UNIX + (CFLAGS_UNIX_DBG if dbg else [])
5dc2bee @vmg Fix compilation in Win32
vmg authored
41
2cd6d68 @vmg Tests now run with the resources folder as a hardcoded path
vmg authored
42 if conf.env.DEST_OS == 'win32':
43 conf.env.PLATFORM = 'win32'
5dc2bee @vmg Fix compilation in Win32
vmg authored
44
2cd6d68 @vmg Tests now run with the resources folder as a hardcoded path
vmg authored
45 if conf.env.CC_NAME == 'msvc':
46 conf.env.CFLAGS = CFLAGS_WIN32 + (CFLAGS_WIN32_DBG if dbg else [])
47 conf.env.LINKFLAGS += CFLAGS_WIN32_L_DBG if dbg else []
48 conf.env.DEFINES += ['WIN32', '_DEBUG', '_LIB', 'ZLIB_WINAPI']
49 zlib_name = 'zlibwapi'
5dc2bee @vmg Fix compilation in Win32
vmg authored
50
2cd6d68 @vmg Tests now run with the resources folder as a hardcoded path
vmg authored
51 elif conf.env.CC_NAME == 'gcc':
52 conf.check(features='c cprogram', lib='pthread', uselib_store='pthread')
5dc2bee @vmg Fix compilation in Win32
vmg authored
53
2cd6d68 @vmg Tests now run with the resources folder as a hardcoded path
vmg authored
54 else:
55 conf.env.PLATFORM = 'unix'
5dc2bee @vmg Fix compilation in Win32
vmg authored
56
2cd6d68 @vmg Tests now run with the resources folder as a hardcoded path
vmg authored
57 # check for Z lib
58 conf.check(features='c cprogram', lib=zlib_name, uselib_store='z', install_path=None)
e06551e @vmg Add library dependencies to the build
vmg authored
59
2cd6d68 @vmg Tests now run with the resources folder as a hardcoded path
vmg authored
60 if conf.options.sha1 not in ['openssl', 'ppc', 'builtin']:
61 ctx.fatal('Invalid SHA1 option')
357547f @vmg Change to waf as the buildsystem
vmg authored
62
2cd6d68 @vmg Tests now run with the resources folder as a hardcoded path
vmg authored
63 # check for libcrypto (openssl) if we are using its SHA1 functions
64 if conf.options.sha1 == 'openssl':
65 conf.check_cfg(package='libcrypto', args=['--cflags', '--libs'], uselib_store='crypto')
66 conf.env.DEFINES += ['OPENSSL_SHA1']
5dc2bee @vmg Fix compilation in Win32
vmg authored
67
2cd6d68 @vmg Tests now run with the resources folder as a hardcoded path
vmg authored
68 elif conf.options.sha1 == 'ppc':
69 conf.env.DEFINES += ['PPC_SHA1']
e06551e @vmg Add library dependencies to the build
vmg authored
70
2cd6d68 @vmg Tests now run with the resources folder as a hardcoded path
vmg authored
71 conf.env.sha1 = conf.options.sha1
357547f @vmg Change to waf as the buildsystem
vmg authored
72
73 def build(bld):
b2898c4 @vmg Add more features to the build system
vmg authored
74
2cd6d68 @vmg Tests now run with the resources folder as a hardcoded path
vmg authored
75 # command '[build|clean|install|uninstall]-static'
76 if bld.variant == 'static':
77 build_library(bld, 'cstlib')
d910be2 @vmg Add separate commands for all possible actions
vmg authored
78
2cd6d68 @vmg Tests now run with the resources folder as a hardcoded path
vmg authored
79 # command '[build|clean|install|uninstall]-shared'
80 elif bld.variant == 'shared':
81 build_library(bld, 'cshlib')
d910be2 @vmg Add separate commands for all possible actions
vmg authored
82
2cd6d68 @vmg Tests now run with the resources folder as a hardcoded path
vmg authored
83 # command '[build|clean]-tests'
84 elif bld.variant == 'tests':
f70cbbc @vmg Link tests with shared library, not static
vmg authored
85 build_library(bld, 'cshlib')
2cd6d68 @vmg Tests now run with the resources folder as a hardcoded path
vmg authored
86 build_tests(bld)
357547f @vmg Change to waf as the buildsystem
vmg authored
87
2cd6d68 @vmg Tests now run with the resources folder as a hardcoded path
vmg authored
88 # command 'build|clean|install|uninstall': by default, run
89 # the same command for both the static and the shared lib
90 else:
91 from waflib import Options
92 Options.commands = [bld.cmd + '-shared', bld.cmd + '-static'] + Options.commands
d910be2 @vmg Add separate commands for all possible actions
vmg authored
93
94 def build_library(bld, lib_str):
2cd6d68 @vmg Tests now run with the resources folder as a hardcoded path
vmg authored
95 directory = bld.path
96
97 sources = directory.ant_glob('src/*.c')
98
99 # Compile platform-dependant code
100 # E.g. src/unix/*.c
101 # src/win32/*.c
102 sources = sources + directory.ant_glob('src/%s/*.c' % bld.env.PLATFORM)
103
104 # SHA1 methods source
105 if bld.env.sha1 == "ppc":
106 sources.append('src/ppc/sha1.c')
107 else:
108 sources.append('src/block-sha1/sha1.c')
109
110 features = ['c', lib_str]
111
112 #------------------------------
113 # Build the main library
114 #------------------------------
115
116 # either as static or shared;
117 bld(features=features,
118 source=sources,
119 target='git2',
120 includes='src',
121 install_path='${LIBDIR}',
122 use=ALL_LIBS
123 )
124
125 # On Unix systems, build the Pkg-config entry file
126 if bld.env.PLATFORM == 'unix':
127 bld(rule="""sed -e 's#@prefix@#$(prefix)#' -e 's#@libdir@#$(libdir)#' < ${SRC} > ${TGT}""",
128 source='libgit2.pc.in',
129 target='libgit2.pc',
130 install_path='${LIBDIR}/pkgconfig',
131 )
132
133 # Install headers
134 bld.install_files('${PREFIX}/include', directory.find_node('src/git2.h'))
135 bld.install_files('${PREFIX}/include/git2', directory.ant_glob('src/git2/*.h'))
b2898c4 @vmg Add more features to the build system
vmg authored
136
a58e6a5 @marvil07 Run ldconfig on install at unix platforms.
marvil07 authored
137 # On Unix systems, let them know about installation
138 if bld.env.PLATFORM == 'unix' and bld.cmd in ['install-static', 'install-shared']:
139 bld.add_post_fun(call_ldconfig)
140
141 def call_ldconfig(bld):
142 bld.exec_command('/sbin/ldconfig')
143
8507ab1 @vmg Improve build system for MSVC
vmg authored
144 def grep_test_header(text, test_file):
2cd6d68 @vmg Tests now run with the resources folder as a hardcoded path
vmg authored
145 return '\n'.join(l for l in test_file.read().splitlines() if text in l)
e06551e @vmg Add library dependencies to the build
vmg authored
146
b2898c4 @vmg Add more features to the build system
vmg authored
147 def build_tests(bld):
2cd6d68 @vmg Tests now run with the resources folder as a hardcoded path
vmg authored
148 import os
149
150 if bld.is_install:
151 return
152
153 directory = bld.path
154 resources_path = directory.find_node('tests/resources/').abspath()
155
156 # Common object with the Test library methods
157 bld.objects(source=['tests/test_helpers.c', 'tests/test_lib.c'], includes=['src', 'tests'], target='test_helper')
158
159 # Build all tests in the tests/ folder
160 for test_file in directory.ant_glob('tests/t????-*.c'):
161 test_name, _ = os.path.splitext(os.path.basename(test_file.abspath()))
162
163 # Preprocess table of contents for each test
164 test_toc_file = directory.make_node('tests/%s.toc' % test_name)
165 if bld.cmd == 'clean-tests': # cleanup; delete the generated TOC file
166 test_toc_file.delete()
167 elif bld.cmd == 'build-tests': # build; create TOC
168 test_toc_file.write(grep_test_header('BEGIN_TEST', test_file))
169
170 # Build individual test (don't run)
171 bld.program(
172 source=[test_file, 'tests/test_main.c'],
173 target=test_name,
174 includes=['src', 'tests'],
175 defines=['TEST_TOC="%s.toc"' % test_name, 'TEST_RESOURCES="%s"' % resources_path],
176 install_path=None,
f70cbbc @vmg Link tests with shared library, not static
vmg authored
177 shlibpath=[directory.find_node('build/tests/').abspath()],
2cd6d68 @vmg Tests now run with the resources folder as a hardcoded path
vmg authored
178 use=['test_helper', 'git2'] + ALL_LIBS # link with all the libs we know
179 # libraries which are not enabled won't link
180 )
b2898c4 @vmg Add more features to the build system
vmg authored
181
d910be2 @vmg Add separate commands for all possible actions
vmg authored
182
183 class _test(BuildContext):
2cd6d68 @vmg Tests now run with the resources folder as a hardcoded path
vmg authored
184 cmd = 'test'
185 fun = 'test'
d910be2 @vmg Add separate commands for all possible actions
vmg authored
186
187 def test(bld):
2cd6d68 @vmg Tests now run with the resources folder as a hardcoded path
vmg authored
188 from waflib import Options
189 Options.commands = ['build-tests', 'run-tests'] + Options.commands
d910be2 @vmg Add separate commands for all possible actions
vmg authored
190
9de351b @vmg Move documentation generation to the Waf system
vmg authored
191 class _build_doc(Context):
192 cmd = 'doxygen'
193 fun = 'build_docs'
194
195 def build_docs(ctx):
196 ctx.exec_command("doxygen api.doxygen")
197 ctx.exec_command("git stash")
198 ctx.exec_command("git checkout gh-pages")
199 ctx.exec_command("cp -Rf apidocs/html/* .")
200 ctx.exec_command("git add .")
201 ctx.exec_command("git commit -am 'generated docs'")
202 ctx.exec_command("git push origin gh-pages")
203 ctx.exec_command("git checkout master")
d910be2 @vmg Add separate commands for all possible actions
vmg authored
204
b2898c4 @vmg Add more features to the build system
vmg authored
205 class _run_tests(Context):
2cd6d68 @vmg Tests now run with the resources folder as a hardcoded path
vmg authored
206 cmd = 'run-tests'
207 fun = 'run_tests'
b2898c4 @vmg Add more features to the build system
vmg authored
208
209 def run_tests(ctx):
f70cbbc @vmg Link tests with shared library, not static
vmg authored
210 import shutil, tempfile, sys, os
b2898c4 @vmg Add more features to the build system
vmg authored
211
2cd6d68 @vmg Tests now run with the resources folder as a hardcoded path
vmg authored
212 failed = False
213 test_folder = tempfile.mkdtemp()
f70cbbc @vmg Link tests with shared library, not static
vmg authored
214 build_folder = ctx.path.find_node('build/tests/')
2cd6d68 @vmg Tests now run with the resources folder as a hardcoded path
vmg authored
215 test_glob = 'build/tests/t????-*'
f70cbbc @vmg Link tests with shared library, not static
vmg authored
216 environ = os.environ.copy()
217 environ_tail = ""
b2898c4 @vmg Add more features to the build system
vmg authored
218
2cd6d68 @vmg Tests now run with the resources folder as a hardcoded path
vmg authored
219 if sys.platform == 'win32':
220 test_glob += '.exe'
f70cbbc @vmg Link tests with shared library, not static
vmg authored
221 environ_var, environ_separator = 'PATH', ';'
222 else:
223 environ_var, environ_separator = 'LD_LIBRARY_PATH', ':'
224
225 if environ_var in environ:
226 environ_tail = environ_separator + environ[environ_var]
227
228 environ[environ_var] = build_folder.abspath() + environ_tail
0ef70b4 @vmg Make the test suite depend on the static library
vmg authored
229
2cd6d68 @vmg Tests now run with the resources folder as a hardcoded path
vmg authored
230 for test in ctx.path.ant_glob(test_glob):
f70cbbc @vmg Link tests with shared library, not static
vmg authored
231 if ctx.exec_command(test.abspath(), cwd=test_folder, env=environ) != 0:
2cd6d68 @vmg Tests now run with the resources folder as a hardcoded path
vmg authored
232 failed = True
233 break
b2898c4 @vmg Add more features to the build system
vmg authored
234
2cd6d68 @vmg Tests now run with the resources folder as a hardcoded path
vmg authored
235 shutil.rmtree(test_folder)
5dc2bee @vmg Fix compilation in Win32
vmg authored
236
2cd6d68 @vmg Tests now run with the resources folder as a hardcoded path
vmg authored
237 if failed:
238 ctx.fatal('Test run failed')
357547f @vmg Change to waf as the buildsystem
vmg authored
239
d910be2 @vmg Add separate commands for all possible actions
vmg authored
240
241 CONTEXTS = {
2cd6d68 @vmg Tests now run with the resources folder as a hardcoded path
vmg authored
242 'build' : BuildContext,
243 'clean' : CleanContext,
244 'install' : InstallContext,
245 'uninstall' : UninstallContext
d910be2 @vmg Add separate commands for all possible actions
vmg authored
246 }
247
248 def build_command(command):
2cd6d68 @vmg Tests now run with the resources folder as a hardcoded path
vmg authored
249 ctx, var = command.split('-')
250 class _gen_command(CONTEXTS[ctx]):
251 cmd = command
252 variant = var
d910be2 @vmg Add separate commands for all possible actions
vmg authored
253
254 build_command('build-static')
255 build_command('build-shared')
256 build_command('build-tests')
257
258 build_command('clean-static')
259 build_command('clean-shared')
260 build_command('clean-tests')
261
262 build_command('install-static')
263 build_command('install-shared')
264
265 build_command('uninstall-static')
266 build_command('uninstall-shared')
357547f @vmg Change to waf as the buildsystem
vmg authored
267
Something went wrong with that request. Please try again.