Index: pjproject/branches/projects/iphone/aconfigure
===================================================================
--- pjproject/branches/projects/iphone/aconfigure	(revision 3167)
+++ pjproject/branches/projects/iphone/aconfigure	(revision 3168)
@@ -672,4 +672,15 @@
 CXXFLAGS
 ac_ct_CXX
+AR
+LD
+LDOUT
+RANLIB
+LIBEXT
+LIBEXT2
+CC_OUT
+CC_INC
+CC_DEF
+CC_OPTIMIZE
+CC_CFLAGS
 ac_pjdir
 ac_build_mak_vars
@@ -1946,5 +1957,5 @@
 ac_config_headers="$ac_config_headers pjlib/include/pj/compat/os_auto.h pjlib/include/pj/compat/m_auto.h pjmedia/include/pjmedia/config_auto.h pjmedia/include/pjmedia-codec/config_auto.h pjsip/include/pjsip/sip_autoconf.h"
 
-ac_config_files="$ac_config_files build.mak build/os-auto.mak pjlib/build/os-auto.mak pjlib-util/build/os-auto.mak pjmedia/build/os-auto.mak pjsip/build/os-auto.mak third_party/build/os-auto.mak third_party/build/portaudio/os-auto.mak"
+ac_config_files="$ac_config_files build.mak build/os-auto.mak build/cc-auto.mak pjlib/build/os-auto.mak pjlib-util/build/os-auto.mak pjmedia/build/os-auto.mak pjsip/build/os-auto.mak third_party/build/os-auto.mak third_party/build/portaudio/os-auto.mak"
 
 
@@ -3246,4 +3257,31 @@
 ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
 ac_compiler_gnu=$ac_cv_c_compiler_gnu
+
+
+if test "$AR" = ""; then AR="$(CROSS_COMPILE)ar rv"; fi
+
+if test "$LD" = ""; then LD="$CC"; fi
+
+if test "$LDOUT" = ""; then LDOUT="-o"; fi
+
+if test "$RANLIB" = ""; then RANLIB="$(CROSSCOMPILE)ranlib"; fi
+
+if test "$OBJEXT" = ""; then OBJEXT='o'; fi
+
+if test "$LIBEXT" = ""; then LIBEXT='a'; fi
+
+if test "$LIBEXT2" = ""; then LIBEXT2=""; fi
+
+if test "$CC_OUT" = ""; then CC_OUT="-o"; fi
+
+if test "$CC_INC" = ""; then CC_INC="-I"; fi
+
+if test "$CC_DEF" = ""; then CC_DEF="-D"; fi
+
+if test "$CC_OPTIMIZE" = ""; then CC_OPTIMIZE="-O2"; fi
+
+if test "$CC_CFLAGS" = ""; then CC_CFLAGS="-Wall"; fi
+
+
 
 
@@ -11003,4 +11041,9 @@
 else
  case $target in
+  arm-apple-darwin*)
+	LIBS="$LIBS -framework CoreAudio -framework CoreFoundation -framework AudioToolbox"
+	{ echo "$as_me:$LINENO: result: Checking sound device backend... AudioUnit" >&5
+echo "${ECHO_T}Checking sound device backend... AudioUnit" >&6; }
+	;;
   *darwin*)
 	LIBS="$LIBS -framework CoreAudio -framework CoreServices -framework AudioUnit -framework AudioToolbox"
@@ -12770,4 +12813,5 @@
     "build.mak") CONFIG_FILES="$CONFIG_FILES build.mak" ;;
     "build/os-auto.mak") CONFIG_FILES="$CONFIG_FILES build/os-auto.mak" ;;
+    "build/cc-auto.mak") CONFIG_FILES="$CONFIG_FILES build/cc-auto.mak" ;;
     "pjlib/build/os-auto.mak") CONFIG_FILES="$CONFIG_FILES pjlib/build/os-auto.mak" ;;
     "pjlib-util/build/os-auto.mak") CONFIG_FILES="$CONFIG_FILES pjlib-util/build/os-auto.mak" ;;
@@ -12896,4 +12940,15 @@
 CXXFLAGS!$CXXFLAGS$ac_delim
 ac_ct_CXX!$ac_ct_CXX$ac_delim
