From be64ab7b04cf8041bc9127e866c4936b9e18ffdf Mon Sep 17 00:00:00 2001 From: "K. Adam Christensen" Date: Wed, 31 Jan 2018 10:54:49 -0800 Subject: [PATCH 01/11] Have the Makefile download and build the mozjpeg dependency. --- .gitignore | 1 + .travis.yml | 10 ------- Makefile | 75 ++++++++++++++++++++++++++++++++++------------------ README.md | 68 ++++++++++++++++++++++------------------------- appveyor.yml | 10 ++----- 5 files changed, 84 insertions(+), 80 deletions(-) diff --git a/.gitignore b/.gitignore index a56bdc4..69d4f31 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,7 @@ src/*.o src/iqa/.svn src/iqa/build +src/mozjpeg jpeg-recompress jpeg-compare jpeg-hash diff --git a/.travis.yml b/.travis.yml index 3a910a4..2c2228c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,15 +5,5 @@ compiler: before_install: - sudo apt-get update -qq - sudo apt-get install -qq build-essential autoconf nasm - - git clone https://github.com/mozilla/mozjpeg.git - - cd mozjpeg - - git fetch origin refs/tags/v3.2:refs/tags/v3.2 - - git fetch --all - - git checkout tags/v3.2 - - autoreconf -fiv - - ./configure --with-jpeg8 - - make && sudo make install - - sudo ln -s /opt/mozjpeg/lib64 /opt/mozjpeg/lib - - cd .. script: - make && make test && cd test && ./test.sh diff --git a/Makefile b/Makefile index d1a2580..e65b14b 100644 --- a/Makefile +++ b/Makefile @@ -2,51 +2,69 @@ CC ?= gcc CFLAGS += -std=c99 -Wall -O3 LDFLAGS += -lm MAKE ?= make +AUTORECONF ?= autoreconf +CMAKE ?= cmake PREFIX ?= /usr/local UNAME_S := $(shell uname -s) - ifeq ($(UNAME_S),Linux) - # Linux (e.g. Ubuntu) - MOZJPEG_PREFIX ?= /opt/mozjpeg - CFLAGS += -I$(MOZJPEG_PREFIX)/include - LIBJPEG = $(MOZJPEG_PREFIX)/lib/libjpeg.a + OS = Unixy else ifeq ($(UNAME_S),Darwin) - # Mac OS X - MOZJPEG_PREFIX ?= /usr/local/opt/mozjpeg - LIBJPEG = $(MOZJPEG_PREFIX)/lib/libjpeg.a - CFLAGS += -I$(MOZJPEG_PREFIX)/include + OS = Unixy else ifeq ($(UNAME_S),FreeBSD) - # FreeBSD - LIBJPEG = $(PREFIX)/lib/mozjpeg/libjpeg.so - CFLAGS += -I$(PREFIX)/include/mozjpeg + OS = Unixy +else + OS = Windows +endif + +ifeq ($(OS),Unixy) + LIBJPEG = src/mozjpeg/.libs/libjpeg.a else - # Windows - LIBJPEG = ../mozjpeg/libjpeg.a - CFLAGS += -I../mozjpeg + LIBJPEG = src/mozjpeg/libjpeg.a endif +CFLAGS += -Isrc/mozjpeg LIBIQA=src/iqa/build/release/libiqa.a all: jpeg-recompress jpeg-compare jpeg-hash +src/mozjpeg: + git clone -b v3.3.1 --single-branch https://github.com/mozilla/mozjpeg.git $@ + +$(LIBJPEG): src/mozjpeg +ifeq ($(OS),Unixy) + cd $< && \ + $(AUTORECONF) -fiv && \ + ./configure --with-jpeg8 && \ + $(MAKE) +else + cd $< && \ + $(CMAKE) -G "MSYS Makefiles" \ + -DCMAKE_C_COMPILER=$(CC) \ + -DCMAKE_MAKE_PROGRAM=$(MAKE) \ + -DCMAKE_BUILD_TYPE=RELWITHDEBINFO \ + -DWITH_JPEG8=1 . && \ + $(MAKE) +endif + touch $@ + $(LIBIQA): cd src/iqa; RELEASE=1 $(MAKE) -jpeg-recompress: jpeg-recompress.c src/util.o src/edit.o src/smallfry.o src/commander.o $(LIBIQA) - $(CC) $(CFLAGS) -o $@ $^ $(LIBJPEG) $(LDFLAGS) +jpeg-recompress: jpeg-recompress.c src/util.o src/edit.o src/smallfry.o src/commander.o $(LIBIQA) $(LIBJPEG) + $(CC) $(CFLAGS) -o $@ $^ $(LDFLAGS) -jpeg-compare: jpeg-compare.c src/util.o src/hash.o src/edit.o src/commander.o src/smallfry.o $(LIBIQA) - $(CC) $(CFLAGS) -o $@ $^ $(LIBJPEG) $(LDFLAGS) +jpeg-compare: jpeg-compare.c src/util.o src/hash.o src/edit.o src/commander.o src/smallfry.o $(LIBIQA) $(LIBJPEG) + $(CC) $(CFLAGS) -o $@ $^ $(LDFLAGS) -jpeg-hash: jpeg-hash.c src/util.o src/hash.o src/commander.o - $(CC) $(CFLAGS) -o $@ $^ $(LIBJPEG) $(LDFLAGS) +jpeg-hash: jpeg-hash.c src/util.o src/hash.o src/commander.o $(LIBJPEG) + $(CC) $(CFLAGS) -o $@ $^ $(LDFLAGS) -%.o: %.c %.h +%.o: %.c %.h src/mozjpeg $(CC) $(CFLAGS) -c -o $@ $< -test: test/test.c src/util.o src/edit.o src/hash.o - $(CC) $(CFLAGS) -o test/$@ $^ $(LIBJPEG) $(LDFLAGS) +test: test/test.c src/util.o src/edit.o src/hash.o $(LIBJPEG) + $(CC) $(CFLAGS) -o test/$@ $^ $(LDFLAGS) ./test/$@ install: all @@ -57,6 +75,13 @@ install: all cp jpeg-hash $(PREFIX)/bin/ clean: - rm -rf jpeg-recompress jpeg-compare jpeg-hash test/test src/*.o src/iqa/build + rm -rf \ + jpeg-recompress \ + jpeg-compare \ + jpeg-hash \ + test/test \ + src/*.o \ + src/iqa/build \ + src/mozjpeg .PHONY: test install clean diff --git a/README.md b/README.md index 371e221..92c3634 100644 --- a/README.md +++ b/README.md @@ -138,72 +138,66 @@ jpeg-hash image.jpg Building -------- + ### Dependencies - * [mozjpeg](https://github.com/mozilla/mozjpeg) + * GCC or Clang + * Make + * [MozJPEG](https://github.com/mozilla/mozjpeg) dependencies + - nasm + - Unix-based only + - autoconf + - automake + - libtool + - Windows only + - cmake #### Ubuntu Ubuntu users can install via `apt-get`: ```bash sudo apt-get install build-essential autoconf pkg-config nasm libtool -git clone https://github.com/mozilla/mozjpeg.git -cd mozjpeg -autoreconf -fiv -./configure --with-jpeg8 -make -sudo make install ``` #### Mac OS X Mac users can install it via [Homebrew](http://brew.sh/): ```bash -brew install mozjpeg +brew install autoconf automake libtool pkg-config nasm +``` + +or via [MacPorts](https://www.macports.org/): + +```bash +sudo port install autoconf automake libtool pkg-config nasm ``` #### FreeBSD ```bash -pkg install mozjpeg -git clone https://github.com/danielgtaylor/jpeg-archive.git -cd jpeg-archive/ -gmake -sudo gmake install +pkg install autoconf automake libtool pkg-config nasm ``` #### Windows -The `Makefile` should work with MinGW/Cygwin/etc and standard GCC. Patches welcome. -To get everything you need to build, install these: +Recommend using [Chocolatey](https://chocolatey.org/). -* [CMake](http://www.cmake.org/files/v3.0/cmake-3.0.0-win32-x86.exe) -* [NASM](http://www.nasm.us/pub/nasm/releasebuilds/2.11.05/win32/) -* [MinGW](http://sourceforge.net/projects/mingw-w64/files/Toolchains%20targetting%20Win32/Personal%20Builds/mingw-builds/installer/mingw-w64-install.exe/download) (installed to e.g. `C:\mingw`) -* [Github for Windows](https://windows.github.com/) +```bash +choco install /y cmake mingw nasm git +``` -Run Github for windows. In the settings, set **Git Bash** as the shell. Open Git Shell from the start menu. +Run the `Git Bash` cmd app. ```bash # Update PATH to include MinGW/NASM bin folder, location on your system may vary -export PATH=$PATH:/c/mingw/mingw32/bin:/c/Program\ Files \(x68\)/nasm - -# Build mozjpeg or download https://www.dropbox.com/s/98jppfgds2xjblu/libjpeg.a -git clone https://github.com/mozilla/mozjpeg.git -cd mozjpeg -cmake -G "MSYS Makefiles" -D CMAKE_C_COMPILER=/c/mingw/bin/gcc.exe -D CMAKE_MAKE_PROGRAM=/c/mingw/bin/mingw32-make.exe -DWITH_JPEG8=1 . -mingw32-make -cd .. - -# Build jpeg-archive -git clone https://github.com/danielgtaylor/jpeg-archive -cd jpeg-archive -CC=gcc mingw32-make +export PATH=$PATH:/c/tools/mingw64//bin:/c/Program\ Files/NASM ``` -JPEG-Archive should now be built. +Or export these to your Windows path and restart `Git Bash`. + +### Compiling -### Compiling (Linux and Mac OS X) -The `Makefile` should work as-is on Ubuntu and Mac OS X. Other platforms may need to set the location of `libjpeg.a` or make other tweaks. +Simply run make. The Makefile will download the MozJPEG dependency for you, +build it, and then use that to link against. ```bash make @@ -229,4 +223,4 @@ License All are released under an MIT license. -http://dgt.mit-license.org/ +http://dgt.mit-license.org/ \ No newline at end of file diff --git a/appveyor.yml b/appveyor.yml index cd6ffc6..348781a 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -2,16 +2,10 @@ version: '{build}' environment: CC: gcc install: -- cinst mingw -- cd %APPVEYOR_BUILD_FOLDER%\.. -- mkdir mozjpeg -- cd mozjpeg -- appveyor DownloadFile https://www.dropbox.com/s/b551b2a1qle5urf/mozjpeg.zip?dl=1 -- 7z e mozjpeg.zip -y > extract.log +- cinst mingw cmake nasm build_script: +- set PATH=%PATH%;C:\tools\mingw64\bin;C:\Program Files\NASM;C:\Program Files\CMake\bin - cd %APPVEYOR_BUILD_FOLDER% -- cd -- set PATH=%PATH%;C:\tools\mingw64\bin - mingw32-make after_build: - 7z a jpeg-archive.zip %APPVEYOR_BUILD_FOLDER%\*.exe From ba12295c444fa89edec20070c778e12c2753d461 Mon Sep 17 00:00:00 2001 From: "K. Adam Christensen" Date: Wed, 31 Jan 2018 11:27:07 -0800 Subject: [PATCH 02/11] Need to configure src/mozjpeg separate from building the libjpeg.a --- .gitignore | 1 + Makefile | 15 +++++++-------- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/.gitignore b/.gitignore index 69d4f31..c548f37 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ +*.exe src/*.o src/iqa/.svn src/iqa/build diff --git a/Makefile b/Makefile index e65b14b..74fd758 100644 --- a/Makefile +++ b/Makefile @@ -30,22 +30,21 @@ all: jpeg-recompress jpeg-compare jpeg-hash src/mozjpeg: git clone -b v3.3.1 --single-branch https://github.com/mozilla/mozjpeg.git $@ - -$(LIBJPEG): src/mozjpeg ifeq ($(OS),Unixy) - cd $< && \ + cd $@ && \ $(AUTORECONF) -fiv && \ - ./configure --with-jpeg8 && \ - $(MAKE) + ./configure --with-jpeg8 else - cd $< && \ + cd $@ && \ $(CMAKE) -G "MSYS Makefiles" \ -DCMAKE_C_COMPILER=$(CC) \ -DCMAKE_MAKE_PROGRAM=$(MAKE) \ -DCMAKE_BUILD_TYPE=RELWITHDEBINFO \ - -DWITH_JPEG8=1 . && \ - $(MAKE) + -DWITH_JPEG8=1 . endif + +$(LIBJPEG): src/mozjpeg + cd $< && $(MAKE) touch $@ $(LIBIQA): From 78baae6fd4441dd54554a420726d6a2461dd1afe Mon Sep 17 00:00:00 2001 From: "K. Adam Christensen" Date: Wed, 31 Jan 2018 12:32:44 -0800 Subject: [PATCH 03/11] The dependency on src/mozjpeg should be an order-only dependency. --- Makefile | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index 74fd758..6a9503a 100644 --- a/Makefile +++ b/Makefile @@ -43,8 +43,8 @@ else -DWITH_JPEG8=1 . endif -$(LIBJPEG): src/mozjpeg - cd $< && $(MAKE) +$(LIBJPEG): | src/mozjpeg + cd $| && $(MAKE) touch $@ $(LIBIQA): @@ -59,7 +59,7 @@ jpeg-compare: jpeg-compare.c src/util.o src/hash.o src/edit.o src/commander.o sr jpeg-hash: jpeg-hash.c src/util.o src/hash.o src/commander.o $(LIBJPEG) $(CC) $(CFLAGS) -o $@ $^ $(LDFLAGS) -%.o: %.c %.h src/mozjpeg +%.o: %.c %.h | src/mozjpeg $(CC) $(CFLAGS) -c -o $@ $< test: test/test.c src/util.o src/edit.o src/hash.o $(LIBJPEG) From 21b4e5b3bd2b586e40e591e57966b348b04ad63f Mon Sep 17 00:00:00 2001 From: "K. Adam Christensen" Date: Wed, 31 Jan 2018 12:36:19 -0800 Subject: [PATCH 04/11] Break clean into two phases - fullclean and clean. `clean` removes build files created by the managed source. `fullclean` does that AND removes external dependencies. --- Makefile | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index 6a9503a..513763d 100644 --- a/Makefile +++ b/Makefile @@ -80,7 +80,9 @@ clean: jpeg-hash \ test/test \ src/*.o \ - src/iqa/build \ - src/mozjpeg + src/iqa/build -.PHONY: test install clean +fullclean: clean + rm -rf src/mozjpeg + +.PHONY: test install clean fullclean From ba087be37d2be1dae9a66c178b1cd0573120116e Mon Sep 17 00:00:00 2001 From: "K. Adam Christensen" Date: Wed, 31 Jan 2018 13:41:11 -0800 Subject: [PATCH 05/11] Don't need to touch libjpeg.a anymore. --- Makefile | 1 - 1 file changed, 1 deletion(-) diff --git a/Makefile b/Makefile index 513763d..4d103f1 100644 --- a/Makefile +++ b/Makefile @@ -45,7 +45,6 @@ endif $(LIBJPEG): | src/mozjpeg cd $| && $(MAKE) - touch $@ $(LIBIQA): cd src/iqa; RELEASE=1 $(MAKE) From 5ec1804382c73d55ba781b6469ae462dacc9c332 Mon Sep 17 00:00:00 2001 From: "K. Adam Christensen" Date: Wed, 31 Jan 2018 13:57:16 -0800 Subject: [PATCH 06/11] Try to speed up the build. --- .travis.yml | 3 +++ appveyor.yml | 1 + 2 files changed, 4 insertions(+) diff --git a/.travis.yml b/.travis.yml index 2c2228c..c9abec6 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,6 +2,9 @@ language: c compiler: - clang - gcc +env: + global: + - MAKEFLAGS="-j2 -l2" before_install: - sudo apt-get update -qq - sudo apt-get install -qq build-essential autoconf nasm diff --git a/appveyor.yml b/appveyor.yml index 348781a..4b5663a 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -6,6 +6,7 @@ install: build_script: - set PATH=%PATH%;C:\tools\mingw64\bin;C:\Program Files\NASM;C:\Program Files\CMake\bin - cd %APPVEYOR_BUILD_FOLDER% +- set MAKEFLAGS=-j2 -l2 - mingw32-make after_build: - 7z a jpeg-archive.zip %APPVEYOR_BUILD_FOLDER%\*.exe From 82666536cac2894aeb051ff00e1e7c1db049f154 Mon Sep 17 00:00:00 2001 From: "K. Adam Christensen" Date: Wed, 31 Jan 2018 14:09:06 -0800 Subject: [PATCH 07/11] Just set job number for MAKEFLAGS, not load. --- .travis.yml | 2 +- appveyor.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index c9abec6..6f93906 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,7 +4,7 @@ compiler: - gcc env: global: - - MAKEFLAGS="-j2 -l2" + - MAKEFLAGS="-j 2" before_install: - sudo apt-get update -qq - sudo apt-get install -qq build-essential autoconf nasm diff --git a/appveyor.yml b/appveyor.yml index 4b5663a..f3f6e19 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -6,7 +6,7 @@ install: build_script: - set PATH=%PATH%;C:\tools\mingw64\bin;C:\Program Files\NASM;C:\Program Files\CMake\bin - cd %APPVEYOR_BUILD_FOLDER% -- set MAKEFLAGS=-j2 -l2 +- set MAKEFLAGS=-j 2 - mingw32-make after_build: - 7z a jpeg-archive.zip %APPVEYOR_BUILD_FOLDER%\*.exe From bcc79f5e2081cacbb25db072f493f09f0603547f Mon Sep 17 00:00:00 2001 From: "K. Adam Christensen" Date: Wed, 31 Jan 2018 14:58:25 -0800 Subject: [PATCH 08/11] Use Release version of MozJPEG on Windows. --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 4d103f1..7b471d4 100644 --- a/Makefile +++ b/Makefile @@ -39,7 +39,7 @@ else $(CMAKE) -G "MSYS Makefiles" \ -DCMAKE_C_COMPILER=$(CC) \ -DCMAKE_MAKE_PROGRAM=$(MAKE) \ - -DCMAKE_BUILD_TYPE=RELWITHDEBINFO \ + -DCMAKE_BUILD_TYPE=RELEASE \ -DWITH_JPEG8=1 . endif From 9270ea827ecf4e6ef01f4dc8734b691480aafcff Mon Sep 17 00:00:00 2001 From: "K. Adam Christensen" Date: Wed, 31 Jan 2018 14:58:40 -0800 Subject: [PATCH 09/11] remove MAKEFLAGS stuff. It's not doing anything special. --- .travis.yml | 3 --- appveyor.yml | 1 - 2 files changed, 4 deletions(-) diff --git a/.travis.yml b/.travis.yml index 6f93906..2c2228c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,9 +2,6 @@ language: c compiler: - clang - gcc -env: - global: - - MAKEFLAGS="-j 2" before_install: - sudo apt-get update -qq - sudo apt-get install -qq build-essential autoconf nasm diff --git a/appveyor.yml b/appveyor.yml index f3f6e19..348781a 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -6,7 +6,6 @@ install: build_script: - set PATH=%PATH%;C:\tools\mingw64\bin;C:\Program Files\NASM;C:\Program Files\CMake\bin - cd %APPVEYOR_BUILD_FOLDER% -- set MAKEFLAGS=-j 2 - mingw32-make after_build: - 7z a jpeg-archive.zip %APPVEYOR_BUILD_FOLDER%\*.exe From 1a6bcdbb0e78fe5a546b0d7d08be837d36fe610f Mon Sep 17 00:00:00 2001 From: "K. Adam Christensen" Date: Tue, 6 Feb 2018 18:37:23 -0800 Subject: [PATCH 10/11] Only compile and pull in mozjpeg if it's not already installed locally. --- Makefile | 48 +++++++----------------------------------------- find_mozjpeg.mk | 18 ++++++++++++++++++ mozjpeg.mk | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 73 insertions(+), 41 deletions(-) create mode 100644 find_mozjpeg.mk create mode 100644 mozjpeg.mk diff --git a/Makefile b/Makefile index 7b471d4..3f80e54 100644 --- a/Makefile +++ b/Makefile @@ -2,49 +2,18 @@ CC ?= gcc CFLAGS += -std=c99 -Wall -O3 LDFLAGS += -lm MAKE ?= make -AUTORECONF ?= autoreconf -CMAKE ?= cmake PREFIX ?= /usr/local -UNAME_S := $(shell uname -s) -ifeq ($(UNAME_S),Linux) - OS = Unixy -else ifeq ($(UNAME_S),Darwin) - OS = Unixy -else ifeq ($(UNAME_S),FreeBSD) - OS = Unixy -else - OS = Windows -endif - -ifeq ($(OS),Unixy) - LIBJPEG = src/mozjpeg/.libs/libjpeg.a -else - LIBJPEG = src/mozjpeg/libjpeg.a -endif -CFLAGS += -Isrc/mozjpeg - -LIBIQA=src/iqa/build/release/libiqa.a +DIR_DEPS = all: jpeg-recompress jpeg-compare jpeg-hash -src/mozjpeg: - git clone -b v3.3.1 --single-branch https://github.com/mozilla/mozjpeg.git $@ -ifeq ($(OS),Unixy) - cd $@ && \ - $(AUTORECONF) -fiv && \ - ./configure --with-jpeg8 -else - cd $@ && \ - $(CMAKE) -G "MSYS Makefiles" \ - -DCMAKE_C_COMPILER=$(CC) \ - -DCMAKE_MAKE_PROGRAM=$(MAKE) \ - -DCMAKE_BUILD_TYPE=RELEASE \ - -DWITH_JPEG8=1 . +include find_mozjpeg.mk +ifeq ($(MOZJPEG_FOUND),0) +include mozjpeg.mk endif -$(LIBJPEG): | src/mozjpeg - cd $| && $(MAKE) +LIBIQA = src/iqa/build/release/libiqa.a $(LIBIQA): cd src/iqa; RELEASE=1 $(MAKE) @@ -58,7 +27,7 @@ jpeg-compare: jpeg-compare.c src/util.o src/hash.o src/edit.o src/commander.o sr jpeg-hash: jpeg-hash.c src/util.o src/hash.o src/commander.o $(LIBJPEG) $(CC) $(CFLAGS) -o $@ $^ $(LDFLAGS) -%.o: %.c %.h | src/mozjpeg +%.o: %.c %.h | $(DIR_DEPS) $(CC) $(CFLAGS) -c -o $@ $< test: test/test.c src/util.o src/edit.o src/hash.o $(LIBJPEG) @@ -81,7 +50,4 @@ clean: src/*.o \ src/iqa/build -fullclean: clean - rm -rf src/mozjpeg - -.PHONY: test install clean fullclean +.PHONY: test install clean diff --git a/find_mozjpeg.mk b/find_mozjpeg.mk new file mode 100644 index 0000000..156a452 --- /dev/null +++ b/find_mozjpeg.mk @@ -0,0 +1,18 @@ +MOZJPEG_FOUND := 0 + +ifndef MOZJPEG_PREFIX + ifneq ($(wildcard /opt/mozjpeg/*),) + MOZJPEG_FOUND = 1 + MOZJPEG_PREFIX = /opt/mozjpeg + else ifneq ($(wildcard /usr/local/opt/mozjpeg),) + MOZJPEG_FOUND = 1 + MOZJPEG_PREFIX = /usr/local/opt/mozjpeg + endif +else + MOZJPEG_FOUND = 1 +endif + +ifeq ($(MOZJPEG_FOUND),1) + CFLAGS += -I$(MOZJPEG_PREFIX)/include + LIBJPEG = $(wildcard $(MOZJPEG_PREFIX)/lib*/libjpeg.a)) +endif diff --git a/mozjpeg.mk b/mozjpeg.mk new file mode 100644 index 0000000..79f938e --- /dev/null +++ b/mozjpeg.mk @@ -0,0 +1,48 @@ +CMAKE ?= cmake +AUTORECONF ?= autoreconf + +DIR_DEPS += src/mozjpeg + +UNAME_S := $(shell uname -s) +ifeq ($(UNAME_S),Linux) + OS = Unixy +else ifeq ($(UNAME_S),Darwin) + OS = Unixy +else ifeq ($(UNAME_S),FreeBSD) + OS = Unixy +else + OS = Windows +endif + +ifeq ($(OS),Unixy) + LIBJPEG = src/mozjpeg/.libs/libjpeg.a +else + LIBJPEG = src/mozjpeg/libjpeg.a +endif +CFLAGS += -Isrc/mozjpeg + +src/mozjpeg: + git clone -b v3.3.1 --single-branch https://github.com/mozilla/mozjpeg.git $@ +ifeq ($(OS),Unixy) + cd $@ && \ + $(AUTORECONF) -fiv && \ + ./configure --with-jpeg8 +else + cd $@ && \ + $(CMAKE) -G "MSYS Makefiles" \ + -DCMAKE_C_COMPILER=$(CC) \ + -DCMAKE_MAKE_PROGRAM=$(MAKE) \ + -DCMAKE_BUILD_TYPE=RELEASE \ + -DWITH_JPEG8=1 . +endif + +$(LIBJPEG): | $(DIR_DEPS) + cd $| && $(MAKE) + +mozjpegclean: + cd src/mozjpeg && $(MAKE) clean + +fullclean: clean + rm -rf src/mozjpeg + +.PHONY: fullclean mozjpegclean From 29baa4b95a3278319c78be643798b56d1c45dccf Mon Sep 17 00:00:00 2001 From: "K. Adam Christensen" Date: Wed, 7 Feb 2018 09:40:30 -0800 Subject: [PATCH 11/11] Correct LIBJPEG. If we are using a preinstalled mozjpeg lib, then it cannot be declared as a dependency. --- Makefile | 11 +++++++---- find_mozjpeg.mk | 2 +- mozjpeg.mk | 2 ++ 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/Makefile b/Makefile index 3f80e54..a19d412 100644 --- a/Makefile +++ b/Makefile @@ -5,6 +5,7 @@ MAKE ?= make PREFIX ?= /usr/local DIR_DEPS = +LIB_DEPS = all: jpeg-recompress jpeg-compare jpeg-hash @@ -18,19 +19,21 @@ LIBIQA = src/iqa/build/release/libiqa.a $(LIBIQA): cd src/iqa; RELEASE=1 $(MAKE) -jpeg-recompress: jpeg-recompress.c src/util.o src/edit.o src/smallfry.o src/commander.o $(LIBIQA) $(LIBJPEG) +LIB_DEPS += $(LIBIQA) + +jpeg-recompress: jpeg-recompress.c src/util.o src/edit.o src/smallfry.o src/commander.o $(LIB_DEPS) $(CC) $(CFLAGS) -o $@ $^ $(LDFLAGS) -jpeg-compare: jpeg-compare.c src/util.o src/hash.o src/edit.o src/commander.o src/smallfry.o $(LIBIQA) $(LIBJPEG) +jpeg-compare: jpeg-compare.c src/util.o src/hash.o src/edit.o src/commander.o src/smallfry.o $(LIB_DEPS) $(CC) $(CFLAGS) -o $@ $^ $(LDFLAGS) -jpeg-hash: jpeg-hash.c src/util.o src/hash.o src/commander.o $(LIBJPEG) +jpeg-hash: jpeg-hash.c src/util.o src/hash.o src/commander.o $(LIB_DEPS) $(CC) $(CFLAGS) -o $@ $^ $(LDFLAGS) %.o: %.c %.h | $(DIR_DEPS) $(CC) $(CFLAGS) -c -o $@ $< -test: test/test.c src/util.o src/edit.o src/hash.o $(LIBJPEG) +test: test/test.c src/util.o src/edit.o src/hash.o $(LIB_DEPS) $(CC) $(CFLAGS) -o test/$@ $^ $(LDFLAGS) ./test/$@ diff --git a/find_mozjpeg.mk b/find_mozjpeg.mk index 156a452..9e97198 100644 --- a/find_mozjpeg.mk +++ b/find_mozjpeg.mk @@ -14,5 +14,5 @@ endif ifeq ($(MOZJPEG_FOUND),1) CFLAGS += -I$(MOZJPEG_PREFIX)/include - LIBJPEG = $(wildcard $(MOZJPEG_PREFIX)/lib*/libjpeg.a)) + LDFLAGS += $(wildcard $(MOZJPEG_PREFIX)/lib*/libjpeg.a) endif diff --git a/mozjpeg.mk b/mozjpeg.mk index 79f938e..7b5bd97 100644 --- a/mozjpeg.mk +++ b/mozjpeg.mk @@ -39,6 +39,8 @@ endif $(LIBJPEG): | $(DIR_DEPS) cd $| && $(MAKE) +LIB_DEPS += $(LIBJPEG) + mozjpegclean: cd src/mozjpeg && $(MAKE) clean