-
Notifications
You must be signed in to change notification settings - Fork 8
/
Makefile
324 lines (261 loc) · 9.76 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
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
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
##//*@@@+++@@@@******************************************************************
##//
##// Copyright � Microsoft Corp.
##// All rights reserved.
##//
##// Redistribution and use in source and binary forms, with or without
##// modification, are permitted provided that the following conditions are met:
##//
##// � Redistributions of source code must retain the above copyright notice,
##// this list of conditions and the following disclaimer.
##// � Redistributions in binary form must reproduce the above copyright notice,
##// this list of conditions and the following disclaimer in the documentation
##// and/or other materials provided with the distribution.
##//
##// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
##// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
##// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
##// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
##// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
##// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
##// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
##// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
##// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
##// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
##// POSSIBILITY OF SUCH DAMAGE.
##//
##//*@@@---@@@@******************************************************************
## Makefile for building JPEG XR Porting Kit
##
build: all
SWIG?=swig
JXR_VERSION=1.1
DIR_SRC=$(CURDIR)
DIR_SYS=image/sys
DIR_DEC=image/decode
DIR_ENC=image/encode
DIR_GLUE=jxrgluelib
DIR_CXX=cpp
DIR_JAVA=java/target/swig
DIR_TEST=jxrtestlib
DIR_EXEC=jxrencoderdecoder
JAVA_PKG=ome/jxrlib
## Are we building shared?
ifneq ($(SHARED),)
PICFLAG=-fPIC
else
PICFLAG=
endif
ifneq ($(BIG_ENDIAN),)
ENDIANFLAG=-D_BIG__ENDIAN_
else
ENDIANFLAG=
endif
ifndef JAVA_HOME
JAVA_HOME:=$(shell jrunscript -e 'java.lang.System.out.println(new java.io.File(java.lang.System.getProperty("java.home")).getParent());')
endif
ifndef JAVA_INCLUDE
JAVA_INCLUDE=$(JAVA_HOME)/include
endif
ifndef DIR_BUILD
DIR_BUILD=$(CURDIR)/build
endif
ifndef PREFIX
PREFIX=/usr/local
endif
ifndef DIR_INSTALL
DIR_INSTALL=$(PREFIX)/lib/jxrlib-$(JXR_VERSION)
endif
CD=cd
MK_DIR=mkdir -p
CFLAGS=-I. -Icommon/include -I$(DIR_SYS) $(ENDIANFLAG) -D__ANSI__ -DDISABLE_PERF_MEASUREMENT -w -Os -fPIC
CXXFLAGS=-I. -Icommon/include -I$(DIR_SYS) -I$(DIR_GLUE) -I$(DIR_TEST) -Wno-self-assign-field -Wno-unsequenced -Os -fPIC
ifdef DEBUG
CFLAGS:=$(CFLAGS) -g -O0 -DDEBUG
CXXFLAGS:= $(CXXFLAGS) -g -O0 -DDEBUG
endif
ifeq ($(strip $(shell uname)), Darwin)
CC?=clang
CXX?=clang++
LIBSUFFIX = dylib
PLATFORM = darwin
else
CC?=cc
CXX?=g++
LIBSUFFIX = so
PLATFORM = linux
endif
STATIC_LIBRARIES=$(DIR_BUILD)/libjxrglue.a $(DIR_BUILD)/libjpegxr.a
SHARED_LIBRARIES=$(DIR_BUILD)/libjxrglue.$(LIBSUFFIX) $(DIR_BUILD)/libjpegxr.$(LIBSUFFIX)
CXX_STATIC_LIBRARIES=$(DIR_BUILD)/libjxr++.a
CXX_SHARED_LIBRARIES=$(DIR_BUILD)/libjxr++.$(LIBSUFFIX)
ifneq ($(SHARED),)
LIBRARIES=$(SHARED_LIBRARIES)
CXX_LIBRARIES=$(CXX_SHARED_LIBRARIES)
else
LIBRARIES=$(STATIC_LIBRARIES)
CXX_LIBRARIES=$(CXX_STATIC_LIBRARIES)
endif
LIBS=-L$(DIR_BUILD) $(shell echo $(LIBRARIES) | sed -E 's%$(DIR_BUILD)/lib([^ ]*)\.(a|$(LIBSUFFIX))%-l\1%g') -lm
CXXLIBS=-L$(DIR_BUILD) -ljxr++ -lcrypto
##--------------------------------
##
## Common files
##
SRC_SYS=adapthuff.c image.c strcodec.c strPredQuant.c strTransform.c perfTimerANSI.c
OBJ_SYS=$(patsubst %.c, $(DIR_BUILD)/$(DIR_SYS)/%.o, $(SRC_SYS))
$(DIR_BUILD)/$(DIR_SYS)/%.o: $(DIR_SRC)/$(DIR_SYS)/%.c
@echo "Building C common files"
$(MK_DIR) $(@D)
$(CC) $(CFLAGS) -c $< -o $@
##--------------------------------
##
## Decode files
##
SRC_DEC=decode.c postprocess.c segdec.c strdec.c strInvTransform.c strPredQuantDec.c JXRTranscode.c
OBJ_DEC=$(patsubst %.c, $(DIR_BUILD)/$(DIR_DEC)/%.o, $(SRC_DEC))
$(DIR_BUILD)/$(DIR_DEC)/%.o: $(DIR_SRC)/$(DIR_DEC)/%.c
@echo "Building C decode files"
$(MK_DIR) $(@D)
$(CC) $(CFLAGS) -c $< -o $@
##--------------------------------
##
## Encode files
##
SRC_ENC=encode.c segenc.c strenc.c strFwdTransform.c strPredQuantEnc.c
OBJ_ENC=$(patsubst %.c, $(DIR_BUILD)/$(DIR_ENC)/%.o, $(SRC_ENC))
$(DIR_BUILD)/$(DIR_ENC)/%.o: $(DIR_SRC)/$(DIR_ENC)/%.c
@echo "Building C encode files"
$(MK_DIR) $(@D)
$(CC) $(CFLAGS) -c $< -o $@
##--------------------------------
##
## JPEG XR library
##
$(DIR_BUILD)/libjpegxr.a: $(OBJ_ENC) $(OBJ_DEC) $(OBJ_SYS)
@echo "Building JPEG XR static lib"
$(MK_DIR) $(@D)
ar rvu $@ $(OBJ_ENC) $(OBJ_DEC) $(OBJ_SYS)
ranlib $@
$(DIR_BUILD)/libjpegxr.$(LIBSUFFIX): $(OBJ_ENC) $(OBJ_DEC) $(OBJ_SYS)
@echo "Building JPEG XR shared lib"
$(MK_DIR) $(@D)
$(CC) -shared $? -o $@
##--------------------------------
##
## Glue files
##
SRC_GLUE=JXRGlue.c JXRMeta.c JXRGluePFC.c JXRGlueJxr.c
OBJ_GLUE=$(patsubst %.c, $(DIR_BUILD)/$(DIR_GLUE)/%.o, $(SRC_GLUE))
$(DIR_BUILD)/$(DIR_GLUE)/%.o: $(DIR_SRC)/$(DIR_GLUE)/%.c
@echo "Building C glue files"
$(MK_DIR) $(@D)
$(CC) $(CFLAGS) -I$(DIR_GLUE) -c $< -o $@
##--------------------------------
##
## C++ files
##
SRC_CXX=$(wildcard $(DIR_SRC)/$(DIR_CXX)/lib/*.cpp)
OBJ_CXX=$(patsubst $(DIR_SRC)/$(DIR_CXX)/lib/%.cpp, $(DIR_BUILD)/$(DIR_CXX)/%.o, $(SRC_CXX))
$(DIR_BUILD)/$(DIR_CXX)/%.o: $(DIR_SRC)/$(DIR_CXX)/lib/%.cpp
@echo "Building C++ files"
$(MK_DIR) $(@D)
$(CXX) $(CXXFLAGS) -I$(DIR_CXX)/lib/ -c $< -o $@
##--------------------------------
##
## Test files
##
SRC_TEST=JXRTest.c JXRTestBmp.c JXRTestHdr.c JXRTestPnm.c JXRTestTif.c JXRTestYUV.c
OBJ_TEST=$(patsubst %.c, $(DIR_BUILD)/$(DIR_TEST)/%.o, $(SRC_TEST))
$(DIR_BUILD)/$(DIR_TEST)/%.o: $(DIR_SRC)/$(DIR_TEST)/%.c
@echo "Building C test files"
$(MK_DIR) $(@D)
$(CC) $(CFLAGS) -I$(DIR_GLUE) -I$(DIR_TEST) -c $< -o $@
##--------------------------------
##
## JPEG XR Glue library
##
$(DIR_BUILD)/libjxrglue.a: $(OBJ_GLUE) $(OBJ_TEST)
@echo "Building glue static lib"
$(MK_DIR) $(@D)
ar rvu $@ $(OBJ_GLUE) $(OBJ_TEST)
ranlib $@
$(DIR_BUILD)/libjxrglue.$(LIBSUFFIX): $(OBJ_GLUE) $(OBJ_TEST)
@echo "Building glue shared lib"
$(MK_DIR) $(@D)
$(CC) -shared $? -o $@
##--------------------------------
##
## C++ Wrapper library
##
$(DIR_BUILD)/libjxr++.a: $(OBJ_CXX) | $(LIBRARIES)
@echo "Building C++ static wrapper lib"
$(MK_DIR) $(@D)
ar rvu $@ $(OBJ_CXX) $(LIBRARIES)
ranlib $@
$(DIR_BUILD)/libjxr++.$(LIBSUFFIX): $(OBJ_CXX) | $(LIBRARIES)
@echo "Building C++ wrapper lib"
$(MK_DIR) $(@D)
$(CXX) -shared $(OBJ_CXX) -fPIC $(LIBS) -o $@
##--------------------------------
##
## Java Wrapper library
##
SRC_JAVA=$(wildcard $(DIR_SRC)/$(DIR_JAVA)/$(JAVA_PKG)/*.java)
swig:
mkdir -p $(DIR_SRC)/$(DIR_JAVA)/$(JAVA_PKG)
$(SWIG) -java -c++ -package ome.jxrlib -outdir $(DIR_SRC)/$(DIR_JAVA)/$(JAVA_PKG) -o $(DIR_SRC)/$(DIR_JAVA)/JXR_wrap.cxx java/JXR.i
$(DIR_BUILD)/libjxrjava.$(LIBSUFFIX): $(LIBRARIES) $(CXX_LIBRARIES)
@echo "Building JNI"
@echo "JAVA_INCLUDE=$(JAVA_INCLUDE)"
$(CXX) -o $(DIR_BUILD)/libjxrjava.$(LIBSUFFIX) -shared -I$(JAVA_INCLUDE) -I$(JAVA_INCLUDE)/$(PLATFORM) -I$(DIR_CXX)/lib $(CXXFLAGS) $(OBJ_SYS) $(OBJ_ENC) $(OBJ_DEC) $(OBJ_GLUE) $(OBJ_TEST) $(OBJ_CXX) $(DIR_JAVA)/JXR_wrap.cxx
##--------------------------------
##
## Enc app files
##
ENCAPP=JxrEncApp
$(DIR_BUILD)/$(ENCAPP): $(DIR_SRC)/$(DIR_EXEC)/$(ENCAPP).c $(LIBRARIES)
@echo "Building JxrEncApp"
$(MK_DIR) $(@D)
$(CC) $< -o $@ $(CFLAGS) -I$(DIR_GLUE) -I$(DIR_TEST) $(LIBS)
##--------------------------------
##
## Dec app files
##
DECAPP=JxrDecApp
$(DIR_BUILD)/$(DECAPP): $(DIR_SRC)/$(DIR_EXEC)/$(DECAPP).c $(LIBRARIES)
@echo "Building JxrDecApp"
$(MK_DIR) $(@D)
$(CC) $< -o $@ $(CFLAGS) -I$(DIR_GLUE) -I$(DIR_TEST) $(LIBS)
##--------------------------------
##
## C++ Decompression app
##
CXXDECAPP=jxrdecode
$(DIR_BUILD)/$(CXXDECAPP): $(DIR_SRC)/$(DIR_CXX)/$(CXXDECAPP).cpp $(LIBRARIES) $(CXX_LIBRARIES)
echo "Building C++ jxrdecode"
$(MK_DIR) $(@D)
$(CXX) $< $(OBJ_CXX) -o $@ -I$(DIR_CXX)/lib $(CXXFLAGS) $(LIBS) $(CXXLIBS)
##--------------------------------
##
## JPEG XR library
##
all: $(DIR_BUILD)/$(ENCAPP) $(DIR_BUILD)/$(DECAPP) $(DIR_BUILD)/$(CXXDECAPP) $(LIBRARIES) $(CXX_LIBRARIES) $(DIR_BUILD)/libjxrjava.$(LIBSUFFIX)
clean:
rm -rf $(DIR_BUILD)/*App $(DIR_BUILD)/**/*.o $(DIR_BUILD)/**/*.class $(DIR_BUILD)/libj*.a $(DIR_BUILD)/libj*.$(LIBSUFFIX) $(DIR_BUILD)/libjxr.pc $(DIR_BUILD)/$(CXXDECAPP) $(DIR_BUILD)/$(JAR)
$(DIR_BUILD)/libjxr.pc: $(DIR_SRC)/libjxr.pc.in
@python -c 'import os; d = { "DIR_INSTALL": "$(DIR_INSTALL)", "JXR_VERSION": "$(JXR_VERSION)", "JXR_ENDIAN": "$(ENDIANFLAG)" }; fin = open("$<", "r"); fout = open("$@", "w+"); fout.writelines( [ l % d for l in fin.readlines()])'
install: all $(DIR_BUILD)/libjxr.pc
install -d $(DIR_INSTALL)/lib/pkgconfig $(DIR_INSTALL)/bin $(DIR_INSTALL)/include/libjxr/common $(DIR_INSTALL)/include/libjxr/image/x86 $(DIR_INSTALL)/include/libjxr/glue $(DIR_INSTALL)/include/libjxr/test $(DIR_INSTALL)/share/doc/jxr-$(JXR_VERSION)
install $(LIBRARIES) $(DIR_INSTALL)/lib
install -m 644 $(DIR_BUILD)/libjxr.pc $(DIR_INSTALL)/lib/pkgconfig
install $(DIR_BUILD)/$(ENCAPP) $(DIR_BUILD)/$(DECAPP) $(DIR_INSTALL)/bin
install -m 644 $(DIR_SRC)/common/include/*.h $(DIR_INSTALL)/include/libjxr/common
install -m 644 $(DIR_SRC)/image/x86/*.h $(DIR_INSTALL)/include/libjxr/image/x86
install -m 644 $(DIR_SRC)/$(DIR_SYS)/*.h $(DIR_INSTALL)/include/libjxr/image
install -m 644 $(DIR_SRC)/$(DIR_ENC)/*.h $(DIR_INSTALL)/include/libjxr/image
install -m 644 $(DIR_SRC)/$(DIR_DEC)/*.h $(DIR_INSTALL)/include/libjxr/image
install -m 644 $(DIR_SRC)/$(DIR_GLUE)/*.h $(DIR_INSTALL)/include/libjxr/glue
install -m 644 $(DIR_SRC)/$(DIR_TEST)/*.h $(DIR_INSTALL)/include/libjxr/test
install -m 644 doc/* $(DIR_INSTALL)/share/doc/jxr-$(JXR_VERSION)
##