+AR!$AR$ac_delim
+LD!$LD$ac_delim
+LDOUT!$LDOUT$ac_delim
+RANLIB!$RANLIB$ac_delim
+LIBEXT!$LIBEXT$ac_delim
+LIBEXT2!$LIBEXT2$ac_delim
+CC_OUT!$CC_OUT$ac_delim
+CC_INC!$CC_INC$ac_delim
+CC_DEF!$CC_DEF$ac_delim
+CC_OPTIMIZE!$CC_OPTIMIZE$ac_delim
+CC_CFLAGS!$CC_CFLAGS$ac_delim
 ac_pjdir!$ac_pjdir$ac_delim
 ac_build_mak_vars!$ac_build_mak_vars$ac_delim
@@ -12923,13 +12978,7 @@
 libssl_present!$libssl_present$ac_delim
 libcrypto_present!$libcrypto_present$ac_delim
-ac_cross_compile!$ac_cross_compile$ac_delim
-ac_linux_poll!$ac_linux_poll$ac_delim
-ac_host!$ac_host$ac_delim
-ac_main_obj!$ac_main_obj$ac_delim
-LIBOBJS!$LIBOBJS$ac_delim
-LTLIBOBJS!$LTLIBOBJS$ac_delim
-_ACEOF
-
-  if test `sed -n "s/.*$ac_delim\$/X/p" conf$$subs.sed | grep -c X` = 92; then
+_ACEOF
+
+  if test `sed -n "s/.*$ac_delim\$/X/p" conf$$subs.sed | grep -c X` = 97; then
     break
   elif $ac_last_try; then
@@ -12950,4 +12999,51 @@
 cat >>$CONFIG_STATUS <<_ACEOF
 cat >"\$tmp/subs-1.sed" <<\CEOF$ac_eof
+/@[a-zA-Z_][a-zA-Z_0-9]*@/!b
+_ACEOF
+sed '
+s/[,\\&]/\\&/g; s/@/@|#_!!_#|/g
+s/^/s,@/; s/!/@,|#_!!_#|/
+:n
+t n
+s/'"$ac_delim"'$/,g/; t
+s/$/\\/; p
+N; s/^.*\n//; s/[,\\&]/\\&/g; s/@/@|#_!!_#|/g; b n
+' >>$CONFIG_STATUS <conf$$subs.sed
+rm -f conf$$subs.sed
+cat >>$CONFIG_STATUS <<_ACEOF
+CEOF$ac_eof
+_ACEOF
+
+
+ac_delim='%!_!# '
+for ac_last_try in false false false false false :; do
+  cat >conf$$subs.sed <<_ACEOF
+ac_cross_compile!$ac_cross_compile$ac_delim
+ac_linux_poll!$ac_linux_poll$ac_delim
+ac_host!$ac_host$ac_delim
+ac_main_obj!$ac_main_obj$ac_delim
+LIBOBJS!$LIBOBJS$ac_delim
+LTLIBOBJS!$LTLIBOBJS$ac_delim
+_ACEOF
+
+  if test `sed -n "s/.*$ac_delim\$/X/p" conf$$subs.sed | grep -c X` = 6; then
+    break
+  elif $ac_last_try; then
+    { { echo "$as_me:$LINENO: error: could not make $CONFIG_STATUS" >&5
+echo "$as_me: error: could not make $CONFIG_STATUS" >&2;}
+   { (exit 1); exit 1; }; }
+  else
+    ac_delim="$ac_delim!$ac_delim _$ac_delim!! "
+  fi
+done
+
+ac_eof=`sed -n '/^CEOF[0-9]*$/s/CEOF/0/p' conf$$subs.sed`
+if test -n "$ac_eof"; then
+  ac_eof=`echo "$ac_eof" | sort -nru | sed 1q`
+  ac_eof=`expr $ac_eof + 1`
+fi
+
+cat >>$CONFIG_STATUS <<_ACEOF
+cat >"\$tmp/subs-2.sed" <<\CEOF$ac_eof
 /@[a-zA-Z_][a-zA-Z_0-9]*@/!b end
 _ACEOF
@@ -13207,5 +13303,5 @@
 s&@abs_top_builddir@&$ac_abs_top_builddir&;t t
 $ac_datarootdir_hack
-" $ac_file_inputs | sed -f "$tmp/subs-1.sed" >$tmp/out
+" $ac_file_inputs | sed -f "$tmp/subs-1.sed" | sed -f "$tmp/subs-2.sed" >$tmp/out
 
 test -z "$ac_datarootdir_hack$ac_datarootdir_seen" &&
