]> granicus.if.org Git - libjpeg-turbo/blobdiff - BUILDING.md
AppVeyor: Use MinGW-builds instead of MSYS2 MinGW
[libjpeg-turbo] / BUILDING.md
index 32a9936e1698dcbdc27bfc3c7359b4f107d8d43d..485144a44b5c5813a3ac4f2844428df93e0dac86 100644 (file)
-*******************************************************************************
-**     Building on Un*x Platforms (including Cygwin and OS X)
-*******************************************************************************
+Building libjpeg-turbo
+======================
 
 
-==================
 Build Requirements
-==================
+------------------
 
--- autoconf 2.56 or later
--- automake 1.7 or later
--- libtool 1.4 or later
-   * If using Xcode 4.3 or later on OS X, autoconf and automake are no longer
-     provided.  The easiest way to obtain them is from MacPorts
-     (http://www.macports.org/).
-
--- NASM or YASM (if building x86 or x86-64 SIMD extensions)
-   * NASM 0.98, or 2.01 or later is required for an x86 build (0.99 and 2.00 do
-     not work properly with libjpeg-turbo's x86 SIMD code.)
-   * NASM 2.00 or later is required for an x86-64 build.
-   * NASM 2.07, or 2.11.09 or later is required for an x86-64 Mac build
-     (2.11.08 does not work properly with libjpeg-turbo's x86-64 SIMD code when
-     building macho64 objects.)  NASM or YASM can be obtained from MacPorts
-     (http://www.macports.org/).
-
-   The binary RPMs released by the NASM project do not work on older Linux
-   systems, such as Red Hat Enterprise Linux 4.  On such systems, you can
-   easily build and install NASM from a source RPM by downloading one of the
-   SRPMs from
-
-   http://www.nasm.us/pub/nasm/releasebuilds
-
-   and executing the following as root:
-
-     ARCH=`uname -m`
-     rpmbuild --rebuild nasm-{version}.src.rpm
-     rpm -Uvh /usr/src/redhat/RPMS/$ARCH/nasm-{version}.$ARCH.rpm
-
-   NOTE: the NASM build will fail if texinfo is not installed.
-
--- GCC v4.1 or later recommended for best performance
-   * Beginning with Xcode 4, Apple stopped distributing GCC and switched to
-     the LLVM compiler.  Xcode v4.0 through v4.6 provides a GCC front end
-     called LLVM-GCC.  Unfortunately, as of this writing, neither LLVM-GCC nor
-     the LLVM (clang) compiler produces optimal performance with libjpeg-turbo.
-     Building libjpeg-turbo with LLVM-GCC v4.2 results in a 10% performance
-     degradation when compressing using 64-bit code, relative to building
-     libjpeg-turbo with GCC v4.2.  Building libjpeg-turbo with LLVM (clang)
-     results in a 20% performance degradation when compressing using 64-bit
-     code, relative to building libjpeg-turbo with GCC v4.2.  If you are
-     running Snow Leopard or earlier, it is suggested that you continue to use
-     Xcode v3.2.6, which provides GCC v4.2.  If you are using Lion or later, it
-     is suggested that you install Apple GCC v4.2 or GCC v5 through MacPorts.
-
--- If building the TurboJPEG Java wrapper, JDK or OpenJDK 1.5 or later is
-   required.  Some systems, such as Solaris 10 and later and Red Hat Enterprise
-   Linux 5 and later, have this pre-installed.  On OS X 10.5 and later, it will
-   be necessary to install the Java Developer Package, which can be downloaded
-   from http://developer.apple.com/downloads (Apple ID required.)  For systems
-   that do not have a JDK installed, you can obtain the Oracle Java Development
-   Kit from http://www.java.com.
 
+### All Systems
 
-==================
-Out-of-Tree Builds
-==================
+- [CMake](http://www.cmake.org) v2.8.12 or later
 
-Binary objects, libraries, and executables are generated in the same directory
-from which configure was executed (the "binary directory"), and this directory
-need not necessarily be the same as the libjpeg-turbo source directory.  You
-can create multiple independent binary directories, in which different versions
-of libjpeg-turbo can be built from the same source tree using different
-compilers or settings.  In the sections below, {build_directory} refers to the
-binary directory, whereas {source_directory} refers to the libjpeg-turbo source
-directory.  For in-tree builds, these directories are the same.
+- [NASM](http://www.nasm.us) or [YASM](http://yasm.tortall.net)
+  (if building x86 or x86-64 SIMD extensions)
+  * If using NASM, 2.10 or later is required.
+  * If using NASM, 2.10 or later (except 2.11.08) is required for an x86-64 Mac
+    build (2.11.08 does not work properly with libjpeg-turbo's x86-64 SIMD code
+    when building macho64 objects.)  NASM or YASM can be obtained from
+    [MacPorts](http://www.macports.org/) or [Homebrew](http://brew.sh/).
+  * If using YASM, 1.2.0 or later is required.
+     - NOTE: Currently, if it is desirable to hide the SIMD function symbols in
+       Mac executables or shared libraries that statically link with
+       libjpeg-turbo, then YASM must be used when building libjpeg-turbo.
+  * If building on Windows, **nasm.exe**/**yasm.exe** should be in your `PATH`.
+  * NASM and YASM are located in the CRB (Code Ready Builder) repository on
+    Red Hat Enterprise Linux 8 and in the PowerTools repository on CentOS 8,
+    which is not enabled by default.
 
+  The binary RPMs released by the NASM project do not work on older Linux
+  systems, such as Red Hat Enterprise Linux 5.  On such systems, you can easily
+  build and install NASM from a source RPM by downloading one of the SRPMs from
 
-======================
-Building libjpeg-turbo
-======================
+  <http://www.nasm.us/pub/nasm/releasebuilds>
 
-The following procedure will build libjpeg-turbo on Linux, FreeBSD, Cygwin, and
-Solaris/x86 systems (on Solaris, this generates a 32-bit library.  See below
-for 64-bit build instructions.)
+  and executing the following as root:
 
-  cd {source_directory}
-  cd {build_directory}
-  sh {source_directory}/configure [additional configure flags]
-  make
+        ARCH=`uname -m`
+        rpmbuild --rebuild nasm-{version}.src.rpm
+        rpm -Uvh /usr/src/redhat/RPMS/$ARCH/nasm-{version}.$ARCH.rpm
 
-This will generate the following files under .libs/
+  NOTE: the NASM build will fail if texinfo is not installed.
 
-  libjpeg.a
-      Static link library for the libjpeg API
 
-  libjpeg.so.{version} (Linux, Unix)
-  libjpeg.{version}.dylib (OS X)
-  cygjpeg-{version}.dll (Cygwin)
-      Shared library for the libjpeg API
+### Un*x Platforms (including Linux, Mac, FreeBSD, Solaris, and Cygwin)
 
-  By default, {version} is 62.1.0, 7.1.0, or 8.0.2, depending on whether
-  libjpeg v6b (default), v7, or v8 emulation is enabled.  If using Cygwin,
-  {version} is 62, 7, or 8.
+- GCC v4.1 (or later) or Clang recommended for best performance
 
-  libjpeg.so (Linux, Unix)
-  libjpeg.dylib (OS X)
-      Development symlink for the libjpeg API
+- If building the TurboJPEG Java wrapper, JDK or OpenJDK 1.5 or later is
+  required.  Most modern Linux distributions, as well as Solaris 10 and later,
+  include JDK or OpenJDK.  On OS X 10.5 and 10.6, it will be necessary to
+  install the Java Developer Package, which can be downloaded from
+  <http://developer.apple.com/downloads> (Apple ID required.)  For other
+  systems, you can obtain the Oracle Java Development Kit from
+  <http://www.oracle.com/technetwork/java/javase/downloads>.
 
-  libjpeg.dll.a (Cygwin)
-      Import library for the libjpeg API
+  * If using JDK 11 or later, CMake 3.10.x or later must also be used.
 
-  libturbojpeg.a
-      Static link library for the TurboJPEG API
+### Windows
 
-  libturbojpeg.so.0.1.0 (Linux, Unix)
-  libturbojpeg.0.1.0.dylib (OS X)
-  cygturbojpeg-0.dll (Cygwin)
-      Shared library for the TurboJPEG API
+- Microsoft Visual C++ 2005 or later
 
-  libturbojpeg.so (Linux, Unix)
-  libturbojpeg.dylib (OS X)
-      Development symlink for the TurboJPEG API
+  If you don't already have Visual C++, then the easiest way to get it is by
+  installing the
+  [Windows SDK](http://msdn.microsoft.com/en-us/windows/bb980924.aspx).
+  The Windows SDK includes both 32-bit and 64-bit Visual C++ compilers and
+  everything necessary to build libjpeg-turbo.
 
-  libturbojpeg.dll.a (Cygwin)
-      Import library for the TurboJPEG API
+  * You can also use Microsoft Visual Studio Express/Community Edition, which
+    is a free download.  (NOTE: versions prior to 2012 can only be used to
+    build 32-bit code.)
+  * If you intend to build libjpeg-turbo from the command line, then add the
+    appropriate compiler and SDK directories to the `INCLUDE`, `LIB`, and
+    `PATH` environment variables.  This is generally accomplished by
+    executing `vcvars32.bat` or `vcvars64.bat` and `SetEnv.cmd`.
+    `vcvars32.bat` and `vcvars64.bat` are part of Visual C++ and are located in
+    the same directory as the compiler.  `SetEnv.cmd` is part of the Windows
+    SDK.  You can pass optional arguments to `SetEnv.cmd` to specify a 32-bit
+    or 64-bit build environment.
 
+   ... OR ...
 
-libjpeg v7 or v8 API/ABI Emulation
-----------------------------------
+- MinGW
 
-Add --with-jpeg7 to the configure command line to build a version of
-libjpeg-turbo that is API/ABI-compatible with libjpeg v7.  Add --with-jpeg8 to
-the configure command to build a version of libjpeg-turbo that is
-API/ABI-compatible with libjpeg v8.  See README-turbo.txt for more information
-on libjpeg v7 and v8 emulation.
+  [MSYS2](http://msys2.github.io/) or [tdm-gcc](http://tdm-gcc.tdragon.net/)
+  recommended if building on a Windows machine.  Both distributions install a
+  Start Menu link that can be used to launch a command prompt with the
+  appropriate compiler paths automatically set.
 
+- If building the TurboJPEG Java wrapper, JDK 1.5 or later is required.  This
+  can be downloaded from
+  <http://www.oracle.com/technetwork/java/javase/downloads>.
 
-In-Memory Source/Destination Managers
--------------------------------------
+  * If using JDK 11 or later, CMake 3.10.x or later must also be used.
 
-When using libjpeg v6b or v7 API/ABI emulation, add --without-mem-srcdst to the
-configure command line to build a version of libjpeg-turbo that lacks the
-jpeg_mem_src() and jpeg_mem_dest() functions.  These functions were not part of
-the original libjpeg v6b and v7 APIs, so removing them ensures strict
-conformance with those APIs.  See README-turbo.txt for more information.
 
+Out-of-Tree Builds
+------------------
 
-Arithmetic Coding Support
--------------------------
+Binary objects, libraries, and executables are generated in the directory from
+which CMake is executed (the "binary directory"), and this directory need not
+necessarily be the same as the libjpeg-turbo source directory.  You can create
+multiple independent binary directories, in which different versions of
+libjpeg-turbo can be built from the same source tree using different compilers
+or settings.  In the sections below, *{build_directory}* refers to the binary
+directory, whereas *{source_directory}* refers to the libjpeg-turbo source
+directory.  For in-tree builds, these directories are the same.
 
-Since the patent on arithmetic coding has expired, this functionality has been
-included in this release of libjpeg-turbo.  libjpeg-turbo's implementation is
-based on the implementation in libjpeg v8, but it works when emulating libjpeg
-v7 or v6b as well.  The default is to enable both arithmetic encoding and
-decoding, but those who have philosophical objections to arithmetic coding can
-add --without-arith-enc or --without-arith-dec to the configure command line to
-disable encoding or decoding (respectively.)
 
+Build Procedure
+---------------
 
-TurboJPEG Java Wrapper
-----------------------
-Add --with-java to the configure command line to incorporate an optional Java
-Native Interface wrapper into the TurboJPEG shared library and build the Java
-front-end classes to support it.  This allows the TurboJPEG shared library to
-be used directly from Java applications.  See java/README for more details.
+NOTE: The build procedures below assume that CMake is invoked from the command
+line, but all of these procedures can be adapted to the CMake GUI as
+well.
 
-You can set the JAVAC, JAR, and JAVA configure variables to specify
-alternate commands for javac, jar, and java (respectively.)  You can also
-set the JAVACFLAGS configure variable to specify arguments that should be
-passed to the Java compiler when building the front-end classes, and JNI_CFLAGS
-to specify arguments that should be passed to the C compiler when building the
-JNI wrapper.  Run 'configure --help' for more details.
 
+### Un*x
 
-========================
-Installing libjpeg-turbo
-========================
-
-If you intend to install these libraries and the associated header files, then
-replace 'make' in the instructions above with
+The following procedure will build libjpeg-turbo on Unix and Unix-like systems.
+(On Solaris, this generates a 32-bit build.  See "Build Recipes" below for
+64-bit build instructions.)
 
-  make install prefix={base dir} libdir={library directory}
+    cd {build_directory}
+    cmake -G"Unix Makefiles" [additional CMake flags] {source_directory}
+    make
 
-For example,
+This will generate the following files under *{build_directory}*:
 
-  make install prefix=/usr/local libdir=/usr/local/lib64
+**libjpeg.a**<br>
+Static link library for the libjpeg API
 
-will install the header files in /usr/local/include and the library files in
-/usr/local/lib64.  If 'prefix' and 'libdir' are not specified, then the default
-is to install the header files in /opt/libjpeg-turbo/include and the library
-files in /opt/libjpeg-turbo/lib32 (32-bit) or /opt/libjpeg-turbo/lib64
-(64-bit.)
+**libjpeg.so.{version}** (Linux, Unix)<br>
+**libjpeg.{version}.dylib** (Mac)<br>
+**cygjpeg-{version}.dll** (Cygwin)<br>
+Shared library for the libjpeg API
 
-NOTE: You can specify a prefix of /usr and a libdir of, for instance,
-/usr/lib64 to overwrite the system's version of libjpeg.  If you do this,
-however, then be sure to BACK UP YOUR SYSTEM'S INSTALLATION OF LIBJPEG before
-overwriting it.  It is recommended that you instead install libjpeg-turbo into
-a non-system directory and manipulate the LD_LIBRARY_PATH or create symlinks
-to force applications to use libjpeg-turbo instead of libjpeg.  See
-README-turbo.txt for more information.
+By default, *{version}* is 62.2.0, 7.2.0, or 8.1.2, depending on whether
+libjpeg v6b (default), v7, or v8 emulation is enabled.  If using Cygwin,
+*{version}* is 62, 7, or 8.
 
+**libjpeg.so** (Linux, Unix)<br>
+**libjpeg.dylib** (Mac)<br>
+Development symlink for the libjpeg API
 
-=============
-Build Recipes
-=============
+**libjpeg.dll.a** (Cygwin)<br>
+Import library for the libjpeg API
 
+**libturbojpeg.a**<br>
+Static link library for the TurboJPEG API
 
-32-bit Build on 64-bit Linux
-----------------------------
+**libturbojpeg.so.0.2.0** (Linux, Unix)<br>
+**libturbojpeg.0.2.0.dylib** (Mac)<br>
+**cygturbojpeg-0.dll** (Cygwin)<br>
+Shared library for the TurboJPEG API
 
-Add
+**libturbojpeg.so** (Linux, Unix)<br>
+**libturbojpeg.dylib** (Mac)<br>
+Development symlink for the TurboJPEG API
 
-  --host i686-pc-linux-gnu CFLAGS='-O3 -m32' LDFLAGS=-m32
+**libturbojpeg.dll.a** (Cygwin)<br>
+Import library for the TurboJPEG API
 
-to the configure command line.
 
+### Visual C++ (Command Line)
 
-64-bit Build on 64-bit OS X
----------------------------
+    cd {build_directory}
+    cmake -G"NMake Makefiles" -DCMAKE_BUILD_TYPE=Release [additional CMake flags] {source_directory}
+    nmake
 
-Add
+This will build either a 32-bit or a 64-bit version of libjpeg-turbo, depending
+on which version of **cl.exe** is in the `PATH`.
 
-  --host x86_64-apple-darwin NASM=/opt/local/bin/nasm
+The following files will be generated under *{build_directory}*:
 
-to the configure command line.  NASM 2.07 or later from MacPorts must be
-installed.
+**jpeg-static.lib**<br>
+Static link library for the libjpeg API
 
+**jpeg{version}.dll**<br>
+DLL for the libjpeg API
 
-32-bit Build on 64-bit OS X
----------------------------
+**jpeg.lib**<br>
+Import library for the libjpeg API
 
-Add
+**turbojpeg-static.lib**<br>
+Static link library for the TurboJPEG API
 
-  --host i686-apple-darwin CFLAGS='-O3 -m32' LDFLAGS=-m32
+**turbojpeg.dll**<br>
+DLL for the TurboJPEG API
 
-to the configure command line.
+**turbojpeg.lib**<br>
+Import library for the TurboJPEG API
 
+*{version}* is 62, 7, or 8, depending on whether libjpeg v6b (default), v7, or
+v8 emulation is enabled.
 
-64-bit Backward-Compatible Build on 64-bit OS X
------------------------------------------------
 
-Add
+### Visual C++ (IDE)
 
-  --host x86_64-apple-darwin NASM=/opt/local/bin/nasm \
-  CFLAGS='-isysroot /Developer/SDKs/MacOSX10.5.sdk \
-    -mmacosx-version-min=10.5 -O3' \
-    LDFLAGS='-isysroot /Developer/SDKs/MacOSX10.5.sdk \
-    -mmacosx-version-min=10.5'
+Choose the appropriate CMake generator option for your version of Visual Studio
+(run `cmake` with no arguments for a list of available generators.)  For
+instance:
 
-to the configure command line.  The OS X 10.5 SDK, and NASM 2.07 or later from
-MacPorts, must be installed.
+    cd {build_directory}
+    cmake -G"Visual Studio 10" [additional CMake flags] {source_directory}
 
+NOTE: Add "Win64" to the generator name (for example, "Visual Studio 10 Win64")
+to build a 64-bit version of libjpeg-turbo.  A separate build directory must be
+used for 32-bit and 64-bit builds.
 
-32-bit Backward-Compatible Build on OS X
-----------------------------------------
+You can then open **ALL_BUILD.vcproj** in Visual Studio and build one of the
+configurations in that project ("Debug", "Release", etc.) to generate a full
+build of libjpeg-turbo.
 
-Add
+This will generate the following files under *{build_directory}*:
 
-  --host i686-apple-darwin \
-    CFLAGS='-isysroot /Developer/SDKs/MacOSX10.5.sdk \
-    -mmacosx-version-min=10.5 -O3 -m32' \
-    LDFLAGS='-isysroot /Developer/SDKs/MacOSX10.5.sdk \
-    -mmacosx-version-min=10.5 -m32'
+**{configuration}/jpeg-static.lib**<br>
+Static link library for the libjpeg API
 
-to the configure command line.  The OS X 10.5 SDK must be installed.
+**{configuration}/jpeg{version}.dll**<br>
+DLL for the libjpeg API
 
+**{configuration}/jpeg.lib**<br>
+Import library for the libjpeg API
 
-64-bit Library Build on 64-bit Solaris
---------------------------------------
+**{configuration}/turbojpeg-static.lib**<br>
+Static link library for the TurboJPEG API
 
-Add
+**{configuration}/turbojpeg.dll**<br>
+DLL for the TurboJPEG API
 
-  --host x86_64-pc-solaris CFLAGS='-O3 -m64' LDFLAGS=-m64
+**{configuration}/turbojpeg.lib**<br>
+Import library for the TurboJPEG API
 
-to the configure command line.
+*{configuration}* is Debug, Release, RelWithDebInfo, or MinSizeRel, depending
+on the configuration you built in the IDE, and *{version}* is 62, 7, or 8,
+depending on whether libjpeg v6b (default), v7, or v8 emulation is enabled.
 
 
-32-bit Build on 64-bit FreeBSD
-------------------------------
+### MinGW
 
-Add
+NOTE: This assumes that you are building on a Windows machine using the MSYS
+environment.  If you are cross-compiling on a Un*x platform (including Mac and
+Cygwin), then see "Build Recipes" below.
 
-  --host i386-unknown-freebsd CC='gcc -B /usr/lib32' CFLAGS='-O3 -m32' \
-    LDFLAGS='-B/usr/lib32'
+    cd {build_directory}
+    cmake -G"MSYS Makefiles" [additional CMake flags] {source_directory}
+    make
 
-to the configure command line.  NASM 2.07 or later from FreeBSD ports must be
-installed.
+This will generate the following files under *{build_directory}*:
 
+**libjpeg.a**<br>
+Static link library for the libjpeg API
 
-Oracle Solaris Studio
----------------------
+**libjpeg-{version}.dll**<br>
+DLL for the libjpeg API
 
-Add
+**libjpeg.dll.a**<br>
+Import library for the libjpeg API
 
-  CC=cc
+**libturbojpeg.a**<br>
+Static link library for the TurboJPEG API
 
-to the configure command line.  libjpeg-turbo will automatically be built with
-the maximum optimization level (-xO5) unless you override CFLAGS.
+**libturbojpeg.dll**<br>
+DLL for the TurboJPEG API
 
-To build a 64-bit version of libjpeg-turbo using Oracle Solaris Studio, add
+**libturbojpeg.dll.a**<br>
+Import library for the TurboJPEG API
 
-  --host x86_64-pc-solaris CC=cc CFLAGS='-xO5 -m64' LDFLAGS=-m64
+*{version}* is 62, 7, or 8, depending on whether libjpeg v6b (default), v7, or
+v8 emulation is enabled.
 
-to the configure command line.
 
+### Debug Build
 
-MinGW Build on Cygwin
----------------------
+Add `-DCMAKE_BUILD_TYPE=Debug` to the CMake command line.  Or, if building
+with NMake, remove `-DCMAKE_BUILD_TYPE=Release` (Debug builds are the default
+with NMake.)
 
-Use CMake (see recipes below)
 
+### libjpeg v7 or v8 API/ABI Emulation
 
-===========
-ARM Support
-===========
+Add `-DWITH_JPEG7=1` to the CMake command line to build a version of
+libjpeg-turbo that is API/ABI-compatible with libjpeg v7.  Add `-DWITH_JPEG8=1`
+to the CMake command line to build a version of libjpeg-turbo that is
+API/ABI-compatible with libjpeg v8.  See [README.md](README.md) for more
+information about libjpeg v7 and v8 emulation.
 
-This release of libjpeg-turbo can use ARM NEON SIMD instructions to accelerate
-JPEG compression/decompression by approximately 2-4x on ARMv7 and later
-platforms.  If libjpeg-turbo is configured on an ARM Linux platform, then the
-build system will automatically include the NEON SIMD routines, if they are
-supported.  Build instructions for other ARM-based platforms follow.
 
+### In-Memory Source/Destination Managers
 
-Building libjpeg-turbo for iOS
-------------------------------
+When using libjpeg v6b or v7 API/ABI emulation, add `-DWITH_MEM_SRCDST=0` to
+the CMake command line to build a version of libjpeg-turbo that lacks the
+`jpeg_mem_src()` and `jpeg_mem_dest()` functions.  These functions were not
+part of the original libjpeg v6b and v7 APIs, so removing them ensures strict
+conformance with those APIs.  See [README.md](README.md) for more information.
 
-iOS platforms, such as the iPhone and iPad, use ARM processors, some of which
-support NEON instructions.  Additional steps are required in order to build
-libjpeg-turbo for these platforms.
 
-Additional build requirements:
+### Arithmetic Coding Support
 
-  gas-preprocessor.pl
-  (https://raw.githubusercontent.com/libjpeg-turbo/gas-preprocessor/master/gas-preprocessor.pl)
-  should be installed in your PATH.
+Since the patent on arithmetic coding has expired, this functionality has been
+included in this release of libjpeg-turbo.  libjpeg-turbo's implementation is
+based on the implementation in libjpeg v8, but it works when emulating libjpeg
+v7 or v6b as well.  The default is to enable both arithmetic encoding and
+decoding, but those who have philosophical objections to arithmetic coding can
+add `-DWITH_ARITH_ENC=0` or `-DWITH_ARITH_DEC=0` to the CMake command line to
+disable encoding or decoding (respectively.)
 
 
-ARM 32-bit Build (Xcode 4.6.x and earlier, LLVM-GCC):
+### TurboJPEG Java Wrapper
 
-Set the following shell variables for simplicity:
+Add `-DWITH_JAVA=1` to the CMake command line to incorporate an optional Java
+Native Interface (JNI) wrapper into the TurboJPEG shared library and build the
+Java front-end classes to support it.  This allows the TurboJPEG shared library
+to be used directly from Java applications.  See [java/README](java/README) for
+more details.
 
-  Xcode 4.2 and earlier:
-  IOS_PLATFORMDIR=/Developer/Platforms/iPhoneOS.platform
-  Xcode 4.3 and later:
-  IOS_PLATFORMDIR=/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform
+If Java is not in your `PATH`, or if you wish to use an alternate JDK to
+build/test libjpeg-turbo, then (prior to running CMake) set the `JAVA_HOME`
+environment variable to the location of the JDK that you wish to use.  The
+`Java_JAVAC_EXECUTABLE`, `Java_JAVA_EXECUTABLE`, and `Java_JAR_EXECUTABLE`
+CMake variables can also be used to specify alternate commands or locations for
+javac, jar, and java (respectively.)  You can also set the
+`CMAKE_JAVA_COMPILE_FLAGS` CMake variable or the `JAVAFLAGS` environment
+variable to specify arguments that should be passed to the Java compiler when
+building the TurboJPEG classes, and the `JAVAARGS` CMake variable to specify
+arguments that should be passed to the JRE when running the TurboJPEG Java unit
+tests.
 
-  IOS_SYSROOT=$IOS_PLATFORMDIR/Developer/SDKs/iPhoneOS*.sdk
-  IOS_GCC=$IOS_PLATFORMDIR/Developer/usr/bin/arm-apple-darwin10-llvm-gcc-4.2
 
-  ARMv6 (code will run on all iOS devices, not SIMD-accelerated):
-  [NOTE: Requires Xcode 4.4.x or earlier]
-  IOS_CFLAGS="-march=armv6 -mcpu=arm1176jzf-s -mfpu=vfp"
+Build Recipes
+-------------
 
-  ARMv7 (code will run on iPhone 3GS-4S/iPad 1st-3rd Generation and newer):
-  IOS_CFLAGS="-march=armv7 -mcpu=cortex-a8 -mtune=cortex-a8 -mfpu=neon"
 
-  ARMv7s (code will run on iPhone 5/iPad 4th Generation and newer):
-  [NOTE: Requires Xcode 4.5 or later]
-  IOS_CFLAGS="-march=armv7s -mcpu=swift -mtune=swift -mfpu=neon"
+### 32-bit Build on 64-bit Linux/Unix/Mac
 
-Follow the procedure under "Building libjpeg-turbo" above, adding
+Use export/setenv to set the following environment variables before running
+CMake:
 
-  --host arm-apple-darwin10 \
-    CC="$IOS_GCC" LD="$IOS_GCC" \
-    CFLAGS="-mfloat-abi=softfp -isysroot $IOS_SYSROOT -O3 $IOS_CFLAGS" \
-    LDFLAGS="-mfloat-abi=softfp -isysroot $IOS_SYSROOT $IOS_CFLAGS"
+    CFLAGS=-m32
+    LDFLAGS=-m32
 
-to the configure command line.
 
+### 64-bit Build on Solaris
 
-ARM 32-bit Build (Xcode 5.0.x and later, Clang):
+Use export/setenv to set the following environment variables before running
+CMake:
 
-Set the following shell variables for simplicity:
+    CFLAGS=-m64
+    LDFLAGS=-m64
 
-  IOS_PLATFORMDIR=/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform
-  IOS_SYSROOT=$IOS_PLATFORMDIR/Developer/SDKs/iPhoneOS*.sdk
-  IOS_GCC=/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang
 
-  ARMv7 (code will run on iPhone 3GS-4S/iPad 1st-3rd Generation and newer):
-  IOS_CFLAGS="-arch armv7"
+### Other Compilers
 
-  ARMv7s (code will run on iPhone 5/iPad 4th Generation and newer):
-  IOS_CFLAGS="-arch armv7s"
+On Un*x systems, prior to running CMake, you can set the `CC` environment
+variable to the command used to invoke the C compiler.
 
-Follow the procedure under "Building libjpeg-turbo" above, adding
 
-  --host arm-apple-darwin10 \
-    CC="$IOS_GCC" LD="$IOS_GCC" \
-    CFLAGS="-mfloat-abi=softfp -isysroot $IOS_SYSROOT -O3 $IOS_CFLAGS" \
-    LDFLAGS="-mfloat-abi=softfp -isysroot $IOS_SYSROOT $IOS_CFLAGS" \
-    CCASFLAGS="-no-integrated-as $IOS_CFLAGS"
+### 32-bit MinGW Build on Un*x (including Mac and Cygwin)
 
-to the configure command line.
+Create a file called **toolchain.cmake** under *{build_directory}*, with the
+following contents:
 
+    set(CMAKE_SYSTEM_NAME Windows)
+    set(CMAKE_SYSTEM_PROCESSOR X86)
+    set(CMAKE_C_COMPILER {mingw_binary_path}/i686-w64-mingw32-gcc)
+    set(CMAKE_RC_COMPILER {mingw_binary_path}/i686-w64-mingw32-windres)
 
-ARMv8 64-bit Build (Xcode 5.0.x and later, Clang):
+*{mingw\_binary\_path}* is the directory under which the MinGW binaries are
+located (usually **/usr/bin**.)  Next, execute the following commands:
 
-Code will run on iPhone 5S/iPad Mini 2/iPad Air and newer.
+    cd {build_directory}
+    cmake -G"Unix Makefiles" -DCMAKE_TOOLCHAIN_FILE=toolchain.cmake \
+      [additional CMake flags] {source_directory}
+    make
 
-Set the following shell variables for simplicity:
 
-  IOS_PLATFORMDIR=/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform
-  IOS_SYSROOT=$IOS_PLATFORMDIR/Developer/SDKs/iPhoneOS*.sdk
-  IOS_GCC=/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang
-  IOS_CFLAGS="-arch arm64"
+### 64-bit MinGW Build on Un*x (including Mac and Cygwin)
 
-Follow the procedure under "Building libjpeg-turbo" above, adding
+Create a file called **toolchain.cmake** under *{build_directory}*, with the
+following contents:
 
-  --host aarch64-apple-darwin \
-    CC="$IOS_GCC" LD="$IOS_GCC" \
-    CFLAGS="-isysroot $IOS_SYSROOT -O3 $IOS_CFLAGS" \
-    LDFLAGS="-isysroot $IOS_SYSROOT $IOS_CFLAGS"
+    set(CMAKE_SYSTEM_NAME Windows)
+    set(CMAKE_SYSTEM_PROCESSOR AMD64)
+    set(CMAKE_C_COMPILER {mingw_binary_path}/x86_64-w64-mingw32-gcc)
+    set(CMAKE_RC_COMPILER {mingw_binary_path}/x86_64-w64-mingw32-windres)
 
-to the configure command line.
+*{mingw\_binary\_path}* is the directory under which the MinGW binaries are
+located (usually **/usr/bin**.)  Next, execute the following commands:
 
+    cd {build_directory}
+    cmake -G"Unix Makefiles" -DCMAKE_TOOLCHAIN_FILE=toolchain.cmake \
+      [additional CMake flags] {source_directory}
+    make
 
-NOTE:  You can also add -miphoneos-version-min={version} to $IOS_CFLAGS above
-in order to support older versions of iOS than the default version supported by
-the SDK.
 
-Once built, lipo can be used to combine the ARMv6, v7, v7s, and/or v8 variants
-into a universal library.
+Building libjpeg-turbo for iOS
+------------------------------
 
+iOS platforms, such as the iPhone and iPad, use ARM processors, and all
+currently supported models include NEON instructions.  Thus, they can take
+advantage of libjpeg-turbo's SIMD extensions to significantly accelerate JPEG
+compression/decompression.  This section describes how to build libjpeg-turbo
+for these platforms.
 
-Building libjpeg-turbo for Android
-----------------------------------
 
-Building libjpeg-turbo for Android platforms requires the Android NDK
-(https://developer.android.com/tools/sdk/ndk) and autotools.  The following is
-a general recipe script that can be modified for your specific needs.
-
-  # Set these variables to suit your needs
-  NDK_PATH={full path to the "ndk" directory-- for example, /opt/android/ndk}
-  BUILD_PLATFORM={the platform name for the NDK package you installed--
-    for example, "windows-x86" or "linux-x86_64"}
-  TOOLCHAIN_VERSION={"4.6", "4.8", etc.  This corresponds to a toolchain
-    directory under ${NDK_PATH}/toolchains/.}
-  ANDROID_VERSION={The minimum version of Android to support-- for example,
-    "9", "19", etc.}
-
-  HOST=arm-linux-androideabi
-  TOOLCHAIN=${NDK_PATH}/toolchains/${HOST}-${TOOLCHAIN_VERSION}/prebuilt/${BUILD_PLATFORM}
-  SYSROOT=${NDK_PATH}/platforms/android-${ANDROID_VERSION}/arch-arm
-  ANDROID_INCLUDES="-I${SYSROOT}/usr/include -I${TOOLCHAIN}/include"
-  ANDROID_CFLAGS="-march=armv7-a -mfloat-abi=softfp -fprefetch-loop-arrays \
-    -fstrict-aliasing --sysroot=${SYSROOT}"
-  export CPP=${TOOLCHAIN}/bin/${HOST}-cpp
-  export AR=${TOOLCHAIN}/bin/${HOST}-ar
-  export AS=${TOOLCHAIN}/bin/${HOST}-as
-  export NM=${TOOLCHAIN}/bin/${HOST}-nm
-  export CC=${TOOLCHAIN}/bin/${HOST}-gcc
-  export LD=${TOOLCHAIN}/bin/${HOST}-ld
-  export RANLIB=${TOOLCHAIN}/bin/${HOST}-ranlib
-  export OBJDUMP=${TOOLCHAIN}/bin/${HOST}-objdump
-  export STRIP=${TOOLCHAIN}/bin/${HOST}-strip
-  cd {build_directory}
-  sh {source_directory}/configure --host=${HOST} \
-    CFLAGS="${ANDROID_INCLUDES} ${ANDROID_CFLAGS} -O3" \
-    CPPFLAGS="${ANDROID_INCLUDES} ${ANDROID_CFLAGS}" \
-    LDFLAGS="${ANDROID_CFLAGS}" --with-simd ${1+"$@"}
-  make
-
-
-*******************************************************************************
-**     Building on Windows (Visual C++ or MinGW)
-*******************************************************************************
+### Additional build requirements
 
+- For configurations that require [gas-preprocessor.pl]
+  (https://raw.githubusercontent.com/libjpeg-turbo/gas-preprocessor/master/gas-preprocessor.pl),
+  it should be installed in your `PATH`.
 
-==================
-Build Requirements
-==================
 
--- CMake (http://www.cmake.org) v2.8.8 or later
+### ARMv7 (32-bit)
 
--- Microsoft Visual C++ 2005 or later
+**gas-preprocessor.pl required**
 
-   If you don't already have Visual C++, then the easiest way to get it is by
-   installing the Windows SDK:
+The following scripts demonstrate how to build libjpeg-turbo to run on the
+iPhone 3GS-4S/iPad 1st-3rd Generation and newer:
 
-   http://msdn.microsoft.com/en-us/windows/bb980924.aspx
+#### Xcode 4.2 and earlier (LLVM-GCC)
 
-   The Windows SDK includes both 32-bit and 64-bit Visual C++ compilers and
-   everything necessary to build libjpeg-turbo.
+    IOS_PLATFORMDIR=/Developer/Platforms/iPhoneOS.platform
+    IOS_SYSROOT=($IOS_PLATFORMDIR/Developer/SDKs/iPhoneOS*.sdk)
+    export CFLAGS="-mfloat-abi=softfp -march=armv7 -mcpu=cortex-a8 -mtune=cortex-a8 -mfpu=neon -miphoneos-version-min=3.0"
 
-   * You can also use Microsoft Visual Studio Express Edition, which is a free
-     download.  (NOTE: versions prior to 2012 can only be used to build 32-bit
-     code.)
-   * If you intend to build libjpeg-turbo from the command line, then add the
-     appropriate compiler and SDK directories to the INCLUDE, LIB, and PATH
-     environment variables.  This is generally accomplished by executing
-     vcvars32.bat or vcvars64.bat and SetEnv.cmd.  vcvars32.bat and
-     vcvars64.bat are part of Visual C++ and are located in the same directory
-     as the compiler.  SetEnv.cmd is part of the Windows SDK.  You can pass
-     optional arguments to SetEnv.cmd to specify a 32-bit or 64-bit build
-     environment.
+    cd {build_directory}
 
-... OR ...
+    cat <<EOF >toolchain.cmake
+    set(CMAKE_SYSTEM_NAME Darwin)
+    set(CMAKE_SYSTEM_PROCESSOR arm)
+    set(CMAKE_C_COMPILER ${IOS_PLATFORMDIR}/Developer/usr/bin/arm-apple-darwin10-llvm-gcc-4.2)
+    EOF
 
--- MinGW
+    cmake -G"Unix Makefiles" -DCMAKE_TOOLCHAIN_FILE=toolchain.cmake \
+      -DCMAKE_OSX_SYSROOT=${IOS_SYSROOT[0]} \
+      [additional CMake flags] {source_directory}
+    make
 
-   MinGW-builds (http://sourceforge.net/projects/mingwbuilds/) or
-   tdm-gcc (http://tdm-gcc.tdragon.net/) recommended if building on a Windows
-   machine.  Both distributions install a Start Menu link that can be used to
-   launch a command prompt with the appropriate compiler paths automatically
-   set.
+#### Xcode 4.3-4.6 (LLVM-GCC)
 
--- NASM (http://www.nasm.us/) 0.98 or later (NASM 2.05 or later is required for
-   a 64-bit build)
+Same as above, but replace the first line with:
 
--- If building the TurboJPEG Java wrapper, JDK 1.5 or later is required.  This
-   can be downloaded from http://www.java.com.
+    IOS_PLATFORMDIR=/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform
 
+#### Xcode 5 and later (Clang)
 
-==================
-Out-of-Tree Builds
-==================
+    IOS_PLATFORMDIR=/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform
+    IOS_SYSROOT=($IOS_PLATFORMDIR/Developer/SDKs/iPhoneOS*.sdk)
+    export CFLAGS="-mfloat-abi=softfp -arch armv7 -miphoneos-version-min=3.0"
+    export ASMFLAGS="-no-integrated-as"
 
-Binary objects, libraries, and executables are generated in the same directory
-from which cmake was executed (the "binary directory"), and this directory need
-not necessarily be the same as the libjpeg-turbo source directory.  You can
-create multiple independent binary directories, in which different versions of
-libjpeg-turbo can be built from the same source tree using different compilers
-or settings.  In the sections below, {build_directory} refers to the binary
-directory, whereas {source_directory} refers to the libjpeg-turbo source
-directory.  For in-tree builds, these directories are the same.
+    cd {build_directory}
 
+    cat <<EOF >toolchain.cmake
+    set(CMAKE_SYSTEM_NAME Darwin)
+    set(CMAKE_SYSTEM_PROCESSOR arm)
+    set(CMAKE_C_COMPILER /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang)
+    EOF
 
-======================
-Building libjpeg-turbo
-======================
+    cmake -G"Unix Makefiles" -DCMAKE_TOOLCHAIN_FILE=toolchain.cmake \
+      -DCMAKE_OSX_SYSROOT=${IOS_SYSROOT[0]} \
+      [additional CMake flags] {source_directory}
+    make
 
 
-Visual C++ (Command Line)
--------------------------
+### ARMv7s (32-bit)
 
-  cd {build_directory}
-  cmake -G "NMake Makefiles" -DCMAKE_BUILD_TYPE=Release {source_directory}
-  nmake
+**gas-preprocessor.pl required**
 
-This will build either a 32-bit or a 64-bit version of libjpeg-turbo, depending
-on which version of cl.exe is in the PATH.
-
-The following files will be generated under {build_directory}:
-
-  jpeg-static.lib
-      Static link library for the libjpeg API
-  sharedlib/jpeg{version}.dll
-      DLL for the libjpeg API
-  sharedlib/jpeg.lib
-      Import library for the libjpeg API
-  turbojpeg-static.lib
-      Static link library for the TurboJPEG API
-  turbojpeg.dll
-      DLL for the TurboJPEG API
-  turbojpeg.lib
-      Import library for the TurboJPEG API
-
-{version} is 62, 7, or 8, depending on whether libjpeg v6b (default), v7, or
-v8 emulation is enabled.
+The following scripts demonstrate how to build libjpeg-turbo to run on the
+iPhone 5/iPad 4th Generation and newer:
 
+#### Xcode 4.5-4.6 (LLVM-GCC)
 
-Visual C++ (IDE)
-----------------
+    IOS_PLATFORMDIR=/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform
+    IOS_SYSROOT=($IOS_PLATFORMDIR/Developer/SDKs/iPhoneOS*.sdk)
+    export CFLAGS="-Wall -mfloat-abi=softfp -march=armv7s -mcpu=swift -mtune=swift -mfpu=neon -miphoneos-version-min=6.0"
 
-Choose the appropriate CMake generator option for your version of Visual Studio
-(run "cmake" with no arguments for a list of available generators.)  For
-instance:
+    cd {build_directory}
 
-  cd {build_directory}
-  cmake -G "Visual Studio 10" {source_directory}
+    cat <<EOF >toolchain.cmake
+    set(CMAKE_SYSTEM_NAME Darwin)
+    set(CMAKE_SYSTEM_PROCESSOR arm)
+    set(CMAKE_C_COMPILER ${IOS_PLATFORMDIR}/Developer/usr/bin/arm-apple-darwin10-llvm-gcc-4.2)
+    EOF
 
-NOTE:  Add "Win64" to the generator name (for example, "Visual Studio 10
-Win64") to build a 64-bit version of libjpeg-turbo.  Recent versions of CMake
-no longer document that.  A separate build directory must be used for 32-bit
-and 64-bit builds.
+    cmake -G"Unix Makefiles" -DCMAKE_TOOLCHAIN_FILE=toolchain.cmake \
+      -DCMAKE_OSX_SYSROOT=${IOS_SYSROOT[0]} \
+      [additional CMake flags] {source_directory}
+    make
 
-You can then open ALL_BUILD.vcproj in Visual Studio and build one of the
-configurations in that project ("Debug", "Release", etc.) to generate a full
-build of libjpeg-turbo.
+#### Xcode 5 and later (Clang)
 
-This will generate the following files under {build_directory}:
-
-  {configuration}/jpeg-static.lib
-      Static link library for the libjpeg API
-  sharedlib/{configuration}/jpeg{version}.dll
-      DLL for the libjpeg API
-  sharedlib/{configuration}/jpeg.lib
-      Import library for the libjpeg API
-  {configuration}/turbojpeg-static.lib
-      Static link library for the TurboJPEG API
-  {configuration}/turbojpeg.dll
-      DLL for the TurboJPEG API
-  {configuration}/turbojpeg.lib
-      Import library for the TurboJPEG API
-
-{configuration} is Debug, Release, RelWithDebInfo, or MinSizeRel, depending on
-the configuration you built in the IDE, and {version} is 62, 7, or 8,
-depending on whether libjpeg v6b (default), v7, or v8 emulation is enabled.
+Same as the ARMv7 build procedure for Xcode 5 and later, except replace the
+compiler flags as follows:
 
+    export CFLAGS="-Wall -mfloat-abi=softfp -arch armv7s -miphoneos-version-min=6.0"
 
-MinGW
------
 
-NOTE: This assumes that you are building on a Windows machine.  If you are
-cross-compiling on a Linux/Unix machine, then see "Build Recipes" below.
-
-  cd {build_directory}
-  cmake -G "MinGW Makefiles" {source_directory}
-  mingw32-make
-
-This will generate the following files under {build_directory}
-
-  libjpeg.a
-      Static link library for the libjpeg API
-  sharedlib/libjpeg-{version}.dll
-      DLL for the libjpeg API
-  sharedlib/libjpeg.dll.a
-      Import library for the libjpeg API
-  libturbojpeg.a
-      Static link library for the TurboJPEG API
-  libturbojpeg.dll
-      DLL for the TurboJPEG API
-  libturbojpeg.dll.a
-      Import library for the TurboJPEG API
-
-{version} is 62, 7, or 8, depending on whether libjpeg v6b (default), v7, or
-v8 emulation is enabled.
+### ARMv8 (64-bit)
 
+**gas-preprocessor.pl required if using Xcode < 6**
 
-Debug Build
------------
+The following script demonstrates how to build libjpeg-turbo to run on the
+iPhone 5S/iPad Mini 2/iPad Air and newer.
 
-Add "-DCMAKE_BUILD_TYPE=Debug" to the cmake command line.  Or, if building with
-NMake, remove "-DCMAKE_BUILD_TYPE=Release" (Debug builds are the default with
-NMake.)
+    IOS_PLATFORMDIR=/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform
+    IOS_SYSROOT=($IOS_PLATFORMDIR/Developer/SDKs/iPhoneOS*.sdk)
+    export CFLAGS="-Wall -arch arm64 -miphoneos-version-min=7.0 -funwind-tables"
 
+    cd {build_directory}
 
-libjpeg v7 or v8 API/ABI Emulation
------------------------------------
+    cat <<EOF >toolchain.cmake
+    set(CMAKE_SYSTEM_NAME Darwin)
+    set(CMAKE_SYSTEM_PROCESSOR aarch64)
+    set(CMAKE_C_COMPILER /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang)
+    EOF
 
-Add "-DWITH_JPEG7=1" to the cmake command line to build a version of
-libjpeg-turbo that is API/ABI-compatible with libjpeg v7.  Add "-DWITH_JPEG8=1"
-to the cmake command to build a version of libjpeg-turbo that is
-API/ABI-compatible with libjpeg v8.  See README-turbo.txt for more information
-on libjpeg v7 and v8 emulation.
+    cmake -G"Unix Makefiles" -DCMAKE_TOOLCHAIN_FILE=toolchain.cmake \
+      -DCMAKE_OSX_SYSROOT=${IOS_SYSROOT[0]} \
+      [additional CMake flags] {source_directory}
+    make
 
+Once built, lipo can be used to combine the ARMv7, v7s, and/or v8 variants into
+a universal library.
 
-In-Memory Source/Destination Managers
--------------------------------------
 
-When using libjpeg v6b or v7 API/ABI emulation, add -DWITH_MEM_SRCDST=0 to the
-CMake command line to build a version of libjpeg-turbo that lacks the
-jpeg_mem_src() and jpeg_mem_dest() functions.  These functions were not part of
-the original libjpeg v6b and v7 APIs, so removing them ensures strict
-conformance with those APIs.  See README-turbo.txt for more information.
+Building libjpeg-turbo for Android
+----------------------------------
 
+Building libjpeg-turbo for Android platforms requires v13b or later of the
+[Android NDK](https://developer.android.com/tools/sdk/ndk).
+
+
+### ARMv7 (32-bit)
+
+The following is a general recipe script that can be modified for your specific
+needs.
+
+    # Set these variables to suit your needs
+    NDK_PATH={full path to the NDK directory-- for example,
+      /opt/android/android-ndk-r16b}
+    TOOLCHAIN={"gcc" or "clang"-- "gcc" must be used with NDK r16b and earlier,
+      and "clang" must be used with NDK r17c and later}
+    ANDROID_VERSION={the minimum version of Android to support-- for example,
+      "16", "19", etc.}
+
+    cd {build_directory}
+    cmake -G"Unix Makefiles" \
+      -DANDROID_ABI=armeabi-v7a \
+      -DANDROID_ARM_MODE=arm \
+      -DANDROID_PLATFORM=android-${ANDROID_VERSION} \
+      -DANDROID_TOOLCHAIN=${TOOLCHAIN} \
+      -DCMAKE_ASM_FLAGS="--target=arm-linux-androideabi${ANDROID_VERSION}" \
+      -DCMAKE_TOOLCHAIN_FILE=${NDK_PATH}/build/cmake/android.toolchain.cmake \
+      [additional CMake flags] {source_directory}
+    make
+
+
+### ARMv8 (64-bit)
+
+The following is a general recipe script that can be modified for your specific
+needs.
+
+    # Set these variables to suit your needs
+    NDK_PATH={full path to the NDK directory-- for example,
+      /opt/android/android-ndk-r16b}
+    TOOLCHAIN={"gcc" or "clang"-- "gcc" must be used with NDK r14b and earlier,
+      and "clang" must be used with NDK r17c and later}
+    ANDROID_VERSION={the minimum version of Android to support.  "21" or later
+      is required for a 64-bit build.}
+
+    cd {build_directory}
+    cmake -G"Unix Makefiles" \
+      -DANDROID_ABI=arm64-v8a \
+      -DANDROID_ARM_MODE=arm \
+      -DANDROID_PLATFORM=android-${ANDROID_VERSION} \
+      -DANDROID_TOOLCHAIN=${TOOLCHAIN} \
+      -DCMAKE_ASM_FLAGS="--target=aarch64-linux-android${ANDROID_VERSION}" \
+      -DCMAKE_TOOLCHAIN_FILE=${NDK_PATH}/build/cmake/android.toolchain.cmake \
+      [additional CMake flags] {source_directory}
+    make
+
+
+### x86 (32-bit)
+
+The following is a general recipe script that can be modified for your specific
+needs.
+
+    # Set these variables to suit your needs
+    NDK_PATH={full path to the NDK directory-- for example,
+      /opt/android/android-ndk-r16b}
+    TOOLCHAIN={"gcc" or "clang"-- "gcc" must be used with NDK r14b and earlier,
+      and "clang" must be used with NDK r17c and later}
+    ANDROID_VERSION={The minimum version of Android to support-- for example,
+      "16", "19", etc.}
+
+    cd {build_directory}
+    cmake -G"Unix Makefiles" \
+      -DANDROID_ABI=x86 \
+      -DANDROID_PLATFORM=android-${ANDROID_VERSION} \
+      -DANDROID_TOOLCHAIN=${TOOLCHAIN} \
+      -DCMAKE_TOOLCHAIN_FILE=${NDK_PATH}/build/cmake/android.toolchain.cmake \
+      [additional CMake flags] {source_directory}
+    make
+
+
+### x86-64 (64-bit)
+
+The following is a general recipe script that can be modified for your specific
+needs.
+
+    # Set these variables to suit your needs
+    NDK_PATH={full path to the NDK directory-- for example,
+      /opt/android/android-ndk-r16b}
+    TOOLCHAIN={"gcc" or "clang"-- "gcc" must be used with NDK r14b and earlier,
+      and "clang" must be used with NDK r17c and later}
+    ANDROID_VERSION={the minimum version of Android to support.  "21" or later
+      is required for a 64-bit build.}
+
+    cd {build_directory}
+    cmake -G"Unix Makefiles" \
+      -DANDROID_ABI=x86_64 \
+      -DANDROID_PLATFORM=android-${ANDROID_VERSION} \
+      -DANDROID_TOOLCHAIN=${TOOLCHAIN} \
+      -DCMAKE_TOOLCHAIN_FILE=${NDK_PATH}/build/cmake/android.toolchain.cmake \
+      [additional CMake flags] {source_directory}
+    make
+
+
+Advanced CMake Options
+----------------------
 
-Arithmetic Coding Support
--------------------------
+To list and configure other CMake options not specifically mentioned in this
+guide, run
 
-Since the patent on arithmetic coding has expired, this functionality has been
-included in this release of libjpeg-turbo.  libjpeg-turbo's implementation is
-based on the implementation in libjpeg v8, but it works when emulating libjpeg
-v7 or v6b as well.  The default is to enable both arithmetic encoding and
-decoding, but those who have philosophical objections to arithmetic coding can
-add "-DWITH_ARITH_ENC=0" or "-DWITH_ARITH_DEC=0" to the cmake command line to
-disable encoding or decoding (respectively.)
+    ccmake {source_directory}
 
+or
 
-TurboJPEG Java Wrapper
-----------------------
-Add "-DWITH_JAVA=1" to the cmake command line to incorporate an optional Java
-Native Interface wrapper into the TurboJPEG shared library and build the Java
-front-end classes to support it.  This allows the TurboJPEG shared library to
-be used directly from Java applications.  See java/README for more details.
+    cmake-gui {source_directory}
 
-If you are using CMake 2.8, you can set the Java_JAVAC_EXECUTABLE,
-Java_JAVA_EXECUTABLE, and Java_JAR_EXECUTABLE CMake variables to specify
-alternate commands or locations for javac, jar, and java (respectively.)  If
-you are using CMake 2.6, set JAVA_COMPILE, JAVA_RUNTIME, and JAVA_ARCHIVE
-instead.  You can also set the JAVACFLAGS CMake variable to specify arguments
-that should be passed to the Java compiler when building the front-end classes.
+from the build directory after initially configuring the build.  CCMake is a
+text-based interactive version of CMake, and CMake-GUI is a GUI version.  Both
+will display all variables that are relevant to the libjpeg-turbo build, their
+current values, and a help string describing what they do.
 
 
-========================
 Installing libjpeg-turbo
 ========================
 
-You can use the build system to install libjpeg-turbo into a directory of your
-choosing (as opposed to creating an installer.)  To do this, add:
-
-  -DCMAKE_INSTALL_PREFIX={install_directory}
+You can use the build system to install libjpeg-turbo (as opposed to creating
+an installer package.)  To do this, run `make install` or `nmake install`
+(or build the "install" target in the Visual Studio IDE.)  Running
+`make uninstall` or `nmake uninstall` (or building the "uninstall" target in
+the Visual Studio IDE) will uninstall libjpeg-turbo.
 
-to the cmake command line.
+The `CMAKE_INSTALL_PREFIX` CMake variable can be modified in order to install
+libjpeg-turbo into a directory of your choosing.  If you don't specify
+`CMAKE_INSTALL_PREFIX`, then the default is:
 
-For example,
+**c:\libjpeg-turbo**<br>
+Visual Studio 32-bit build
 
-  cmake -G "NMake Makefiles" -DCMAKE_BUILD_TYPE=Release \
-    -DCMAKE_INSTALL_PREFIX=c:\libjpeg-turbo {source_directory}
-  nmake install
+**c:\libjpeg-turbo64**<br>
+Visual Studio 64-bit build
 
-will install the header files in c:\libjpeg-turbo\include, the library files
-in c:\libjpeg-turbo\lib, the DLL's in c:\libjpeg-turbo\bin, and the
-documentation in c:\libjpeg-turbo\doc.
-
-
-=============
-Build Recipes
-=============
+**c:\libjpeg-turbo-gcc**<br>
+MinGW 32-bit build
 
+**c:\libjpeg-turbo-gcc64**<br>
+MinGW 64-bit build
 
-64-bit MinGW Build on Cygwin
-----------------------------
+**/opt/libjpeg-turbo**<br>
+Un*x
 
-  cd {build_directory}
-  CC=/usr/bin/x86_64-w64-mingw32-gcc \
-    cmake -G "Unix Makefiles" -DCMAKE_SYSTEM_NAME=Windows \
-    -DCMAKE_RC_COMPILER=/usr/bin/x86_64-w64-mingw32-windres.exe \
-    {source_directory}
-  make
+The default value of `CMAKE_INSTALL_PREFIX` causes the libjpeg-turbo files to
+be installed with a directory structure resembling that of the official
+libjpeg-turbo binary packages.  Changing the value of `CMAKE_INSTALL_PREFIX`
+(for instance, to **/usr/local**) causes the libjpeg-turbo files to be
+installed with a directory structure that conforms to GNU standards.
 
-This produces a 64-bit build of libjpeg-turbo that does not depend on
-cygwin1.dll or other Cygwin DLL's.  The mingw64-x86_64-gcc-core and
-mingw64-x86_64-gcc-g++ packages (and their dependencies) must be installed.
+The `CMAKE_INSTALL_BINDIR`, `CMAKE_INSTALL_DATAROOTDIR`,
+`CMAKE_INSTALL_DOCDIR`, `CMAKE_INSTALL_INCLUDEDIR`, `CMAKE_INSTALL_JAVADIR`,
+`CMAKE_INSTALL_LIBDIR`, and `CMAKE_INSTALL_MANDIR` CMake variables allow a
+finer degree of control over where specific files in the libjpeg-turbo
+distribution should be installed.  These directory variables can either be
+specified as absolute paths or as paths relative to `CMAKE_INSTALL_PREFIX` (for
+instance, setting `CMAKE_INSTALL_DOCDIR` to **doc** would cause the
+documentation to be installed in **${CMAKE\_INSTALL\_PREFIX}/doc**.)  If a
+directory variable contains the name of another directory variable in angle
+brackets, then its final value will depend on the final value of that other
+variable.  For instance, the default value of `CMAKE_INSTALL_MANDIR` is
+**\<CMAKE\_INSTALL\_DATAROOTDIR\>/man**.
 
+NOTE: If setting one of these directory variables to a relative path using the
+CMake command line, you must specify that the variable is of type `PATH`.
+For example:
 
-32-bit MinGW Build on Cygwin
-----------------------------
+    cmake -G"{generator type}" -DCMAKE_INSTALL_LIBDIR:PATH=lib {source_directory}
 
-  cd {build_directory}
-  CC=/usr/bin/i686-w64-mingw32-gcc \
-    cmake -G "Unix Makefiles" -DCMAKE_SYSTEM_NAME=Windows \
-    -DCMAKE_RC_COMPILER=/usr/bin/i686-w64-mingw32-windres.exe \
-    {source_directory}
-  make
+Otherwise, CMake will assume that the path is relative to the build directory
+rather than the install directory.
 
-This produces a 32-bit build of libjpeg-turbo that does not depend on
-cygwin1.dll or other Cygwin DLL's.  The mingw64-i686-gcc-core and
-mingw64-i686-gcc-g++ packages (and their dependencies) must be installed.
 
+Creating Distribution Packages
+==============================
 
-MinGW Build on Linux
---------------------
+The following commands can be used to create various types of distribution
+packages:
 
-  cd {build_directory}
-  CC={mingw_binary_path}/i386-mingw32-gcc \
-    cmake -G "Unix Makefiles" -DCMAKE_SYSTEM_NAME=Windows \
-    -DCMAKE_AR={mingw_binary_path}/i386-mingw32-ar \
-    -DCMAKE_RANLIB={mingw_binary_path}/i386-mingw32-ranlib \
-    {source_directory}
-  make
 
+Linux
+-----
 
-*******************************************************************************
-**     Creating Release Packages
-*******************************************************************************
-
-The following commands can be used to create various types of release packages:
+    make rpm
 
+Create Red Hat-style binary RPM package.  Requires RPM v4 or later.
 
-Unix/Linux
-----------
+    make srpm
 
-make rpm
+This runs `make dist` to create a pristine source tarball, then creates a
+Red Hat-style source RPM package from the tarball.  Requires RPM v4 or later.
 
-  Create Red Hat-style binary RPM package.  Requires RPM v4 or later.
+    make deb
 
-make srpm
+Create Debian-style binary package.  Requires dpkg.
 
-  This runs 'make dist' to create a pristine source tarball, then creates a
-  Red Hat-style source RPM package from the tarball.  Requires RPM v4 or later.
 
-make deb
+Mac
+---
 
-  Create Debian-style binary package.  Requires dpkg.
+    make dmg
 
-make dmg
+Create Mac package/disk image.  This requires pkgbuild and productbuild, which
+are installed by default on OS X 10.7 and later and which can be obtained by
+installing Xcode 3.2.6 (with the "Unix Development" option) on OS X 10.6.
+Packages built in this manner can be installed on OS X 10.5 and later, but they
+must be built on OS X 10.6 or later.
 
-  Create Macintosh package/disk image.  This requires pkgbuild and
-  productbuild, which are installed by default on OS X 10.7 and later and which
-  can be obtained by installing Xcode 3.2.6 (with the "Unix Development"
-  option) on OS X 10.6.  Packages built in this manner can be installed on OS X
-  10.5 and later, but they must be built on OS X 10.6 or later.
+    make udmg
 
-make udmg [BUILDDIR32={32-bit build directory}]
+This creates a Mac package/disk image that contains universal x86-64/i386/ARM
+binaries.  The following CMake variables control which architectures are
+included in the universal binaries.  Setting any of these variables to an empty
+string excludes that architecture from the package.
 
-  On 64-bit OS X systems, this creates a Macintosh package and disk image that
-  contains universal i386/x86-64 binaries.  You should first configure a 32-bit
-  out-of-tree build of libjpeg-turbo, then configure a 64-bit out-of-tree
-  build, then run 'make udmg' from the 64-bit build directory.  The build
-  system will look for the 32-bit build under {source_directory}/osxx86 by
-  default, but you can override this by setting the BUILDDIR32 variable on the
-  make command line as shown above.
+* `OSX_32BIT_BUILD`: Directory containing an i386 (32-bit) Mac build of
+  libjpeg-turbo (default: *{source_directory}*/osxx86)
+* `IOS_ARMV7_BUILD`: Directory containing an ARMv7 (32-bit) iOS build of
+  libjpeg-turbo (default: *{source_directory}*/iosarmv7)
+* `IOS_ARMV7S_BUILD`: Directory containing an ARMv7s (32-bit) iOS build of
+  libjpeg-turbo (default: *{source_directory}*/iosarmv7s)
+* `IOS_ARMV8_BUILD`: Directory containing an ARMv8 (64-bit) iOS build of
+  libjpeg-turbo (default: *{source_directory}*/iosarmv8)
 
-make iosdmg [BUILDDIR32={32-bit build directory}] \
-  [BUILDDIRARMV6={ARMv6 build directory}] \
-  [BUILDDIRARMV7={ARMv7 build directory}] \
-  [BUILDDIRARMV7S={ARMv7s build directory}] \
-  [BUILDDIRARMV8={ARMv8 build directory}]
+You should first use CMake to configure i386, ARMv7, ARMv7s, and/or ARMv8
+sub-builds of libjpeg-turbo (see "Build Recipes" and "Building libjpeg-turbo
+for iOS" above) in build directories that match those specified in the
+aforementioned CMake variables.  Next, configure the primary build of
+libjpeg-turbo as an out-of-tree build, and build it.  Once the primary build
+has been built, run `make udmg` from the build directory.  The packaging system
+will build the sub-builds, use lipo to combine them into a single set of
+universal binaries, then package the universal binaries in the same manner as
+`make dmg`.
 
-  On OS X systems, this creates a Macintosh package and disk image in which the
-  libjpeg-turbo static libraries contain ARM architectures necessary to build
-  iOS applications.  If building on an x86-64 system, the binaries will also
-  contain the i386 architecture, as with 'make udmg' above.  You should first
-  configure ARMv6, ARMv7, ARMv7s, and/or ARMv8 out-of-tree builds of
-  libjpeg-turbo (see "Building libjpeg-turbo for iOS" above.)  If you are
-  building an x86-64 version of libjpeg-turbo, you should configure a 32-bit
-  out-of-tree build as well.  Next, build libjpeg-turbo as you would normally,
-  using an out-of-tree build.  When it is built, run 'make iosdmg' from the
-  build directory.  The build system will look for the ARMv6 build under
-  {source_directory}/iosarmv6 by default, the ARMv7 build under
-  {source_directory}/iosarmv7 by default, the ARMv7s build under
-  {source_directory}/iosarmv7s by default, the ARMv8 build under
-  {source_directory}/iosarmv8 by default, and (if applicable) the 32-bit build
-  under {source_directory}/osxx86 by default, but you can override this by
-  setting the BUILDDIR32, BUILDDIRARMV6, BUILDDIRARMV7, BUILDDIRARMV7S, and/or
-  BUILDDIRARMV8 variables on the make command line as shown above.
 
-  NOTE: If including an ARMv8 build in the package, then you may need to use
-  Xcode's version of lipo instead of the operating system's.  To do this, pass
-  an argument of LIPO="xcrun lipo" on the make command line.
+Cygwin
+------
 
-make cygwinpkg
+    make cygwinpkg
 
-  Build a Cygwin binary package.
+Build a Cygwin binary package.
 
 
 Windows
@@ -830,47 +778,48 @@ Windows
 
 If using NMake:
 
-  cd {build_directory}
-  nmake installer
+    cd {build_directory}
+    nmake installer
 
 If using MinGW:
 
-  cd {build_directory}
-  make installer
-
-If using the Visual Studio IDE, build the "installer" project.
+    cd {build_directory}
+    make installer
 
-The installer package (libjpeg-turbo[-gcc][64].exe) will be located under
-{build_directory}.  If building using the Visual Studio IDE, then the installer
-package will be located in a subdirectory with the same name as the
-configuration you built (such as {build_directory}\Debug\ or
-{build_directory}\Release\).
+If using the Visual Studio IDE, build the "installer" target.
 
-Building a Windows installer requires the Nullsoft Install System
-(http://nsis.sourceforge.net/.)  makensis.exe should be in your PATH.
+The installer package (libjpeg-turbo-*{version}*[-gcc|-vc][64].exe) will be
+located under *{build_directory}*.  If building using the Visual Studio IDE,
+then the installer package will be located in a subdirectory with the same name
+as the configuration you built (such as *{build_directory}*\Debug\ or
+*{build_directory}*\Release\).
 
+Building a Windows installer requires the
+[Nullsoft Install System](http://nsis.sourceforge.net/).  makensis.exe should
+be in your `PATH`.
 
-*******************************************************************************
-**     Regression testing
-*******************************************************************************
 
-The most common way to test libjpeg-turbo is by invoking 'make test' on
-Unix/Linux platforms or 'ctest' on Windows platforms, once the build has
-completed.  This runs a series of tests to ensure that mathematical
-compatibility has been maintained between libjpeg-turbo and libjpeg v6b.  This
-also invokes the TurboJPEG unit tests, which ensure that the colorspace
-extensions, YUV encoding, decompression scaling, and other features of the
-TurboJPEG C and Java APIs are working properly (and, by extension, that the
-equivalent features of the underlying libjpeg API are also working.)
-
-Invoking 'make testclean' or 'nmake testclean' (if using NMake) or building
-the 'testclean' target (if using the Visual Studio IDE) will clean up the
-output images generated by 'make test'.
+Regression testing
+==================
 
-On Unix/Linux platforms, more extensive tests of the TurboJPEG C and Java
-wrappers can be run by invoking 'make tjtest'.  These extended TurboJPEG tests
+The most common way to test libjpeg-turbo is by invoking `make test` (Un*x) or
+`nmake test` (Windows command line) or by building the "RUN_TESTS" target
+(Visual Studio IDE), once the build has completed.  This runs a series of tests
+to ensure that mathematical compatibility has been maintained between
+libjpeg-turbo and libjpeg v6b.  This also invokes the TurboJPEG unit tests,
+which ensure that the colorspace extensions, YUV encoding, decompression
+scaling, and other features of the TurboJPEG C and Java APIs are working
+properly (and, by extension, that the equivalent features of the underlying
+libjpeg API are also working.)
+
+Invoking `make testclean` (Un*x) or `nmake testclean` (Windows command line) or
+building the "testclean" target (Visual Studio IDE) will clean up the output
+images generated by the tests.
+
+On Un*x platforms, more extensive tests of the TurboJPEG C and Java wrappers
+can be run by invoking `make tjtest`.  These extended TurboJPEG tests
 essentially iterate through all of the available features of the TurboJPEG APIs
-that are not covered by the TurboJPEG unit tests (this includes the lossless
+that are not covered by the TurboJPEG unit tests (including the lossless
 transform options) and compare the images generated by each feature to images
 generated using the equivalent feature in the libjpeg API.  The extended
 TurboJPEG tests are meant to test for regressions in the TurboJPEG wrappers,