# This file is part of BigPNG, a File Format plugin for Adobe Photoshop(R) # Copyright (C) 2010 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 DLL and CS2/Mac Mach-O plugin bundle # by Toby Thain # ---------- variables & flags ---------- EXEC = BigPNG VERSION := $(shell perl -n -e 'm/^.*VERSION_STR[[:blank:]]+\"([^"]*)\"/ && print $$1;' version.h) MINGW_CC = i386-mingw32msvc-gcc DLLWRAP = i386-mingw32msvc-dllwrap WINDRES = i386-mingw32msvc-windres # Note: Only CS2 SDK or later is supported directly for OS X builds. # Older SDKs lack the required CodeMachOPowerPC property. PSAPI = ../adobe_photoshop_cs5_sdk_mac/photoshopapi ZLIB = ../zlib-1.2.5 LIBPNG = ../libpng-1.4.3 PNGOPTS = -DPNG_USER_WIDTH_MAX=1073741824 \ -DPNG_USER_HEIGHT_MAX=1073741824 CFLAGS += -Wall -O2 CPPFLAGS += -I$(PSAPI)/pica_sp -I$(PSAPI)/photoshop \ -I$(LIBPNG) -I../common/adobeplugin -I../common/tt \ -DWANT_LARGE_FILES $(PNGOPTS) REZFLAGS = $(ARCH) $(subst -D, -d , $(PNGOPTS)) # ---------- source & object files ---------- # where to find .c source files vpath %.c ../common/tt ../common/adobeplugin # list source files OBJ_COMMON = main.o read.o readpng.o write.o writepng.o file_io.o ui.o str.o # derive lists of object files, separate for each platform OBJ_OSX := $(addprefix obj/, $(OBJ_COMMON) \ ui_mac.o ui_compat_mac.o ui_cocoa.o dbg_mac.o largefiles_forks.o ) \ $(LIBPNG)/libpng.a $(ZLIB)/libz.a # must be in this order for link to succeed on 10.4.11 OBJ_W32 := $(addprefix obj_w32/, $(OBJ_COMMON) \ ui_win.o ui_compat_win.o dbg_win.o file_compat_win.o dllmain.o res.o ) \ $(LIBPNG)/libpng.a $(ZLIB)/libz.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 DISTDMG = dist/$(EXEC)-$(VERSION).dmg $(PLUGIN_OSX) : CFLAGS += $(ARCH) $(PLUGIN_OSX) : LDFLAGS += $(ARCH) $(PLUGIN_OSX) : CPPFLAGS += -DMAC_ENV -Dmacintosh -I/Developer/Headers/FlatCarbon # Win32 plugin DLL to build PLUGIN_W32 = $(EXEC).8bi DISTZIP = dist/$(EXEC)-$(VERSION)-win.zip $(PLUGIN_W32) : CPPFLAGS += -DWIN_ENV # ---------- targets ---------- .PHONY : thin cs3 cs5 dll zip dmg clean realclean # targets for OS X Mach-O (bundle) format runtimes: # 'thin' - current host architecture (for testing) # 'cs3' - Universal (PPC & Intel architectures; CS2, CS3 and CS4) # 'cs5' - 32-bit and 64-bit Intel (CS5) thin cs3 cs5 : $(PLUGIN_PARTS) # See: http://developer.apple.com/documentation/Porting/Conceptual/PortingUnix/compiling/chapter_4_section_3.html#//apple_ref/doc/uid/TP40002850-BAJCFEBA cs3 : ARCH = -arch ppc -arch i386 cs3 : CFLAGS += -isysroot /Developer/SDKs/MacOSX10.4u.sdk -mmacosx-version-min=10.4 cs3 : LDFLAGS += -Wl,-syslibroot,/Developer/SDKs/MacOSX10.4u.sdk -mmacosx-version-min=10.4 cs5 : ARCH = -arch i386 -arch x86_64 cs5 : CFLAGS += -isysroot /Developer/SDKs/MacOSX10.5.sdk -mmacosx-version-min=10.5 cs5 : LDFLAGS += -Wl,-syslibroot,/Developer/SDKs/MacOSX10.5.sdk -mmacosx-version-min=10.5 # build Win32 DLL plugin (requires MinGW) dll : $(PLUGIN_W32) $(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 > $@ clean : rm -fr $(OBJ_OSX) $(OBJ_W32) $(PLUGIN_W32) $(BUNDLE) ## Important: use 'make realclean' if changing build architectures (e.g. between cs3/cs5). realclean : clean $(ZLIB)/Makefile $(LIBPNG)/Makefile -make -C $(ZLIB) clean -make -C $(LIBPNG) clean rm -f *.x *.obj obj/* obj_w32/* $(EXEC).lib $(EXEC).exp $(ZLIB)/Makefile $(LIBPNG)/Makefile zip : $(DISTZIP) $(DISTZIP) : $(PLUGIN_W32) dist/README.html dist/gpl.html T=`mktemp -d`; \ D=$$T/$(EXEC)-$(VERSION); \ mkdir $$D; \ cp $^ $$D; \ cd $$T; \ zip -9 -r temp.zip $(EXEC)-$(VERSION); \ mv temp.zip $(PWD)/$@; \ rm -fr $$T @ ls -l $@ dist/gpl.html : curl http://www.gnu.org/licenses/gpl.html | \ sed -e 's%% %' \ -e 's%% %' > $@ dmg : $(DISTDMG) # create an Apple disk image (dmg) archive of the distribution kit $(DISTDMG) : $(PLUGIN_PARTS) dist/gpl.html version.h DIR=`mktemp -d $(EXEC)-XXXX`; \ cp -Rp dist/gpl.html $(BUNDLE) $$DIR; \ hdiutil create -srcfolder $$DIR -ov -volname "$(EXEC) $(VERSION)" \ -imagekey zlib-level=9 -fs HFS+ $@; \ rm -fr $$DIR @ ls -l $@ # ---------- compile rules ---------- obj/%.o : %.c ; $(CC) -o $@ -c $< $(CFLAGS) $(CPPFLAGS) obj/%.o : %.m ; $(CC) -o $@ -c $< $(CFLAGS) $(CPPFLAGS) obj_w32/%.o : %.c ; $(MINGW_CC) -o $@ -c $< $(CFLAGS) $(CPPFLAGS) # note dependencies on version.h: obj_w32/res.o : plugin.rc PiPL.rc ui_win.rc version.h $(WINDRES) -i $< -o $@ $(CPPFLAGS) obj_w32/ui_win.o : version.h # compile Mac resources (into data fork of .rsrc file) $(PLUGIN_RSRC) : $(BUNDLE) PiPL_macho.r ui_mac.r PiPL_common.r version.h mkdir -p $(dir $@) /Developer/Tools/Rez -o $@ -useDF PiPL_macho.r ui_mac.r \ $(REZFLAGS) \ -i /Developer/Headers/FlatCarbon \ -i $(PSAPI)/Resources \ -i $(PSAPI)/Photoshop ls -l $@ # ---------- build zlib ---------- $(ZLIB)/libz.a : $(ZLIB)/Makefile make -C $(ZLIB) libz.a $(ZLIB)/Makefile : $(ZLIB)/configure cd $(ZLIB) && CFLAGS="$(CFLAGS) -DNO_GZIP" ./configure --static # ---------- build libpng ---------- $(LIBPNG)/libpng.a : $(LIBPNG)/Makefile CPPFLAGS="-DPNG_NO_STDIO -DPNG_NO_MNG_FEATURES \ -DPNG_NO_PROGRESSIVE_READ $(PNGOPTS)" \ make -C $(LIBPNG) libpng.a $(LIBPNG)/Makefile : $(LIBPNG)/scripts/makefile.darwin sed -e 's%\.\./zlib%$(ZLIB)%' -e 's%^CC=.*%CC += $(CFLAGS) $$(CPPFLAGS)%' $< > $@ # ---------- link rules ---------- $(PLUGIN_OSX) : $(BUNDLE) exports.exp $(OBJ_OSX) mkdir -p $(dir $@) $(CC) -bundle -o $@ $(OBJ_OSX) $(LDFLAGS) \ -exported_symbols_list exports.exp \ -framework Carbon -framework System -framework AppKit ls -l $@ file $@ # link Win32 DLL $(PLUGIN_W32) : exports.def $(OBJ_W32) $(DLLWRAP) -o $@ -def $^ -mwindows -s ls -l $@ # --------------------