# This file is part of WebPFormat, a File Format plugin for Adobe Photoshop # Copyright (C) 2010-2013 Toby Thain, toby@telegraphics.com.au # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA # GNU Makefile # builds Win32 plugin DLL, or Mac OS X Mach-O plugin bundle (CS2 and later) # by Toby Thain # ---------- pre-requisites ---------- # 0. You need Apple's Developer Tools installed, for Mac OS X builds. # or, you need MinGW installed to do Win32 builds (cross-builds # are possible from Linux, OS X, or any other system with MinGW). # (If you are using Micro$oft compilers on Windows or WINE, # e.g. for 64-bit builds, use NMAKE.MAK instead of this Makefile.) # 1. You need the 'common' project library checked out alongside icoformat: # $ svn checkout http://telegraphics.com.au/svn/common/trunk/ common # 2. You need a Photoshop SDK, appropriate to your target Photoshop runtime. # Obtain from Adobe: http://www.adobe.com/devnet/photoshop/sdk/index.html PSAPI = ../adobe_photoshop_cs5_sdk_mac/photoshopapi # 3. You need the libvpx library. LIBVPX = libvpx LIBVPX_TAG = v1.2.0 # in turn, libvpx requires yasm to build for x86: # http://www.tortall.net/projects/yasm/ AS=/usr/local/bin/yasm # 4. You need libwebp. LIBWEBP = libwebp LIBWEBP_TAG = v0.3.1 VPX_CPPFLAGS = -DVPX_CODEC_DISABLE_COMPAT # On OS X, this program is compiled as Objective C++. # See: http://developer.apple.com/mac/library/documentation/Cocoa/Conceptual/ObjectiveC/Articles/ocCPlusPlus.html#//apple_ref/doc/uid/TP30001163-CH10-SW1 # ---------- variables & flags ---------- EXEC = WebPFormat VERSION := $(shell perl -n -e 'm/^.*VERSION_STR[[:blank:]]+\"([^"]*)\"/ && print $$1;' version.h) # in CS3(CS2?), PiPL FormatFlags added a 'fmtCannotCreateThumbnail' bit # older SDKs don't have this, so comment out this define if using them REZFLAGS = $(ARCH) -d CS3SDK CFLAGS += -Wall -O2 CPPFLAGS += -I$(PSAPI)/pica_sp -I$(PSAPI)/photoshop \ -I../common/adobeplugin -I../common/tt \ -I$(LIBVPX) -I$(LIBWEBP) # ---------- source & object files ---------- # where to find source files vpath %.c ../common/tt ../common/adobeplugin vpath %.m cocoa # list source files OBJ_COMMON = main.o main_lossless.o read.o decode.o write.o encode.o \ scripting.o file_io.o ui.o str.o # object files, separate for each platform OBJ_OSX := $(addprefix obj/, $(OBJ_COMMON) \ ui_mac.o ui_compat_mac.o dbg_mac.o largefiles_forks.o \ ui_cocoa.o WebPEncodeQualityController.o ) \ $(LIBVPX)/libvpx.a # ---------- executables ---------- # constituent files of Mac OS X plugin bundle # Adobe's plugs use .plugin extension BUNDLE = $(EXEC).plugin PLUGIN_OSX = $(BUNDLE)/Contents/MacOS/$(EXEC) PLUGIN_RSRC = $(BUNDLE)/Contents/Resources/$(EXEC).rsrc PLUGIN_PARTS = $(PLUGIN_OSX) \ $(PLUGIN_RSRC) \ $(BUNDLE)/Contents/Info.plist \ $(BUNDLE)/Contents/PkgInfo \ $(BUNDLE)/Contents/Resources/WebPEncodeQuality.nib DISTDMG = dist/$(EXEC)-$(VERSION).dmg # -DMAC_ENV is for the Adobe SDK # -DMACMACHO is for this plugin's use (to detect Mach-O build) # -Dmacintosh is for anyone who STILL doesn't get it $(PLUGIN_OSX) : CFLAGS += $(ARCH) $(PLUGIN_OSX) : LDFLAGS += $(ARCH) $(PLUGIN_OSX) : CPPFLAGS += -DMAC_ENV -DMACMACHO -Dmacintosh -DWANT_LARGE_FILES \ -I/Developer/Headers/FlatCarbon # ---------- targets ---------- # Notes: If building on OS X 10.4, # - if using older Xcode (e.g. 2.1), the option '-mmmacosx-version-min' must be removed. # - older Rez does not support -arch, you need to upgrade to Xcode 2.5 to build Universal (for CS3/4) # - the cs5 target cannot be built on OS X 10.4 (it requires 10.5 SDK) # - 'cs2' target does not currently build (10.4.11, Xcode 2.5), link failure: # /usr/libexec/gcc/powerpc-apple-darwin8/4.0.1/ld: Undefined symbols: # _vsnprintf$LDBL128 # _sprintf$LDBL128 # _fprintf$LDBL128 # Interesting thread: http://lists.apple.com/archives/xcode-users/2005/Dec/msg00022.html # but there seems to be no real solution. In short, you can't really # cross-build for CS2, from 10.4 Tiger, using the right SDK. # My workaround is to build on 10.4 with just 'make', which builds a plugin # that works with Photoshop CS2 on 10.4. # This uses default 10.4 compiler, SDK; I am not sure if this will produce # a plugin that runs on OS X 10.2.x or 10.3.x (and I can't easily test). # - `make` on 10.4 fails on recent libvpx Makefiles due to a bug with define/enddef processing. # This can be worked around by building a current version of make from sources. # cs5 target: OS X 10.6 cannot build this for PowerPC. # llvm-gcc-4.2: error trying to exec '/usr/bin/../llvm-gcc-4.2/bin/powerpc-apple-darwin10-llvm-gcc-4.2': execvp: No such file or directory # # Also the PowerPC assembler appears not to be installed on OS X 10.6 # recent Developer Tools. .PHONY : thin cs2 cs3 cs5 cs6 dmg clean realclean # targets for OS X Mach-O (bundle) format runtimes: # 'thin' - single architecture, of build host # 'cs2' - PowerPC only # 'cs3' - Universal (PPC & Intel architectures; CS3 and CS4) # 'cs5' - 32-bit and 64-bit Intel (CS5, CS6) thin cs2 cs3 cs5 cs6 : $(PLUGIN_PARTS) # Min system for CS2: Mac OS X v.10.2.8 cs2 : ARCH = -arch ppc cs2 : VPXTARGET = ppc32-darwin8-gcc # compat 10.4 cs2 : CFLAGS += -isysroot /Developer/SDKs/MacOSX10.2.8.sdk cs2 : CPPFLAGS += -DGCC_VERSION_ppc=3.3 cs2 : LDFLAGS += -Wl,-syslibroot,/Developer/SDKs/MacOSX10.2.8.sdk # See: http://developer.apple.com/documentation/Porting/Conceptual/PortingUnix/compiling/chapter_4_section_3.html#//apple_ref/doc/uid/TP40002850-BAJCFEBA # gcc 4.2 (OS X 10.6) has trouble building the universal plugin: # Min system for CS3: Mac OS X v.10.4.8 cs3 : ARCH = -arch ppc -arch i386 cs3 : VPXTARGET = universal-darwin8-gcc # compat 10.4 cs3 cs2 : CC = /usr/bin/gcc-4.0 cs3 : CFLAGS += -isysroot /Developer/SDKs/MacOSX10.4u.sdk cs3 : LDFLAGS += -Wl,-syslibroot,/Developer/SDKs/MacOSX10.4u.sdk cs3 cs5 : LDFLAGSFINAL += -read_only_relocs suppress # work around addressing in libvpx asm # Min system: 10.5.7, 10.6+ cs5 : ARCH = -arch i386 -arch x86_64 cs5 : VPXTARGET = universal-darwin9-gcc # compat 10.5 cs5 : CFLAGS += -isysroot /Developer/SDKs/MacOSX10.5.sdk cs5 : LDFLAGS += -Wl,-syslibroot,/Developer/SDKs/MacOSX10.5.sdk # The cs6 target is provided in order to make it possible to build # on a 10.6 system. Otherwise, the CS5 build will work with CS6. # If you build the plugin with 'thin' (default target) # on a 64-bit Intel system, my experience is that the PiPL is set up # for 32 bit only, and does not load in Photoshop on the # same system. (Even though Rez doc says arch defaults properly?!) # Mac CS6 is 64 bit only. Min system: 10.6.8, 10.7+ cs6 : ARCH = -arch x86_64 cs6 : VPXTARGET = x86_64-darwin10-gcc # compat 10.6 cs6 : CFLAGS += -isysroot /Developer/SDKs/MacOSX10.6.sdk cs6 : LDFLAGS += -Wl,-syslibroot,/Developer/SDKs/MacOSX10.6.sdk $(BUNDLE) : mkdir -p $@ /Developer/Tools/SetFile -a B $@ # insert correct executable name and version string in bundle's Info.plist $(BUNDLE)/Contents/Info.plist : Info.plist.tmpl $(BUNDLE) version.h mkdir -p $(dir $@) sed -e "s/%VERSION_STR%/$(VERSION)/" -e "s/%EXEC%/$(EXEC)/" $< > $@ $(BUNDLE)/Contents/PkgInfo : $(BUNDLE) mkdir -p $(dir $@) printf 8BIF8BIM > $@ # Copy the nib folders, without Svn metadata $(BUNDLE)/Contents/Resources/%.nib : cocoa/%.nib mkdir -p $@ cp $% %' \ -e 's%% %' > $@ dmg : $(DISTDMG) # create an Apple disk image (dmg) archive of the distribution kit $(DISTDMG) : $(PLUGIN_PARTS) dist/README.html dist/gpl.html version.h DIR=`mktemp -d $(EXEC)-XXXX`; \ cp -Rp dist/README.html dist/gpl.html $(BUNDLE) $$DIR; \ hdiutil create -srcfolder $$DIR -ov -volname "$(EXEC) $(VERSION)" \ -imagekey zlib-level=9 -fs HFS+ $@; \ rm -fr $$DIR @ ls -l $@ # ---------- libvpx ---------- $(LIBVPX) : git clone -b $(LIBVPX_TAG) http://git.chromium.org/webm/libvpx.git $(LIBVPX) $(LIBWEBP) : git clone -b $(LIBWEBP_TAG) http://git.chromium.org/webm/libwebp.git $(LIBWEBP) # ---------- compile rules ---------- obj/%.o : %.c ; $(CC) -o $@ -c $< $(ARCHCFLAGS) $(CFLAGS) $(CPPFLAGS) obj/%.o : %.m ; $(CC) -o $@ -c $< $(ARCHCFLAGS) $(CFLAGS) $(CPPFLAGS) # compile Mac resources (into data fork of .rsrc file) $(PLUGIN_RSRC) : $(BUNDLE) PiPL_macho.r ui_mac.r scripting.r ui_defs.h version.h mkdir -p $(dir $@) /Developer/Tools/Rez -o $@ -useDF $(filter %.r,$^) \ $(REZFLAGS) \ -i /Developer/Headers/FlatCarbon \ -i $(PSAPI)/Resources \ -i $(PSAPI)/Photoshop ls -l $@ # ---------- build libvpx and vp8 codec ---------- # The dep on this Makefile is to ensure we get a reconfigure if any # of the configure options are changed, or if the git tag is changed. $(LIBVPX)/Makefile : $(LIBVPX)/configure Makefile cd $(LIBVPX) \ && git checkout $(LIBVPX_TAG) \ && CC=$(CC) LD=$(CC) AS=$(AS) CPPFLAGS="$(VPX_CPPFLAGS)" \ ./configure --target=$(VPXTARGET) \ --enable-runtime-cpu-detect \ --enable-vp8 \ --enable-postproc \ --enable-small \ --disable-examples \ --disable-multithread \ --disable-spatial-resampling \ --disable-unit-tests $(LIBVPX)/libvpx.a : $(LIBVPX)/Makefile $(MAKE) -C $(LIBVPX) # We need to hack the original Makefile around a bit, so we can pass # our build flags. [Shame on you libwebp for not allowing # customisation via environment.] $(LIBWEBP)/Makefile.webpformat : $(LIBWEBP)/makefile.unix sed -e '/^EXTRA_FLAGS=/d' \ -e '/^CC =/d' \ -e '/^AR =/d' \ -e '/^ARFLAGS =/d' \ -e 's/CFLAGS =/CFLAGS +=/' \ -e 's/LDFLAGS =/LDFLAGS +=/' \ $< > $@ # This shameful hack works around that fact that neither ar nor ld # can produce a fat library file. (OTOH, libvpx manages to create a # universal .a, so there must be a way. Making libwebp do whatever # libvpx does is going to be trickier than this hack though.) # Instead, we collect the names of the object files and link with them # directly. ONE DAY, a change in libwebp makefile will break this. $(LIBWEBP)/libwebp.objects.txt : $(LIBWEBP)/Makefile.webpformat Makefile cd $(LIBWEBP) \ && git checkout $(LIBWEBP_TAG) \ && $(MAKE) -f Makefile.webpformat src/libwebp.a \ CC="$(CC)" CFLAGS="$(CFLAGS)" LDFLAGS="$(LDFLAGS)" ARFLAGS="" \ AR="echo > libwebp.objects.txt" # ---------- link rules ---------- # Make sure library headers are available obj/decode.o : decode.c $(LIBWEBP) $(LIBVPX) obj/encode.o : encode.c $(LIBWEBP) $(LIBVPX) obj/read.o : read.c $(LIBWEBP) $(PLUGIN_OSX) : $(BUNDLE) exports.exp $(OBJ_OSX) $(LIBWEBP)/libwebp.objects.txt mkdir -p $(dir $@) LIBWEBP_OBJ="$(addprefix $(LIBWEBP)/,$(filter %.o,$(shell cat $(LIBWEBP)/libwebp.objects.txt)))" && \ $(CC) -bundle -o $@ $(OBJ_OSX) $$LIBWEBP_OBJ $(LDFLAGS) $(LDFLAGSFINAL) \ -exported_symbols_list exports.exp \ -framework Carbon -framework System -framework AppKit ls -l $@ file $@ # --------------------