3 ### Build script for the TrIPE Android app
5 ### (c) 2018 Straylight/Edgeware
8 ###----- Licensing notice ---------------------------------------------------
10 ### This file is part of the Trivial IP Encryption (TrIPE) Android app.
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.
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
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/>.
25 PACKAGE
= tripe-android
26 VERSION
:= $(shell .
/auto-version
)
28 .SECONDEXPANSION
: #sorry
30 ###--------------------------------------------------------------------------
33 ## Where to put the object files.
38 CFLAGS
= -O2
-g
-Wall
-pedantic
-Werror
44 ## External `pkg-config' packages required.
47 ## Java development kit.
48 JDKDIR
= /usr
/lib
/jvm
/default-java
50 JNI_INCLUDES
= $(JDKDIR
)/include $(JDKDIR
)/include/$(JDK_PLAT
)
52 ## Default arguments for the Java runtime.
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
)
64 JAVAC
= javac
$(JAVADEFS
)
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
)
78 ifeq "$(explicit-tmpdir-p),$(noip-available-p)" "t,t"
79 SCALAC
= $(NOIP
) fsc
$(JAVADEFS
)
80 SCALAC_RESET
= $(SCALAC
) -reset
82 SCALAC
= scalac
$(JAVADEFS
)
85 SCALAFLAGS
= -optimise
-Xlint
-Xlint
:-package-object-classes \
86 -Yinline-warnings
:false
87 SCALA_REPL
= $(NOIP
) scala
$(JAVADEFS
)
89 ## Silent-rules is on by default.
92 ## Allow local overrides at this point.
95 ###--------------------------------------------------------------------------
96 ### Silent-rules machinery.
98 v_tag
= $(call v_tag_
$V,$1)
99 v_tag_0
= @printf
" %-8s %s\n" "$1" "$@";
104 ###--------------------------------------------------------------------------
105 ### External native packages.
107 PKGS_CFLAGS
:= $(foreach p
,$(PKGS
),$(shell pkg-config
--cflags $p))
108 PKGS_LIBS
:= $(foreach p
,$(PKGS
),$(shell pkg-config
--libs
$p))
110 ALL_CFLAGS
= $(CFLAGS
) -fPIC \
111 $(addprefix -I
,$(JNI_INCLUDES
)) \
116 ###--------------------------------------------------------------------------
117 ### Various other tweaks and overrides.
119 ## Hack around https://issues.scala-lang.org/browse/SI-9689
120 SCALAFLAGS
+= -Yno-load-impl-class
122 ###--------------------------------------------------------------------------
123 ### And now we can start building things.
132 ###--------------------------------------------------------------------------
136 $(call v_tag
,CC
)mkdir
-p
$(OUTDIR
) && \
137 $(CC
) -c
$(ALL_CFLAGS
) -MMD
-o
$@
$<
140 DISTFILES
+= $(ALL_SOURCES
)
142 objects
= $(patsubst %.c
,$(OUTDIR
)%$2,$1)
143 CLEANFILES
+= $(OUTDIR
)*.o
$(OUTDIR
)*.d
145 ###--------------------------------------------------------------------------
148 ## Java and Scala source files turn into multiple `.class' files with
149 ## unpredictable names. Rather than try to guess stable outputs for these
150 ## sources, we make artificial `timestamp' files and uses these in our
152 CLASSDIR
= $(OUTDIR
)cls
/
153 stamps
= $(patsubst %,$(OUTDIR
)%.stamp
,$1)
155 clean::; rm -rf
$(CLASSDIR
)
156 CLEANFILES
+= $(OUTDIR
)*.stamp
158 ## Compiling actual Java code. Note that this confuses the resident Scala
159 ## compiler, so we have to reset it here.
161 $(OUTDIR
)%.stamp
: %.java
162 $(call v_tag
,JAVAC
)mkdir
-p
$(CLASSDIR
) && \
163 $(JAVAC
) -d
$(CLASSDIR
) -cp
$(CLASSDIR
) $(JAVAFLAGS
) $< && \
165 $(V_AT
)$(SCALAC_RESET
)
167 ## Compiling Scala code.
169 $(OUTDIR
)%.stamp
: %.scala
170 $(call v_tag
,SCALAC
)mkdir
-p
$(CLASSDIR
) && \
171 $(SCALAC
) -d
$(CLASSDIR
) -cp
$(CLASSDIR
) $(SCALAFLAGS
) $< && \
174 ###--------------------------------------------------------------------------
175 ### Native-code libraries.
180 shlibfile
= $(patsubst %,$(OUTDIR
)lib
%.so
,$1)
181 SHLIBFILES
= $(call shlibfile
,$(SHLIBS
))
182 TARGETS
+= $(SHLIBFILES
)
183 ALL_SOURCES
+= $(foreach l
,$(SHLIBS
),$($l_SOURCES))
185 $(SHLIBFILES
): $(OUTDIR
)lib
%.so
: $$(call objects
,$$($$*_SOURCES
),.o
)
186 $(call v_tag
,LD
)$(LD
) $(LDFLAGS.so
) -o
$@
$^
$(LIBS
)
188 ###--------------------------------------------------------------------------
191 ## Writing things out longhand is tedious. `CLASSES' is a list of entries of
192 ## the form `SRC[:DEP,...]', saying that `SRC.ext', being a source file
193 ## capable of being built into `.class' files and setting `SRC.stamp', should
194 ## be so built, and that it depends on other similar sources named DEP having
198 CLASSES
+= admin
:sys
,util
200 CLASSES
+= keys
:tar,sys
,util
203 ## Machinery for parsing the `CLASSES' list.
205 class-name
= $(firstword $(subst :, ,$1))
206 class-deps
= $(subst $(COMMA
), ,$(word 2,$(subst :, ,$1)))
208 CLASS_NAMES
= $(foreach c
,$(CLASSES
),$(call class-name
,$c))
210 all:: $(call stamps
,$(CLASS_NAMES
))
212 $(foreach c
,$(CLASSES
),$(eval
$(call stamps
,$(call class-name
,$c)): \
213 $(call stamps
,$(call class-deps
,$c))))
215 DISTFILES
+= $(foreach c
,$(CLASSES
),\
216 $(foreach e
,$(CLSEXT
),\
217 $(wildcard $(call class-name
,$c).
$e)))
219 ###--------------------------------------------------------------------------
220 ### Distribution arrangements.
223 DISTFILES
+= Makefile
224 DISTFILES
+= auto-version
226 distdir
= $(PACKAGE
)-$(VERSION
)
227 DISTTAR
= $(distdir
).
tar.gz
230 rm -rf
$(OUTDIR
)$(distdir
)
231 mkdir
$(OUTDIR
)$(distdir
)
232 echo
$(VERSION
) >$(OUTDIR
)$(distdir
)/RELEASE
233 set
-e
; for i in
$(DISTFILES
); do \
234 case
$$i in
*/*) mkdir
-p
$(OUTDIR
)$(distdir
)/$${i
%/*} ;; esac
; \
235 cp
$$i $(OUTDIR
)$(distdir
)/; \
240 set
-e
; cd
$(OUTDIR
); tar chozf ..
/$(DISTTAR
) $(distdir
)
244 ###--------------------------------------------------------------------------
245 ### Finishing touches.
249 clean::; rm -f
$(CLEANFILES
) $(TARGETS
)
252 $(SCALA_REPL
) -cp
$(CLASSDIR
) -Djava.library.path
=$(OUTDIR
)
255 -include $(call objects
,$(ALL_SOURCES
),.d
)
257 ###----- That's all, folks --------------------------------------------------