3 * Makefile for phpxmlrpc library.
4 * To be used with the Pake tool: https://github.com/indeyets/pake/wiki
6 * @todo allow user to specify location for zip command
7 * @todo allow user to specify release number and tag/branch to use
14 protected static $buildDir = 'build/';
15 protected static $libVersion;
16 protected static $sourceBranch = 'master';
18 public static function libVersion()
20 return self::$libVersion;
23 public static function buildDir()
25 return self::$buildDir;
28 public static function workspaceDir()
30 return self::buildDir().'workspace';
33 /// most likely things will break if this one is moved outside of BuildDir
34 public static function distDir()
36 return self::buildDir().'xmlrpc-'.self::libVersion();
39 /// these will be generated in BuildDir
40 public static function distFiles()
43 'xmlrpc-'.self::libVersion().'.tar.gz',
44 'xmlrpc-'.self::libVersion().'.zip',
48 public static function sourceRepo()
50 return 'https://github.com/gggeek/phpxmlrpc';
53 /// @todo move git branch to be a named option?
54 public static function getOpts($args=array(), $cliOpts=array())
57 throw new \Exception('Missing library version argument');
58 self::$libVersion = $args[0];
60 self::$sourceBranch = $args[1];
62 pake_echo('---'.self::$libVersion.'---');
70 use PhpXmlRpc\Builder;
72 function run_default($task=null, $args=array(), $cliOpts=array())
74 echo "Syntax: pake {\$pake-options} \$task \$lib-version [\$git-tag]\n";
76 echo " Run 'pake help' to list all pake options\n";
77 echo " Run 'pake -T' to list all available tasks\n";
80 function run_getopts($task=null, $args=array(), $cliOpts=array())
82 Builder::getOpts($args, $cliOpts);
86 * Downloads source code in the build workspace directory, optionally checking out the given branch/tag
88 function run_init($task=null, $args=array(), $cliOpts=array())
90 // download the current version into the workspace
91 $targetDir = Builder::workspaceDir();
92 $targetBranch = 'php53';
94 // check if workspace exists and is not already set to the correct repo
95 if (is_dir($targetDir) && pakeGit::isRepository($targetDir)) {
96 $repo = new pakeGit($targetDir);
97 $remotes = $repo->remotes();
98 if (trim($remotes['origin']['fetch']) != Builder::sourceRepo()) {
99 throw new Exception("Directory '$targetDir' exists and is not linked to correct git repo");
102 /// @todo should we not just fetch instead?
105 pake_mkdirs(dirname($targetDir));
106 $repo = pakeGit::clone_repository(Builder::sourceRepo(), Builder::workspaceDir());
109 $repo->checkout($targetBranch);
113 * Runs all the build steps.
115 * (does nothing by itself, as all the steps are managed via task dependencies)
117 function run_build($task=null, $args=array(), $cliOpts=array())
122 * Generates documentation in all formats
124 function run_doc($task=null, $args=array(), $cliOpts=array())
129 function run_clean_dist()
131 pake_remove_dir(Builder::distDir());
132 $finder = pakeFinder::type('file')->name(Builder::distFiles());
133 pake_remove($finder, Builder::buildDir());
137 * Creates the tarballs for a release
139 function run_dist($task=null, $args=array(), $cliOpts=array())
141 // copy workspace dir into dist dir, without git
142 pake_mkdirs(Builder::distDir());
143 $finder = pakeFinder::type('any')->ignore_version_control();
144 pake_mirror($finder, realpath(Builder::workspaceDir()), realpath(Builder::distDir()));
146 // remove unwanted files from dist dir
148 // also: do we still need to run dos2unix?
151 chdir(dirname(Builder::distDir()));
152 foreach(Builder::distFiles() as $distFile) {
153 // php can not really create good zip files via phar: they are not compressed!
154 if (substr($distFile, -4) == '.zip') {
157 pake_sh("$cmd $distFile $extra ".basename(Builder::distDir()));
160 $finder = pakeFinder::type('any')->pattern(basename(Builder::distDir()).'/**');
161 // see https://bugs.php.net/bug.php?id=58852
162 $pharFile = str_replace(Builder::libVersion(), '_LIBVERSION_', $distFile);
163 pakeArchive::createArchive($finder, '.', $pharFile);
164 rename($pharFile, $distFile);
170 * Cleans up the build directory
171 * @todo 'make clean' usually just removes the results of the build, distclean removes all but sources
173 function run_clean($task=null, $args=array(), $cliOpts=array())
175 pake_remove_dir(Builder::buildDir());
178 // helper task: display help text
179 pake_task( 'default' );
180 // internal task: parse cli options
181 pake_task('getopts');
182 pake_task('init', 'getopts');
183 pake_task('doc', 'getopts', 'init');
184 pake_task('build', 'getopts', 'init', 'doc');
185 pake_task('dist', 'getopts', 'init', 'build', 'clean-dist');
186 pake_task('clean-dist', 'getopts');
187 pake_task('clean', 'getopts');