-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
107 lines (83 loc) · 2.47 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
#
# Makefile to build the remote protocol
#
# Main target
# anymote: creates a jar containing the protocol
# anymoteJava: compiles the java sources
# proto: compiles the protocol buffers
.PHONY: proto anymote anymoteJava clean cleanProto default
default: anymote
###############
# DEFINITIONS #
###############
# Sources top directory
JAVA_SRC_TOP := src
# Package name
PACKAGE_NAME := com/google/anymote
# Complete path to sources
JAVA_SRC_DIR := $(JAVA_SRC_TOP)/$(PACKAGE_NAME)
# Java sources
JAVA_SRC := $(JAVA_SRC_DIR)/common/*.java \
$(JAVA_SRC_DIR)/device/*.java \
$(JAVA_SRC_DIR)/server/*.java
# .class targets
JAVA_SRC_CLASSES = $(patsubst %.java,%.class,$(wildcard $(JAVA_SRC)))
# Classpath
JAVA_CLASSPATH := $(subst jar ,jar:,$(strip "bin:$(wildcard jar/*.jar)"))
# Location to put the generated .class
JAVA_OUT := bin
# Name for the jar that will be created
JAR_NAME := anymote.jar
####################
# PROTOCOL BUFFERS #
####################
# Sources directory for protocols buffers
PROTO_SRC_DIR := proto
# Location for the java files generated by the proto compiler
PROTO_JAVA_OUT := proto_out
# Creates the needed directories
$(PROTO_JAVA_OUT) $(JAVA_OUT):
-mkdir -p $@
# Definition of the .proto and the corresponding java generated files.
$(PROTO_JAVA_OUT)/$(PACKAGE_NAME)/RemoteProto.java: $(PROTO_SRC_DIR)/remote.proto
$(genproto)
$(PROTO_JAVA_OUT)/$(PACKAGE_NAME)/Codes.java: $(PROTO_SRC_DIR)/keycodes.proto
$(genproto)
# All java files generated from proto.
ALL_GENPROTOS := \
$(PROTO_JAVA_OUT)/$(PACKAGE_NAME)/RemoteProto.java \
$(PROTO_JAVA_OUT)/$(PACKAGE_NAME)/Codes.java
# Rule to build a .proto in the proto/ directory
define genproto
protoc \
--java_out=$(PROTO_JAVA_OUT) \
-I $(PROTO_SRC_DIR) \
$<
endef
# Compiles the proto
proto: $(PROTO_JAVA_OUT) $(ALL_GENPROTOS)
#################
# JAVA COMPILER #
#################
# compiles a java source
%.class: %.java
javac \
-sourcepath "$(JAVA_SRC_TOP):$(PROTO_JAVA_OUT)" \
-classpath $(JAVA_CLASSPATH) \
-d $(JAVA_OUT)/ \
$?
#################
# PROJECT RULES #
#################
# Compiles the java sources for the project
anymoteJava: $(JAVA_OUT) proto $(JAVA_SRC_CLASSES)
# Cleans the generated protocol buffers
cleanProto:
-rm -rf $(PROTO_JAVA_OUT)
# Cleans the project
clean: cleanProto
-rm -rf $(JAVA_OUT)
-rm $(JAR_NAME)
# Complete and clean build of the project returns a jar.
anymote: clean anymoteJava
jar cf $(JAR_NAME) -C $(JAVA_OUT) $(shell ls $(JAVA_OUT))