Commit | Line | Data |
---|---|---|
3a2f1a4b | 1 | ### -*-makefile-*- |
9c15124f MW |
2 | ### |
3 | ### Build script for the TrIPE Android app | |
4 | ### | |
5 | ### (c) 2018 Straylight/Edgeware | |
6 | ### | |
3a2f1a4b | 7 | |
9c15124f MW |
8 | ###----- Licensing notice --------------------------------------------------- |
9 | ### | |
10 | ### This file is part of the Trivial IP Encryption (TrIPE) Android app. | |
11 | ### | |
12 | ### TrIPE is free software: you can redistribute it and/or modify it under | |
13 | ### the terms of the GNU General Public License as published by the Free | |
14 | ### Software Foundation; either version 3 of the License, or (at your | |
15 | ### option) any later version. | |
16 | ### | |
17 | ### TrIPE is distributed in the hope that it will be useful, but WITHOUT | |
18 | ### ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
19 | ### FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
20 | ### for more details. | |
21 | ### | |
22 | ### You should have received a copy of the GNU General Public License | |
23 | ### along with TrIPE. If not, see <https://www.gnu.org/licenses/>. | |
24 | ||
25 | PACKAGE = tripe-android | |
26 | VERSION := $(shell ./auto-version) | |
27 | ||
28 | .SECONDEXPANSION: #sorry | |
29 | ||
30 | ###-------------------------------------------------------------------------- | |
31 | ### Build parameters. | |
32 | ||
33 | ## Where to put the object files. | |
34 | OUTDIR = out/ | |
35 | ||
36 | ## Native C compiler. | |
37 | CC = gcc | |
38 | CFLAGS = -O2 -g -Wall -pedantic -Werror | |
39 | ||
40 | ## Native linker. | |
41 | LD = gcc | |
42 | LDFLAGS.so = -shared | |
43 | ||
44 | ## External `pkg-config' packages required. | |
45 | PKGS = mLib catacomb | |
46 | ||
47 | ## Java development kit. | |
48 | JDKDIR = /usr/lib/jvm/default-java | |
49 | JDK_PLAT = linux | |
50 | JNI_INCLUDES = $(JDKDIR)/include $(JDKDIR)/include/$(JDK_PLAT) | |
51 | ||
52 | ## Default arguments for the Java runtime. | |
53 | JAVADEFS = | |
54 | ||
55 | ## The Java runtime, for some reason, hardcodes its default for | |
56 | ## `java.io.tmpdir', inviting security problems. If the user has defined a | |
57 | ## `TMPDIR', then persuade Java to use it. | |
58 | explicit-tmpdir-p = $(if $(filter-out undefined,$(origin TMPDIR)),t,nil) | |
59 | ifeq ($(explicit-tmpdir-p), t) | |
60 | JAVADEFS += -Djava.io.tmpdir=$(TMPDIR) | |
61 | endif | |
62 | ||
63 | ## Java compiler. | |
64 | JAVAC = javac $(JAVADEFS) | |
65 | JAVAFLAGS = | |
66 | ||
67 | ## Scala compiler. | |
68 | ## | |
69 | ## Unfortunately, `fsc' is a total security disaster. On the other hand, | |
70 | ## `scalac' is rather slow. If we're running with a custom `TMPDIR', and the | |
71 | ## `noip' wrapper <https://git.distorted.org.uk/~mdw/preload-hacks/> is | |
72 | ## available, then we can tame `fsc' enough that it's probably safe to run; | |
73 | ## otherwise, it's too risky to enable by default. | |
74 | noip-available-p := $(shell noip echo t 2>/dev/null || echo nil) | |
75 | ifeq ($(noip-available-p), t) | |
76 | NOIP = noip | |
77 | endif | |
78 | ifeq "$(explicit-tmpdir-p),$(noip-available-p)" "t,t" | |
79 | SCALAC = $(NOIP) fsc $(JAVADEFS) | |
80 | SCALAC_RESET = $(SCALAC) -reset | |
81 | else | |
82 | SCALAC = scalac $(JAVADEFS) | |
83 | SCALAC_RESET = | |
84 | endif | |
5c2b1515 MW |
85 | SCALAFLAGS = -optimise -feature -deprecation -Xfatal-warnings \ |
86 | -Xlint -Xlint:-package-object-classes \ | |
9c15124f MW |
87 | -Yinline-warnings:false |
88 | SCALA_REPL = $(NOIP) scala $(JAVADEFS) | |
89 | ||
90 | ## Silent-rules is on by default. | |
3a2f1a4b | 91 | V = 0 |
9c15124f MW |
92 | |
93 | ## Allow local overrides at this point. | |
94 | -include local.mk | |
95 | ||
96 | ###-------------------------------------------------------------------------- | |
97 | ### Silent-rules machinery. | |
98 | ||
3a2f1a4b MW |
99 | v_tag = $(call v_tag_$V,$1) |
100 | v_tag_0 = @printf " %-8s %s\n" "$1" "$@"; | |
9c15124f | 101 | |
3a2f1a4b MW |
102 | V_AT = $(V_AT_$V) |
103 | V_AT_0 = @ | |
104 | ||
9c15124f MW |
105 | ###-------------------------------------------------------------------------- |
106 | ### External native packages. | |
3a2f1a4b | 107 | |
8eabb4ff MW |
108 | PKGS_CFLAGS := $(foreach p,$(PKGS),$(shell pkg-config --cflags $p)) |
109 | PKGS_LIBS := $(foreach p,$(PKGS),$(shell pkg-config --libs $p)) | |
110 | ||
9c15124f MW |
111 | ALL_CFLAGS = $(CFLAGS) -fPIC \ |
112 | $(addprefix -I,$(JNI_INCLUDES)) \ | |
113 | $(PKGS_CFLAGS) | |
3a2f1a4b | 114 | |
8eabb4ff | 115 | LIBS = $(PKGS_LIBS) |
3a2f1a4b | 116 | |
9c15124f MW |
117 | ###-------------------------------------------------------------------------- |
118 | ### Various other tweaks and overrides. | |
3a2f1a4b | 119 | |
8eabb4ff MW |
120 | ## Hack around https://issues.scala-lang.org/browse/SI-9689 |
121 | SCALAFLAGS += -Yno-load-impl-class | |
122 | ||
9c15124f MW |
123 | ###-------------------------------------------------------------------------- |
124 | ### And now we can start building things. | |
125 | ||
3a2f1a4b MW |
126 | all:: |
127 | .PHONY: all | |
128 | ||
9c15124f MW |
129 | CLEANFILES = |
130 | clean:: | |
131 | .PHONY: clean | |
132 | ||
133 | ###-------------------------------------------------------------------------- | |
134 | ### Native C code. | |
3a2f1a4b | 135 | |
2812483e | 136 | out/%.o: %.c |
9c15124f MW |
137 | $(call v_tag,CC)mkdir -p $(OUTDIR) && \ |
138 | $(CC) -c $(ALL_CFLAGS) -MMD -o$@ $< | |
139 | ||
140 | ALL_SOURCES = | |
141 | DISTFILES += $(ALL_SOURCES) | |
142 | ||
143 | objects = $(patsubst %.c,$(OUTDIR)%$2,$1) | |
2812483e MW |
144 | CLEANFILES += $(OUTDIR)*.o $(OUTDIR)*.d |
145 | ||
9c15124f MW |
146 | ###-------------------------------------------------------------------------- |
147 | ### Java classes. | |
148 | ||
149 | ## Java and Scala source files turn into multiple `.class' files with | |
150 | ## unpredictable names. Rather than try to guess stable outputs for these | |
151 | ## sources, we make artificial `timestamp' files and uses these in our | |
152 | ## dependencies. | |
2812483e | 153 | CLASSDIR = $(OUTDIR)cls/ |
9c15124f MW |
154 | stamps = $(patsubst %,$(OUTDIR)%.stamp,$1) |
155 | ||
156 | clean::; rm -rf $(CLASSDIR) | |
157 | CLEANFILES += $(OUTDIR)*.stamp | |
158 | ||
159 | ## Compiling actual Java code. Note that this confuses the resident Scala | |
160 | ## compiler, so we have to reset it here. | |
161 | CLSISH += java | |
2812483e | 162 | $(OUTDIR)%.stamp: %.java |
2a02a846 MW |
163 | $(call v_tag,JAVAC)mkdir -p $(CLASSDIR) && \ |
164 | $(JAVAC) -d $(CLASSDIR) -cp $(CLASSDIR) $(JAVAFLAGS) $< && \ | |
165 | echo built >$@ | |
9c15124f MW |
166 | $(V_AT)$(SCALAC_RESET) |
167 | ||
168 | ## Compiling Scala code. | |
169 | CLSEXT += scala | |
2812483e | 170 | $(OUTDIR)%.stamp: %.scala |
2a02a846 MW |
171 | $(call v_tag,SCALAC)mkdir -p $(CLASSDIR) && \ |
172 | $(SCALAC) -d $(CLASSDIR) -cp $(CLASSDIR) $(SCALAFLAGS) $< && \ | |
173 | echo built >$@ | |
3a2f1a4b | 174 | |
9c15124f MW |
175 | ###-------------------------------------------------------------------------- |
176 | ### Native-code libraries. | |
177 | ||
178 | SHLIBS += toy | |
179 | toy_SOURCES = jni.c | |
3a2f1a4b | 180 | |
9c15124f MW |
181 | shlibfile = $(patsubst %,$(OUTDIR)lib%.so,$1) |
182 | SHLIBFILES = $(call shlibfile,$(SHLIBS)) | |
183 | TARGETS += $(SHLIBFILES) | |
184 | ALL_SOURCES += $(foreach l,$(SHLIBS),$($l_SOURCES)) | |
185 | ||
186 | $(SHLIBFILES): $(OUTDIR)lib%.so: $$(call objects,$$($$*_SOURCES),.o) | |
8eabb4ff MW |
187 | $(call v_tag,LD)$(LD) $(LDFLAGS.so) -o$@ $^ $(LIBS) |
188 | ||
9c15124f MW |
189 | ###-------------------------------------------------------------------------- |
190 | ### Java classes. | |
191 | ||
192 | ## Writing things out longhand is tedious. `CLASSES' is a list of entries of | |
193 | ## the form `SRC[:DEP,...]', saying that `SRC.ext', being a source file | |
194 | ## capable of being built into `.class' files and setting `SRC.stamp', should | |
195 | ## be so built, and that it depends on other similar sources named DEP having | |
196 | ## been so built. | |
2812483e | 197 | CLASSES += util |
9c15124f MW |
198 | CLASSES += sys:util |
199 | CLASSES += admin:sys,util | |
200 | CLASSES += tar:util | |
04a5abae MW |
201 | CLASSES += progress:sys,util |
202 | CLASSES += keys:progress,tar,sys,util | |
203 | CLASSES += terminal:progress,sys,util | |
9c15124f MW |
204 | CLASSES += main:sys |
205 | ||
206 | ## Machinery for parsing the `CLASSES' list. | |
207 | COMMA = , | |
208 | class-name = $(firstword $(subst :, ,$1)) | |
209 | class-deps = $(subst $(COMMA), ,$(word 2,$(subst :, ,$1))) | |
210 | ||
211 | CLASS_NAMES = $(foreach c,$(CLASSES),$(call class-name,$c)) | |
212 | ||
213 | all:: $(call stamps,$(CLASS_NAMES)) | |
214 | ||
215 | $(foreach c,$(CLASSES),$(eval $(call stamps,$(call class-name,$c)): \ | |
216 | $(call stamps,$(call class-deps,$c)))) | |
217 | ||
218 | DISTFILES += $(foreach c,$(CLASSES),\ | |
219 | $(foreach e,$(CLSEXT),\ | |
220 | $(wildcard $(call class-name,$c).$e))) | |
221 | ||
222 | ###-------------------------------------------------------------------------- | |
223 | ### Distribution arrangements. | |
224 | ||
225 | DISTFILES += COPYING | |
226 | DISTFILES += Makefile | |
227 | DISTFILES += auto-version | |
228 | ||
229 | distdir = $(PACKAGE)-$(VERSION) | |
230 | DISTTAR = $(distdir).tar.gz | |
231 | ||
232 | distdir: | |
233 | rm -rf $(OUTDIR)$(distdir) | |
234 | mkdir $(OUTDIR)$(distdir) | |
235 | echo $(VERSION) >$(OUTDIR)$(distdir)/RELEASE | |
236 | set -e; for i in $(DISTFILES); do \ | |
237 | case $$i in */*) mkdir -p $(OUTDIR)$(distdir)/$${i%/*} ;; esac; \ | |
238 | cp $$i $(OUTDIR)$(distdir)/; \ | |
239 | done | |
240 | .PHONY: distdir | |
241 | ||
242 | dist: distdir | |
243 | set -e; cd $(OUTDIR); tar chozf ../$(DISTTAR) $(distdir) | |
244 | rm -rf $(distdir) | |
245 | .PHONY: dist | |
246 | ||
247 | ###-------------------------------------------------------------------------- | |
248 | ### Finishing touches. | |
3a2f1a4b MW |
249 | |
250 | all:: $(TARGETS) | |
9c15124f MW |
251 | |
252 | clean::; rm -f $(CLEANFILES) $(TARGETS) | |
3a2f1a4b | 253 | |
04a5abae | 254 | repl: all |
9c15124f MW |
255 | $(SCALA_REPL) -cp $(CLASSDIR) -Djava.library.path=$(OUTDIR) |
256 | .PHONY: repl | |
2812483e | 257 | |
9c15124f | 258 | -include $(call objects,$(ALL_SOURCES),.d) |
3a2f1a4b | 259 | |
9c15124f | 260 | ###----- That's all, folks -------------------------------------------------- |