diff --git a/.gitignore b/.gitignore index a56bdc4..c548f37 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,8 @@ +*.exe 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 f9e7cd4..3dbddfb 100644 --- a/Makefile +++ b/Makefile @@ -4,54 +4,37 @@ LDFLAGS += -lm MAKE ?= make PREFIX ?= /usr/local -UNAME_S := $(shell uname -s) +DIR_DEPS = +LIB_DEPS = -ifeq ($(UNAME_S),Linux) - # Linux (e.g. Ubuntu) - MOZJPEG_PREFIX ?= /opt/mozjpeg - CFLAGS += -I$(MOZJPEG_PREFIX)/include +all: jpeg-recompress jpeg-compare jpeg-hash - ifneq ("$(wildcard $(MOZJPEG_PREFIX)/lib64/libjpeg.a)","") - LIBJPEG = $(MOZJPEG_PREFIX)/lib64/libjpeg.a - else - LIBJPEG = $(MOZJPEG_PREFIX)/lib/libjpeg.a - endif -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 -else ifeq ($(UNAME_S),FreeBSD) - # FreeBSD - LIBJPEG = $(PREFIX)/lib/mozjpeg/libjpeg.so - CFLAGS += -I$(PREFIX)/include/mozjpeg -else - # Windows - LIBJPEG = ../mozjpeg/libjpeg.a - CFLAGS += -I../mozjpeg +include find_mozjpeg.mk +ifeq ($(MOZJPEG_FOUND),0) +include mozjpeg.mk endif -LIBIQA=src/iqa/build/release/libiqa.a - -all: jpeg-recompress jpeg-compare jpeg-hash +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 $(LIBIQA) - $(CC) $(CFLAGS) -o $@ $^ $(LIBJPEG) $(LDFLAGS) +LIB_DEPS += $(LIBIQA) + +jpeg-recompress: jpeg-recompress.c src/util.o src/edit.o src/smallfry.o $(LIB_DEPS) + $(CC) $(CFLAGS) -o $@ $^ $(LDFLAGS) -jpeg-compare: jpeg-compare.c src/util.o src/hash.o src/edit.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/smallfry.o $(LIB_DEPS) + $(CC) $(CFLAGS) -o $@ $^ $(LDFLAGS) -jpeg-hash: jpeg-hash.c src/util.o src/hash.o - $(CC) $(CFLAGS) -o $@ $^ $(LIBJPEG) $(LDFLAGS) +jpeg-hash: jpeg-hash.c src/util.o src/hash.o $(LIB_DEPS) + $(CC) $(CFLAGS) -o $@ $^ $(LDFLAGS) -%.o: %.c %.h +%.o: %.c %.h | $(DIR_DEPS) $(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 $(LIB_DEPS) + $(CC) $(CFLAGS) -o test/$@ $^ $(LDFLAGS) ./test/$@ install: all @@ -62,6 +45,12 @@ 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 .PHONY: test install clean diff --git a/README.md b/README.md index adcd7e5..c453b47 100644 --- a/README.md +++ b/README.md @@ -138,40 +138,47 @@ 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: @@ -181,29 +188,32 @@ To get everything you need to build, install these: * [MinGW](https://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/) -Run Github for windows. In the settings, set **Git Bash** as the shell. Open Git Shell from the start menu. +Recommend using [Chocolatey](https://chocolatey.org/) to install and manage. + +```bash +choco install /y cmake mingw nasm git +``` + +Run the `Git Bash` cmd app. ```bash # Update PATH to include MinGW/NASM bin folder, location on your system may vary export PATH=/c/mingw/mingw32/bin:/c/Program\ Files \(x68\)/nasm:$PATH -# 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=gcc.exe -D CMAKE_MAKE_PROGRAM=mingw32-make.exe -D WITH_JPEG8=1 -mingw32-make -cd .. - -# Build jpeg-archive +# Get jpeg-archive git clone https://github.com/danielgtaylor/jpeg-archive + +# Build jpeg-archive. mozjpeg is downloaded and compiled automatically. cd jpeg-archive CC=gcc mingw32-make ``` -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 +239,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 diff --git a/find_mozjpeg.mk b/find_mozjpeg.mk new file mode 100644 index 0000000..9e97198 --- /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 + LDFLAGS += $(wildcard $(MOZJPEG_PREFIX)/lib*/libjpeg.a) +endif diff --git a/mozjpeg.mk b/mozjpeg.mk new file mode 100644 index 0000000..7b5bd97 --- /dev/null +++ b/mozjpeg.mk @@ -0,0 +1,50 @@ +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) + +LIB_DEPS += $(LIBJPEG) + +mozjpegclean: + cd src/mozjpeg && $(MAKE) clean + +fullclean: clean + rm -rf src/mozjpeg + +.PHONY: fullclean mozjpegclean