Source

makeicns / Makefile.brad

Full commit
# The MIT License
# http://www.opensource.org/licenses/mit-license.php

SHELL := /bin/sh

VERSION = 1.5

# determine Mercurial's changeset (this works on MacPorts)
ifneq ($(wildcard .hg_archival.txt),)
	CHANGESET = $(shell grep 'node:' .hg_archival.txt | sed 's/node:[ \t]*\([[:xdigit:]]\{12\}\).*/\1/')
endif

# if the above failed due to missing .hg_archival.txt simply fall back to using hg itself
CHANGESET ?= $(shell hg id -i | sed 's/+//')

# In case we don't get the changeset by the above two methods
CHANGESET ?= undefined

# Set Mac OSX versions according to Xcode

# Get Mac OSX version info
MAC_OS_X_VERSION = $(shell sw_vers -productVersion)
MAC_OS_X_VERSION_MAJOR = $(shell sw_vers -productVersion | sed 's/\([0-9]*\.[0-9]*\)\..*/\1/' )
MAC_OS_X_XCODE_VERSION = $(shell sw_vers -productVersion | awk 'BEGIN { FS = "." } ; {print $$1$$2"0"} ;')
MAC_OS_X_XCODE_VAR = $(shell sw_vers -productVersion | awk 'BEGIN { FS = "." } ; {print "MAC_OS_X_VERSION_"$$1"_"$$2} ;')
SYSTEM_PROCESSOR_TYPE = $(shell uname -p)

# Are we on a system greater than Mac OS X Leopard
MAC_OS_X_XCODE_VERSION_GREATER_THAN_1050 = $(shell if [ $(MAC_OS_X_XCODE_VERSION) -gt 1050 ]; then \
		echo yes; \
	else \
		echo no; \
	fi;)

# Set SDK if not set
SDK ?= $(wildcard /Developer/SDKs/MacOSX$(MAC_OS_X_VERSION_MAJOR)*)

# Set default compilers
CC ?= gcc
CXX ?= g++

# Set CFLAGS
CFLAGS += -DVERSION=$(VERSION) -DCHANGESET=$(CHAMAC_OS_X_XCODE_VERSIONNGESET) -O2 -fpascal-strings \
	-D$(MAC_OS_X_XCODE_VAR)=$(MAC_OS_X_XCODE_VERSION) \
	-DMAC_OS_X_VERSION_MAX_ALLOWED=$(MAC_OS_X_XCODE_VERSION) \
	-DMAC_OS_X_VERSION_MIN_REQUIRED=$(MAC_OS_X_XCODE_VERSION)

# Set LDFLAGS
LDFLAGS += -framework Foundation -framework AppKit -framework Carbon

# Are we on a system greater than Mac OS X Leopard
MAC_OS_X_XCODE_VERSION_GREATER_THAN_1050 = $(shell if [ $(MAC_OS_X_XCODE_VERSION) -gt 1050 ]; then \
		echo yes; \
	else \
		echo no; \
	fi;)

# Set additional CFLAGS
ifeq ($(MAC_OS_X_XCODE_VERSION_GREATER_THAN_1050),yes)
	CFLAGS += -arch x86_64
else
	CFLAGS += -arch $(shell uname -m)
endif

# If building universal set additional CFLAGS
ifeq ($(BUILD_UNIVERSAL),yes)
	ifeq ($(MAC_OS_X_XCODE_VERSION_GREATER_THAN_1050),yes)
		CFLAGS += -arch i386
	else
		ifeq ($(MAC_OS_X_XCODE_VERSION),1040)
			ifneq ($(SYSTEM_PROCESSOR_TYPE),powerpc)
				CFLAGS += -arch powerpc
			else
				CFLAGS += -arch i386
			endif
		else
			ifneq ($(SYSTEM_PROCESSOR_TYPE),ppc)
				CFLAGS += -arch ppc
			else
				CFLAGS += -arch i386
			endif
		endif
	endif
endif

# Set LDFLAGS
ifneq ($(SDK),)
	LDFLAGS += -isysroot $(SDK)
endif

.PHONY: all target clean dist test help

all: target makeicns

makeicns: makeicns.o IconFamily.o NSString+CarbonFSRefCreation.o 
	$(CXX) -o $@ $^ $(LDFLAGS)

target:
	@echo "Building makeicns $(VERSION) for Mac OS X $(MAC_OS_X_VERSION) system"
	@echo "MAC_OS_X_VERSION = $(MAC_OS_X_VERSION)"
	@echo "MAC_OS_X_XCODE_VERSION = $(MAC_OS_X_XCODE_VERSION)"
	@echo "MAC_OS_X_XCODE_VAR = $(MAC_OS_X_XCODE_VAR)"
	@echo "SDK = $(SDK)"
	@echo "CFLAGS = $(CFLAGS)"
	@echo "LDFLAGS = $(LDFLAGS)"

clean:
	rm -rf makeicns.o IconFamily.o NSString+CarbonFSRefCreation.o test.icns makeicns

dist: 
	rm -rf makeicns-$(VERSION).tar.gz
	tar cjf makeicns-$(VERSION).tar.gz Makefile makeicns.m IconFamily.m IconFamily.h \
		NSString+CarbonFSRefCreation.m NSString+CarbonFSRefCreation.h

test:
	./makeicns -in test.png -out test.icns

help:
	@echo ""
	@echo "		Environment vars that effect build "
	@echo ""
	@echo "		CC=/path sets the C compiler path. default: gcc"
	@echo "		CXX=/path sets the C++ compiler path. default: g++"
	@echo "		CFLAGS"
	@echo "		LDFLAGS"
	@echo "		SDK=/path sets Developer SDKs, default: dynamic"
	@echo "		BUILD_UNIVERSAL=yes builds universal binaries. default no"
	@echo "				On Snow Leopard this sets -arch i386 -arch x86_64"
	@echo "				On all others this sets -arch i386 -arch ppc"
	@echo ""
	@echo "		example: CC=/usr/bin/gcc-4.2 CXX=/usr/bin/g++-4.2 BUILD_UNIVERSAL=yes make"
	@echo ""