Add static library support.
Add static library support.
1.1 --- a/README.md Sat Nov 23 16:36:51 2013 -0800
1.2 +++ b/README.md Sat Nov 23 16:58:06 2013 -0800
1.3 @@ -1,6 +1,6 @@
1.4 AMBuild is a lightweight build system designed for performance and accuracy. There are two versions provided - the original version, released in 2009, and AMBuild 2, a modernized rewrite released in 2013. Both are geared at C/C++ projects which require programmatic flexibility in their builds, and precise control over C/C++ compiler flags.
1.5
1.6 -AMBuild requires Python 2.7 or higher, or Python 3.2 or higher.
1.7 +AMBuild requires Python 2.6 or higher, or Python 3.1 or higher.
1.8
1.9 # AMBuild 2
1.10
2.1 --- a/ambuild2/frontend/cpp.py Sat Nov 23 16:36:51 2013 -0800
2.2 +++ b/ambuild2/frontend/cpp.py Sat Nov 23 16:58:06 2013 -0800
2.3 @@ -289,6 +289,9 @@
2.4 def Library(self, name):
2.5 return Library(self, name)
2.6
2.7 + def StaticLibrary(self, name):
2.8 + return StaticLibrary(self, name)
2.9 +
2.10 @staticmethod
2.11 def Dep(text, node=None):
2.12 return Dep(text, node)
2.13 @@ -434,13 +437,8 @@
2.14 else:
2.15 self.linker_ = self.compiler.cc
2.16
2.17 - argv = self.linker_.command.split(' ')
2.18 - for objfile in self.objects:
2.19 - argv.append(objfile.outputFile)
2.20 - for rcfile in self.resources:
2.21 - argv.append(rcfile.outputFile)
2.22 -
2.23 - argv = self.generateBinary(cx, argv)
2.24 + files = [out.outputFile for out in self.objects + self.resources]
2.25 + argv = self.generateBinary(cx, files)
2.26
2.27 self.argv = argv
2.28 if self.linker_.pdbSuffix:
2.29 @@ -453,7 +451,10 @@
2.30 super(Program, self).__init__(compiler, name)
2.31 self.outputFile = name + util.ExecutableSuffix()
2.32
2.33 - def generateBinary(self, cx, argv):
2.34 + def generateBinary(self, cx, files):
2.35 + argv = self.linker_.command.split(' ')
2.36 + argv += files
2.37 +
2.38 if isinstance(self.linker_, MSVC):
2.39 argv.append('/link')
2.40 argv.extend(LinkFlags(self.compiler))
2.41 @@ -472,7 +473,10 @@
2.42 super(Library, self).__init__(compiler, name)
2.43 self.outputFile = name + util.SharedLibSuffix()
2.44
2.45 - def generateBinary(self, cx, argv):
2.46 + def generateBinary(self, cx, files):
2.47 + argv = self.linker_.command.split(' ')
2.48 + argv += files
2.49 +
2.50 if isinstance(self.linker_, MSVC):
2.51 argv.append('/link')
2.52 argv.extend(LinkFlags(self.compiler))
2.53 @@ -490,3 +494,16 @@
2.54 argv.extend(['-o', self.outputFile])
2.55
2.56 return argv
2.57 +
2.58 +class StaticLibrary(BinaryBuilder):
2.59 + def __init__(self, compiler, name):
2.60 + super(StaticLibrary, self).__init__(compiler, name)
2.61 + self.outputFile = util.StaticLibPrefix() + name + util.StaticLibSuffix()
2.62 +
2.63 + def generateBinary(self, cx, files):
2.64 + if isinstance(self.linker_, MSVC):
2.65 + argv = ['lib.exe', '/OUT:' + self.outputFile]
2.66 + else:
2.67 + argv = ['ar', 'rcs', self.outputFile]
2.68 + argv += files
2.69 + return argv
3.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
3.2 +++ b/tests/staticlib/AMBuildScript Sat Nov 23 16:58:06 2013 -0800
3.3 @@ -0,0 +1,10 @@
3.4 +# vim: set ts=8 sts=2 tw=99 et ft=python:
3.5 +import os, sys
3.6 +
3.7 +builder.DetectCompilers()
3.8 +
3.9 +program = builder.compiler.StaticLibrary("hello")
3.10 +program.sources = [
3.11 + 'main.cpp'
3.12 +]
3.13 +builder.Add(program)
4.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
4.2 +++ b/tests/staticlib/configure.py Sat Nov 23 16:58:06 2013 -0800
4.3 @@ -0,0 +1,6 @@
4.4 +# vim: set sts=2 ts=8 sw=2 tw=99 et:
4.5 +import sys
4.6 +from ambuild2 import run
4.7 +
4.8 +builder = run.PrepareBuild(sourcePath = sys.path[0])
4.9 +builder.Configure()
5.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
5.2 +++ b/tests/staticlib/generate_header.py Sat Nov 23 16:58:06 2013 -0800
5.3 @@ -0,0 +1,9 @@
5.4 +# vim: set sts=2 ts=8 sw=2 tw=99 et:
5.5 +import sys
5.6 +
5.7 +with open(sys.argv[1], 'w') as fp:
5.8 + fp.write("""
5.9 +#ifndef HELLO_STRING
5.10 +# define HELLO_STRING "HELLO!"
5.11 +#endif
5.12 +""")
6.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
6.2 +++ b/tests/staticlib/main.cpp Sat Nov 23 16:58:06 2013 -0800
6.3 @@ -0,0 +1,7 @@
6.4 +#include <stdio.h>
6.5 +
6.6 +extern "C" int egg()
6.7 +{
6.8 + return printf("hello!\n");
6.9 +}
6.10 +