Commit f8b0fe79 authored by Andreas Tille's avatar Andreas Tille

New upstream version 2.8.2

parent 313ff529
*.dylib
*.mode1v3
*.o
*.lo
*.pbxproj
*.pbxuser
build
DerivedData
pngquant
lib/libimagequant.a
config.mk
test/test
[submodule "lib"]
path = lib
url = https://github.com/ImageOptim/libimagequant.git
version 2.8
-----------
- libimagequant is a separate project
- --strip option to disable copying of PNG metadata
version 2.7
-----------
- improved dithering of saturated and semitransparent colors
- fixed order of log output when using openmp
- improved quality sanity check in --skip-if-larger option
- disabled palette post-processing on colors from --map option to preserve them exactly
version 2.6
-----------
- when source image has no color profile information, the output won't have either
version 2.5 version 2.5
----------- -----------
- replaced color search algorithm with vantage point tree, which is much faster and more reliable - replaced color search algorithm with vantage point tree, which is much faster and more reliable
- deprecated IE6 workaround - deprecated IE6 workaround
- warn when compiled without color profile support
- Rust API for libimagequant
version 2.4 version 2.4
----------- -----------
- fixed remapping of bright colors when dithering - fixed remapping of bright colors when dithering
- added libimagequant API to add fixed preset colors to the palette
version 2.3 version 2.3
----------- -----------
......
# Contributor Covenant Code of Conduct
## Our Pledge
In the interest of fostering an open and welcoming environment, we as
contributors and maintainers pledge to making participation in our project and
our community a harassment-free experience for everyone, regardless of age, body
size, disability, ethnicity, gender identity and expression, level of experience,
nationality, personal appearance, race, religion, or sexual identity and
orientation.
## Our Standards
Examples of behavior that contributes to creating a positive environment
include:
* Using welcoming and inclusive language
* Being respectful of differing viewpoints and experiences
* Gracefully accepting constructive criticism
* Focusing on what is best for the community
* Showing empathy towards other community members
Examples of unacceptable behavior by participants include:
* The use of sexualized language or imagery and unwelcome sexual attention or
advances
* Trolling, insulting/derogatory comments, and personal or political attacks
* Public or private harassment
* Publishing others' private information, such as a physical or electronic
address, without explicit permission
* Other conduct which could reasonably be considered inappropriate in a
professional setting
## Our Responsibilities
Project maintainers are responsible for clarifying the standards of acceptable
behavior and are expected to take appropriate and fair corrective action in
response to any instances of unacceptable behavior.
Project maintainers have the right and responsibility to remove, edit, or
reject comments, commits, code, wiki edits, issues, and other contributions
that are not aligned to this Code of Conduct, or to ban temporarily or
permanently any contributor for other behaviors that they deem inappropriate,
threatening, offensive, or harmful.
## Scope
This Code of Conduct applies both within project spaces and in public spaces
when an individual is representing the project or its community. Examples of
representing a project or community include using an official project e-mail
address, posting via an official social media account, or acting as an appointed
representative at an online or offline event. Representation of a project may be
further defined and clarified by project maintainers.
## Enforcement
Instances of abusive, harassing, or otherwise unacceptable behavior may be
reported by contacting the project team at kornel@geekhood.net. All
complaints will be reviewed and investigated and will result in a response that
is deemed necessary and appropriate to the circumstances. The project team is
obligated to maintain confidentiality with regard to the reporter of an incident.
Further details of specific enforcement policies may be posted separately.
Project maintainers who do not follow or enforce the Code of Conduct in good
faith may face temporary or permanent repercussions as determined by other
members of the project's leadership.
## Attribution
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
available at [http://contributor-covenant.org/version/1/4][version]
[homepage]: http://contributor-covenant.org
[version]: http://contributor-covenant.org/version/1/4/
Thank you for contributing! pngquant and libimagequant are licensed under multiple
licensed, so to make things clear, I'm accepting contributions as licensed under
the BSD 2-clause license:
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
This diff is collapsed.
To build pngquant from source on Mac OS X and most Linux distributions, To get the code:
simply run:
$ git clone --recursive https://github.com/pornel/pngquant.git
To build pngquant from source on macOS and most Linux distributions, run:
$ make $ make
......
-include config.mk -include config.mk
BIN ?= pngquant BIN ?= pngquant
BINPREFIX = $(DESTDIR)$(PREFIX)/bin BINPREFIX ?= $(DESTDIR)$(PREFIX)/bin
MANPREFIX ?= $(DESTDIR)$(PREFIX)/share/man
OBJS = pngquant.o rwpng.o OBJS = pngquant.o rwpng.o
COCOA_OBJS = rwpng_cocoa.o COCOA_OBJS = rwpng_cocoa.o
...@@ -11,23 +12,27 @@ OBJS += $(COCOA_OBJS) ...@@ -11,23 +12,27 @@ OBJS += $(COCOA_OBJS)
endif endif
STATICLIB = lib/libimagequant.a STATICLIB = lib/libimagequant.a
SHAREDLIB = lib/libimagequant.so
DISTFILES = *.[chm] pngquant.1 Makefile configure README.md INSTALL CHANGELOG COPYRIGHT DISTFILES = *.[chm] pngquant.1 Makefile configure README.md INSTALL CHANGELOG COPYRIGHT
TARNAME = pngquant-$(VERSION) TARNAME = pngquant-$(VERSION)
TARFILE = $(TARNAME)-src.tar.bz2 TARFILE = $(TARNAME)-src.tar.gz
LIBDISTFILES = lib/*.[ch] lib/COPYRIGHT lib/MANUAL.md lib/configure lib/Makefile LIBDISTFILES = lib/*.[ch] lib/COPYRIGHT lib/README.md lib/configure lib/Makefile
DLL=libimagequant.dll TESTBIN = test/test
DLLIMP=libimagequant_dll.a
DLLDEF=libimagequant_dll.def
all: $(BIN) all: $(BIN)
staticlib: staticlib: $(STATICLIB)
$(STATICLIB): config.mk $(LIBDISTFILES)
$(MAKE) -C lib static $(MAKE) -C lib static
$(STATICLIB): config.mk staticlib sharedlib: lib/libimagequant.h
$(MAKE) -C lib shared
$(SHAREDLIB): config.mk sharedlib
$(OBJS): $(wildcard *.h) config.mk $(OBJS): $(wildcard *.h) config.mk
...@@ -37,8 +42,20 @@ rwpng_cocoa.o: rwpng_cocoa.m ...@@ -37,8 +42,20 @@ rwpng_cocoa.o: rwpng_cocoa.m
$(BIN): $(OBJS) $(STATICLIB) $(BIN): $(OBJS) $(STATICLIB)
$(CC) $^ $(CFLAGS) $(LDFLAGS) -o $@ $(CC) $^ $(CFLAGS) $(LDFLAGS) -o $@
test: $(BIN) $(TESTBIN): test/test.o $(STATICLIB)
./test/test.sh ./test $(BIN) $(CC) $^ $(CFLAGS) $(LDFLAGS) -o $@
test: $(BIN) $(TESTBIN)
./test/test.sh ./test $(BIN) $(TESTBIN)
bin.shared: $(OBJS) $(SHAREDLIB)
$(CC) $^ $(CFLAGS) $(LDFLAGS) -o $(BIN)
testbin.shared: test/test.o $(SHAREDLIB)
$(CC) $^ $(CFLAGS) $(LDFLAGS) -o $(TESTBIN)
test.shared: bin.shared testbin.shared
./test/test.sh ./test $(BIN) $(TESTBIN)
dist: $(TARFILE) dist: $(TARFILE)
...@@ -47,16 +64,19 @@ $(TARFILE): $(DISTFILES) ...@@ -47,16 +64,19 @@ $(TARFILE): $(DISTFILES)
mkdir -p $(TARNAME)/lib mkdir -p $(TARNAME)/lib
cp $(DISTFILES) $(TARNAME) cp $(DISTFILES) $(TARNAME)
cp $(LIBDISTFILES) $(TARNAME)/lib cp $(LIBDISTFILES) $(TARNAME)/lib
tar -cjf $(TARFILE) --numeric-owner --exclude='._*' $(TARNAME) tar -czf $(TARFILE) --numeric-owner --exclude='._*' $(TARNAME)
rm -rf $(TARNAME) rm -rf $(TARNAME)
-shasum $(TARFILE) -shasum $(TARFILE)
install: $(BIN) install: $(BIN) $(BIN).1
-mkdir -p '$(BINPREFIX)' -mkdir -p '$(BINPREFIX)'
-mkdir -p '$(MANPREFIX)/man1'
install -m 0755 -p '$(BIN)' '$(BINPREFIX)/$(BIN)' install -m 0755 -p '$(BIN)' '$(BINPREFIX)/$(BIN)'
install -m 0644 -p '$(BIN).1' '$(MANPREFIX)/man1/'
uninstall: uninstall:
rm -f '$(BINPREFIX)/$(BIN)' rm -f '$(BINPREFIX)/$(BIN)'
rm -f '$(MANPREFIX)/man1/$(BIN).1'
clean: clean:
$(MAKE) -C lib clean $(MAKE) -C lib clean
...@@ -64,12 +84,15 @@ clean: ...@@ -64,12 +84,15 @@ clean:
distclean: clean distclean: clean
$(MAKE) -C lib distclean $(MAKE) -C lib distclean
rm -f config.mk pngquant-*-src.tar.bz2 rm -f config.mk pngquant-*-src.tar.gz
config.mk: config.mk: lib/libimagequant.h
ifeq ($(filter %clean %distclean, $(MAKECMDGOALS)), ) ifeq ($(filter %clean %distclean, $(MAKECMDGOALS)), )
./configure ./configure
endif endif
lib/libimagequant.h:
git submodule init && git submodule update || true
.PHONY: all clean dist distclean dll install uninstall test staticlib .PHONY: all clean dist distclean dll install uninstall test staticlib
.DELETE_ON_ERROR: .DELETE_ON_ERROR:
#pngquant 2 # pngquant 2
This is the official `pngquant` and `libimagequant`. [pngquant](https://pngquant.org) converts 24/32-bit RGBA PNGs to 8-bit palette with *alpha channel preserved*.
Such images are fully standards-compliant and are supported by all web browsers.
[pngquant](http://pngquant.org) converts 24/32-bit RGBA PNGs to 8-bit palette with *alpha channel preserved*. Quantized files are often 60-80% smaller than their 24/32-bit versions.
Such images are compatible with all modern browsers, and a special compatibility setting exists which helps transparency degrade well in Internet Explorer 6.
Quantized files are often 40-70% smaller than their 24/32-bit version. This utility works on Linux, Mac OS X and Windows. [This](https://github.com/pornel/pngquant) is the official `pngquant` repository.
This utility works on Linux, Mac OS X and Windows. ## Usage
##Usage
- batch conversion of multiple files: `pngquant *.png` - batch conversion of multiple files: `pngquant *.png`
- Unix-style stdin/stdout chaining: `… | pngquant - | …` - Unix-style stdin/stdout chaining: `… | pngquant - | …`
To further reduce file size, try [optipng](http://optipng.sourceforge.net) or [ImageOptim](http://imageoptim.pornel.net). To further reduce file size, try [optipng](http://optipng.sourceforge.net), [ImageOptim](https://imageoptim.com), or [zopflipng](https://github.com/google/zopfli).
##Improvements since 1.0 ## Improvements since 1.0
Generated files are both smaller and look much better. Generated files are both smaller and look much better.
...@@ -24,74 +22,76 @@ Generated files are both smaller and look much better. ...@@ -24,74 +22,76 @@ Generated files are both smaller and look much better.
- more accurate remapping of semitransparent colors - more accurate remapping of semitransparent colors
- special dithering algorithm that does not add noise in well-quantized areas of the image - special dithering algorithm that does not add noise in well-quantized areas of the image
- uses variance instead of popularity for box selection (improvement suggested in the original median cut paper)
- feedback loop that repeats median cut for poorly quantized colors
- additional colormap improvement using Voronoi iteration
- supports much larger number of colors in input images without degradation of quality - supports much larger number of colors in input images without degradation of quality
- gamma correction (output is always generated with gamma 2.2 for web compatibility) - gamma correction and optional color profile support (output is always in gamma 2.2 for web compatibility)
* More flexible commandline usage
- number of colors defaults to 256
- long options and standard switches like `--` and `-` are allowed
* Refactored and modernised code * Refactored and modernised code
- C99 with no workarounds for old systems - quantization [moved to standalone libimagequant](https://github.com/ImageOptim/libimagequant)
- floating-point math used throughout - C99 with no workarounds for legacy systems or compilers ([apart from Visual Studio](https://github.com/pornel/pngquant/tree/msvc))
- Intel SSE optimisations - Intel SSE optimisations and floating-point math used throughout
- multicore support via OpenMP - multicore support via OpenMP
- quantization moved to standalone libimagequant
##Options ## Options
See `pngquant -h` for full list. See `pngquant -h` for full list.
###`--quality min-max` ### `--quality min-max`
`min` and `max` are numbers in range 0 (worst) to 100 (perfect), similar to JPEG. pngquant will use the least amount of colors required to meet or exceed the `max` quality. If conversion results in quality below the `min` quality the image won't be saved (if outputting to stdin, 24-bit original will be output) and pngquant will exit with status code 99. `min` and `max` are numbers in range 0 (worst) to 100 (perfect), similar to JPEG. pngquant will use the least amount of colors required to meet or exceed the `max` quality. If conversion results in quality below the `min` quality the image won't be saved (if outputting to stdin, 24-bit original will be output) and pngquant will exit with status code 99.
pngquant --quality=65-80 image.png pngquant --quality=65-80 image.png
###`--ext new.png` ### `--ext new.png`
Set custom extension (suffix) for output filename. By default `-or8.png` or `-fs8.png` is used. If you use `--ext=.png --force` options pngquant will overwrite input files in place (use with caution). Set custom extension (suffix) for output filename. By default `-or8.png` or `-fs8.png` is used. If you use `--ext=.png --force` options pngquant will overwrite input files in place (use with caution).
###`-o out.png` or `--output out.png` ### `-o out.png` or `--output out.png`
Writes converted file to the given path. When this option is used only single input file is allowed. Writes converted file to the given path. When this option is used only single input file is allowed.
###`--skip-if-larger` ### `--skip-if-larger`
Don't write converted files if the conversion isn't worth it. Don't write converted files if the conversion isn't worth it.
###`--speed N` ### `--speed N`
Speed/quality trade-off from 1 (brute-force) to 11 (fastest). The default is 3. Speed 10 has 5% lower quality, but is 8 times faster than the default. Speed 11 disables dithering and lowers compression level. Speed/quality trade-off from 1 (brute-force) to 11 (fastest). The default is 3. Speed 10 has 5% lower quality, but is 8 times faster than the default. Speed 11 disables dithering and lowers compression level.
###`--nofs` ### `--nofs`
Disables Floyd-Steinberg dithering. Disables Floyd-Steinberg dithering.
###`--floyd=0.5` ### `--floyd=0.5`
Controls level of dithering (0 = none, 1 = full). Controls level of dithering (0 = none, 1 = full). Note that the `=` character is required.
###`--posterize bits` ### `--posterize bits`
Reduce precision of the palette by number of bits. Use when the image will be displayed on low-depth screens (e.g. 16-bit displays or compressed textures in ARGB444 format). Reduce precision of the palette by number of bits. Use when the image will be displayed on low-depth screens (e.g. 16-bit displays or compressed textures in ARGB444 format).
###`--version` ### `--strip`
Don't copy optional PNG chunks. Metadata is always removed on Mac (when using Cocoa reader).
### `--version`
Print version information to stdout. Print version information to stdout.
###`-` ### `-`
Read image from stdin and send result to stdout. Read image from stdin and send result to stdout.
###`--` ### `--`
Stops processing of arguments. This allows use of file names that start with `-`. If you're using pngquant in a script, it's advisable to put this before file names: Stops processing of arguments. This allows use of file names that start with `-`. If you're using pngquant in a script, it's advisable to put this before file names:
pngquant $OPTIONS -- "$FILE" pngquant $OPTIONS -- "$FILE"
## License
pngquant is dual-licensed:
* GPL v3 or later, and additional copyright notice must be kept for older parts of the code. See [COPYRIGHT](https://github.com/pornel/pngquant/blob/master/COPYRIGHT) for details.
* For use in non-GPL software (e.g. closed-source or App Store distribution) please ask kornel@pngquant.org for a commercial license.
...@@ -2,6 +2,12 @@ ...@@ -2,6 +2,12 @@
CONFIG="config.mk" CONFIG="config.mk"
PREFIX="/usr/local" PREFIX="/usr/local"
test -f lib/libimagequant.h || { git submodule init && git submodule update; } || {
echo "error: libimagequant not found in ./lib/"
echo "If you're using git, do clone with --recursive, or download from https://github.com/ImageOptim/libimagequant"
exit 1;
}
VERSION=$(grep LIQ_VERSION_STRING lib/libimagequant.h | grep -Eo "2\.[0-9.]+") VERSION=$(grep LIQ_VERSION_STRING lib/libimagequant.h | grep -Eo "2\.[0-9.]+")
DEBUG= DEBUG=
...@@ -40,8 +46,8 @@ for i in "$@"; do ...@@ -40,8 +46,8 @@ for i in "$@"; do
help "--with-lcms2/--without-lcms2 compile with color profile support" help "--with-lcms2/--without-lcms2 compile with color profile support"
if [[ "$OSTYPE" =~ "darwin" ]]; then if [[ "$OSTYPE" =~ "darwin" ]]; then
help "--with-cocoa/--without-cocoa use Cocoa framework to read images" help "--with-cocoa/--without-cocoa use Cocoa framework to read images"
help "--with-libpng=<dir> search for libpng in directory"
fi fi
help "--with-libpng=<dir> search for libpng in directory"
echo echo
help "CC=<compiler> use given compiler command" help "CC=<compiler> use given compiler command"
help "CFLAGS=<flags> pass options to the compiler" help "CFLAGS=<flags> pass options to the compiler"
...@@ -102,8 +108,7 @@ fi ...@@ -102,8 +108,7 @@ fi
EXTRA_LDFLAGS="$EXTRA_LDFLAGS ${i#*=}" EXTRA_LDFLAGS="$EXTRA_LDFLAGS ${i#*=}"
;; ;;
*) *)
echo "error: unknown switch ${i%%=*} (see $0 --help for the list)" echo "warning: unknown switch ${i%%=*} (see $0 --help for the list)"
exit 1
;; ;;
esac esac
done done
...@@ -130,23 +135,23 @@ status() { ...@@ -130,23 +135,23 @@ status() {
# Append to CFLAGS if compiler supports flag, with optional prerequisite. # Append to CFLAGS if compiler supports flag, with optional prerequisite.
# Fails on errors and warnings. # Fails on errors and warnings.
conditional_cflags() { conditional_cflags() {
if [ -z "echo | $("$CC" -xc -S -o /dev/null $2 $1 2>&1)" ]; then if [ -z "$(echo | "$CC" -xc -S -o /dev/null $2 $1 - 2>&1)" ]; then
cflags "$1" cflags "$1"
fi fi
} }
# returns first matching file in directory # returns first matching file in directory
find_f() { find_f() {
echo $(find "$1" -not -type d -name "$2" -print -quit 2> /dev/null) echo $(find "$1" -not -path '*/.git/*' -not -type d -name "$2" -print -quit 2> /dev/null)
} }
# returns first matching file in directory (no symlinks) # returns first matching file in directory (no symlinks)
find_h() { find_h() {
echo $(find "$1" -type f -name "$2" -print -quit 2> /dev/null) echo $(find "$1" -not -path '*/.*/*' -type f -name "$2" -print -quit 2> /dev/null)
} }
find_pkgconfig() { find_pkgconfig() {
LIBNAME=$1 local LIBNAME=$1
if pkg-config --exists "$LIBNAME" &> /dev/null; then if pkg-config --exists "$LIBNAME" &> /dev/null; then
cflags "$(pkg-config --cflags "$LIBNAME")" cflags "$(pkg-config --cflags "$LIBNAME")"
lflags "$(pkg-config --libs "$LIBNAME")" lflags "$(pkg-config --libs "$LIBNAME")"
...@@ -157,13 +162,13 @@ find_pkgconfig() { ...@@ -157,13 +162,13 @@ find_pkgconfig() {
} }
find_static() { find_static() {
LIBNAME=$1 local LIBNAME=$1
HEADERPATTERN=$2 local HEADERPATTERN=$2
STATICPATTERN=$3 local STATICPATTERN=$3
HPATH=$(find_h . "$HEADERPATTERN") local HPATH=$(find_h . "$HEADERPATTERN")
if [ -n "$HPATH" ]; then if [ -n "$HPATH" ]; then
APATH=$(find_f . "$STATICPATTERN") local APATH=$(find_f . "$STATICPATTERN")
if [ -n "$APATH" ]; then if [ -n "$APATH" ]; then
cflags "-I${HPATH%/*}" cflags "-I${HPATH%/*}"
lflags "${APATH}" lflags "${APATH}"
...@@ -174,12 +179,32 @@ find_static() { ...@@ -174,12 +179,32 @@ find_static() {
return 1 return 1
} }
find_dynamic() {
local LIBNAME=$1
local HEADERPATTERN=$2
local DYNAMICPATTERN=$3
local HEADERDIR=$4
local LIBDIR=$5
local HPATH=$(find_h "$HEADERDIR" "$HEADERPATTERN")
if [ -n "$HPATH" ]; then
local SOPATH=$(find_f "$LIBDIR" "$DYNAMICPATTERN")
if [ -n "$SOPATH" ]; then
cflags "-I${HPATH%/*}"
lflags "-L${SOPATH%/*} -l$DYNAMICLIBNAME"
status "$LIBNAME" "shared ... $SOPATH"
return 0
fi
fi
return 1
}
find_library() { find_library() {
LIBNAME=$1 local LIBNAME=$1
DYNAMICLIBNAME=$2 local DYNAMICLIBNAME=$2
HEADERPATTERN=$3 local HEADERPATTERN=$3
STATICPATTERN=$4 local STATICPATTERN=$4
DYNAMICPATTERN=$5 local DYNAMICPATTERN=$5
# try static in current directory first # try static in current directory first
if find_static "$LIBNAME" "$HEADERPATTERN" "$STATICPATTERN"; then if find_static "$LIBNAME" "$HEADERPATTERN" "$STATICPATTERN"; then
...@@ -193,15 +218,8 @@ find_library() { ...@@ -193,15 +218,8 @@ find_library() {
for i in "${DIRS[@]}"; do for i in "${DIRS[@]}"; do
DIR=($i) DIR=($i)
HPATH=$(find_h "${DIR[0]}" "$HEADERPATTERN") if find_dynamic "$LIBNAME" "$HEADERPATTERN" "$DYNAMICPATTERN" "${DIR[0]}" "${DIR[1]}"; then
if [ -n "$HPATH" ]; then return 0
SOPATH=$(find_f "${DIR[1]}" "$DYNAMICPATTERN")
if [ -n "$SOPATH" ]; then
cflags "-I${HPATH%/*}"
lflags "-L${SOPATH%/*} -l$DYNAMICLIBNAME"
status "$LIBNAME" "shared ... $SOPATH"
return 0
fi
fi fi
done done
return 1 return 1
...@@ -229,22 +247,22 @@ error() { ...@@ -229,22 +247,22 @@ error() {
echo echo
# basic check # basic check
if ! echo "int main(){}" | "$CC" -xc -std=c99 -o /dev/null - &> /dev/null; then if ! echo "int main(){}" | "$CC" -xc -std=c99 -o /dev/null - > /dev/null; then
error "Compiler" "$CC failed to compile anything (make sure it's installed and supports C99)" error "Compiler" "$CC failed to compile anything (make sure it's installed and supports C99)"
fi fi
status "Compiler" "$CC" status "Compiler" "$CC"
# init flags # init flags
CFLAGS=${CFLAGS:--O3 -fno-math-errno -funroll-loops -fomit-frame-pointer -Wall} CFLAGS=${CFLAGS:--fno-math-errno -funroll-loops -fomit-frame-pointer -Wall}
cflags "-std=c99 -I." cflags "-std=c99 -I."
# DEBUG # DEBUG
if [ -z "$DEBUG" ]; then if [ -z "$DEBUG" ]; then
cflags "-DNDEBUG" cflags "-O3 -DNDEBUG"
status "Debug" "no" status "Debug" "no"
else else
cflags "-g" cflags "-O1 -g"
status "Debug" "yes" status "Debug" "yes"
fi fi
...@@ -308,7 +326,13 @@ if [[ "$OSTYPE" =~ "darwin" ]]; then ...@@ -308,7 +326,13 @@ if [[ "$OSTYPE" =~ "darwin" ]]; then
fi fi
# pairs of possible *.h and lib*.so locations # pairs of possible *.h and lib*.so locations
DIRS=("/usr/local/include /usr/local/lib" DIRS=()
if command -v >/dev/null libpng-config; then
DIRS+=("$(libpng-config --prefix) $(libpng-config --libdir)")
fi
DIRS+=("/usr/local/include /usr/local/lib"
"/usr/include /usr/lib" "/usr/include /usr/lib"
"/opt/local/include /opt/local/lib" # macports "/opt/local/include /opt/local/lib" # macports
) )
...@@ -328,16 +352,16 @@ fi ...@@ -328,16 +352,16 @@ fi
# libpng # libpng
# try if given flags are enough # try if given flags are enough
SUCCESS=0 HAS_LIBPNG=0
if echo "#include \"png.h\" if echo "#include \"png.h\"
int main(){ int main(){
return !png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL); return !png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
}" | "$CC" -xc -std=c99 -o /dev/null $CFLAGS $LDFLAGS - &> /dev/null; then }" | "$CC" -xc -std=c99 -o /dev/null $CFLAGS $LDFLAGS - &> /dev/null; then
status "libpng" "custom flags" status "libpng" "custom flags"
SUCCESS=1 HAS_LIBPNG=1
fi fi
if [ "$SUCCESS" -eq 0 ]; then if [ "$HAS_LIBPNG" -eq 0 ]; then
# try static in the given directory # try static in the given directory
PNGH=$(find_h "$LIBPNG_DIR" "png.h") PNGH=$(find_h "$LIBPNG_DIR" "png.h")
if [ -n "$PNGH" ]; then if [ -n "$PNGH" ]; then
...@@ -349,15 +373,15 @@ if [ "$SUCCESS" -eq 0 ]; then ...@@ -349,15 +373,15 @@ if [ "$SUCCESS" -eq 0 ]; then
cflags "-I${PNGH%/*}" cflags "-I${PNGH%/*}"
lflags "${LIBPNGA}" lflags "${LIBPNGA}"
status "libpng" "static (${PNGH_STRING})" status "libpng" "static (${PNGH_STRING})"
SUCCESS=1 HAS_LIBPNG=1
fi fi
fi fi
fi fi
fi