blob: 429963ea41980d296cea2a7e6ce2417b17016f95 [file] [log] [blame] [view]
Andrew Top84143442018-07-12 10:44:23 -07001Building libjpeg-turbo
2======================
3
4
5Build Requirements
6------------------
7
8
9### All Systems
10
11- [CMake](http://www.cmake.org) v2.8.12 or later
12
13- [NASM](http://www.nasm.us) or [YASM](http://yasm.tortall.net)
14 (if building x86 or x86-64 SIMD extensions)
15 * If using NASM, 2.10 or later is required.
16 * If using NASM, 2.10 or later (except 2.11.08) is required for an x86-64 Mac
17 build (2.11.08 does not work properly with libjpeg-turbo's x86-64 SIMD code
18 when building macho64 objects.) NASM or YASM can be obtained from
19 [MacPorts](http://www.macports.org/) or [Homebrew](http://brew.sh/).
20 * If using YASM, 1.2.0 or later is required.
21 - NOTE: Currently, if it is desirable to hide the SIMD function symbols in
22 Mac executables or shared libraries that statically link with
23 libjpeg-turbo, then YASM must be used when building libjpeg-turbo.
24 * If building on Windows, **nasm.exe**/**yasm.exe** should be in your `PATH`.
25
26 The binary RPMs released by the NASM project do not work on older Linux
27 systems, such as Red Hat Enterprise Linux 5. On such systems, you can easily
28 build and install NASM from a source RPM by downloading one of the SRPMs from
29
30 <http://www.nasm.us/pub/nasm/releasebuilds>
31
32 and executing the following as root:
33
34 ARCH=`uname -m`
35 rpmbuild --rebuild nasm-{version}.src.rpm
36 rpm -Uvh /usr/src/redhat/RPMS/$ARCH/nasm-{version}.$ARCH.rpm
37
38 NOTE: the NASM build will fail if texinfo is not installed.
39
40
41### Un*x Platforms (including Linux, Mac, FreeBSD, Solaris, and Cygwin)
42
43- GCC v4.1 (or later) or Clang recommended for best performance
44
45- If building the TurboJPEG Java wrapper, JDK or OpenJDK 1.5 or later is
46 required. Most modern Linux distributions, as well as Solaris 10 and later,
47 include JDK or OpenJDK. On OS X 10.5 and 10.6, it will be necessary to
48 install the Java Developer Package, which can be downloaded from
49 <http://developer.apple.com/downloads> (Apple ID required.) For other
50 systems, you can obtain the Oracle Java Development Kit from
51 <http://www.java.com>.
52
53
54### Windows
55
56- Microsoft Visual C++ 2005 or later
57
58 If you don't already have Visual C++, then the easiest way to get it is by
59 installing the
60 [Windows SDK](http://msdn.microsoft.com/en-us/windows/bb980924.aspx).
61 The Windows SDK includes both 32-bit and 64-bit Visual C++ compilers and
62 everything necessary to build libjpeg-turbo.
63
64 * You can also use Microsoft Visual Studio Express/Community Edition, which
65 is a free download. (NOTE: versions prior to 2012 can only be used to
66 build 32-bit code.)
67 * If you intend to build libjpeg-turbo from the command line, then add the
68 appropriate compiler and SDK directories to the `INCLUDE`, `LIB`, and
69 `PATH` environment variables. This is generally accomplished by
70 executing `vcvars32.bat` or `vcvars64.bat` and `SetEnv.cmd`.
71 `vcvars32.bat` and `vcvars64.bat` are part of Visual C++ and are located in
72 the same directory as the compiler. `SetEnv.cmd` is part of the Windows
73 SDK. You can pass optional arguments to `SetEnv.cmd` to specify a 32-bit
74 or 64-bit build environment.
75
76 ... OR ...
77
78- MinGW
79
80 [MSYS2](http://msys2.github.io/) or [tdm-gcc](http://tdm-gcc.tdragon.net/)
81 recommended if building on a Windows machine. Both distributions install a
82 Start Menu link that can be used to launch a command prompt with the
83 appropriate compiler paths automatically set.
84
85- If building the TurboJPEG Java wrapper, JDK 1.5 or later is required. This
86 can be downloaded from <http://www.java.com>.
87
88
89Out-of-Tree Builds
90------------------
91
92Binary objects, libraries, and executables are generated in the directory from
93which CMake is executed (the "binary directory"), and this directory need not
94necessarily be the same as the libjpeg-turbo source directory. You can create
95multiple independent binary directories, in which different versions of
96libjpeg-turbo can be built from the same source tree using different compilers
97or settings. In the sections below, *{build_directory}* refers to the binary
98directory, whereas *{source_directory}* refers to the libjpeg-turbo source
99directory. For in-tree builds, these directories are the same.
100
101
102Build Procedure
103---------------
104
105NOTE: The build procedures below assume that CMake is invoked from the command
106line, but all of these procedures can be adapted to the CMake GUI as
107well.
108
109
110### Un*x
111
112The following procedure will build libjpeg-turbo on Unix and Unix-like systems.
113(On Solaris, this generates a 32-bit build. See "Build Recipes" below for
11464-bit build instructions.)
115
116 cd {build_directory}
117 cmake -G"Unix Makefiles" [additional CMake flags] {source_directory}
118 make
119
120This will generate the following files under *{build_directory}*:
121
122**libjpeg.a**<br>
123Static link library for the libjpeg API
124
125**libjpeg.so.{version}** (Linux, Unix)<br>
126**libjpeg.{version}.dylib** (Mac)<br>
127**cygjpeg-{version}.dll** (Cygwin)<br>
128Shared library for the libjpeg API
129
130By default, *{version}* is 62.2.0, 7.2.0, or 8.1.2, depending on whether
131libjpeg v6b (default), v7, or v8 emulation is enabled. If using Cygwin,
132*{version}* is 62, 7, or 8.
133
134**libjpeg.so** (Linux, Unix)<br>
135**libjpeg.dylib** (Mac)<br>
136Development symlink for the libjpeg API
137
138**libjpeg.dll.a** (Cygwin)<br>
139Import library for the libjpeg API
140
141**libturbojpeg.a**<br>
142Static link library for the TurboJPEG API
143
144**libturbojpeg.so.0.2.0** (Linux, Unix)<br>
145**libturbojpeg.0.2.0.dylib** (Mac)<br>
146**cygturbojpeg-0.dll** (Cygwin)<br>
147Shared library for the TurboJPEG API
148
149**libturbojpeg.so** (Linux, Unix)<br>
150**libturbojpeg.dylib** (Mac)<br>
151Development symlink for the TurboJPEG API
152
153**libturbojpeg.dll.a** (Cygwin)<br>
154Import library for the TurboJPEG API
155
156
157### Visual C++ (Command Line)
158
159 cd {build_directory}
160 cmake -G"NMake Makefiles" -DCMAKE_BUILD_TYPE=Release [additional CMake flags] {source_directory}
161 nmake
162
163This will build either a 32-bit or a 64-bit version of libjpeg-turbo, depending
164on which version of **cl.exe** is in the `PATH`.
165
166The following files will be generated under *{build_directory}*:
167
168**jpeg-static.lib**<br>
169Static link library for the libjpeg API
170
171**jpeg{version}.dll**<br>
172DLL for the libjpeg API
173
174**jpeg.lib**<br>
175Import library for the libjpeg API
176
177**turbojpeg-static.lib**<br>
178Static link library for the TurboJPEG API
179
180**turbojpeg.dll**<br>
181DLL for the TurboJPEG API
182
183**turbojpeg.lib**<br>
184Import library for the TurboJPEG API
185
186*{version}* is 62, 7, or 8, depending on whether libjpeg v6b (default), v7, or
187v8 emulation is enabled.
188
189
190### Visual C++ (IDE)
191
192Choose the appropriate CMake generator option for your version of Visual Studio
193(run `cmake` with no arguments for a list of available generators.) For
194instance:
195
196 cd {build_directory}
197 cmake -G"Visual Studio 10" [additional CMake flags] {source_directory}
198
199NOTE: Add "Win64" to the generator name (for example, "Visual Studio 10 Win64")
200to build a 64-bit version of libjpeg-turbo. A separate build directory must be
201used for 32-bit and 64-bit builds.
202
203You can then open **ALL_BUILD.vcproj** in Visual Studio and build one of the
204configurations in that project ("Debug", "Release", etc.) to generate a full
205build of libjpeg-turbo.
206
207This will generate the following files under *{build_directory}*:
208
209**{configuration}/jpeg-static.lib**<br>
210Static link library for the libjpeg API
211
212**{configuration}/jpeg{version}.dll**<br>
213DLL for the libjpeg API
214
215**{configuration}/jpeg.lib**<br>
216Import library for the libjpeg API
217
218**{configuration}/turbojpeg-static.lib**<br>
219Static link library for the TurboJPEG API
220
221**{configuration}/turbojpeg.dll**<br>
222DLL for the TurboJPEG API
223
224**{configuration}/turbojpeg.lib**<br>
225Import library for the TurboJPEG API
226
227*{configuration}* is Debug, Release, RelWithDebInfo, or MinSizeRel, depending
228on the configuration you built in the IDE, and *{version}* is 62, 7, or 8,
229depending on whether libjpeg v6b (default), v7, or v8 emulation is enabled.
230
231
232### MinGW
233
234NOTE: This assumes that you are building on a Windows machine using the MSYS
235environment. If you are cross-compiling on a Un*x platform (including Mac and
236Cygwin), then see "Build Recipes" below.
237
238 cd {build_directory}
239 cmake -G"MSYS Makefiles" [additional CMake flags] {source_directory}
240 make
241
242This will generate the following files under *{build_directory}*:
243
244**libjpeg.a**<br>
245Static link library for the libjpeg API
246
247**libjpeg-{version}.dll**<br>
248DLL for the libjpeg API
249
250**libjpeg.dll.a**<br>
251Import library for the libjpeg API
252
253**libturbojpeg.a**<br>
254Static link library for the TurboJPEG API
255
256**libturbojpeg.dll**<br>
257DLL for the TurboJPEG API
258
259**libturbojpeg.dll.a**<br>
260Import library for the TurboJPEG API
261
262*{version}* is 62, 7, or 8, depending on whether libjpeg v6b (default), v7, or
263v8 emulation is enabled.
264
265
266### Debug Build
267
268Add `-DCMAKE_BUILD_TYPE=Debug` to the CMake command line. Or, if building
269with NMake, remove `-DCMAKE_BUILD_TYPE=Release` (Debug builds are the default
270with NMake.)
271
272
273### libjpeg v7 or v8 API/ABI Emulation
274
275Add `-DWITH_JPEG7=1` to the CMake command line to build a version of
276libjpeg-turbo that is API/ABI-compatible with libjpeg v7. Add `-DWITH_JPEG8=1`
277to the CMake command line to build a version of libjpeg-turbo that is
278API/ABI-compatible with libjpeg v8. See [README.md](README.md) for more
279information about libjpeg v7 and v8 emulation.
280
281
282### In-Memory Source/Destination Managers
283
284When using libjpeg v6b or v7 API/ABI emulation, add `-DWITH_MEM_SRCDST=0` to
285the CMake command line to build a version of libjpeg-turbo that lacks the
286`jpeg_mem_src()` and `jpeg_mem_dest()` functions. These functions were not
287part of the original libjpeg v6b and v7 APIs, so removing them ensures strict
288conformance with those APIs. See [README.md](README.md) for more information.
289
290
291### Arithmetic Coding Support
292
293Since the patent on arithmetic coding has expired, this functionality has been
294included in this release of libjpeg-turbo. libjpeg-turbo's implementation is
295based on the implementation in libjpeg v8, but it works when emulating libjpeg
296v7 or v6b as well. The default is to enable both arithmetic encoding and
297decoding, but those who have philosophical objections to arithmetic coding can
298add `-DWITH_ARITH_ENC=0` or `-DWITH_ARITH_DEC=0` to the CMake command line to
299disable encoding or decoding (respectively.)
300
301
302### TurboJPEG Java Wrapper
303
304Add `-DWITH_JAVA=1` to the CMake command line to incorporate an optional Java
305Native Interface (JNI) wrapper into the TurboJPEG shared library and build the
306Java front-end classes to support it. This allows the TurboJPEG shared library
307to be used directly from Java applications. See [java/README](java/README) for
308more details.
309
310If Java is not in your `PATH`, or if you wish to use an alternate JDK to
311build/test libjpeg-turbo, then (prior to running CMake) set the `JAVA_HOME`
312environment variable to the location of the JDK that you wish to use. The
313`Java_JAVAC_EXECUTABLE`, `Java_JAVA_EXECUTABLE`, and `Java_JAR_EXECUTABLE`
314CMake variables can also be used to specify alternate commands or locations for
315javac, jar, and java (respectively.) You can also set the
316`CMAKE_JAVA_COMPILE_FLAGS` CMake variable or the `JAVAFLAGS` environment
317variable to specify arguments that should be passed to the Java compiler when
318building the TurboJPEG classes, and the `JAVAARGS` CMake variable to specify
319arguments that should be passed to the JRE when running the TurboJPEG Java unit
320tests.
321
322
323Build Recipes
324-------------
325
326
327### 32-bit Build on 64-bit Linux/Unix/Mac
328
329Use export/setenv to set the following environment variables before running
330CMake:
331
332 CFLAGS=-m32
333 LDFLAGS=-m32
334
335
336### 64-bit Build on Solaris
337
338Use export/setenv to set the following environment variables before running
339CMake:
340
341 CFLAGS=-m64
342 LDFLAGS=-m64
343
344
345### Other Compilers
346
347On Un*x systems, prior to running CMake, you can set the `CC` environment
348variable to the command used to invoke the C compiler.
349
350
351### 32-bit MinGW Build on Un*x (including Mac and Cygwin)
352
353Create a file called **toolchain.cmake** under *{build_directory}*, with the
354following contents:
355
356 set(CMAKE_SYSTEM_NAME Windows)
357 set(CMAKE_SYSTEM_PROCESSOR X86)
358 set(CMAKE_C_COMPILER {mingw_binary_path}/i686-w64-mingw32-gcc)
359 set(CMAKE_RC_COMPILER {mingw_binary_path}/i686-w64-mingw32-windres)
360
361*{mingw\_binary\_path}* is the directory under which the MinGW binaries are
362located (usually **/usr/bin**.) Next, execute the following commands:
363
364 cd {build_directory}
365 cmake -G"Unix Makefiles" -DCMAKE_TOOLCHAIN_FILE=toolchain.cmake \
366 [additional CMake flags] {source_directory}
367 make
368
369
370### 64-bit MinGW Build on Un*x (including Mac and Cygwin)
371
372Create a file called **toolchain.cmake** under *{build_directory}*, with the
373following contents:
374
375 set(CMAKE_SYSTEM_NAME Windows)
376 set(CMAKE_SYSTEM_PROCESSOR AMD64)
377 set(CMAKE_C_COMPILER {mingw_binary_path}/x86_64-w64-mingw32-gcc)
378 set(CMAKE_RC_COMPILER {mingw_binary_path}/x86_64-w64-mingw32-windres)
379
380*{mingw\_binary\_path}* is the directory under which the MinGW binaries are
381located (usually **/usr/bin**.) Next, execute the following commands:
382
383 cd {build_directory}
384 cmake -G"Unix Makefiles" -DCMAKE_TOOLCHAIN_FILE=toolchain.cmake \
385 [additional CMake flags] {source_directory}
386 make
387
388
389Building libjpeg-turbo for iOS
390------------------------------
391
392iOS platforms, such as the iPhone and iPad, use ARM processors, and all
393currently supported models include NEON instructions. Thus, they can take
394advantage of libjpeg-turbo's SIMD extensions to significantly accelerate JPEG
395compression/decompression. This section describes how to build libjpeg-turbo
396for these platforms.
397
398
399### Additional build requirements
400
401- For configurations that require [gas-preprocessor.pl]
402 (https://raw.githubusercontent.com/libjpeg-turbo/gas-preprocessor/master/gas-preprocessor.pl),
403 it should be installed in your `PATH`.
404
405
406### ARMv7 (32-bit)
407
408**gas-preprocessor.pl required**
409
410The following scripts demonstrate how to build libjpeg-turbo to run on the
411iPhone 3GS-4S/iPad 1st-3rd Generation and newer:
412
413#### Xcode 4.2 and earlier (LLVM-GCC)
414
415 IOS_PLATFORMDIR=/Developer/Platforms/iPhoneOS.platform
416 IOS_SYSROOT=($IOS_PLATFORMDIR/Developer/SDKs/iPhoneOS*.sdk)
417 export CFLAGS="-mfloat-abi=softfp -march=armv7 -mcpu=cortex-a8 -mtune=cortex-a8 -mfpu=neon -miphoneos-version-min=3.0"
418
419 cat <<EOF >toolchain.cmake
420 set(CMAKE_SYSTEM_NAME Darwin)
421 set(CMAKE_SYSTEM_PROCESSOR arm)
422 set(CMAKE_C_COMPILER ${IOS_PLATFORMDIR}/Developer/usr/bin/arm-apple-darwin10-llvm-gcc-4.2)
423 EOF
424
425 cd {build_directory}
426 cmake -G"Unix Makefiles" -DCMAKE_TOOLCHAIN_FILE=toolchain.cmake \
427 -DCMAKE_OSX_SYSROOT=${IOS_SYSROOT[0]} \
428 [additional CMake flags] {source_directory}
429 make
430
431#### Xcode 4.3-4.6 (LLVM-GCC)
432
433Same as above, but replace the first line with:
434
435 IOS_PLATFORMDIR=/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform
436
437#### Xcode 5 and later (Clang)
438
439 IOS_PLATFORMDIR=/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform
440 IOS_SYSROOT=($IOS_PLATFORMDIR/Developer/SDKs/iPhoneOS*.sdk)
441 export CFLAGS="-mfloat-abi=softfp -arch armv7 -miphoneos-version-min=3.0"
442 export ASMFLAGS="-no-integrated-as"
443
444 cat <<EOF >toolchain.cmake
445 set(CMAKE_SYSTEM_NAME Darwin)
446 set(CMAKE_SYSTEM_PROCESSOR arm)
447 set(CMAKE_C_COMPILER /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang)
448 EOF
449
450 cd {build_directory}
451 cmake -G"Unix Makefiles" -DCMAKE_TOOLCHAIN_FILE=toolchain.cmake \
452 -DCMAKE_OSX_SYSROOT=${IOS_SYSROOT[0]} \
453 [additional CMake flags] {source_directory}
454 make
455
456
457### ARMv7s (32-bit)
458
459**gas-preprocessor.pl required**
460
461The following scripts demonstrate how to build libjpeg-turbo to run on the
462iPhone 5/iPad 4th Generation and newer:
463
464#### Xcode 4.5-4.6 (LLVM-GCC)
465
466 IOS_PLATFORMDIR=/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform
467 IOS_SYSROOT=($IOS_PLATFORMDIR/Developer/SDKs/iPhoneOS*.sdk)
468 export CFLAGS="-Wall -mfloat-abi=softfp -march=armv7s -mcpu=swift -mtune=swift -mfpu=neon -miphoneos-version-min=6.0"
469
470 cat <<EOF >toolchain.cmake
471 set(CMAKE_SYSTEM_NAME Darwin)
472 set(CMAKE_SYSTEM_PROCESSOR arm)
473 set(CMAKE_C_COMPILER ${IOS_PLATFORMDIR}/Developer/usr/bin/arm-apple-darwin10-llvm-gcc-4.2)
474 EOF
475
476 cd {build_directory}
477 cmake -G"Unix Makefiles" -DCMAKE_TOOLCHAIN_FILE=toolchain.cmake \
478 -DCMAKE_OSX_SYSROOT=${IOS_SYSROOT[0]} \
479 [additional CMake flags] {source_directory}
480 make
481
482#### Xcode 5 and later (Clang)
483
484Same as the ARMv7 build procedure for Xcode 5 and later, except replace the
485compiler flags as follows:
486
487 export CFLAGS="-Wall -mfloat-abi=softfp -arch armv7s -miphoneos-version-min=6.0"
488
489
490### ARMv8 (64-bit)
491
492**gas-preprocessor.pl required if using Xcode < 6**
493
494The following script demonstrates how to build libjpeg-turbo to run on the
495iPhone 5S/iPad Mini 2/iPad Air and newer.
496
497 IOS_PLATFORMDIR=/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform
498 IOS_SYSROOT=($IOS_PLATFORMDIR/Developer/SDKs/iPhoneOS*.sdk)
499 export CFLAGS="-Wall -arch arm64 -miphoneos-version-min=7.0 -funwind-tables"
500
501 cat <<EOF >toolchain.cmake
502 set(CMAKE_SYSTEM_NAME Darwin)
503 set(CMAKE_SYSTEM_PROCESSOR aarch64)
504 set(CMAKE_C_COMPILER /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang)
505 EOF
506
507 cd {build_directory}
508 cmake -G"Unix Makefiles" -DCMAKE_TOOLCHAIN_FILE=toolchain.cmake \
509 -DCMAKE_OSX_SYSROOT=${IOS_SYSROOT[0]} \
510 [additional CMake flags] {source_directory}
511 make
512
513Once built, lipo can be used to combine the ARMv7, v7s, and/or v8 variants into
514a universal library.
515
516
517Building libjpeg-turbo for Android
518----------------------------------
519
520Building libjpeg-turbo for Android platforms requires the
521[Android NDK](https://developer.android.com/tools/sdk/ndk).
522
523
524### ARMv7 (32-bit)
525
526The following is a general recipe script that can be modified for your specific
527needs.
528
529 # Set these variables to suit your needs
530 NDK_PATH={full path to the "ndk" directory-- for example, /opt/android/sdk/ndk-bundle}
531 BUILD_PLATFORM={the platform name for the NDK package you installed--
532 for example, "windows-x86" or "linux-x86_64" or "darwin-x86_64"}
533 TOOLCHAIN_VERSION={"4.8", "4.9", "clang3.5", etc. This corresponds to a
534 toolchain directory under ${NDK_PATH}/toolchains/.}
535 ANDROID_VERSION={The minimum version of Android to support-- for example,
536 "16", "19", etc.}
537
538 # It should not be necessary to modify the rest
539 HOST=arm-linux-androideabi
540 SYSROOT=${NDK_PATH}/platforms/android-${ANDROID_VERSION}/arch-arm
541 export CFLAGS="-march=armv7-a -mfloat-abi=softfp -fprefetch-loop-arrays \
542 -D__ANDROID_API__=${ANDROID_VERSION} --sysroot=${SYSROOT} \
543 -isystem ${NDK_PATH}/sysroot/usr/include \
544 -isystem ${NDK_PATH}/sysroot/usr/include/${HOST}"
545 export LDFLAGS=-pie
546 TOOLCHAIN=${NDK_PATH}/toolchains/${HOST}-${TOOLCHAIN_VERSION}/prebuilt/${BUILD_PLATFORM}
547
548 cat <<EOF >toolchain.cmake
549 set(CMAKE_SYSTEM_NAME Linux)
550 set(CMAKE_SYSTEM_PROCESSOR arm)
551 set(CMAKE_C_COMPILER ${TOOLCHAIN}/bin/${HOST}-gcc)
552 set(CMAKE_FIND_ROOT_PATH ${TOOLCHAIN}/${HOST})
553 EOF
554
555 cd {build_directory}
556 cmake -G"Unix Makefiles" -DCMAKE_TOOLCHAIN_FILE=toolchain.cmake \
557 -DCMAKE_POSITION_INDEPENDENT_CODE=1 \
558 [additional CMake flags] {source_directory}
559 make
560
561
562### ARMv8 (64-bit)
563
564The following is a general recipe script that can be modified for your specific
565needs.
566
567 # Set these variables to suit your needs
568 NDK_PATH={full path to the "ndk" directory-- for example, /opt/android/sdk/ndk-bundle}
569 BUILD_PLATFORM={the platform name for the NDK package you installed--
570 for example, "windows-x86" or "linux-x86_64" or "darwin-x86_64"}
571 TOOLCHAIN_VERSION={"4.8", "4.9", "clang3.5", etc. This corresponds to a
572 toolchain directory under ${NDK_PATH}/toolchains/.}
573 ANDROID_VERSION={The minimum version of Android to support. "21" or later
574 is required for a 64-bit build.}
575
576 # It should not be necessary to modify the rest
577 HOST=aarch64-linux-android
578 SYSROOT=${NDK_PATH}/platforms/android-${ANDROID_VERSION}/arch-arm64
579 export CFLAGS="-D__ANDROID_API__=${ANDROID_VERSION} --sysroot=${SYSROOT} \
580 -isystem ${NDK_PATH}/sysroot/usr/include \
581 -isystem ${NDK_PATH}/sysroot/usr/include/${HOST}"
582 export LDFLAGS=-pie
583 TOOLCHAIN=${NDK_PATH}/toolchains/${HOST}-${TOOLCHAIN_VERSION}/prebuilt/${BUILD_PLATFORM}
584
585 cat <<EOF >toolchain.cmake
586 set(CMAKE_SYSTEM_NAME Linux)
587 set(CMAKE_SYSTEM_PROCESSOR aarch64)
588 set(CMAKE_C_COMPILER ${TOOLCHAIN}/bin/${HOST}-gcc)
589 set(CMAKE_FIND_ROOT_PATH ${TOOLCHAIN}/${HOST})
590 EOF
591
592 cd {build_directory}
593 cmake -G"Unix Makefiles" -DCMAKE_TOOLCHAIN_FILE=toolchain.cmake \
594 -DCMAKE_POSITION_INDEPENDENT_CODE=1 \
595 [additional CMake flags] {source_directory}
596 make
597
598
599### x86 (32-bit)
600
601The following is a general recipe script that can be modified for your specific
602needs.
603
604 # Set these variables to suit your needs
605 NDK_PATH={full path to the "ndk" directory-- for example, /opt/android/sdk/ndk-bundle}
606 BUILD_PLATFORM={the platform name for the NDK package you installed--
607 for example, "windows-x86" or "linux-x86_64" or "darwin-x86_64"}
608 TOOLCHAIN_VERSION={"4.8", "4.9", "clang3.5", etc. This corresponds to a
609 toolchain directory under ${NDK_PATH}/toolchains/.}
610 ANDROID_VERSION={The minimum version of Android to support-- for example,
611 "16", "19", etc.}
612
613 # It should not be necessary to modify the rest
614 HOST=i686-linux-android
615 SYSROOT=${NDK_PATH}/platforms/android-${ANDROID_VERSION}/arch-x86
616 export CFLAGS="-D__ANDROID_API__=${ANDROID_VERSION} --sysroot=${SYSROOT} \
617 -isystem ${NDK_PATH}/sysroot/usr/include \
618 -isystem ${NDK_PATH}/sysroot/usr/include/${HOST}"
619 export LDFLAGS=-pie
620 TOOLCHAIN=${NDK_PATH}/toolchains/x86-${TOOLCHAIN_VERSION}/prebuilt/${BUILD_PLATFORM}
621
622 cat <<EOF >toolchain.cmake
623 set(CMAKE_SYSTEM_NAME Linux)
624 set(CMAKE_SYSTEM_PROCESSOR i386)
625 set(CMAKE_C_COMPILER ${TOOLCHAIN}/bin/${HOST}-gcc)
626 set(CMAKE_FIND_ROOT_PATH ${TOOLCHAIN}/${HOST})
627 EOF
628
629 cd {build_directory}
630 cmake -G"Unix Makefiles" -DCMAKE_TOOLCHAIN_FILE=toolchain.cmake \
631 -DCMAKE_POSITION_INDEPENDENT_CODE=1 \
632 [additional CMake flags] {source_directory}
633 make
634
635
636### x86-64 (64-bit)
637
638The following is a general recipe script that can be modified for your specific
639needs.
640
641 # Set these variables to suit your needs
642 NDK_PATH={full path to the "ndk" directory-- for example, /opt/android/sdk/ndk-bundle}
643 BUILD_PLATFORM={the platform name for the NDK package you installed--
644 for example, "windows-x86" or "linux-x86_64" or "darwin-x86_64"}
645 TOOLCHAIN_VERSION={"4.8", "4.9", "clang3.5", etc. This corresponds to a
646 toolchain directory under ${NDK_PATH}/toolchains/.}
647 ANDROID_VERSION={The minimum version of Android to support. "21" or later
648 is required for a 64-bit build.}
649
650 # It should not be necessary to modify the rest
651 HOST=x86_64-linux-android
652 SYSROOT=${NDK_PATH}/platforms/android-${ANDROID_VERSION}/arch-x86_64
653 export CFLAGS="-D__ANDROID_API__=${ANDROID_VERSION} --sysroot=${SYSROOT} \
654 -isystem ${NDK_PATH}/sysroot/usr/include \
655 -isystem ${NDK_PATH}/sysroot/usr/include/${HOST}"
656 export LDFLAGS=-pie
657 TOOLCHAIN=${NDK_PATH}/toolchains/x86_64-${TOOLCHAIN_VERSION}/prebuilt/${BUILD_PLATFORM}
658
659 cat <<EOF >toolchain.cmake
660 set(CMAKE_SYSTEM_NAME Linux)
661 set(CMAKE_SYSTEM_PROCESSOR x86_64)
662 set(CMAKE_C_COMPILER ${TOOLCHAIN}/bin/${HOST}-gcc)
663 set(CMAKE_FIND_ROOT_PATH ${TOOLCHAIN}/${HOST})
664 EOF
665
666 cd {build_directory}
667 cmake -G"Unix Makefiles" -DCMAKE_TOOLCHAIN_FILE=toolchain.cmake \
668 -DCMAKE_POSITION_INDEPENDENT_CODE=1 \
669 [additional CMake flags] {source_directory}
670 make
671
672
673If building for Android 4.0.x (API level < 16) or earlier, remove
674`-DCMAKE_POSITION_INDEPENDENT_CODE=1` from the CMake arguments and `-pie` from
675`LDFLAGS`.
676
677
678Advanced CMake Options
679----------------------
680
681To list and configure other CMake options not specifically mentioned in this
682guide, run
683
684 ccmake {source_directory}
685
686or
687
688 cmake-gui {source_directory}
689
690from the build directory after initially configuring the build. CCMake is a
691text-based interactive version of CMake, and CMake-GUI is a GUI version. Both
692will display all variables that are relevant to the libjpeg-turbo build, their
693current values, and a help string describing what they do.
694
695
696Installing libjpeg-turbo
697========================
698
699You can use the build system to install libjpeg-turbo (as opposed to creating
700an installer package.) To do this, run `make install` or `nmake install`
701(or build the "install" target in the Visual Studio IDE.) Running
702`make uninstall` or `nmake uninstall` (or building the "uninstall" target in
703the Visual Studio IDE) will uninstall libjpeg-turbo.
704
705The `CMAKE_INSTALL_PREFIX` CMake variable can be modified in order to install
706libjpeg-turbo into a directory of your choosing. If you don't specify
707`CMAKE_INSTALL_PREFIX`, then the default is:
708
709**c:\libjpeg-turbo**<br>
710Visual Studio 32-bit build
711
712**c:\libjpeg-turbo64**<br>
713Visual Studio 64-bit build
714
715**c:\libjpeg-turbo-gcc**<br>
716MinGW 32-bit build
717
718**c:\libjpeg-turbo-gcc64**<br>
719MinGW 64-bit build
720
721**/opt/libjpeg-turbo**<br>
722Un*x
723
724The default value of `CMAKE_INSTALL_PREFIX` causes the libjpeg-turbo files to
725be installed with a directory structure resembling that of the official
726libjpeg-turbo binary packages. Changing the value of `CMAKE_INSTALL_PREFIX`
727(for instance, to **/usr/local**) causes the libjpeg-turbo files to be
728installed with a directory structure that conforms to GNU standards.
729
730The `CMAKE_INSTALL_BINDIR`, `CMAKE_INSTALL_DATAROOTDIR`,
731`CMAKE_INSTALL_DOCDIR`, `CMAKE_INSTALL_INCLUDEDIR`, `CMAKE_INSTALL_JAVADIR`,
732`CMAKE_INSTALL_LIBDIR`, and `CMAKE_INSTALL_MANDIR` CMake variables allow a
733finer degree of control over where specific files in the libjpeg-turbo
734distribution should be installed. These directory variables can either be
735specified as absolute paths or as paths relative to `CMAKE_INSTALL_PREFIX` (for
736instance, setting `CMAKE_INSTALL_DOCDIR` to **doc** would cause the
737documentation to be installed in **${CMAKE\_INSTALL\_PREFIX}/doc**.) If a
738directory variable contains the name of another directory variable in angle
739brackets, then its final value will depend on the final value of that other
740variable. For instance, the default value of `CMAKE_INSTALL_MANDIR` is
741**\<CMAKE\_INSTALL\_DATAROOTDIR\>/man**.
742
743NOTE: If setting one of these directory variables to a relative path using the
744CMake command line, you must specify that the variable is of type `PATH`.
745For example:
746
747 cmake -G"{generator type}" -DCMAKE_INSTALL_LIBDIR:PATH=lib {source_directory}
748
749Otherwise, CMake will assume that the path is relative to the build directory
750rather than the install directory.
751
752
753Creating Distribution Packages
754==============================
755
756The following commands can be used to create various types of distribution
757packages:
758
759
760Linux
761-----
762
763 make rpm
764
765Create Red Hat-style binary RPM package. Requires RPM v4 or later.
766
767 make srpm
768
769This runs `make dist` to create a pristine source tarball, then creates a
770Red Hat-style source RPM package from the tarball. Requires RPM v4 or later.
771
772 make deb
773
774Create Debian-style binary package. Requires dpkg.
775
776
777Mac
778---
779
780 make dmg
781
782Create Mac package/disk image. This requires pkgbuild and productbuild, which
783are installed by default on OS X 10.7 and later and which can be obtained by
784installing Xcode 3.2.6 (with the "Unix Development" option) on OS X 10.6.
785Packages built in this manner can be installed on OS X 10.5 and later, but they
786must be built on OS X 10.6 or later.
787
788 make udmg
789
790This creates a Mac package/disk image that contains universal x86-64/i386/ARM
791binaries. The following CMake variables control which architectures are
792included in the universal binaries. Setting any of these variables to an empty
793string excludes that architecture from the package.
794
795* `OSX_32BIT_BUILD`: Directory containing an i386 (32-bit) Mac build of
796 libjpeg-turbo (default: *{source_directory}*/osxx86)
797* `IOS_ARMV7_BUILD`: Directory containing an ARMv7 (32-bit) iOS build of
798 libjpeg-turbo (default: *{source_directory}*/iosarmv7)
799* `IOS_ARMV7S_BUILD`: Directory containing an ARMv7s (32-bit) iOS build of
800 libjpeg-turbo (default: *{source_directory}*/iosarmv7s)
801* `IOS_ARMV8_BUILD`: Directory containing an ARMv8 (64-bit) iOS build of
802 libjpeg-turbo (default: *{source_directory}*/iosarmv8)
803
804You should first use CMake to configure i386, ARMv7, ARMv7s, and/or ARMv8
805sub-builds of libjpeg-turbo (see "Build Recipes" and "Building libjpeg-turbo
806for iOS" above) in build directories that match those specified in the
807aforementioned CMake variables. Next, configure the primary build of
808libjpeg-turbo as an out-of-tree build, and build it. Once the primary build
809has been built, run `make udmg` from the build directory. The packaging system
810will build the sub-builds, use lipo to combine them into a single set of
811universal binaries, then package the universal binaries in the same manner as
812`make dmg`.
813
814
815Cygwin
816------
817
818 make cygwinpkg
819
820Build a Cygwin binary package.
821
822
823Windows
824-------
825
826If using NMake:
827
828 cd {build_directory}
829 nmake installer
830
831If using MinGW:
832
833 cd {build_directory}
834 make installer
835
836If using the Visual Studio IDE, build the "installer" target.
837
838The installer package (libjpeg-turbo-*{version}*[-gcc|-vc][64].exe) will be
839located under *{build_directory}*. If building using the Visual Studio IDE,
840then the installer package will be located in a subdirectory with the same name
841as the configuration you built (such as *{build_directory}*\Debug\ or
842*{build_directory}*\Release\).
843
844Building a Windows installer requires the
845[Nullsoft Install System](http://nsis.sourceforge.net/). makensis.exe should
846be in your `PATH`.
847
848
849Regression testing
850==================
851
852The most common way to test libjpeg-turbo is by invoking `make test` (Un*x) or
853`nmake test` (Windows command line) or by building the "RUN_TESTS" target
854(Visual Studio IDE), once the build has completed. This runs a series of tests
855to ensure that mathematical compatibility has been maintained between
856libjpeg-turbo and libjpeg v6b. This also invokes the TurboJPEG unit tests,
857which ensure that the colorspace extensions, YUV encoding, decompression
858scaling, and other features of the TurboJPEG C and Java APIs are working
859properly (and, by extension, that the equivalent features of the underlying
860libjpeg API are also working.)
861
862Invoking `make testclean` (Un*x) or `nmake testclean` (Windows command line) or
863building the "testclean" target (Visual Studio IDE) will clean up the output
864images generated by the tests.
865
866On Un*x platforms, more extensive tests of the TurboJPEG C and Java wrappers
867can be run by invoking `make tjtest`. These extended TurboJPEG tests
868essentially iterate through all of the available features of the TurboJPEG APIs
869that are not covered by the TurboJPEG unit tests (including the lossless
870transform options) and compare the images generated by each feature to images
871generated using the equivalent feature in the libjpeg API. The extended
872TurboJPEG tests are meant to test for regressions in the TurboJPEG wrappers,
873not in the underlying libjpeg API library.