-
Notifications
You must be signed in to change notification settings - Fork 83
/
Make.rules
292 lines (247 loc) · 10.5 KB
/
Make.rules
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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
# Copyright (C) 1999 Eric Yeo. All rights reserved.
# Fix obscure libtool issue
ifdef CYGPATH
export echo=echo
endif
# This is the main Java sources.
ifndef JAVA_SRC_DIR
JAVA_SRC_DIR = $(PROJ_BASE_DIR)src
endif
# This is where the Java classes are compiled to.
ifndef JAVA_CLASSES_DIR
JAVA_CLASSES_DIR = $(PROJ_BASE_DIR)classes
endif
# This is where generated files should go
ifndef GENERATED_DIR
GENERATED_DIR = $(PROJ_BASE_DIR)generated
endif
# This is where C object files should go
ifndef OBJ_DIR
OBJ_DIR = $(PROJ_BASE_DIR)obj
endif
# This is where the library files should go
ifndef LIB_DIR
LIB_DIR = $(PROJ_BASE_DIR)lib
endif
# This is where we generate javadoc files to
ifndef JAVADOC_DIR
JAVADOC_DIR = $(prefix)/doc/javadoc
endif
# Defines the Java compiler if one is not defined
ifndef JAVAC
JAVAC = javac
endif
# Define the Java header generator
ifndef JAVAH
JAVAH = javah
endif
# Define where libtool is
ifndef LIBTOOL
top_builddir = $(PROJ_BASE_DIR)
LIBTOOL = /bin/bash $(PROJ_BASE_DIR)libtool
endif
# We have to work out the which package we are in
CURRENT_DIR = $(shell pwd)
JAVA_PACKAGE_REL_PATH = $(subst $(JAVA_SRC_DIR)/,,$(CURRENT_DIR))
JAVA_PACKAGE = $(subst /,.,$(JAVA_PACKAGE_REL_PATH))
JAVA_PACKAGE_DIR = $(JAVA_CLASSES_DIR)/$(JAVA_PACKAGE_REL_PATH)
PACKAGE_GENERATED_INPUT_DIR = $(GENERATED_DIR)/$(JAVA_PACKAGE_REL_PATH)
PACKAGE_OBJ_DIR = $(OBJ_DIR)/$(JAVA_PACKAGE_REL_PATH)
# Workout if we need the class path from the environment
ifdef CLASSPATH
TRAILING_CLASSPATH = $(CLASSSEP)$(CLASSPATH)
else
TRAILING_CLASSPATH =
endif
ifdef CYGPATH
JAVA_SRC_PATH = "$(shell cygpath -C UTF8 -s -w "$(JAVA_SRC_DIR)")"
JAVA_CLASSES_PATH = "$(shell cygpath -C UTF8 -s -w "$(JAVA_CLASSES_DIR)")"
PACKAGE_GENERATED_OUTPUT_DIR = "$(shell cygpath -C UTF8 -s -w "$(PACKAGE_GENERATED_INPUT_DIR)")"
JAVA_CLASS_PATH = "$(shell cygpath -c UTF8 -s -w "$(JAVA_CLASSES_DIR)")$(TRAILING_CLASSPATH)"
else
JAVA_SRC_PATH = "$(JAVA_SRC_DIR)"
JAVA_CLASSES_PATH = "$(JAVA_CLASSES_DIR)"
PACKAGE_GENERATED_OUTPUT_DIR = "$(PACKAGE_GENERATED_INPUT_DIR)"
JAVA_CLASS_PATH = "$(JAVA_CLASSES_DIR)$(TRAILING_CLASSPATH)"
endif
# The rule to make class files from java files.
$(JAVA_PACKAGE_DIR)/%.class: %.java
@-mkdir -p $(dir $@)
$(JAVAC) $(JFLAGS) -d $(JAVA_CLASSES_PATH) \
-sourcepath $(JAVA_SRC_PATH) \
-classpath $(JAVA_CLASS_PATH) $<
# Default make rule.
default-target: java_classes_target lib_target dir_target
# If the SRC_FILES are not defined, we use all .java files
ifndef JAVA_SRC_FILES
JAVA_SRC_FILES = $(wildcard *.java)
endif
# Work out the corresponding .class file we need to make
JAVA_CLASSES := $(foreach i,$(JAVA_SRC_FILES),$(JAVA_PACKAGE_DIR)/$(subst .java,.class,$i))
java_classes_target: $(JAVA_CLASSES)
ifdef JNI_LIB_NAME
# If JNI_LIB_NAME is specified, that indicates to the rules that
# we want a shared library generated.
ifdef CYGPATH
JNI_LIB = $(LIB_DIR)/lib$(JNI_LIB_NAME)-$(MAJOR).$(MINOR).$(MICRO)$(SHARED_LIB_EXT)
else
JNI_LIB = $(LIB_DIR)/lib$(JNI_LIB_NAME)-$(MAJOR).$(MINOR).$(MICRO).la
endif
# The Makefile should specify JNI_SRC_FILES to indicate which
# Java source files can be used to generate JNI headers.
JNI_BASE_HEADERS = $(subst .java,.h,$(JNI_SRC_FILES))
JNI_HEADER_PREFIX = $(subst .,_,$(JAVA_PACKAGE_REL_PATH))
JNI_HEADERS = $(foreach f,$(JNI_BASE_HEADERS),$(PACKAGE_GENERATED_INPUT_DIR)/$(JNI_HEADER_PREFIX)_$(f))
JNI_CLASS_BASE_FILES = $(subst .java,.class,$(JNI_SRC_FILES))
JNI_CLASS_FILES = $(foreach f,$(JNI_CLASS_BASE_FILES),$(JAVA_PACKAGE_DIR)/$(f))
# Need to force these files to be made
$(JNI_CLASS_FILES):
# Work out where the object files should go.
JNI_IMPL = $(foreach f,$(subst .h,.c,$(JNI_BASE_HEADERS)),$(JNI_HEADER_PREFIX)_$(f)) $(JNI_EXTRAS)
JNI_BASE_OBJ = $(foreach f,$(subst .c,.lo,$(JNI_IMPL)),$(f))
JNI_OBJ = $(foreach f,$(JNI_BASE_OBJ),$(PACKAGE_OBJ_DIR)/$(f))
# This is used to compile the C sources that defines the native
# methods. The Makefile must specify INCLUDES for the include file
# path.
CFLAGS += $(INCLUDES)
# The rule to make JNI header files from java files.
# Rule to make header files from java class files.
# The originating java source must contain native method specifications.
$(PACKAGE_GENERATED_INPUT_DIR)/$(JNI_HEADER_PREFIX)_%.h: $(JAVA_PACKAGE_DIR)/%.class
@-rm -f $@ > /dev/null 2>&1
@-mkdir -p $(dir $@)
ifeq ($(notdir $(JAVAH)),javah)
"$(JAVAH)" $(JAVAH_OPT) $(PACKAGE_GENERATED_OUTPUT_DIR) \
-classpath $(JAVA_CLASS_PATH) $(JAVA_PACKAGE).$(subst .class,,$(notdir $<))
else
"$(JAVAH)" $(JAVAH_OPT) $(PACKAGE_GENERATED_OUTPUT_DIR) \
-classpath $(JAVA_CLASS_PATH) $(subst .class,.java,$(notdir $<))
endif
# Rule to compile JNI C files
$(PACKAGE_OBJ_DIR)/%.lo: %.c $(PACKAGE_GENERATED_INPUT_DIR)/%.h
@-mkdir -p $(dir $@)
$(LIBTOOL) --mode=compile $(CC) -I$(PACKAGE_GENERATED_INPUT_DIR) $(CFLAGS) -c $< -o $@
$(PACKAGE_OBJ_DIR)/%.lo: %.c
@-mkdir -p $(dir $@)
$(LIBTOOL) --mode=compile $(CC) $(CFLAGS) -c $< -o $@
# Rule to generate autodependencies in the case where JNI is used.
JNI_DEP_FILE = .jnidep
$(JNI_DEP_FILE): $(JNI_HEADERS) $(JNI_IMPL) Makefile
@case $(CC) in \
*gcc) \
echo Autogenerating C dependencies.; \
$(CC) -M $(CFLAGS) -I$(PACKAGE_GENERATED_INPUT_DIR) \
$(JNI_IMPL) > .jnidep.tmp; \
sed -e "s;\(.*\)\.o:;$(PACKAGE_OBJ_DIR)/\1.lo:;" \
< .jnidep.tmp > $@; \
rm .jnidep.tmp > /dev/null 2>&1; \
$(MAKE) $(MFLAGS) lib_target; \
;; \
*) \
touch $(JNI_DEP_FILE); \
echo Unable to autogenerate C dependencies.; \
echo Run "make clean" if rebuilding.; \
;; \
esac
lib_target: $(JNI_DEP_FILE) $(JNI_LIB)
# Build the JNI shared library
$(JNI_LIB): $(JNI_OBJ)
ifdef CYGPATH
$(LIBTOOL) --mode=link $(CC) \
-dynamiclib \
-shared -XCClinker -shared \
$(LIBTOOL_LINK_FLAG) \
-version-info $(MAJOR):$(MINOR):$(MICRO) \
-rpath $(libdir) $(SHARED_LDFLAGS) $(LDFLAGS) \
-o $(JNI_LIB) \
$(JNI_OBJ) $(JNI_LINK_LIBS) $(EXTRA_LIBS)
else
$(LIBTOOL) --mode=link $(CC) \
-dynamiclib \
-shared \
$(LIBTOOL_LINK_FLAG) \
-version-info $(MAJOR):$(MINOR):$(MICRO) \
-rpath $(libdir) $(SHARED_LDFLAGS) $(LDFLAGS) \
-o $(JNI_LIB) \
$(JNI_OBJ) $(JNI_LINK_LIBS) $(EXTRA_LIBS)
endif
# Change install name shown by otool -L if tool available.
@-mkdir -p "$(JAVA_CLASSES_DIR)/resources"
@-cp $(PROJ_BASE_DIR)lib/.libs/lib$(JNI_LIB_NAME)-$(MAJOR).$(MINOR).$(MICRO)$(SHARED_LIB_EXT) "$(JAVA_CLASSES_DIR)/resources/lib$(JNI_LIB_NAME)$(SHARED_LIB_EXT)"
@-ln -s $(PROJ_BASE_DIR)lib/.libs/lib$(JNI_LIB_NAME)-$(MAJOR).$(MINOR).$(MICRO)$(SHARED_LIB_EXT) $(PROJ_BASE_DIR)/lib/lib$(JNI_LIB_NAME)$(SHARED_LIB_EXT)
@-ln -s $(PROJ_BASE_DIR)lib/jmagick-$(MAJOR).$(MINOR).$(MICRO).jar $(PROJ_BASE_DIR)/lib/jmagick.jar
ifdef DARWIN
# Mac OS X
@-echo "Using install_name_tool..."
@-/usr/bin/install_name_tool -id $(PROJ_BASE_DIR)lib/lib$(JNI_LIB_NAME)$(SHARED_LIB_EXT) $(PROJ_BASE_DIR)/lib/lib$(JNI_LIB_NAME)-$(MAJOR).$(MINOR).$(MICRO)$(SHARED_LIB_EXT)
endif
## @-install_name_tool -id $(JNI_LIB) $(PROJ_BASE_DIR)/lib/lib$(JNI_LIB_NAME)-$(MAJOR).$(MINOR).$(MICRO)$(SHARED_LIB_EXT)
## # @-ln -s $(PROJ_BASE_DIR)lib/lib$(JNI_LIB_NAME)-$(MAJOR).$(MINOR).$(MICRO)$(SHARED_LIB_EXT) $(PROJ_BASE_DIR)/lib/lib$(JNI_LIB_NAME)$(SHARED_LIB_EXT)
## @-ln -s $(PROJ_BASE_DIR)lib/lib$(JNI_LIB_NAME)-$(MAJOR).$(MINOR).$(MICRO)$(SHARED_LIB_EXT) $(PROJ_BASE_DIR)/lib/lib$(JNI_LIB_NAME)$(SHARED_LIB_EXT)
## @-ln -s $(PROJ_BASE_DIR)lib/jmagick-$(MAJOR).$(MINOR).$(MICRO).jar $(PROJ_BASE_DIR)/lib/jmagick.jar
ifndef CLEANING
ifeq ($(wildcard $(JNI_DEP_FILE)), $(JNI_DEP_FILE))
include $(JNI_DEP_FILE)
endif
endif
else
lib_target:
endif
ifdef DIRS
dir_target:
@for d in $(DIRS); do \
if [ -f $$d/Makefile ]; then \
$(MAKE) -C $$d -w; \
else \
echo Ignoring $$d. No Makefile.;\
fi; \
done
else
dir_target:
endif
# List of files we want to remove
CLEAN_LIST += $(JAVA_CLASSES) $(JNI_HEADERS) $(JNI_DEP_FILE) $(JNI_OBJ) ./lib/jmagick.jar
CLEAN_NESTED_CLASSES := $(filter %.class,$(CLEAN_LIST))
CLEAN_NESTED_CLASSES := $(patsubst %.class,%$$*.class,$(CLEAN_NESTED_CLASSES))
CLEAN_NESTED_CLASSES := $(foreach i,$(CLEAN_NESTED_CLASSES),$(wildcard $i))
CLEAN_NESTED_CLASSES := $(subst $$,\$$,$(CLEAN_NESTED_CLASSES))
CLEAN_LIST += $(CLEAN_NESTED_CLASSES)
CLEAN_LIST += $(subst .lo,.o,$(JNI_OBJ))
clean:
@echo Cleaning `pwd` ...
@-rm -rf $(CLEAN_LIST) > /dev/null 2>&1
ifdef JNI_LIB_NAME
@-rm -f $(PROJ_BASE_DIR)/lib/lib$(JNI_LIB_NAME)$(SHARED_LIB_EXT) > /dev/null 2>&1
endif
## @-rm $(libdir)/lib
ifdef DIRS
@for d in $(DIRS); do \
if [ -f $$d/Makefile ]; then \
$(MAKE) -C $$d -w CLEANING=yes clean; \
else \
echo Ignoring $$d. No Makefile.; \
fi; \
done
endif
# For each directory install the necessary files
install: extra-install
@echo Installing `pwd` ...
ifdef DIRS
@for d in $(DIRS); do \
if [ -f $$d/Makefile ]; then \
$(MAKE) -C $$d -w install; \
else \
echo Ignoring $$d. No Makefile.; \
fi; \
done
endif
ifdef JNI_LIB_NAME
## @-ln -s $(libdir)/lib$(JNI_LIB_NAME)-$(MAJOR).$(MINOR).$(MICRO)$(SHARED_LIB_EXT) $(libdir)/lib$(JNI_LIB_NAME)$(SHARED_LIB_EXT)
# Mac OS X
ifdef DARWIN
@-echo "Using install_name_tool..."
@-/usr/bin/install_name_tool -id $(libdir)/lib$(JNI_LIB_NAME)$(SHARED_LIB_EXT) $(libdir)/lib$(JNI_LIB_NAME)-$(MAJOR).$(MINOR).$(MICRO)$(SHARED_LIB_EXT)
endif
@-pwddir=`pwd`;cd $(libdir); ln -fs ./lib$(JNI_LIB_NAME)-$(MAJOR).$(MINOR).$(MICRO)$(SHARED_LIB_EXT) ./lib$(JNI_LIB_NAME)$(SHARED_LIB_EXT);cd $(pwddir)
endif #JNI_LIB_NAME
extra-install::