# libpngMakefile.gnu for Cygwin. # builds both dll (with import lib) and static lib versions # of the library, and builds two copies of pngtest: one # statically linked and one dynamically linked. # # Last Change: Sep 12 2002 22:14:10 EDT # # "Deluxe" enhancements (C)2002 Soren Andersen: # *-* Supports building outside the source directory. # *-* Extensively tests post-install lib configuration mechanisms. # *-* Makes convenient the building of special libPNG debug libs. # *-* Automates cpu and asm / mmx optimizations: # --IMPORTANT! to use this feature you must either argue on the make commandline: # # $ make all [-f libpngMakefile.gnu] HOST_CPU={x}86 [THREAD_RECKLESS=(1|0)] \ # [PREFIX={/path/to/install/to}] etc... # where {x} is an Intel-compatible cpu version (3,4,5,6); OR you must make # sure the special makefile include named "get_hostcpu.mk" # is located in some dir 'make' will look in for *include*'ed makefiles. # # -------------------------------------------------------------------- # Copyright (C) 2002 Soren Andersen # Derived from makefile.cygwin, based on the makefile for linux-elf w/mmx by: # Copyright (C) 1998-2000 Greg Roelofs # Copyright (C) 1996, 1997 Andreas Dilger # For conditions of distribution and use, see copyright notice in png.h # --------------------------------------------------------------------- help: usage # Usage message. usage: @echo -e 'Options:\n' \ ' SRCDIR=[path]\n' \ ' PNG_DEBUG=[1 or 2 or 3]\n' \ ' THREAD_RECKLESS=[0 or 1]\n' \ ' HOST_CPU=[x86]\n' \ ' DESTDIR=[path]\n' \ ' ZLIBLIB=[path]\n' \ ' ZLIBINC=[path]\n' \ ' CONTAINS_ZLIB=[path]\n' ifeq "$(strip $(filter help,$(MAKECMDGOALS))$(filter usage,$(MAKECMDGOALS)))" "" # ********************************************************************* # Leave all this stuff alone. It is here at the beginning for a reason. # Don't even read these 'make' arcana ;-) # ********************************************************************* all: build-setup-info SHELL = /bin/bash ifneq "$(SRCDIR)" "" VPATH = $(SRCDIR) else SRCDIR = . endif # begin host-cpu detection conditional makefile include --------------- ifeq "$(strip $(filter clean,$(MAKECMDGOALS)))" "" ifeq "$(filter %86,$(HOST_CPU))" "" DEFNUL = s = $(DEFNUL) # what we want is the SPACE between the null macro and the hash. DECRUFTED = $(filter-out - -- --%,$(MFLAGS)) LOOK4WHERE= $(subst -I$s,,$(patsubst -%I,-I,$(DECRUFTED))) FOUND_CPUTOOL = $(firstword \ $(wildcard $(addsuffix /get_hostcpu.mk,$(LOOK4WHERE) /usr/local/include))) $(CURDIR)/_cpu_tool.mk: $(FOUND_CPUTOOL) $(MAKE) -f $(FOUND_CPUTOOL) # This isn't boilerplate, it needs to be regenerated on each machine: include $(CURDIR)/_cpu_tool.mk endif endif # end cpu-detection conditional makefile include ---------------------- ifeq "$(strip $(filter clean,$(MAKECMDGOALS)))" "" ifndef PREFIX prefix := /usr define WARN_NO_PREFIX echo -e '\n \ You have not specified a "PREFIX=" location. Defaulting to "/usr".\n \ Before building "install-shared" or "install-config" be sure you\n \ specify the install location prefix you really want.\n' endef else prefix := $(PREFIX) endif endif # ********************************************************************** # OK, now you can look again. # ********************************************************************** # override DESTDIR= on the make install command line to easily support # installing into a temporary location. Example: # # make install DESTDIR=/tmp/build/libpng # # If you're going to install into a temporary location # via DESTDIR, that # location must already exist before you execute `make install'. DESTDIR = # A given, on this platform: CC = gcc # Where the zlib library and include files are located. On my Cygwin, # /usr/lib is required but the cpp finds the headers in /usr/include # without any help. ifndef CONTAINS_ZLIB ZLIBLIB = /usr/lib ZLIBINC = else ZLIBLIB = . ZLIBINC = $(CONTAINS_ZLIB) endif ifdef MINGW MINGW_CCFLAGS=-mno-cygwin -fnative-struct -I/usr/include/mingw MINGW_LDFLAGS=-mno-cygwin -L/usr/lib/mingw $(warning Be sure you are pointing "ZLIBINC" and "ZLIBLIB" towards \ a non-Cygwin Zlib installation if building on MinGW.) endif WARNMORE = $(strip -Wwrite-strings -Wpointer-arith -Wshadow \ -Wmissing-declarations -Wtraditional -Wcast-align \ -Wstrict-prototypes -Wmissing-prototypes) ### ********** NOTES ON CFLAGS *********** ### if you don't need thread safety, and want the maximum asm accel, ### argue in `make' invocation or uncomment here: # THREAD_RECKLESS=1 ### else if you want thread-safe asm acceleration or are not sure, use # THREAD_RECKLESS=0 ASM_CODE = ifdef THREAD_RECKLESS ifeq "$(THREAD_RECKLESS)" "1" ASM_CODE = -DPNG_THREAD_UNSAFE_OK -DPNG_USE_PNGGCCRD endif ifeq "$(THREAD_RECKLESS)" "0" ASM_CODE = -DPNG_USE_PNGGCCRD endif endif HOST_CPU ?= 386 ALIGN ?= $(if $(filter 386,$(HOST_CPU)),-malign-loops=2 -malign-functions=2) # For i386, we're told use: ALIGN=-malign-loops=2 -malign-functions=2 ### To get debugging, more CC warnings, etc. add the below to CFLAGS: # $(WARNMORE) -g -DPNG_DEBUG=5 CFLAGS= $(strip $(MINGW_CCFLAGS) $(addprefix -I,$(SRCDIR) $(ZLIBINC)) \ -Wall -O3 $(ALIGN) -funroll-loops -fomit-frame-pointer \ $(addprefix -mcpu=i,$(HOST_CPU)) $(ASM_CODE)) MKDIR = /bin/mkdir -pv RANLIB = ranlib INCPATH =$(prefix)/include LIBPATH =$(prefix)/lib BINPATH =$(prefix)/bin MANPATH =$(prefix)/man MAN3PATH=$(MANPATH)/man3 MAN5PATH=$(MANPATH)/man5 # ******************************************************************** # ********* NO USER-SERVICEABLE PARTS BELOW THIS POINT? ********** # ******************************************************************** # VERSION ADAPTATION VERS_STR = const char png_libpng_ver.\{4\} = "\([0-9]\.[0-9]\.[0-9][^"]\+\)";#" VERS_FOUND := $(strip $(shell sed -n -e 's,${VERS_STR},\1,p' ${SRCDIR}/png.c)) PNGMIN = $(if $(VERS_FOUND),$(VERS_FOUND), \ $(error "Could not parse the version from png.c!")) PNGDLL = $(strip $(shell echo ${PNGMIN} |sed -n -e 's,\([0-9]\)\.\([0-9]\).*$$,\1\2,p')) # BPLAT := $(shell uname -s) # ifneq "$(strip $(findstring cygwin,$(BPLAT))$(findstring CYGWIN,$(BPLAT)))" "" DBGLEV = $(if ${PNG_DEBUG},-dbg$(PNG_DEBUG)) LIBNAME = libpng$(PNGDLL) PNGMAJ = 0 PNGVER = $(PNGMAJ).$(PNGMIN) # Cosmetic: shortened strings: S = $(SRCDIR) D = $(DESTDIR) SHAREDLIB = $(subst lib,$(if $(filter \ undefined,$(origin MINGW)),cyg,lib),$(LIBNAME)$(DBGLEV).dll) STATLIB = $(subst $(PNGDLL),,$(LIBNAME))$(DBGLEV).a IMPTLIB = $(LIBNAME)$(DBGLEV).dll.a EXEEXT = .exe ifdef CONTAINS_ZLIB LD_LIBZLINK = -Wl,--warn-once $(addprefix -L,$(ZLIBLIB)) -Bstatic -lz -Bdynamic else LD_LIBZLINK = -Wl,--warn-once $(addprefix -L,$(ZLIBLIB)) -Bdynamic -lz endif override LDFLAGS += $(strip -L. $(MINGW_LDFLAGS) $(subst lib,-l,$(LIBNAME)$(DBGLEV))) LD_SO_FLAGS = $(strip -shared $(MINGW_LDFLAGS) -Wl,--disable-auto-image-base \ -Wl,--out-implib=$(IMPTLIB)) # -Wl,--major-image-version,,--minor-image-version, #--enable-extra-pe-debug ,--compat-implib ifdef MINGW LD_SO_FLAGS += -Wl,--export-all endif LDEXTRA = -Wl,--warn-once $(addprefix -L,$(ZLIBLIB)) -lz APP_CFLAGS = $(filter-out -DPNG_BUILD_DLL,$(CFLAGS)) OBJS = png.o pngset.o pngget.o pngrutil.o pngtrans.o pngwutil.o \ pngread.o pngrio.o pngwio.o pngwrite.o pngrtran.o \ pngwtran.o pngmem.o pngerror.o pngpread.o ifneq "$(findstring -DPNG_USE_PNGGCCRD,$(CFLAGS))" "" OBJS += pnggccrd.o endif OBJSDLL := $(OBJS:.o=.pic.o) ifdef PNG_DEBUG CFLAGS += -DPNG_DEBUG=$(PNG_DEBUG) endif # PATTERNS .SUFFIXES: .c .o .pic.o $(OBJS) : %.o : %.c $(CC) -c -DPNG_STATIC $(CFLAGS) -o $@ $< $(OBJSDLL) : CFLAGS += -DPNG_BUILD_DLL $(OBJSDLL) : %.pic.o : %.c $(CC) -c $(CFLAGS) -o $@ $< # TARGETS # ".PHONY" means that none of these targets' commands actually result in # the writing of a *disk file* with that *name*. All this does is # to protect us from missing the rebuilding of a needed target if by some # weird accident a file actually named one of these things gets created # in the dirs 'make' looks at. Hey, it could happen. .PHONY: all static shared all-static all-shared build-setup-info \ advise-no-prefix test test-static test-shared test-config-install \ clean clean-o clean-all-but-installable install-static install-shared \ install-man install-headers install-config help usage all: build-setup-info all-static all-shared # Build this target alone to pre-verify that "make [...] install" # will do what you want/expect before committing yourself. build-setup-info: advise-no-prefix @echo ; \ echo ' Building libPNG '\"$(PNGVER)\" on host CPU: \"i$(HOST_CPU)\" ; ifdef PNG_DEBUG @echo ' Enabling libPNG DEBUG level '\"$(PNG_DEBUG)\" endif @echo -e ' Versioning Details:\n ' \ $(addsuffix '\n ',PNGDLL=$(PNGDLL) LIBNAME=$(LIBNAME) SHAREDLIB=$(SHAREDLIB)); \ echo -n ' Install Locations - '\"prefix\" is set to: \"$(prefix)\"; \ echo -e $(addprefix '\n ', \ $(join \ $(strip '$$INCPATH' '$$LIBPATH' '$$BINPATH' '$$MANPATH' '$$MAN3PATH' '$$MAN5PATH'), \ $(addprefix =$(D), \ $(strip $(INCPATH) $(LIBPATH) $(BINPATH) $(MANPATH) $(MAN3PATH) $(MAN5PATH) \ )))); advise-no-prefix: ifdef WARN_NO_PREFIX @$(WARN_NO_PREFIX) else @: endif # System facility support for libpng detection for future builds against # libpng. Two different systems being supported here: 'pkg-config' and # 'libpng-config'. libpng$(DBGLEV).pc: scripts/libpng.pc.in @echo -e Making pkg-config file for this libpng installation..'\n' \ using PREFIX=\"$(prefix)\"'\n' cat $(S)/scripts/libpng.pc.in | sed -e s\!@PREFIX@!$(prefix)! | \ sed -e s/-lm// > libpng$(DBGLEV).pc ifeq "$(PNGVER)" "0.1.2.2" libpng$(DBGLEV)-config: : else libpng$(DBGLEV)-config: scripts/libpng-config-head.in scripts/libpng-config-body.in @echo -e Making $(LIBNAME)$(DBGLEV) \"libpng-config\" file for this libpng \ installation.. using PREFIX=\"$(prefix)\"'\n' ( cat $(S)/scripts/libpng-config-head.in; \ echo prefix=\"$(prefix)\"; \ echo cppflags=\"-I$(INCPATH)/$(LIBNAME)$(DBGLEV)\"; \ echo cflags=\"\"; \ echo ldflags=\"-L$(LIBPATH)\"; \ echo libs=\"$(subst lib,-l,$(LIBNAME)$(DBGLEV))\"; \ cat $(S)/scripts/libpng-config-body.in ) > libpng$(DBGLEV)-config chmod +x libpng$(DBGLEV)-config endif static: all-static shared: all-shared all-static: $(STATLIB) pngtest-stat$(EXEEXT) all-shared: $(SHAREDLIB) pngtest$(EXEEXT) $(STATLIB): $(OBJS) ar crs $@ $(OBJS) $(SHAREDLIB): $(if $(CONTAINS_ZLIB),libz.a) $(OBJSDLL) $(strip $(CC) $(LD_SO_FLAGS) -o $@ $(OBJSDLL) $(LD_LIBZLINK)) pngtest.pic.o: pngtest.c $(CC) $(APP_CFLAGS) -c $< -o $@ pngtest$(EXEEXT): pngtest.pic.o $(SHAREDLIB) $(CC) $(APP_CFLAGS) $< $(patsubst png%,png%.dll,$(LDFLAGS)) -o $@ # $(LDEXTRA) was at the end of the above command, but does not always # seem to be needed. pngtest.o: pngtest.c $(CC) $(APP_CFLAGS) -DPNG_STATIC -c $< -o $@ pngtest-stat$(EXEEXT): pngtest.o $(STATLIB) $(CC) -static $(APP_CFLAGS) $< $(subst $(PNGDLL),,$(LDFLAGS)) $(LDEXTRA) -o $@ # Running tests. test: test-static test-shared test-static: pngtest-stat$(EXEEXT) ./pngtest-stat $(S)/pngtest.png test-shared: pngtest$(EXEEXT) ./pngtest $(S)/pngtest.png # Installation support. ifndef CONTAINS_ZLIB install: install-static install-shared \ install-man install-config test-config-install else install: @echo -e Building libpng with zlib internal (\"CONTAINS_ZLIB\") is an \ experimental feature,\nand actually installing it is unsupported at this time. endif install-static: $(STATLIB) install-headers install-man -@if [ ! -d $(D)$(LIBPATH) ]; then $(MKDIR) $(D)$(LIBPATH); fi install -m 644 $(STATLIB) $(D)$(LIBPATH)/libpng$(PNGVER)$(DBGLEV).a -@rm -f $(D)$(LIBPATH)/$(STATLIB) (cd $(D)$(LIBPATH); ln -sf libpng$(PNGVER)$(DBGLEV).a $(STATLIB)) install-shared: $(SHAREDLIB) install-config install-headers install-man -@if [ ! -d $(D)$(LIBPATH) ]; then $(MKDIR) $(D)$(LIBPATH); fi -@if [ ! -d $(D)$(BINPATH) ]; then $(MKDIR) $(D)$(BINPATH); fi -@if [ ! -d $(D)$(LIBPATH)/pkgconfig ]; then \ $(MKDIR) $(D)$(LIBPATH)/pkgconfig; fi -@/bin/rm -f $(D)$(LIBPATH)/pkgconfig/$(LIBNAME)$(DBGLEV).pc -@/bin/rm -f $(D)$(LIBPATH)/pkgconfig/libpng$(DBGLEV).pc install -m 644 $(IMPTLIB) $(D)$(LIBPATH)/$(IMPTLIB) -@rm -f $(D)$(patsubst $(PNGDLL),,$(LIBPATH)/$(IMPTLIB)) (cd $(D)$(LIBPATH); ln -sf $(LIBNAME)$(DBGLEV).dll.a $(subst $(PNGDLL),,$(IMPTLIB))) install -s -m 755 $(SHAREDLIB) $(D)$(BINPATH) install -m 644 libpng$(DBGLEV).pc $(D)$(LIBPATH)/pkgconfig/$(LIBNAME)$(DBGLEV).pc (cd $(D)$(LIBPATH)/pkgconfig; ln -sf $(LIBNAME)$(DBGLEV).pc libpng$(DBGLEV).pc) install-headers: -@if [ ! -d $(D)$(INCPATH) ]; then \ $(MKDIR) $(D)$(INCPATH); fi -@if [ ! -d $(D)$(INCPATH)/$(LIBNAME) ]; then \ $(MKDIR) $(D)$(INCPATH)/$(LIBNAME); fi -@rm -f $(D)$(INCPATH)/png.h -@rm -f $(D)$(INCPATH)/pngconf.h install -m 644 $(S)/png.h $(S)/pngconf.h $(D)$(INCPATH)/$(LIBNAME) -@rm -f $(D)$(INCPATH)/libpng (cd $(D)$(INCPATH); ln -sf $(LIBNAME) libpng; ln -sf $(LIBNAME)/* .) install-man: -@if [ ! -d $(D)$(MAN3PATH) ]; then \ $(MKDIR) $(D)$(MAN3PATH); fi -@if [ ! -d $(D)$(MAN5PATH) ]; then \ $(MKDIR) $(D)$(MAN5PATH); fi install -m 644 $(S)/libpngpf.3 $(S)/libpng.3 $(D)$(MAN3PATH) install -m 644 $(S)/png.5 $(D)$(MAN5PATH) install-config: libpng$(DBGLEV).pc libpng$(DBGLEV)-config -@if [ ! -d $(D)$(BINPATH) ]; then \ mkdir $(D)$(BINPATH); fi -@/bin/rm -f $(D)$(BINPATH)/libpng$(DBGLEV)-config -@/bin/rm -f $(D)$(BINPATH)/$(LIBNAME)$(DBGLEV)-config -@if [ -f libpng$(DBGLEV)-config ]; then \ cp libpng$(DBGLEV)-config $(D)$(BINPATH)/$(LIBNAME)$(DBGLEV)-config; \ chmod 755 $(D)$(BINPATH)/$(LIBNAME)$(DBGLEV)-config; \ (cd $(D)$(BINPATH); ln -sf $(LIBNAME)$(DBGLEV)-config libpng$(DBGLEV)-config); \ else echo 'No $(LIBNAME)$(DBGLEV)-config script to install, this version \ of libpng did not supply one.'; fi # Run this to verify that a future `configure' run will pick up the settings # you want. test-config-install: SHELL=/bin/bash test-config-install: @echo -e '\n \ ---------------------------------------------\n' \ Testing libpng$(DBGLEV)-config functions...'\n' @ for TYRA in LDFLAGS CPPFLAGS CFLAGS LIBS VERSION; \ do \ printf "(%d)\t %10s =%s\n" $$(($$gytiu + 1)) $$TYRA \ "$$($(D)$(BINPATH)/libpng$(DBGLEV)-config `echo --$$TYRA |tr '[:upper:]' '[:lower:]'`)"; \ gytiu=$$(( $$gytiu + 1 )); \ done @echo -e ' \ ---------------------------------------------\n' Testing pkg-config functions...'\n' @if pkg-config --version >/dev/null; then \ export PKG_CONFIG_PATH="`cygpath -au $(D)$(LIBPATH)/pkgconfig`"; \ for TYRA in CFLAGS LIBS MODVERSION; \ do \ printf "(%d)\t %10s =%s\n" $$(($$gytiu + 1)) $$TYRA \ "$$(pkg-config `echo --$$TYRA |tr '[:upper:]' '[:lower:]'` libpng$(DBGLEV))"; \ gytiu=$$(( $$gytiu + 1 )); \ done; \ else \ echo 'For your information: You do not seem to have "pkg-config" installed'; \ echo 'on your system :-(. See http://www.freedesktop.org/software/pkgconfig/'; \ echo or install "pkg-config" using the Cygwin "setup.exe" utility. ; \ fi @echo -e ' \ ---------------------------------------------\n' \ Finished testing library configuration-data installations. # Housekeeping. clean: clean-o clean-all-but-installable -rm -f *.a $(SHAREDLIB) libpng*-config libpng*.pc clean-o: -@rm -f *.pic.o *.o # Below refers to saving libpng*.a, *png*.dll, png.h, # libpng-config libpng.pc, and pngconf.h clean-all-but-installable: -@rm -f *.pic.o *.o \ pngtest-stat$(EXEEXT) pngtest$(EXEEXT) *.mk \ pngout.png makehelper_hostcpu.exe DOCS = ANNOUNCE CHANGES INSTALL KNOWNBUG LICENSE README TODO Y2KINFO # ---------------------------------------------------------------------- # EXPERIMENTAL ZLIB INCLUSION (in PNG DLL shared library) # ---------------------------------------------------------------------- ifdef CONTAINS_ZLIB SZv = -DZLIB_VERSION=1.1.4s ZOBJS = adler32.o compress.o crc32.o gzio.o uncompr.o \ deflate.o trees.o zutil.o inflate.o infblock.o \ inftrees.o infcodes.o infutil.o inffast.o CAN_ASM = $(if \ $(strip $(findstring 586,$(HOST_CPU))$(findstring 686,$(HOST_CPU))),-DASMV) ZSOURCES = $(ZOBJS:.o=.c) vpath zObj/*.o . $(CONTAINS_ZLIB) .INTERMEDIATE: $(ZSOURCES:.c=.d) match.s \ $(addprefix zObj/,$(if $(CAN_ASM),match.o) $(ZOBJS)) $(ZSOURCES:.c=.d) : %.d : $(CONTAINS_ZLIB)/%.c $(CC) $(CAN_ASM) -DHAVE_UNISTD_H -MM $< >$@ ZlibDEPS.mk: $(ZSOURCES:.c=.d) $(addprefix $(CONTAINS_ZLIB)/,$(ZSOURCES)) cat $(ZSOURCES:.c=.d) >$@ include ZlibDEPS.mk match.s: $(CONTAINS_ZLIB)/contrib/asm$(HOST_CPU)/match.S $(CC) -E $< > match.s zObj/match.o: match.s $(CC) -c $< -o $@ zObj: -@mkdir $@ libz.a: zObj $(addprefix zObj/,$(if $(CAN_ASM),match.o) $(ZOBJS)) ar crs $@ $(strip $(wordlist 2,$(words $^), $^)) $(addprefix zObj/,$(ZOBJS)): CPPFLAGS = -O3 $(CAN_ASM) -DHAVE_UNISTD_H \ -funroll-loops -fomit-frame-pointer $(if $(MINGW),-fnative-struct) $(addprefix zObj/,$(ZOBJS)): $(CC) $(CPPFLAGS) -o $@ -c $(CONTAINS_ZLIB)/$(patsubst %.o,%.c,$(notdir $@)) endif # ---------------------------------------------------------------------- endif # DO NOT DELETE THIS LINE -- make depend depends on it. png.o png.pic.o: png.h pngconf.h png.c pngerror.o pngerror.pic.o: png.h pngconf.h pngerror.c pngrio.o pngrio.pic.o: png.h pngconf.h pngrio.c pngwio.o pngwio.pic.o: png.h pngconf.h pngwio.c pngmem.o pngmem.pic.o: png.h pngconf.h pngmem.c pngset.o pngset.pic.o: png.h pngconf.h pngset.c pngget.o pngget.pic.o: png.h pngconf.h pngget.c pngread.o pngread.pic.o: png.h pngconf.h pngread.c pngrtran.o pngrtran.pic.o: png.h pngconf.h pngrtran.c pngrutil.o pngrutil.pic.o: png.h pngconf.h pngrutil.c pngtrans.o pngtrans.pic.o: png.h pngconf.h pngtrans.c pngwrite.o pngwrite.pic.o: png.h pngconf.h pngwrite.c pngwtran.o pngwtran.pic.o: png.h pngconf.h pngwtran.c pngwutil.o pngwutil.pic.o: png.h pngconf.h pngwutil.c pngpread.o pngpread.pic.o: png.h pngconf.h pngpread.c pngtest.o: png.h pngconf.h pngtest.c pngtest-stat.o: png.h pngconf.h pngtest.c