Source

makeicns / Makefile

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

VERSION = 1.4.10

# 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
ifneq ($(wildcard .hg),)
	CHANGESET ?= $(shell hg id -i | sed 's/+//')
endif

CHANGESET ?=

# get Mac OSX version info
MACOS_MAJOR = $(shell sw_vers -productVersion | sed 's/\([0-9]*\)\.[0-9]*\..*/\1/' )
MACOS_MINOR = $(shell sw_vers -productVersion | sed 's/[0-9]*\.\([0-9]*\)\..*/\1/' )
DARWIN_MAJOR = $(shell uname -r | sed 's/\([0-9]*\)\..*/\1/' )
SDK ?= $(wildcard /Developer/SDKs/MacOSX$(MACOS_MAJOR).$(MACOS_MINOR)*)

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

# set CFLAGS
CFLAGS += -DVERSION=\"$(VERSION)\" -DCHANGESET=\"$(CHANGESET)\" -O2 -fpascal-strings

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

# set build system
ifeq ($(DARWIN_MAJOR),11)
	BUILD_SYSTEM = LION
endif
ifeq ($(DARWIN_MAJOR),10)
	BUILD_SYSTEM = SNOWLEOPARD
  DM_GT_9 = true
endif
ifeq ($(DARWIN_MAJOR),9)
  BUILD_SYSTEM = LEOPARD
endif
ifeq ($(DARWIN_MAJOR),8)
  BUILD_SYSTEM = TIGER
endif
ifeq ($(DARWIN_MAJOR),7)
  BUILD_SYSTEM = PANTHER
endif
ifeq ($(BUILD_SYSTEM),)
  BUILD_SYSTEM = UNSUPPORTED
  $(warning building for an UNSUPPORTED OS)
endif
DARWIN_MAJOR_GT_9 := $(shell [ $(DARWIN_MAJOR) -ge 9  && echo true)

# set additional CFLAGS
ifeq ($(BUILD_UNIVERSAL),yes)
	if [ $(DARWIN_MAJOR_GT_9) ]
		CFLAGS += -arch i386 -arch x86_64
	else
		CFLAGS += -arch i386 -arch ppc
	fi
endif

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

.PHONY: all target clean dist test help beautify

all: target makeicns

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

target:
	@echo "Building makeicns $(VERSION) for Mac OS X $(BUILD_SYSTEM) system"
	@echo "MACOS_MAJOR = $(MACOS_MAJOR)"
	@echo "MACOS_MINOR = $(MACOS_MINOR)"
	@echo "DARWIN_MAJOR = $(DARWIN_MAJOR)"
	@echo "SDK = $(SDK)"

clean:
	rm -rf makeicns.o IconFamily.o NSString+CarbonFSRefCreation.o *.icns makeicns *.unc-backup*

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; open test.icns
	./makeicns -in test-nonsquare_tall.png               -out t.icns ; open t.icns
	./makeicns -in test-nonsquare_tall.png -align left   -out tl.icns; open tl.icns
	./makeicns -in test-nonsquare_tall.png -align right  -out tr.icns; open tr.icns
	./makeicns -in test-nonsquare_wide.png               -out w.icns ; open w.icns
	./makeicns -in test-nonsquare_wide.png -align top    -out wt.icns; open wt.icns
	./makeicns -in test-nonsquare_wide.png -align bottom -out wb.icns; open wb.icns

beautify:
	uncrustify -c makeicns.uncrustify --replace makeicns.m IconFamily.m IconFamily.h NSString+CarbonFSRefCreation.m NSString+CarbonFSRefCreation.h

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 or greater 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 ""