-CFLAGS=-g -O2 -arch i386
-CFLAGS64=-g -O2 -arch x86_64
+SDKROOT ?= /
+ifeq "$(RC_TARGET_CONFIG)" "iPhone"
+Embedded?=YES
+else
+Embedded?=$(shell echo $(SDKROOT) | grep -iq iphoneos && echo YES || echo NO)
+endif
-TARGETS = MPMMtest MPMMtest_64 KQMPMMtest KQMPMMtest_64 KQMPMMtestD KQMPMMtest_64D
+CC:=xcrun -sdk "$(SDKROOT)" cc
-all: $(TARGETS)
+SYMROOT?=$(shell /bin/pwd)
-MPMMtest: MPMMtest.c
- ${CC} ${CFLAGS} -o $@ $?
+CFLAGS := -g -O2
-MPMMtest_64: MPMMtest.c
- ${CC} ${CFLAGS64} -o $@ $?
+ifdef RC_ARCHS
+ ARCHS:=$(RC_ARCHS)
+ else
+ ifeq "$(Embedded)" "YES"
+ ARCHS:=armv7 armv7s
+ else
+ ARCHS:=x86_64 i386
+ endif
+endif
-KQMPMMtest: KQMPMMtest.c
- ${CC} ${CFLAGS} -o $@ $?
+ARCH_32 := $(filter-out %64, $(ARCHS))
+ARCH_32_FLAGS := $(patsubst %, -arch %, $(ARCH_32))
+ARCH_64 := $(filter %64, $(ARCHS))
+ARCH_64_FLAGS := $(patsubst %, -arch %, $(ARCH_64))
-KQMPMMtest_64: KQMPMMtest.c
- ${CC} ${CFLAGS64} -o $@ $?
+DSTROOT?=$(shell /bin/pwd)
-KQMPMMtestD: KQMPMMtest.c
- ${CC} ${CFLAGS} -DDIRECT_MSG_RCV=1 -o $@ $?
+ARCH_32_TARGETS := MPMMtest KQMPMMtest KQMPMMtestD
+ARCH_64_TARGETS := MPMMtest_64 KQMPMMtest_64 KQMPMMtest_64D
+TARGETS := $(if $(ARCH_64), $(ARCH_64_TARGETS)) $(if $(ARCH_32), $(ARCH_32_TARGETS))
-KQMPMMtest_64D: KQMPMMtest.c
- ${CC} ${CFLAGS64} -DDIRECT_MSG_RCV=1 -o $@ $?
+all: $(addprefix $(DSTROOT)/, $(TARGETS))
+
+$(DSTROOT)/MPMMtest: MPMMtest.c
+ ${CC} ${CFLAGS} ${ARCH_32_FLAGS} -o $(SYMROOT)/$(notdir $@) $?
+ if [ ! -e $@ ]; then ditto $(SYMROOT)/$(notdir $@) $@; fi
+
+$(DSTROOT)/MPMMtest_64: MPMMtest.c
+ ${CC} ${CFLAGS} ${ARCH_64_FLAGS} -o $(SYMROOT)/$(notdir $@) $?
+ if [ ! -e $@ ]; then ditto $(SYMROOT)/$(notdir $@) $@; fi
+
+$(DSTROOT)/KQMPMMtest: KQMPMMtest.c
+ ${CC} ${CFLAGS} ${ARCH_32_FLAGS} -o $(SYMROOT)/$(notdir $@) $?
+ if [ ! -e $@ ]; then ditto $(SYMROOT)/$(notdir $@) $@; fi
+
+$(DSTROOT)/KQMPMMtest_64: KQMPMMtest.c
+ ${CC} ${CFLAGS} ${ARCH_64_FLAGS} -o $(SYMROOT)/$(notdir $@) $?
+ if [ ! -e $@ ]; then ditto $(SYMROOT)/$(notdir $@) $@; fi
+
+$(DSTROOT)/KQMPMMtestD: KQMPMMtest.c
+ ${CC} ${CFLAGS} ${ARCH_32_FLAGS} -DDIRECT_MSG_RCV=1 -o $(SYMROOT)/$(notdir $@) $?
+ if [ ! -e $@ ]; then ditto $(SYMROOT)/$(notdir $@) $@; fi
+
+$(DSTROOT)/KQMPMMtest_64D: KQMPMMtest.c
+ ${CC} ${CFLAG} ${ARCH_64_FLAGS} -DDIRECT_MSG_RCV=1 -o $(SYMROOT)/$(notdir $@) $?
+ if [ ! -e $@ ]; then ditto $(SYMROOT)/$(notdir $@) $@; fi
clean:
- rm -rf $(TARGETS) *.dSYM
+ rm -rf $(addprefix $(DSTROOT)/,$(TARGETS)) $(addprefix $(SYMROOT)/,$(TARGETS)) $(SYMROOT)/*.dSYM