Index: pjproject/branches/projects/iphone/aconfigure.ac
===================================================================
--- pjproject/branches/projects/iphone/aconfigure.ac	(revision 3167)
+++ pjproject/branches/projects/iphone/aconfigure.ac	(revision 3168)
@@ -14,4 +14,5 @@
 AC_CONFIG_FILES([build.mak 
 		 build/os-auto.mak 
+		 build/cc-auto.mak
 		 pjlib/build/os-auto.mak 
 		 pjlib-util/build/os-auto.mak 
@@ -34,7 +35,37 @@
 CXXFLAGS="$CFLAGS $CXXFLAGS"
 
+dnl #
+dnl # Configure tools
+dnl #
 AC_PROG_CC
 AC_PROG_CXX
 AC_LANG_C
+
+if test "$AR" = ""; then AR="$(CROSS_COMPILE)ar rv"; fi
+AC_SUBST(AR)
+if test "$LD" = ""; then LD="$CC"; fi
+AC_SUBST(LD)
+if test "$LDOUT" = ""; then LDOUT="-o"; fi
+AC_SUBST(LDOUT)
+if test "$RANLIB" = ""; then RANLIB="$(CROSSCOMPILE)ranlib"; fi
+AC_SUBST(RANLIB)
+if test "$OBJEXT" = ""; then OBJEXT='o'; fi
+AC_SUBST(OBJEXT)
+if test "$LIBEXT" = ""; then LIBEXT='a'; fi
+AC_SUBST(LIBEXT)
+if test "$LIBEXT2" = ""; then LIBEXT2=""; fi
+AC_SUBST(LIBEXT2)
+if test "$CC_OUT" = ""; then CC_OUT="-o"; fi
+AC_SUBST(CC_OUT)
+if test "$CC_INC" = ""; then CC_INC="-I"; fi
+AC_SUBST(CC_INC)
+if test "$CC_DEF" = ""; then CC_DEF="-D"; fi
+AC_SUBST(CC_DEF)
+if test "$CC_OPTIMIZE" = ""; then CC_OPTIMIZE="-O2"; fi
+AC_SUBST(CC_OPTIMIZE)
+if test "$CC_CFLAGS" = ""; then CC_CFLAGS="-Wall"; fi
+AC_SUBST(CC_CFLAGS)
+
+
 
 AC_SUBST(ac_pjdir)
@@ -475,4 +506,8 @@
 else
  case $target in
+  arm-apple-darwin*)
+	LIBS="$LIBS -framework CoreAudio -framework CoreFoundation -framework AudioToolbox"
+	AC_MSG_RESULT([Checking sound device backend... AudioUnit])
+	;;
   *darwin*)
 	LIBS="$LIBS -framework CoreAudio -framework CoreServices -framework AudioUnit -framework AudioToolbox"
Index: pjproject/branches/projects/iphone/build.mak.in
===================================================================
--- pjproject/branches/projects/iphone/build.mak.in	(revision 3167)
+++ pjproject/branches/projects/iphone/build.mak.in	(revision 3168)
@@ -61,5 +61,6 @@
 # CFLAGS, LDFLAGS, and LIBS to be used by applications
 export PJDIR := @ac_pjdir@
-export APP_CC := $(CROSS_COMPILE)$(CC_NAME)
+export APP_CC := @CC@
+export APP_CXX := @CXX@
 export APP_CFLAGS := -DPJ_AUTOCONF=1\
 	@CFLAGS@\
@@ -106,4 +107,5 @@
 export PJ_DIR := $(PJDIR)
 export PJ_CC := $(APP_CC)
+export PJ_CXX := $(APP_CXX)
 export PJ_CFLAGS := $(APP_CFLAGS)
 export PJ_CXXFLAGS := $(APP_CXXFLAGS)
Index: pjproject/branches/projects/iphone/build/cc-auto.mak.in
===================================================================
--- pjproject/branches/projects/iphone/build/cc-auto.mak.in	(revision 3168)
+++ pjproject/branches/projects/iphone/build/cc-auto.mak.in	(revision 3168)
@@ -0,0 +1,21 @@
+export CC = @CC@ -c
+export CXX = @CXX@ -c
+export AR = @AR@
+export LD = @LD@
+export LDOUT = -o 
+export RANLIB = @RANLIB@
+
+export OBJEXT := .@OBJEXT@
+export LIBEXT := .@LIBEXT@
+export LIBEXT2 := @LIBEXT2@
+
+export CC_OUT := @CC_OUT@
+export CC_INC := @CC_INC@
+export CC_DEF := @CC_DEF@
+export CC_OPTIMIZE := @CC_OPTIMIZE@
+export CC_LIB := -l
+
+export CC_SOURCES :=
+export CC_CFLAGS := @CC_CFLAGS@
+export CC_LDFLAGS :=
+
Index: pjproject/branches/projects/iphone/build/common.mak
===================================================================
--- pjproject/branches/projects/iphone/build/common.mak	(revision 3167)
+++ pjproject/branches/projects/iphone/build/common.mak	(revision 3168)
@@ -16,4 +16,13 @@
 #
 -include cc-$(CC_NAME).mak
