# This file is part of icoformat, a Windows Icon (ICO) File Format # plugin for Adobe Photoshop # Copyright (C) 2002-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 = ICOFormat 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 PSAPI = "../Adobe Photoshop CS3 Public Beta SDK/photoshopapi" # in CS3(CS2?), PiPL FormatFlags added a 'fmtCannotCreateThumbnail' bit # older SDKs don't have this, so comment out this define if using them REZFLAGS = -d CS3SDK ZLIB = ../zlib-1.2.3 LIBPNG = ../libpng-1.4.0 CFLAGS += -Wall -O2 CPPFLAGS += -I$(PSAPI)/pica_sp -I$(PSAPI)/photoshop -I$(ZLIB) -I$(LIBPNG) \ -I../common/adobeplugin -I../common/tt \ -DNO_GZIP -DPNG_NO_STDIO -DPNG_NO_MNG_FEATURES \ -DPNG_USER_WIDTH_MAX=30000 -DPNG_USER_HEIGHT_MAX=30000 \ -DPNG_NO_PROGRESSIVE_READ # ---------- source & object files ---------- # where to find .c source files vpath %.c ../common/tt ../common/adobeplugin $(ZLIB) $(LIBPNG) # list source files ZLIBSRC = adler32.c deflate.c inftrees.c uncompr.c \ compress.c zutil.c crc32.c inflate.c inffast.c trees.c PNGSRC = png.c pngerror.c pngget.c pngmem.c pngpread.c \ pngread.c pngrio.c pngrtran.c pngrutil.c pngset.c \ pngtrans.c pngwio.c pngwrite.c pngwtran.c pngwutil.c SRC_COMMON = main.c ico_io.c read.c readpng.c write.c writepng.c \ estimate.c ui.c file_io.c str.c dprintf.c \ $(ZLIBSRC) $(PNGSRC) SRC_OSX = ui_mac.c ui_compat_mac.c dbg_mac.c SRC_W32 = ui_win.c ui_compat_win.c dbg_win.c file_compat_win.c dllmain.c # derive lists of object files, separate for each platform OBJ_OSX := $(patsubst %.c, obj/%.o, $(SRC_COMMON) $(SRC_OSX)) OBJ_W32 := $(patsubst %.c, obj_w32/%.o, $(SRC_COMMON) $(SRC_W32)) obj_w32/res.o # ---------- 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 # -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) : CPPFLAGS += -DMAC_ENV -DMACMACHO -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 ---------- # build everything all : dll osx # build Win32 DLL plugin (requires MinGW) dll : $(PLUGIN_W32) # build OS X Mach-O (bundle) format plugin, for Photoshop CS2 & later # 'osx' - for current architecture only # 'fat' - Universal (PPC & Intel architectures) osx fat : $(PLUGIN_PARTS) # See: http://developer.apple.com/documentation/Porting/Conceptual/PortingUnix/compiling/chapter_4_section_3.html#//apple_ref/doc/uid/TP40002850-BAJCFEBA fat : CFLAGS += -isysroot /Developer/SDKs/MacOSX10.4u.sdk -arch ppc -arch i386 fat : LDFLAGS += -Wl,-syslibroot,/Developer/SDKs/MacOSX10.4u.sdk -arch ppc -arch i386 fat : REZFLAGS += -arch ppc -arch i386 $(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 $(BUNDLE) version.h mkdir -p $(dir $@) sed -e s/VERSION_STR/$(VERSION)/ -e s/EXEC/$(EXEC)/ $< > $@ $(BUNDLE)/Contents/PkgInfo : $(BUNDLE) mkdir -p $(dir $@) echo -n 8BIF8BIM > $@ clean : rm -fr $(OBJ_OSX) $(OBJ_W32) $(PLUGIN_W32) $(BUNDLE) realclean : clean rm -f *.x *.obj $(EXEC).lib $(EXEC).exp 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/README.html dist/gpl.html version.h @ INFO=`lipo -info $(PLUGIN_OSX)`; \ FILE=`echo $$INFO | awk '/^Non.*ppc$$/ { print "For CS2 ("$$6" only)" } \ /^Arc/ { print "For CS3 (Universal binary)" }'`; \ DIR=`mktemp -d $(EXEC)-XXXX`; \ echo $$INFO > $$DIR/$$FILE; \ cp -Rp dist/README.html dist/gpl.html $(BUNDLE) $$DIR; \ hdiutil create -srcfolder $$DIR -ov -volname "$(EXEC) $(VERSION)" $@; \ rm -fr $$DIR @ ls -l $@ # ---------- compile rules ---------- obj/%.o : %.c ; $(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 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 $@ # ---------- 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 ls -l $@ file $@ # link Win32 DLL $(PLUGIN_W32) : exports.def $(OBJ_W32) $(DLLWRAP) -o $@ -def $^ -mwindows -s ls -l $@ # --------------------