forked from leifeld/dna
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmakefile2
190 lines (170 loc) · 6.86 KB
/
makefile2
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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
# define makefile variables for programs and compilers
JAVAC := javac
FIND := find
RM := rm -rf
MKDIR := mkdir -p
CP := cp -r
RBUILD := R CMD build
RSCRIPT := Rscript -e
LATEX := texi2pdf
# define makefile variables for directories and files
OUTPUT_DIR := output
SOURCE_DIR := DNA/src
LIB_DIR := DNA/lib
SAMPLE_DIR := sample
SAMPLE_FILE := sample.dna
R_DIR := rDNA
MANUAL_DIR := manual
MANUAL_FILE := dna-manual
# define makefile variable for DNA JAR file name with version number
# 1. match version line in Dna.java using grep
# 2. remove string after version information using sed
# 3. remove string before version information using sec (including two tabs)
# 4. replace first space by dash
# 5. replace second space by nothing
# 6. wrap in file name
VERSION := $(shell grep -P 'version = ".+"' DNA/src/dna/Dna.java | sed 's/";//' | sed 's/\t\tversion = "//' | sed 's/ /-/ ' | sed 's/ //')
JARFILE := dna-${VERSION}.jar
RDNAVERSION := $(shell grep -P '^Version: .+' $(R_DIR)/DESCRIPTION | sed 's/Version: //')
# make all and print a final message that we're done
all: sample rDNA manual
@echo done.
# compile the manual using knitr and texi2pdf
manual: rdnainst
$(RSCRIPT) "if(! 'knitr' %in% installed.packages()) install.packages('knitr')"; \
$(RSCRIPT) "if(! 'ggplot2' %in% installed.packages()) install.packages('ggplot2')"; \
$(RSCRIPT) "if(! 'gridExtra' %in% installed.packages()) install.packages('gridExtra')"; \
$(RSCRIPT) "if(! 'kableExtra' %in% installed.packages()) install.packages('kableExtra')"; \
$(RSCRIPT) "if(! 'LexisNexisTools' %in% installed.packages()) install.packages('LexisNexisTools')"; \
$(RSCRIPT) "if(! 'quanteda.textmodels' %in% installed.packages()) install.packages('quanteda.textmodels')"; \
$(RSCRIPT) "if(! 'statnet' %in% installed.packages()) install.packages('statnet')"; \
$(RSCRIPT) "if(! 'igraph' %in% installed.packages()) install.packages('igraph')"; \
$(RSCRIPT) "if(! 'rJava' %in% installed.packages()) install.packages('rJava')"; \
$(RSCRIPT) "if(! 'quanteda.corpora' %in% installed.packages()) remotes::install_github('quanteda/quanteda.corpora')"; \
$(MKDIR) $(OUTPUT_DIR); \
$(CP) $(MANUAL_DIR) $(OUTPUT_DIR); \
cd $(OUTPUT_DIR)/$(MANUAL_DIR); \
$(RSCRIPT) "library(knitr); knit('$(MANUAL_FILE).Rnw')"; \
$(LATEX) $(MANUAL_FILE).tex; \
mv *.pdf ..; \
cd ..; \
$(RM) $(MANUAL_DIR)
# install rDNA
rdnainst: rDNA-full-temp
$(RSCRIPT) "if(! 'devtools' %in% installed.packages()) install.packages('devtools')"; \
cd $(OUTPUT_DIR)/rtemp; \
$(RSCRIPT) "devtools::install('rDNA', dependencies = TRUE, upgrade = FALSE)"; \
cd ..; \
$(RM) rtemp; \
cd ..; \
rmdir --ignore-fail-on-non-empty $(OUTPUT_DIR)
# compile rDNA source package without DNA
rDNA: mkdir-output
$(RBUILD) $(R_DIR); \
mv $(R_DIR)*.tar.gz $(OUTPUT_DIR)
# compile rDNA source package with DNA
rDNA-full: rDNA-full-temp
cd $(OUTPUT_DIR)/rtemp; \
$(RBUILD) $(R_DIR); \
mv $(R_DIR)_${RDNAVERSION}.tar.gz ../$(R_DIR)_full_${RDNAVERSION}.tar.gz; \
cd ..; \
$(RM) rtemp
# create temporary version of full rDNA package
rDNA-full-temp: mkdir-output compile-java
$(MKDIR) $(OUTPUT_DIR)/rtemp; \
$(CP) $(R_DIR) $(OUTPUT_DIR)/rtemp; \
cd $(OUTPUT_DIR); \
$(MKDIR) temp; \
mv src temp/; \
cd temp/src; \
jar cmf ../../../$(SOURCE_DIR)/META-INF/MANIFEST.MF ../../${JARFILE} *; \
chmod +x ../../$(JARFILE); \
cd ../..; \
$(MKDIR) rtemp/$(R_DIR)/inst/java/; \
mv ${JARFILE} rtemp/$(R_DIR)/inst/java/; \
$(RM) temp; \
# copy-sample - copy the sample.dna database to the output directory
sample: mkdir-output
$(CP) $(SAMPLE_DIR)/$(SAMPLE_FILE) $(OUTPUT_DIR)/
# create jar file based on MANIFEST from source directory and make executable
dna: compile-java
cd $(OUTPUT_DIR)/src/; \
jar cmf ../../$(SOURCE_DIR)/META-INF/MANIFEST.MF ../${JARFILE} *; \
chmod +x ../$(JARFILE); \
cd ..; \
$(RM) src/
# compile-java - compile main class (trickling down to all dependencies),
# then delete sources from output directory
compile-java: extract-jar-libs
cd $(OUTPUT_DIR)/src/; \
$(JAVAC) -version; \
$(JAVAC) --release 8 dna/Dna.java; \
$(JAVAC) --release 8 dna/export/ExporterR.java; \
$(FIND) . -name '*.java' -exec $(RM) {} \;
# extract-jar-libs - extract libraries
extract-jar-libs: copy-java-libs
cd $(OUTPUT_DIR)/src/; \
$(FIND) . -name '*.jar' -exec jar xf {} \;; \
$(RM) *.jar
# copy-java-libs - copy the jar libraries to the src directory in the output directory
copy-java-libs: copy-java-sources
$(CP) $(LIB_DIR)/*.jar $(OUTPUT_DIR)/src/
# copy-java-sources - copy the Java source files to the output directory
copy-java-sources: mkdir-output
$(CP) $(SOURCE_DIR) $(OUTPUT_DIR)
# mkdir-output - create output directory
mkdir-output:
$(MKDIR) $(OUTPUT_DIR)
# clean up: remove output directory and all contents
.PHONY: clean
clean:
$(RM) $(OUTPUT_DIR)
# check and test rDNA
test-rDNA: rDNA
cd $(OUTPUT_DIR); \
R CMD check --no-multiarch --no-manual --as-cran $(R_DIR)_$(RDNAVERSION).tar.gz
# test manual
test-manual:
$(eval MANUALSIZE = $(shell pdftotext '$(OUTPUT_DIR)/$(MANUAL_FILE).pdf' - | wc -w))
@if [ ${MANUALSIZE} -gt 40000 ]; \
then echo "PASS: DNA manual PDF contains ${MANUALSIZE} words (test requires > 40000)."; \
exit 0; \
else echo "FAIL: DNA manual PDF contains ${MANUALSIZE} words (test requires > 40000)."; \
exit 1; \
fi
# test sample
test-sample:
$(eval SAMPLETEST1 = $(shell sqlite3 $(OUTPUT_DIR)/$(SAMPLE_FILE) "SELECT EXISTS (SELECT * FROM sqlite_master WHERE type='table' AND name='<tableName>');"))
@if [ ${SAMPLETEST1} = 0 ]; \
then echo PASS: sample.dna contains tables.; \
exit 0; \
else echo FAIL: sample.dna does not contain any tables.; \
exit 1; \
fi
$(eval SAMPLETEST2 = $(shell sqlite3 $(OUTPUT_DIR)/$(SAMPLE_FILE) "PRAGMA integrity_check;"))
@if [ ${SAMPLETEST2} = ok ]; \
then echo PASS: sample.dna passed sqlite3 integrity test.; \
exit 0; \
else echo FAIL: sample.dna did not pass sqlite3 integrity test.; \
exit 1; \
fi
# test dna
test-dna:
@if jar -tvf $(OUTPUT_DIR)/$(JARFILE) | grep ' dna/Dna\.class'; \
then echo PASS: $(JARFILE) contains Dna.class.; \
exit 0; \
else echo FAIL: $(JARFILE) does not contain Dna.class.; \
exit 1; \
fi
@if jar -tvf $(OUTPUT_DIR)/$(JARFILE) | grep ' dna/export/ExporterR\.class'; \
then echo PASS: $(JARFILE) contains ExporterR.class.; \
exit 0; \
else echo FAIL: $(JARFILE) does not contain ExporterR.class.; \
exit 1; \
fi
@if jar -tvf $(OUTPUT_DIR)/$(JARFILE) | grep ' libjri.so'; \
then echo PASS: $(JARFILE) contains libjri.so in root directory.; \
exit 0; \
else echo FAIL: $(JARFILE) does not contain libjri.so in root directory.; \
exit 1; \
fi