Skip to content

Commit 7736b77

Browse files
markwuweynhamz
authored andcommitted
Add a Makefile to build a stand-alone PHAR executable
1 parent 69d2dc2 commit 7736b77

File tree

5 files changed

+95
-9
lines changed

5 files changed

+95
-9
lines changed

.gitignore

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
vendor
2-
composer.phar
31
tests/*.expect
42
tests/*.result
3+
build/
4+
vendor/
5+
phpctags

Makefile

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
source := README.md \
2+
ChangeLog.md \
3+
composer.json \
4+
composer.lock \
5+
bootstrap.php \
6+
PHPCtags.class.php
7+
8+
.PHONY: all
9+
all: phpctags
10+
11+
.PHONY: clean
12+
clean:
13+
@echo "Cleaning executables ..."
14+
@rm -f ./phpctags
15+
@rm -f ./build/phpctags.phar
16+
@echo "Done!"
17+
18+
.PHONY: dist-clean
19+
dist-clean:
20+
@echo "Cleaning old build files and vendor libraries ..."
21+
@rm -rf ./build
22+
@rm -rf ./vendor
23+
@echo "Done!"
24+
25+
.PHONY: install
26+
install: phpctags
27+
@echo "Sorry, you need to move phpctags to /usr/bin/phpctags or /usr/local/bin/phpctags or any place you want manually."
28+
29+
build:
30+
@if [ ! -x build ]; \
31+
then \
32+
mkdir build; \
33+
fi
34+
35+
build/composer.phar: | build
36+
@echo "Installing composer ..."
37+
@curl -s http://getcomposer.org/installer | php -- --install-dir=build
38+
39+
vendor: composer.lock build/composer.phar
40+
@echo "Installing vendor libraries ..."
41+
@php build/composer.phar install
42+
@touch vendor/
43+
44+
build/phpctags.phar: vendor $(source) | build
45+
@php -dphar.readonly=0 buildPHAR.php
46+
@chmod +x build/phpctags.phar
47+
48+
phpctags: build/phpctags.phar
49+
@echo "Building phpctags ..."
50+
@cp build/phpctags.phar phpctags
51+
@echo "Done!"

README.md

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,9 @@ Enjoy!
1818
Installation
1919
------------
2020

21-
We use [composer](http://getcomposer.org/) for dependency management, run the
22-
following commands under the project directory to get composer and install the
23-
dependency.
24-
25-
curl -s http://getcomposer.org/installer | php
26-
php composer.phar install
21+
Installation is simple, just run `make` in the root directory of the source,
22+
you will get a `phpctags` PHAR executable, add it to your `$PATH`, then you
23+
can invoke `phpcatgs` directly from anywhere.
2724

2825
See [phpctags on packagist](http://packagist.org/packages/techlivezheng/phpctags)
2926
for more details.

phpctags renamed to bootstrap.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
#!/usr/bin/env php
21
<?php
32
if (file_exists($autoload = __DIR__ . '/vendor/autoload.php')) {
43
require($autoload);

buildPHAR.php

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?php
2+
3+
$phar = new Phar('build/phpctags.phar', 0, 'phpctags.phar');
4+
5+
$phar->buildFromIterator(
6+
new RecursiveIteratorIterator(
7+
new RecursiveCallbackFilterIterator(
8+
new RecursiveDirectoryIterator(
9+
getcwd(),
10+
FilesystemIterator::SKIP_DOTS
11+
),
12+
function ($current) {
13+
$excludes = array(
14+
'.*',
15+
'tags',
16+
'build/*',
17+
'tests/*',
18+
'Makefile',
19+
'phpctags.sh',
20+
'buildPHAR.php',
21+
);
22+
23+
foreach($excludes as $exclude) {
24+
if (fnmatch(getcwd().'/'.$exclude, $current->getPathName())) {
25+
return false;
26+
}
27+
}
28+
29+
return true;
30+
}
31+
)
32+
),
33+
getcwd()
34+
);
35+
36+
$phar->setStub(
37+
"#!/usr/bin/env php\n".$phar->createDefaultStub('bootstrap.php')
38+
);

0 commit comments

Comments
 (0)