Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Have the Makefile handle the MozJPEG dependency if it's not on the user's system. #81

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
*.exe
src/*.o
src/iqa/.svn
src/iqa/build
src/mozjpeg
jpeg-recompress
jpeg-compare
jpeg-hash
Expand Down
10 changes: 0 additions & 10 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
61 changes: 25 additions & 36 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand 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
62 changes: 36 additions & 26 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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
Expand All @@ -229,4 +239,4 @@ License

All are released under an MIT license.

http://dgt.mit-license.org/
http://dgt.mit-license.org/
10 changes: 2 additions & 8 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 18 additions & 0 deletions find_mozjpeg.mk
Original file line number Diff line number Diff line change
@@ -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
50 changes: 50 additions & 0 deletions mozjpeg.mk
Original file line number Diff line number Diff line change
@@ -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