# -*- mode: makefile -*-
#
# Build universal curl linked to libcurl framework. The built exeutable
# can be distributed in an application bundle Resources or MacOS
# directory, with the libcurl.framework in the bundle Frameworks
# directory.
#
# Usage:
#
#	cd curl-x.x.x
#	make -f /path/to/makefile 
#
# Copyright (C) 1998 - 2006, Daniel Stenberg, <daniel@haxx.se>, et al.
#
# This software is licensed as described in the file COPYING, which
# you should have received as part of this distribution. The terms
# are also available at http://curl.haxx.se/docs/copyright.html.
#
# You may opt to use, copy, modify, merge, publish, distribute and/or sell
# copies of the Software, and permit persons to whom the Software is
# furnished to do so, under the terms of the COPYING file.
#
# This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
# KIND, either express or implied.

BUILD_DIR := $(CURDIR)/build
FRAMEWORK_DIR := $(BUILD_DIR)/Frameworks
SDK := /Developer/SDKs/MacOSX10.4u.sdk
FRAMEWORK_PATH := DYLD_FRAMEWORK_PATH=$(FRAMEWORK_DIR):$(DYLD_FRAMEWORK_PATH)
LINK_WITH_FRAMEWORK := LDADD="-framework libcurl" \
	DEPENDENCIES="$(FRAMEWORK_DIR)/libcurl.framework"


# Run make install in src to update curl
all: configure framework
	cd src; make install \
		curl_LDADD="-framework libcurl" \
		curl_DEPENDENCIES="$(FRAMEWORK_DIR)/libcurl.framework"

# Run libcurl.framework.make in lib to update the framework
framework: configure
	cd lib; make build -e -f libcurl.framework.make
	mkdir -p $(FRAMEWORK_DIR)
	ditto lib/libcurl.framework $(FRAMEWORK_DIR)/libcurl.framework

# Configure for universal build 
configure: 
	./configure --prefix=$(BUILD_DIR) \
		--disable-dependency-tracking \
		CFLAGS="-F$(FRAMEWORK_DIR) -isysroot $(SDK) -arch ppc -arch i386" \
		LDFLAGS="-Wl,-syslibroot,$(SDK) -arch ppc -arch i386"

test:
	$(FRAMEWORK_PATH) make test $(LINK_WITH_FRAMEWORK)

test-full:
	$(FRAMEWORK_PATH) make test-full $(LINK_WITH_FRAMEWORK)

test-torture:
	$(FRAMEWORK_PATH) make test-torture $(LINK_WITH_FRAMEWORK)

clean:
	cd lib; make clean -e -f libcurl.framework.make
	make clean

.PHONY: all framework configure test clean

