]> git.proxmox.com Git - libgit2.git/blob - wscript
Run ldconfig on install at unix platforms.
[libgit2.git] / wscript
1 from waflib.Context import Context
2 from waflib.Build import BuildContext, CleanContext, \
3 InstallContext, UninstallContext
4
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']
11
12 ALL_LIBS = ['z', 'crypto', 'pthread']
13
14 def options(opt):
15 opt.load('compiler_c')
16 opt.add_option('--sha1', action='store', default='builtin',
17 help="Use the builtin SHA1 routines (builtin), the \
18 PPC optimized version (ppc) or the SHA1 functions from OpenSSL (openssl)")
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)')
25
26 def configure(conf):
27
28 # load the MSVC configuration flags
29 if conf.options.msvc:
30 conf.env['MSVC_VERSIONS'] = ['msvc ' + conf.options.msvc]
31
32 conf.env['MSVC_TARGETS'] = [conf.options.arch]
33
34 # default configuration for C programs
35 conf.load('compiler_c')
36
37 dbg = conf.options.debug
38 zlib_name = 'z'
39
40 conf.env.CFLAGS = CFLAGS_UNIX + (CFLAGS_UNIX_DBG if dbg else [])
41
42 if conf.env.DEST_OS == 'win32':
43 conf.env.PLATFORM = 'win32'
44
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'
50
51 elif conf.env.CC_NAME == 'gcc':
52 conf.check(features='c cprogram', lib='pthread', uselib_store='pthread')
53
54 else:
55 conf.env.PLATFORM = 'unix'
56
57 # check for Z lib
58 conf.check(features='c cprogram', lib=zlib_name, uselib_store='z', install_path=None)
59
60 if conf.options.sha1 not in ['openssl', 'ppc', 'builtin']:
61 ctx.fatal('Invalid SHA1 option')
62
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']
67
68 elif conf.options.sha1 == 'ppc':
69 conf.env.DEFINES += ['PPC_SHA1']
70
71 conf.env.sha1 = conf.options.sha1
72
73 def build(bld):
74
75 # command '[build|clean|install|uninstall]-static'
76 if bld.variant == 'static':
77 build_library(bld, 'cstlib')
78
79 # command '[build|clean|install|uninstall]-shared'
80 elif bld.variant == 'shared':
81 build_library(bld, 'cshlib')
82
83 # command '[build|clean]-tests'
84 elif bld.variant == 'tests':
85 build_library(bld, 'cshlib')
86 build_tests(bld)
87
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
93
94 def build_library(bld, lib_str):
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'))
136
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
144 def grep_test_header(text, test_file):
145 return '\n'.join(l for l in test_file.read().splitlines() if text in l)
146
147 def build_tests(bld):
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,
177 shlibpath=[directory.find_node('build/tests/').abspath()],
178 use=['test_helper', 'git2'] + ALL_LIBS # link with all the libs we know
179 # libraries which are not enabled won't link
180 )
181
182
183 class _test(BuildContext):
184 cmd = 'test'
185 fun = 'test'
186
187 def test(bld):
188 from waflib import Options
189 Options.commands = ['build-tests', 'run-tests'] + Options.commands
190
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")
204
205 class _run_tests(Context):
206 cmd = 'run-tests'
207 fun = 'run_tests'
208
209 def run_tests(ctx):
210 import shutil, tempfile, sys, os
211
212 failed = False
213 test_folder = tempfile.mkdtemp()
214 build_folder = ctx.path.find_node('build/tests/')
215 test_glob = 'build/tests/t????-*'
216 environ = os.environ.copy()
217 environ_tail = ""
218
219 if sys.platform == 'win32':
220 test_glob += '.exe'
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
229
230 for test in ctx.path.ant_glob(test_glob):
231 if ctx.exec_command(test.abspath(), cwd=test_folder, env=environ) != 0:
232 failed = True
233 break
234
235 shutil.rmtree(test_folder)
236
237 if failed:
238 ctx.fatal('Test run failed')
239
240
241 CONTEXTS = {
242 'build' : BuildContext,
243 'clean' : CleanContext,
244 'install' : InstallContext,
245 'uninstall' : UninstallContext
246 }
247
248 def build_command(command):
249 ctx, var = command.split('-')
250 class _gen_command(CONTEXTS[ctx]):
251 cmd = command
252 variant = var
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')
267