# This file is part of "psdrecover", a File Format
# plugin for Adobe Photoshop
# Copyright (C) 2007-2011 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 OS X Mach-O plugin bundle (for CS2/3/4/5)
# ---------- variables & flags ----------
EXEC = PSDRecover
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_cs5_sdk_mac/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 = $(ARCH) -d CS3SDK
# location of psdparse source files (as defined by svn externals property)
PSDPARSE = psdparse
CFLAGS += -Wall -O2
CPPFLAGS += -I$(PSAPI)/Pica_sp -I$(PSAPI)/Photoshop -I$(PSAPI)/General \
-I../common/adobeplugin -I../common/tt -I$(PSDPARSE) \
-DPSDPARSE_PLUGIN -DPSBSUPPORT -DWANT_LARGE_FILES
# ---------- source & object files ----------
# where to find .c source files
vpath %.c ../common/tt ../common/adobeplugin $(PSDPARSE)
vpath %.m cocoa
# list object files
PSDPARSE_OBJ = extra.o descriptor.o resources.o icc.o channel.o plugin.o \
unpackbits.o constants.o psd.o util.o psd_zip.o duotone.o \
pdf.o
OBJ_COMMON = main.o read.o ui.o file_io.o str.o $(PSDPARSE_OBJ)
OBJ_OSX := ui_mac.o ui_compat_mac.o dbg_mac.o largefiles_forks.o \
ui_cocoa.o PsdExtractChooseLayerController.o \
$(OBJ_COMMON)
OBJ_W32 := ui_win.o ui_compat_win.o dbg_win.o largefiles_win.o \
file_compat_win.o dllmain.o obj_w32/res.o \
$(OBJ_COMMON)
# ---------- executables ----------
# parts of Mac OS X plugin bundle to build
# 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/PsdExtractChooseLayer.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 \
-I/Developer/Headers/FlatCarbon
# Win32 plugin DLL to build
PLUGIN_W32 = $(EXEC).8bi
DISTARCHIVE = dist/$(EXEC)-$(VERSION)-win.zip
$(PLUGIN_W32) : CPPFLAGS += -DWIN_ENV
# ---------- 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.
.PHONY : thin cs2 cs3 cs5 dll zip dmg clean
# 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
thin cs2 cs3 cs5 : $(PLUGIN_PARTS)
# Min system for CS2: Mac OS X v.10.2.8
cs2 : ARCH = -arch ppc
cs2 : CFLAGS += -isysroot /Developer/SDKs/MacOSX10.2.8.sdk -mmacosx-version-min=10.2
cs2 : LDFLAGS += -Wl,-syslibroot,/Developer/SDKs/MacOSX10.2.8.sdk -mmacosx-version-min=10.2
# 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 : CC = /usr/bin/gcc-4.0
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
$(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 $*.nib $@
clean :
rm -fr $(OBJ_OSX) $(OBJ_W32) $(PLUGIN_W32) $(BUNDLE)
zip : $(DISTARCHIVE)
$(DISTARCHIVE) : $(PLUGIN_W32) dist/README.txt dist/gpl.html
zip -j -9 $@ $^
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.txt dist/gpl.html
@ DIR=`mktemp -d $(EXEC)-XXXX`; \
cp -Rp dist/README.txt 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)
obj/PsdExtractChooseLayerController.o : cocoa/PsdExtractChooseLayerController.h
# note dependencies on version.h:
obj_w32/res.o : plugin.rc PiPL.rc ui_win.rc version.h
$(WINDRES) -i $< -o $@
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 ----------
# link OS X Mach-O executable
$(PLUGIN_OSX) : $(BUNDLE) exports.exp $(OBJ_OSX) $(PLUGIN_RSRC)
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 $@
# --------------------