AMBuild.dist
changeset 106 8534dbfb8c1a
child 128 6eed87ebc5ce
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/AMBuild.dist	Sat Jul 28 14:43:57 2012 -0700
     1.3 @@ -0,0 +1,88 @@
     1.4 +# vim: set ts=2 sw=2 tw=99 noet ft=python: 
     1.5 +# 
     1.6 +# Copyright (C) 2004-2012 David Anderson
     1.7 +# 
     1.8 +# This file is part of SourcePawn.
     1.9 +# 
    1.10 +# SourcePawn is free software: you can redistribute it and/or modify it under
    1.11 +# the terms of the GNU General Public License as published by the Free
    1.12 +# Software Foundation, either version 3 of the License, or (at your option)
    1.13 +# any later version.
    1.14 +# 
    1.15 +# SourcePawn is distributed in the hope that it will be useful, but WITHOUT ANY
    1.16 +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
    1.17 +# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
    1.18 +# 
    1.19 +# You should have received a copy of the GNU General Public License along with
    1.20 +# SourcePawn. If not, see http://www.gnu.org/licenses/.
    1.21 +#
    1.22 +import os
    1.23 +import os.path
    1.24 +import shutil
    1.25 +import ambuild.osutil as osutil
    1.26 +from ambuild.command import Command
    1.27 +
    1.28 +job = AMBuild.AddJob('dist')
    1.29 +
    1.30 +# Single file copy
    1.31 +class CopyFile(Command):
    1.32 +	def __init__(self, filename, fromPath, toPath):
    1.33 +		Command.__init__(self)
    1.34 +		self.fromPath = os.path.join(fromPath, filename)
    1.35 +		self.toPath = toPath
    1.36 +
    1.37 +	def run(self, runner, job):
    1.38 +		runner.PrintOut('copy {0} to {1}'.format(self.fromPath, self.toPath))
    1.39 +		shutil.copy(self.fromPath, self.toPath)
    1.40 +
    1.41 +# Create a folder
    1.42 +class CreateFolder(Command):
    1.43 +	def __init__(self, folder):
    1.44 +		Command.__init__(self)
    1.45 +		self.folder = folder
    1.46 +
    1.47 +	def run(self, runner, job):
    1.48 +		runner.PrintOut('mkdir {0}'.format(self.folder))
    1.49 +		os.makedirs(self.folder)
    1.50 +
    1.51 +
    1.52 +def ShouldCopy(filename, fromPath, toPath):
    1.53 +	fromfile = os.path.join(fromPath, filename)
    1.54 +	tofile = os.path.join(AMBuild.outputFolder, 'dist', toPath, filename)
    1.55 +	if not osutil.FileExists(tofile):
    1.56 +		return True
    1.57 +	return osutil.IsFileNewer(fromfile, tofile)
    1.58 +
    1.59 +def AddCopy(job, filename, fromPath, toPath):
    1.60 +	if not ShouldCopy(filename, fromPath, toPath):
    1.61 +		return
    1.62 +	job.AddCommand(CopyFile(filename, fromPath, toPath))
    1.63 +
    1.64 +def AddFolder(job, folder):
    1.65 +	if not os.path.exists(os.path.join(AMBuild.outputFolder, 'dist', folder)):
    1.66 +		job.AddCommand(CreateFolder(folder))
    1.67 +
    1.68 +libkeima = osutil.StaticLibPrefix() + 'keima' + osutil.StaticLibSuffix()
    1.69 +spshell = 'spshell' + osutil.ExecutableSuffix()
    1.70 +
    1.71 +AddFolder(job, 'include')
    1.72 +AddFolder(job, 'lib')
    1.73 +AddFolder(job, 'bin')
    1.74 +
    1.75 +AddCopy(job,
    1.76 +        'keima.h',
    1.77 +        os.path.join(AMBuild.sourceFolder, 'include'),
    1.78 +        'include')
    1.79 +AddCopy(job,
    1.80 +        'keima_util.h',
    1.81 +        os.path.join(AMBuild.sourceFolder, 'include'),
    1.82 +        'include')
    1.83 +AddCopy(job,
    1.84 +        libkeima,
    1.85 +        os.path.join(AMBuild.outputFolder, 'keima'),
    1.86 +        'lib')
    1.87 +AddCopy(job,
    1.88 +        spshell,
    1.89 +        os.path.join(AMBuild.outputFolder, 'spshell'),
    1.90 +        'bin')
    1.91 +