blob: 38b86bd76225a5589dac9a82161455c512e56d81 [file] [log] [blame]
Jerome Poichet7c997852014-05-20 10:50:05 -07001#
2# Makefile to build the Polo library
3#
4
5# Main target
6# polo: creates a jar containing the protocol (default)
7# poloJava: compiles the java sources
8# proto: compiles the protocol buffers
9
10.PHONY: proto polo poloJava clean cleanProto default
11
12default: polo
13
14###############
15# DEFINITIONS #
16###############
17# Sources top directory
18JAVA_SRC_TOP := src
19
20# Package name
21PACKAGE_NAME := com/google/polo
22
23# Complete path to sources
24JAVA_SRC_DIR := $(JAVA_SRC_TOP)/$(PACKAGE_NAME)
25
26JAVA_SRC := $(shell find $(JAVA_SRC_DIR) -name '*.java')
27
28# .class targets
29JAVA_SRC_CLASSES = $(patsubst %.java,%.class,$(JAVA_SRC))
30
31# Classpath
32JAVA_CLASSPATH := $(subst jar ,jar:,$(strip "bin:$(wildcard jar/*.jar)"))
33
34# Location to put the generated .class
35JAVA_OUT := bin
36
37# Name for the jar that will be created
38JAR_NAME := polo.jar
39
40####################
41# PROTOCOL BUFFERS #
42####################
43# Sources directory for protocols buffers
44PROTO_SRC_DIR := ../proto
45
46# Location for the java files generated by the proto compiler
47PROTO_JAVA_OUT := proto_out
48
49# Creates the needed directories
50$(PROTO_JAVA_OUT) $(JAVA_OUT):
51 -mkdir -p $@
52
53# Definition of the .proto and the corresponding java generated files.
54$(PROTO_JAVA_OUT)/$(PACKAGE_NAME)/wire/protobuf/PoloProto.java: $(PROTO_SRC_DIR)/polo.proto
55 $(genproto)
56
57# All java files generated from proto.
58ALL_GENPROTOS := \
59 $(PROTO_JAVA_OUT)/$(PACKAGE_NAME)/wire/protobuf/PoloProto.java
60
61# Rule to build a .proto in the proto/ directory
62define genproto
63 protoc \
64 --java_out=$(PROTO_JAVA_OUT) \
65 -I $(PROTO_SRC_DIR) \
66 $<
67endef
68
69# Compiles the proto
70proto: $(PROTO_JAVA_OUT) $(ALL_GENPROTOS)
71
72#################
73# JAVA COMPILER #
74#################
75# compiles a java source
76%.class: %.java
77 javac \
78 -sourcepath "$(JAVA_SRC_TOP):$(PROTO_JAVA_OUT)" \
79 -classpath $(JAVA_CLASSPATH) \
80 -d $(JAVA_OUT)/ \
81 $?
82
83#################
84# PROJECT RULES #
85#################
86# Compiles the java sources for the project
87poloJava: $(JAVA_OUT) proto $(JAVA_SRC_CLASSES)
88
89# Cleans the generated protocol buffers
90cleanProto:
91 -rm -rf $(PROTO_JAVA_OUT)
92
93# Cleans the project
94clean: cleanProto
95 -rm -rf $(JAVA_OUT)
96 -rm $(JAR_NAME)
97
98# Complete and clean build of the project returns a jar.
99polo: clean poloJava
100 jar cf $(JAR_NAME) -C $(JAVA_OUT) $(shell ls $(JAVA_OUT))