-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathMakefile
143 lines (130 loc) · 5.83 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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
VERSION = 1.5
UTILS = boolify \
cumsum \
diffs \
div \
exp \
exp10 \
exp2 \
hist \
histbin \
inrange \
len \
line \
log \
log10 \
log2 \
lwhich \
max \
mean \
median \
min \
mult \
ncol \
range \
round \
showcol \
stripfilt \
sum \
table
LINKSCRIPT = linkscript.sh
COPYSCRIPT = copyscript.sh
SCRIPTDIR = $(shell dirname $(realpath $(lastword $(MAKEFILE_LIST))))
ZIPFILE = tinyutils-$(VERSION).zip
TARBALL = tinyutils-$(VERSION).tar.gz
TESTDIR = tests
TESTINPUT = tinyutils.dat
TESTEXPECT = tinyutils.expected
TESTOUTPUT = tinyutils.output
TESTDIFF = tinyutils.testdiff
all: test zipfile tarball linkscript copyscript
linkscript: $(UTILS)
@echo "#!/bin/sh" > $(LINKSCRIPT)
@echo "SCRIPTDIR=$(SCRIPTDIR)" >> $(LINKSCRIPT)
@echo "for util in $(UTILS) ; do" >> $(LINKSCRIPT)
@echo " if [ ! -e \$$util -o -L \$$util ] ; then" >> $(LINKSCRIPT)
@echo " ln -sf $(SCRIPTDIR)/\$$util \$$util" >> $(LINKSCRIPT)
@echo " else" >> $(LINKSCRIPT)
@echo " echo Not linking \$$util: file exists and is not a symbolic link" >> $(LINKSCRIPT)
@echo " fi" >> $(LINKSCRIPT)
@echo "done" >> $(LINKSCRIPT)
@chmod +x $(LINKSCRIPT)
@echo "$(LINKSCRIPT) created, run it to create symbolic links to tinyutils in current directory"
copyscript: $(UTILS)
@echo "#!/bin/sh" > $(COPYSCRIPT)
@echo "SCRIPTDIR=$(SCRIPTDIR)" >> $(COPYSCRIPT)
@echo "for util in $(UTILS) ; do" >> $(COPYSCRIPT)
@echo " if [ ! -e \$$util ] ; then" >> $(COPYSCRIPT)
@echo " cp -pv $(SCRIPTDIR)/\$$util \$$util" >> $(COPYSCRIPT)
@echo " else" >> $(COPYSCRIPT)
@echo " echo Not copying \$$util: file exists" >> $(COPYSCRIPT)
@echo " fi" >> $(COPYSCRIPT)
@echo "done" >> $(COPYSCRIPT)
@chmod +x $(COPYSCRIPT)
@echo "$(COPYSCRIPT) created, run it to copy tinyutils to current directory"
zipfile: $(UTILS) $(TESTDIR) Makefile README.md
@if [ -e $(TESTDIR)/$(TESTDIFF) -o -e $(TESTDIR)/$(TESTOUTPUT) ] ; then \
echo "$(TESTDIR)/ still contains $(TESTDIFF) and/or $(TESTOUTPUT)" ; \
exit 1; \
fi ;
@( echo "Creating zipfile for version $(VERSION)" ; \
rm -f $(ZIPFILE) ; \
chmod 755 $(UTILS) $(TESTDIR); \
chmod 644 $(TESTDIR)/* Makefile README.md; \
zip -r $(ZIPFILE) $^ && echo "Created $(ZIPFILE)" ; \
)
tarball: $(UTILS) $(TESTDIR) Makefile README.md
@if [ -e $(TESTDIR)/$(TESTDIFF) -o -e $(TESTDIR)/$(TESTOUTPUT) ] ; then \
echo "$(TESTDIR)/ still contains $(TESTDIFF) and/or $(TESTOUTPUT)" ; \
exit 1; \
fi ;
@( echo "Creating tarball for version $(VERSION)" ; \
rm -f $(TARBALL) ; \
chmod 755 $(UTILS) $(TESTDIR); \
chmod 644 $(TESTDIR)/* Makefile README.md; \
tar cvzf $(TARBALL) $^ && echo "Created $(TARBALL)" ; \
)
test: $(TESTDIR)/$(TESTOUTPUT)
@( cd $(TESTDIR); \
if diff $(TESTOUTPUT) $(TESTEXPECT) > $(TESTDIFF) ; then \
echo "PASSED tinyutils test" ; \
rm -f $(TESTOUTPUT) $(TESTDIFF) ; \
else \
echo "FAILED** tinyutils test, diff file in $(TESTDIR)/$(TESTDIFF)" ; \
fi ; \
)
# Output for table test is sorted for comparison because keys come out in various orders
$(TESTDIR)/$(TESTOUTPUT): $(UTILS)
@( cd $(TESTDIR); rm -f $(TESTDIFF) ; \
cat /dev/null > $(TESTOUTPUT) ; \
for U in boolify cumsum diffs exp exp10 exp2 hist histbin log log10 log2 max mean median min range stripfilt sum ncol len showcol; do \
echo $$U >> $(TESTOUTPUT) ;\
../$$U $(TESTINPUT) >> $(TESTOUTPUT) ; \
done ; \
echo 'mult mult=2' >> $(TESTOUTPUT); ../mult mult=2 $(TESTINPUT) >> $(TESTOUTPUT) ; \
echo 'div div=2' >> $(TESTOUTPUT); ../div div=2 $(TESTINPUT) >> $(TESTOUTPUT) ; \
echo 'round digits=0' >> $(TESTOUTPUT); ../round digits=0 $(TESTINPUT) >> $(TESTOUTPUT) ; \
echo 'table | sort -k1,1 -n' >> $(TESTOUTPUT); ../table $(TESTINPUT) | sort -k1,1 -n >> $(TESTOUTPUT) ; \
echo 'stripfilt inverse=1' >> $(TESTOUTPUT); ../stripfilt inverse=1 $(TESTINPUT) >> $(TESTOUTPUT) ; \
echo 'stripfilt header=0 inverse=1' >> $(TESTOUTPUT); ../stripfilt header=0 inverse=1 $(TESTINPUT) >> $(TESTOUTPUT) ; \
echo 'stripfilt inverse=1 inverse_early=0 header=0' >> $(TESTOUTPUT); ../stripfilt inverse=1 inverse_early=0 header=0 $(TESTINPUT) >> $(TESTOUTPUT) ; \
echo 'inrange abs=4' >> $(TESTOUTPUT); ../inrange abs=4 $(TESTINPUT) >> $(TESTOUTPUT) ; \
echo 'inrange min=1 max=8' >> $(TESTOUTPUT); ../inrange min=1 max=8 $(TESTINPUT) >> $(TESTOUTPUT) ; \
echo 'inrange min=1 max=8 inverse=1' >> $(TESTOUTPUT); ../inrange min=1 max=8 inverse=1 $(TESTINPUT) >> $(TESTOUTPUT) ; \
echo 'line line=2' >> $(TESTOUTPUT); ../line line=2 $(TESTINPUT) >> $(TESTOUTPUT) ; \
echo 'line line=5 around=2' >> $(TESTOUTPUT); ../line line=5 around=2 $(TESTINPUT) >> $(TESTOUTPUT) ; \
echo 'line min=7' >> $(TESTOUTPUT); ../line min=7 $(TESTINPUT) >> $(TESTOUTPUT) ; \
echo 'line max=2' >> $(TESTOUTPUT); ../line max=2 $(TESTINPUT) >> $(TESTOUTPUT) ; \
echo 'line min=3 max=4' >> $(TESTOUTPUT); ../line min=3 max=4 $(TESTINPUT) >> $(TESTOUTPUT) ; \
echo 'line stride=3' >> $(TESTOUTPUT); ../line stride=3 $(TESTINPUT) >> $(TESTOUTPUT) ; \
echo 'line stride=3 first=2' >> $(TESTOUTPUT); ../line stride=3 first=2 $(TESTINPUT) >> $(TESTOUTPUT) ; \
echo 'line stride=3 chunk=2' >> $(TESTOUTPUT); ../line stride=3 chunk=2 $(TESTINPUT) >> $(TESTOUTPUT) ; \
echo 'line stride=3 first=2 chunk=2' >> $(TESTOUTPUT); ../line stride=3 first=2 chunk=2 $(TESTINPUT) >> $(TESTOUTPUT) ; \
echo 'line stride=3 first=2 inverse=1' >> $(TESTOUTPUT); ../line stride=3 first=2 inverse=1 $(TESTINPUT) >> $(TESTOUTPUT) ; \
echo 'lwhich val=0' >> $(TESTOUTPUT); ../lwhich val=0 $(TESTINPUT) >> $(TESTOUTPUT) ; \
echo 'lwhich val=4' >> $(TESTOUTPUT); ../lwhich val=4 $(TESTINPUT) >> $(TESTOUTPUT) ; \
echo 'lwhich val=4 inverse=1' >> $(TESTOUTPUT); ../lwhich val=4 inverse=1 $(TESTINPUT) >> $(TESTOUTPUT) ; \
)
clean:
rm -f $(LINKSCRIPT) $(COPYSCRIPT) $(ZIPFILE) $(TARBALL) ; ( cd $(TESTDIR) ; rm -f $(TESTDIFF) $(TESTOUTPUT) )
.PHONY: $(UTILS)