Project

General

Profile

Statistics
| Branch: | Tag: | Revision:

gdp / lang / java / makefile @ master

History | View | Annotate | Download (10.4 KB)

1 05afb3fb Nitesh Mor
# Makefile org.terraswarm Global Data Plane sources
2
#
3
# @Version: $Id: makefile 72425 2015-05-27 21:01:46Z cxh $
4
# @Author: Christopher Brooks
5
#
6 8dfe32c1 Christopher Brooks
# @Copyright (c) 2014-2016 The Regents of the University of California.
7 05afb3fb Nitesh Mor
# All rights reserved.
8
#
9
# Permission is hereby granted, without written agreement and without
10
# license or royalty fees, to use, copy, modify, and distribute this
11
# software and its documentation for any purpose, provided that the
12
# above copyright notice and the following two paragraphs appear in all
13
# copies of this software.
14
#
15
# IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY
16
# FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
17
# ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF
18
# THE UNIVERSITY OF CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF
19
# SUCH DAMAGE.
20
#
21
# THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,
22
# INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
23
# MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE
24
# PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE UNIVERSITY OF
25
# CALIFORNIA HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES,
26
# ENHANCEMENTS, OR MODIFICATIONS.
27
#
28
# 						PT_COPYRIGHT_VERSION_2
29
# 						COPYRIGHTENDKEY
30
##########################################################################
31
32 5318e936 Christopher Brooks
# To update the GDP version, see ../../gdp/gdp_version.h
33 9dd555a1 Christopher Brooks
#
34
# If you change the GDP version, see the instructions in package.html
35
#
36 f4e6400b Nitesh Mor
GDPLIBMAJVER=2
37 5528e679 Nitesh Mor
GDPLIBMINVER=1
38
GDP_PATCH_VERSION=2
39 6e36d992 Christopher Brooks
40
GDP_MAJOR_MINOR_VERSION=$(GDPLIBMAJVER).$(GDPLIBMINVER)
41
42 05afb3fb Nitesh Mor
all: jclass
43 7dd392de Christopher Brooks
44
# JNA will look for the GDP shared library in the classpath.
45
46
# https://github.com/java-native-access/jna/blob/master/www/GettingStarted.md
47
# says that JNA will look in os-arch/library, where os-arch is JNA's
48
# canonical prefix for the platform.  The shared library is
49
# automatically extracted.
50
51
52
GDP_JAR=gdp-$(GDP_MAJOR_MINOR_VERSION)-$(GDP_PATCH_VERSION).jar
53
# The format of the gdp library version must be the same on all
54
# platforms.  See org/terraswarm/gdp/GdpNLibrary.java, where N is the
55
# version number.
56
DARWIN_LIB=libgdp.$(GDP_MAJOR_MINOR_VERSION).dylib
57
LINUX_LIB=libgdp.$(GDP_MAJOR_MINOR_VERSION).so
58 555f8f27 Christopher Brooks
LINUX_LIB2=libgdp.so$($(GDP_MAJOR_MINOR_VERSION)
59 675bf903 Christopher Brooks
LINUX_DASH_LIB=libgdp-$(GDP_MAJOR_MINOR_VERSION).so
60 555f8f27 Christopher Brooks
61 e3adf64d Christopher Brooks
install: all darwin/$(DARWIN_LIB) linux-x86-64-rhel/$(LINUX_LIB) linux-x86-64/$(LINUX_LIB)
62
	jar cf $(GDP_JAR) org/terraswarm/gdp/*.class darwin linux-x86-64-rhel linux-x86-64
63 7dd392de Christopher Brooks
64
darwin/$(DARWIN_LIB): 
65
	if [ ! -d darwin ]; then mkdir darwin; fi
66
	if [ -f ../../libs/$(DARWIN_LIB) ]; then \
67
		echo "Copying ../../libs/$(DARWIN_LIB) to $@"; \
68
		cp ../../libs/$(DARWIN_LIB) $@; \
69
	else \
70
		if [ -f $(PTII)/lib/$(DARWIN_LIB) ]; then \
71
			echo "Copying $(PTII)/lib/$(DARWIN_LIB) to $@"; \
72
			cp $(PTII)/lib/$(DARWIN_LIB) $@; \
73
		else \
74
			echo "Could not find the Darwin GDP shared library, so the jar file will not contain it."; \
75
		fi \
76
	fi
77
78 e3adf64d Christopher Brooks
linux-x86-64-rhel/$(LINUX_LIB):
79
	if [ ! -d linux-x86-64-rhel ]; then mkdir linux-x86-64-rhel; fi
80
	if [ -f /etc/redhat-release -a -f ../../libs/$(LINUX_DASH_LIB) ]; then \
81 675bf903 Christopher Brooks
		echo "Copying ../../libs/$(LINUX_DASH_LIB) to $@"; \
82
		cp ../../libs/$(LINUX_DASH_LIB) $@; \
83 7dd392de Christopher Brooks
	else \
84 555f8f27 Christopher Brooks
		if [ -f $(PTII)/lib/linux-x86-64-rhel/$(LINUX_LIB) ]; then \
85
			echo "Copying $(PTII)/lib/linux-x86-64-rhel/$(LINUX_LIB) to $@"; \
86
			cp $(PTII)/lib/linux-x86-64-rhel/$(LINUX_LIB) $@; \
87 cfccd718 Christopher Brooks
		else \
88
			echo "Could not find the Linux GDP RHEL shared library, so the jar file will not contain it."; \
89
		fi \
90
	fi
91
92
linux-x86-64/$(LINUX_LIB):
93
	if [ ! -d linux-x86-64 ]; then mkdir linux-x86-64; fi
94 555f8f27 Christopher Brooks
	if [ ! -f /etc/redhat-release -a -f ../../libs/$(LINUX_LIB2) ]; then \
95
		echo "Copying ../../libs/$(LINUX_LIB2) to $@"; \
96
		cp ../../libs/$(LINUX_LIB2) $@; \
97 cfccd718 Christopher Brooks
	else \
98 7dd392de Christopher Brooks
		if [ -f $(PTII)/lib/$(LINUX_LIB) ]; then \
99
			echo "Copying $(PTII)/lib/$(LINUX_LIB) to $@"; \
100
			cp $(PTII)/lib/$(LINUX_LIB) $@; \
101
		else \
102 cfccd718 Christopher Brooks
			echo "Could not find the Linux GDP non-RHEL shared library, so the jar file will not contain it."; \
103 7dd392de Christopher Brooks
		fi \
104
	fi
105 05afb3fb Nitesh Mor
106
##############################
107 5318e936 Christopher Brooks
JNA_JAR = jna-4.2.2.jar
108 05afb3fb Nitesh Mor
JNAERATOR_VERSION = 0.12
109
JNAERATOR_JAR = jnaerator-$(JNAERATOR_VERSION)-shaded.jar
110
JNAERATOR_RUNTIME_JAR = jnaerator-runtime-$(JNAERATOR_VERSION).jar
111
112 d7f34b51 Christopher Brooks
BUILD_JARS=$(JNA_JAR) $(JNAERATOR_JAR) $(JNAERATOR_RUNTIME_JAR)
113
114 05afb3fb Nitesh Mor
### Download required files. If there is an updated version of these, it needs
115
### to be manually updated.
116
117
$(JNA_JAR):
118 f4e6400b Nitesh Mor
	echo "Fetching $@ from maven repositories. If this fails, you might have to update paths and such."; \
119
	wget 'https://repo1.maven.org/maven2/net/java/dev/jna/jna/4.2.2/$@' -O $@; \
120 cb262f61 Christopher Brooks
	status=$$?; \
121
	if [ $$status -ne 0 ]; then \
122 f4e6400b Nitesh Mor
		echo "Failed to get $@ from maven.java.net."; \
123 cb262f61 Christopher Brooks
	fi
124 05afb3fb Nitesh Mor
125
$(JNAERATOR_JAR):
126 f4e6400b Nitesh Mor
	echo "Fetching $@ from maven repositories. If this fails, you might have to update paths and such."; \
127
	wget 'https://repo1.maven.org/maven2/com/nativelibs4java/jnaerator/$(JNAERATOR_VERSION)/$@' -O $@; \
128 cb262f61 Christopher Brooks
	status=$$?; \
129
	if [ $$status -ne 0 ]; then \
130 f4e6400b Nitesh Mor
		echo "Failed to get $@ from maven.java.net."; \
131 cb262f61 Christopher Brooks
	fi
132 05afb3fb Nitesh Mor
133
$(JNAERATOR_RUNTIME_JAR):
134 f4e6400b Nitesh Mor
	echo "Fetching $@ from maven repositories. If this fails, you might have to update paths and such."; \
135
	wget 'https://repo1.maven.org/maven2/com/nativelibs4java/jnaerator-runtime/$(JNAERATOR_VERSION)/$@' -O $@; \
136 cb262f61 Christopher Brooks
	status=$$?; \
137
	if [ $$status -ne 0 ]; then \
138 f4e6400b Nitesh Mor
		echo "Failed to get $@ from maven.java.net."; \
139 cb262f61 Christopher Brooks
	fi
140
141 05afb3fb Nitesh Mor
142
##############################
143
144
## Header files that we need to interpret the compiled library
145 e2d0b4ef Nitesh Mor
## Apparently -I has no effect on JNA, and it fails to find event2/buffer.h 
146
##   from the system default paths
147
148 05afb3fb Nitesh Mor
149 7f4ed8df Nitesh Mor
ROOT = ../..
150 05afb3fb Nitesh Mor
GDP_SRC = $(ROOT)
151 8b3d2c61 Nitesh Mor
EVENT_HDRS = $(shell if [ -e /usr/include/event2/buffer.h ]; then echo /usr/include; \
152
		elif [ -e /usr/local/include/event2/buffer.h ]; then echo /usr/local/include; \
153 74978c59 Christopher Brooks
		elif [ -e /opt/local/include/event2/buffer.h ]; then echo /opt/local/include; \
154 8b3d2c61 Nitesh Mor
		else echo unknown; fi )
155 05afb3fb Nitesh Mor
PWD = $(ROOT)/lang/java/
156
157
GDP_H_FILES = \
158
	$(GDP_SRC)/gdp/gdp.h \
159
	$(GDP_SRC)/gdp/gdp_buf.h \
160
	$(GDP_SRC)/ep/ep.h \
161 ed6f51e7 Nitesh Mor
	$(GDP_SRC)/ep/ep_dbg.h \
162
	$(GDP_SRC)/ep/ep_thr.h
163 05afb3fb Nitesh Mor
164 8b3d2c61 Nitesh Mor
LIBEVENT_H_FILES = \
165
    $(EVENT_HDRS)/event2/buffer.h
166 7f4ed8df Nitesh Mor
167 05afb3fb Nitesh Mor
168
### Auto-generating java files
169
170
# We define gdp_datum_t and gdp_datum as void * so that JNAerator does not generate gdp_datum.java, which would refer to pthreads.
171 e2d0b4ef Nitesh Mor
jna: $(JNAERATOR_JAR) $(JNAERATOR_RUNTIME_JAR) $(GDP_H_FILES) $(LIBEVENT_H_FILES)
172
	java -jar $(JNAERATOR_JAR) -runtime JNA -f \
173 05afb3fb Nitesh Mor
		-Dgdp_datum_t="void *" -Dgdp_datum="void *" \
174 6e36d992 Christopher Brooks
		-library gdp.$(GDP_MAJOR_MINOR_VERSION) -I ../../gdp -I ../.. \
175 ed6f51e7 Nitesh Mor
		$(GDP_H_FILES) $(LIBEVENT_H_FILES) \
176
		-o . -library event2 -I/usr/include -I/usr/local/include \
177
                -package org.terraswarm.gdp  -v  -noJar -noComp
178 e2d0b4ef Nitesh Mor
	# Fix up NativeSize. We want our included version of NativeSize be used, instead of JNAerator's version:
179 b091a5d5 Christopher Brooks
	# We use sed -i here, which varies between Mac OS X and RHEL.  However calling sed twice like this works.
180 efb666af Christopher Brooks
	for file in org/terraswarm/gdp/*.java org/terraswarm/gdp/*/*.java; do \
181 b091a5d5 Christopher Brooks
		echo "Fixing $$file"; \
182
		sed -i -e "s@Gdp[0-9]*Library@Gdp${GDPLIBMAJVER}${GDPLIBMINVER}Library@" $$file; \
183
		sed -i -e 's@com.ochafik.lang.jnaerator.runtime.NativeSize@org.terraswarm.gdp.NativeSize@' $$file; \
184 e2d0b4ef Nitesh Mor
	done
185
	# Empty target. See https://www.gnu.org/software/make/manual/html_node/Empty-Targets.html
186
	touch jna
187 05afb3fb Nitesh Mor
188
189
### Compiling .java files to .class files
190
191
JSRCS_LIB = $(wildcard org/terraswarm/gdp/*.java)
192
JSRCS_APPS = $(wildcard org/terraswarm/gdp/apps/*.java)
193
JSRCS = $(JSRCS_LIB) $(JSRCS_APPS)
194
195
# Java rules
196
CLASSPATH = $(JNA_JAR):$(JNAERATOR_RUNTIME_JAR):$(PWD)
197
198
JAVAC = javac
199 5528e679 Nitesh Mor
# JFLAGS = -Xlint:deprecation
200 05afb3fb Nitesh Mor
201
.SUFFIXES: .class .java
202
.java.class:
203
	CLASSPATH="$(CLASSPATH):$(PWD)" "$(JAVAC)" $(JFLAGS) $<
204
205
JCLASS = $(JSRCS:%.java=%.class)
206
207
jclass: jna $(JNA_JAR) $(JSRCS) $(JCLASS)
208
209
210
### apps
211
212
JAVA = java
213 c809f99f Nitesh Mor
LOG_NAME = logjava              # You probably want to override this on command-line.
214
LOGD_NAME = docker.gdplogd      # You probably want to override this on command-line.
215 61797ff5 Nitesh Mor
KEYFILE = non-existent.pem      # You probably want to override this on command-line.
216 05afb3fb Nitesh Mor
217 096b8eaa Nitesh Mor
runCreateTest: all
218 45244c29 Nitesh Mor
	DYLD_LIBRARY_PATH=$(GDP_SRC)/libs LD_LIBRARY_PATH=$(GDP_SRC)/libs $(JAVA) -Djna.debug_load=true -Djna.dump_memory=true -classpath $(CLASSPATH) org.terraswarm.gdp.apps.CreateTest $(LOG_NAME) $(LOGD_NAME)
219 61797ff5 Nitesh Mor
runCreateTestWithKey: all
220
	DYLD_LIBRARY_PATH=$(GDP_SRC)/libs LD_LIBRARY_PATH=$(GDP_SRC)/libs $(JAVA) -Djna.debug_load=true -Djna.dump_memory=true -classpath $(CLASSPATH) org.terraswarm.gdp.apps.CreateTestWithKey $(LOG_NAME) $(KEYFILE) $(LOGD_NAME)
221 a20b2118 Nitesh Mor
runNameTest: all
222 45244c29 Nitesh Mor
	DYLD_LIBRARY_PATH=$(GDP_SRC)/libs LD_LIBRARY_PATH=$(GDP_SRC)/libs $(JAVA) -Djna.debug_load=true -Djna.dump_memory=true -classpath $(CLASSPATH) org.terraswarm.gdp.apps.NameTest 
223 a20b2118 Nitesh Mor
runHelloWorld: all
224 c809f99f Nitesh Mor
	DYLD_LIBRARY_PATH=$(GDP_SRC)/libs LD_LIBRARY_PATH=$(GDP_SRC)/libs $(JAVA) -Djna.debug_load=true -Djna.dump_memory=true -classpath $(CLASSPATH) org.terraswarm.gdp.apps.HelloWorld $(LOG_NAME)
225
runReaderTestSubscribe: all
226
	DYLD_LIBRARY_PATH=$(GDP_SRC)/libs LD_LIBRARY_PATH=$(GDP_SRC)/libs $(JAVA) -Djna.debug_load=true -Djna.dump_memory=true -classpath $(CLASSPATH) org.terraswarm.gdp.apps.ReaderTestSubscribe $(LOG_NAME)
227 7ca2a4b3 Nitesh Mor
228 e2d0b4ef Nitesh Mor
#
229
#runReaderTest: org/terraswarm/gdp/apps/ReaderTest.class
230 c809f99f Nitesh Mor
#	DYLD_LIBRARY_PATH=$(GDP_SRC)/libs LD_LIBRARY_PATH=$(GDP_SRC)/libs $(JAVA) -Djna.debug_load=true -Djna.dump_memory=true -classpath $(CLASSPATH) org.terraswarm.gdp.apps.ReaderTest $(LOG_NAME)
231 e2d0b4ef Nitesh Mor
#
232
#runReaderTestPtIILib: org/terraswarm/gdp/apps/ReaderTest.class
233 c809f99f Nitesh Mor
#	DYLD_LIBRARY_PATH=$(GDP_SRC)/libs LD_LIBRARY_PATH=$(GDP_SRC)/libs $(JAVA) -Djna.debug_load=true -Djna.dump_memory=true -classpath $(CLASSPATH) org.terraswarm.gdp.apps.ReaderTest $(LOG_NAME)
234 e2d0b4ef Nitesh Mor
#
235
#runReaderTestSubscriber: org/terraswarm/gdp/apps/ReaderTest.class
236 c809f99f Nitesh Mor
#	DYLD_LIBRARY_PATH=$(GDP_SRC)/libs LD_LIBRARY_PATH=$(GDP_SRC)/libs $(JAVA) -Djna.debug_load=true -Djna.dump_memory=true -classpath $(CLASSPATH) org.terraswarm.gdp.apps.ReaderTest -s $(LOG_NAME)
237 e2d0b4ef Nitesh Mor
#
238
#runWriterTest: org/terraswarm/gdp/apps/WriterTest.class
239 c809f99f Nitesh Mor
#	DYLD_LIBRARY_PATH=$(GDP_SRC)/libs LD_LIBRARY_PATH=$(GDP_SRC)/libs $(JAVA) -Djna.debug_load=true -Djna.dump_memory=true -classpath $(CLASSPATH) org.terraswarm.gdp.apps.WriterTest $(LOG_NAME)
240 e2d0b4ef Nitesh Mor
#
241 05afb3fb Nitesh Mor
242
### 
243
244
clean:
245 5528e679 Nitesh Mor
	cp org/terraswarm/gdp/EP_CRYPTO_KEY.java /tmp/EP_CRYPTO_KEY.java ; rm -f jna _* org/terraswarm/gdp/*.class org/terraswarm/gdp/EP* org/terraswarm/gdp/e* org/terraswarm/gdp/*Library.java org/terraswarm/gdp/apps/*.class $(GDP_JAR).jar ; mv /tmp/EP_CRYPTO_KEY.java org/terraswarm/gdp/.
246 e3adf64d Christopher Brooks
	rm -rf darwin linux-x86-64-rhel linux-x86-64
247 d7f34b51 Christopher Brooks
	@echo "Run 'make distclean' to remove $(BUILD_JARS)"
248 05afb3fb Nitesh Mor
249
distclean: clean
250
	rm -f *.jar