forked from CpanelInc/tech-vm_setup
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
80 lines (71 loc) · 2.51 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
PROJECT=vm_setup.pl
SHELL=/bin/sh
PATH=/usr/local/cpanel/3rdparty/perl/526/bin:/usr/local/cpanel/3rdparty/perl/524/bin:/usr/local/cpanel/3rdparty/bin:/sbin:/bin:/usr/sbin:/usr/bin
PERLCRITIC=perlcritic
PERLCRITICRC=tools/.perlcriticrc
PERLTIDY=perltidy
PERLTIDYRC=tools/.perltidyrc
NEW_VER=$(shell grep 'our $$VERSION' $(PROJECT) | awk '{print $$4}' | sed -e "s/'//g" -e 's/;//')
.DEFAULT: help
.IGNORE: clean
.PHONY: clean commit final help test tidy
.PRECIOUS: $(PROJECT)
.SILENT: commit final help $(PROJECT).tdy test tidy
# A line beginning with a double hash mark is used to provide help text for the target that follows it when running 'make help' or 'make'. The help target must be first.
# "Invisible" targets should not be marked with help text.
## Show this help
help:
printf "\nAvailable targets:\n"
awk '/^[a-zA-Z\-\_0-9]+:/ { \
helpMessage = match(lastLine, /^## (.*)/); \
if (helpMessage) { \
helpCommand = substr($$1, 0, index($$1, ":")-1); \
helpMessage = substr(lastLine, RSTART + 3, RLENGTH); \
printf "%-15s - %s\n", helpCommand, helpMessage; \
} \
} \
{ lastLine = $$0 }' $(MAKEFILE_LIST)
printf "\n"
## Clean up
clean:
$(RM) $(PROJECT).tdy
## Commit an intermediate change
commit: tidy
ifndef COMMITMSG
echo 'COMMITMSG is undefined. Add COMMITMSG="My commit description" to make command line.' && exit 2
endif
git add $(PROJECT)
git commit -m "$(COMMITMSG)"
## Make final commit
final:
git add $(PROJECT)
git commit -m "$(PROJECT) $(NEW_VER)"
echo 'Ready to git push to origin!'
$(PROJECT).tdy: $(PROJECT)
which $(PERLTIDY) | egrep -q '/usr/local/cpanel' || echo "cPanel perltidy not found! Are you running this on a WHM 64+ system?"
echo "-- Running tidy"
$(PERLTIDY) --profile=$(PERLTIDYRC) $(PROJECT)
## Run basic tests
test:
[ -e /usr/local/cpanel/version ] || ( echo "You're not running this on a WHM system."; exit 2 )
echo "-- Running perl syntax check"
perl -c $(PROJECT) || ( echo "$(PROJECT) perl syntax check failed"; exit 2 )
echo "-- Running perlcritic"
$(PERLCRITIC) --profile $(PERLCRITICRC) $(PROJECT)
## Run perltidy, compare, and ask for overwrite
tidy: test $(PROJECT).tdy
echo "-- Checking if tidy"
if ( diff -u $(PROJECT) $(PROJECT).tdy > /dev/null ); then \
echo "$(PROJECT) is tidy."; \
exit 0; \
else \
diff -u $(PROJECT) $(PROJECT).tdy | less -F; \
cp -i $(PROJECT).tdy $(PROJECT); \
if ( diff -u $(PROJECT) $(PROJECT).tdy > /dev/null ); then \
echo "$(PROJECT) is tidy."; \
exit 0; \
else \
echo "$(PROJECT) is NOT tidy."; \
exit 2; \
fi; \
fi;