+
+#
+# Include auto configured compiler specification.
+# This will override the compiler settings above.
+# Currently this is made OPTIONAL, to prevent people
+# from getting errors because they don't re-run ./configure
+# after downloading new PJSIP.
+#
+-include $(PJDIR)/build/cc-auto.mak
 
 #
Index: pjproject/branches/projects/iphone/build/rules.mak
===================================================================
--- pjproject/branches/projects/iphone/build/rules.mak	(revision 3167)
+++ pjproject/branches/projects/iphone/build/rules.mak	(revision 3168)
@@ -66,4 +66,7 @@
 	@echo $(APP)_LDFLAGS=$($(APP)_LDFLAGS)
 	@echo DEPFLAGS=$(DEPFLAGS)
+	@echo CC=$(CC)
+	@echo AR=$(AR)
+	@echo RANLIB=$(RANLIB)
 
 print_bin: print_common
Index: pjproject/branches/projects/iphone/configure-iphone
===================================================================
--- pjproject/branches/projects/iphone/configure-iphone	(revision 3168)
+++ pjproject/branches/projects/iphone/configure-iphone	(revision 3168)
@@ -0,0 +1,61 @@
+#!/bin/bash
+
+if test "$*" = "--help" -o "$*" = "-h"; then
+  echo "configure-iphone [SDK=name_path] [OPTIONS]"
+  echo ""
+  echo "SDK=name_path   Choose which SDK to use. Value can be SDK name (e.g."
+  echo "                iPhoneOS2.2.1.sdk) or the full path of the SDK"
+  echo "OPTIONS         Other options that will be passed directly to "
+  echo "                ./aconfigure script. Run ./aconfigure --help for"
+  echo "                more info."
+  echo ""
+  exit 0
+fi
+
+F="configure-iphone"
+
+# Set the main iPhone developer directory, if not set
+if test "x${DEVPATH}" = "x"; then
+  DEVPATH=/Developer/Platforms/iPhoneOS.platform/Developer
+fi
+
+# Make sure $DEVPATH directory exist
+if test ! -d $DEVPATH; then
+  echo "$F error: directory $DEVPATH does not exist. Please install iPhone development kit"
+  exit 1
+fi
+
+# Choose SDK version to use
+if test "x$SDK" = "x"; then
+  # If SDK is not set, use the latest one
+  for f in `ls $DEVPATH/SDKs/`; do echo $f | sed 's/\(.sdk\)//'; done | sort | tail -1 > tmpsdkname
+  SDK=`cat tmpsdkname`.sdk
+  rm -f tmpsdkname
+  echo "$F info: using ${SDK}"
+  SDKPATH=${DEVPATH}/SDKs/${SDK}
+elif test -d ${SDK}; then
+  # .. else if SDK is set and it points to a valid path, just use it
+  SDKPATH=${SDK}
+else
+  # .. else assume the SDK name is used.
+  SDKPATH=${DEVPATH}/SDKs/${SDK}
+fi
+
+# Test the SDK directory
+if test ! -d ${SDKPATH}/usr/include; then
+  echo "$F error: unable to find valid iPhone SDK in ${SDKPATH}"
+  exit 1
+fi
+
+# Settings to feed to configure script
+export CFLAGS="-O2 -arch armv6 -isysroot ${SDKPATH}"
+export LDFLAGS="-O2 -arch armv6 -isysroot ${SDKPATH} -framework AudioToolbox -framework Foundation"
+export AR="${DEVPATH}/usr/bin/libtool -static -o"
+export RANLIB="echo ranlib"
+# Use gcc -E as preprocessor instead of cpp, since cpp will find the
+# header files in standard /usr/include
+export CPP="${DEVPATH}/usr/bin/arm-apple-darwin9-gcc -E -isysroot ${SDKPATH}"
+
+# And finally invoke configure script itself
+./aconfigure --host=arm-apple-darwin9 --disable-floating-point $*
+
