]> git.saurik.com Git - apple/ld64.git/blob - unit-tests/include/common.makefile
ld64-274.1.tar.gz
[apple/ld64.git] / unit-tests / include / common.makefile
1 # stuff to include in every test Makefile
2
3 SHELL = /bin/sh
4
5 # set default to be host
6 ARCH ?= $(shell arch)
7
8 # set default to be all
9 VALID_ARCHS ?= "i386 x86_64 armv6"
10
11
12 MYDIR=$(shell cd ../../bin;pwd)
13 LD = ld
14 OBJECTDUMP = ObjectDump
15 OBJCIMAGEINFO = objcimageinfo
16 MACHOCHECK = machocheck
17 OTOOL = xcrun otool
18 REBASE = rebase
19 DYLDINFO = dyldinfo
20
21 ifdef BUILT_PRODUCTS_DIR
22 # if run within Xcode, add the just built tools to the command path
23 PATH := ${BUILT_PRODUCTS_DIR}:${MYDIR}:${PATH}
24 COMPILER_PATH := ${BUILT_PRODUCTS_DIR}:${COMPILER_PATH}
25 LD_PATH = ${BUILT_PRODUCTS_DIR}
26 LD = ${BUILT_PRODUCTS_DIR}/ld
27 OBJECTDUMP = ${BUILT_PRODUCTS_DIR}/ObjectDump
28 OBJCIMAGEINFO = ${BUILT_PRODUCTS_DIR}/objcimageinfo
29 MACHOCHECK = ${BUILT_PRODUCTS_DIR}/machocheck
30 REBASE = ${BUILT_PRODUCTS_DIR}/rebase
31 UNWINDDUMP = ${BUILT_PRODUCTS_DIR}/unwinddump
32 DYLDINFO = ${BUILT_PRODUCTS_DIR}/dyldinfo
33 else
34 ifneq "$(findstring /unit-tests/test-cases/, $(shell pwd))" ""
35 # if run from Terminal inside unit-test directory
36 RELEASEADIR=$(shell cd ../../../build/Release-assert;pwd)
37 DEBUGDIR=$(shell cd ../../../build/Debug;pwd)
38 PATH := ${RELEASEADIR}:${RELEASEDIR}:${DEBUGDIR}:${MYDIR}:${PATH}
39 COMPILER_PATH := ${RELEASEADIR}:${RELEASEDIR}:${DEBUGDIR}:${COMPILER_PATH}
40 LD_PATH = ${DEBUGDIR}
41 LD = ${DEBUGDIR}/ld
42 OBJECTDUMP = ${DEBUGDIR}/ObjectDump
43 OBJCIMAGEINFO = ${DEBUGDIR}/objcimageinfo
44 MACHOCHECK = ${DEBUGDIR}/machocheck
45 REBASE = ${DEBUGDIR}/rebase
46 UNWINDDUMP = ${DEBUGDIR}/unwinddump
47 DYLDINFO = ${DEBUGDIR}/dyldinfo
48 else
49 PATH := ${MYDIR}:${PATH}:
50 COMPILER_PATH := ${MYDIR}:${COMPILER_PATH}:
51 endif
52 endif
53 export PATH
54 export COMPILER_PATH
55 export GCC_EXEC_PREFIX=garbage
56
57 IOS_SDK = $(shell xcodebuild -sdk iphoneos.internal -version Path 2>/dev/null)
58 OSX_SDK = $(shell xcodebuild -sdk macosx.internal -version Path 2>/dev/null)
59 ifeq ($(ARCH),ppc)
60 OSX_SDK = /Developer/SDKs/MacOSX10.6.sdk
61 endif
62
63 CC = $(shell xcrun -find clang) -arch ${ARCH} -mmacosx-version-min=10.8 -isysroot $(OSX_SDK)
64 CCFLAGS = -Wall
65 LDFLAGS = -syslibroot $(OSX_SDK)
66 ASMFLAGS =
67 VERSION_NEW_LINKEDIT = -mmacosx-version-min=10.6
68 VERSION_OLD_LINKEDIT = -mmacosx-version-min=10.4
69 LD_NEW_LINKEDIT = -macosx_version_min 10.6
70
71 CXX = $(shell xcrun -find clang++) -arch ${ARCH} -isysroot $(OSX_SDK)
72 CXXFLAGS = -Wall -stdlib=libc++
73
74 ifeq ($(ARCH),armv6)
75 LDFLAGS := -syslibroot $(IOS_SDK)
76 override FILEARCH = arm
77 CC = $(shell xcrun -find clang) -arch ${ARCH} -ccc-install-dir ${LD_PATH} -miphoneos-version-min=5.0 -isysroot $(IOS_SDK)
78 CXX = $(shell xcrun -find clang++) -arch ${ARCH} -ccc-install-dir ${LD_PATH} -miphoneos-version-min=5.0 -isysroot $(IOS_SDK)
79 VERSION_NEW_LINKEDIT = -miphoneos-version-min=4.0
80 VERSION_OLD_LINKEDIT = -miphoneos-version-min=3.0
81 LD_SYSROOT = -syslibroot $(IOS_SDK)
82 LD_NEW_LINKEDIT = -ios_version_min 4.0
83 else
84 FILEARCH = $(ARCH)
85 endif
86
87 ifeq ($(ARCH),armv7)
88 LDFLAGS := -syslibroot $(IOS_SDK)
89 override FILEARCH = arm
90 CC = $(shell xcrun -find clang) -arch ${ARCH} -ccc-install-dir ${LD_PATH} -miphoneos-version-min=5.0 -isysroot $(IOS_SDK)
91 CXX = $(shell xcrun -find clang++) -arch ${ARCH} -ccc-install-dir ${LD_PATH} -miphoneos-version-min=5.0 -isysroot $(IOS_SDK)
92 VERSION_NEW_LINKEDIT = -miphoneos-version-min=4.0
93 VERSION_OLD_LINKEDIT = -miphoneos-version-min=3.0
94 LD_SYSROOT = -syslibroot $(IOS_SDK)
95 LD_NEW_LINKEDIT = -ios_version_min 4.0
96 else
97 FILEARCH = $(ARCH)
98 endif
99
100 ifeq ($(ARCH),thumb)
101 LDFLAGS := -syslibroot $(IOS_SDK)
102 CCFLAGS += -mthumb
103 CXXFLAGS += -mthumb
104 override ARCH = armv6
105 override FILEARCH = arm
106 CC = $(shell xcrun -find clang) -arch ${ARCH} -ccc-install-dir ${LD_PATH} -miphoneos-version-min=5.0 -isysroot $(IOS_SDK)
107 CXX = $(shell xcrun -find clang++) -arch ${ARCH} -ccc-install-dir ${LD_PATH} -miphoneos-version-min=5.0 -isysroot $(IOS_SDK)
108 VERSION_NEW_LINKEDIT = -miphoneos-version-min=4.0
109 VERSION_OLD_LINKEDIT = -miphoneos-version-min=3.0
110 LD_SYSROOT = -syslibroot $(IOS_SDK)
111 LD_NEW_LINKEDIT = -ios_version_min 4.0
112 else
113 FILEARCH = $(ARCH)
114 endif
115
116 ifeq ($(ARCH),thumb2)
117 LDFLAGS := -syslibroot $(IOS_SDK)
118 CCFLAGS += -mthumb
119 CXXFLAGS += -mthumb
120 override ARCH = armv7
121 override FILEARCH = arm
122 CC = $(shell xcrun -find clang) -arch ${ARCH} -ccc-install-dir ${LD_PATH} -miphoneos-version-min=5.0 -isysroot $(IOS_SDK)
123 CXX = $(shell xcrun -find clang++) -arch ${ARCH} -ccc-install-dir ${LD_PATH} -miphoneos-version-min=5.0 -isysroot $(IOS_SDK)
124 VERSION_NEW_LINKEDIT = -miphoneos-version-min=4.0
125 VERSION_OLD_LINKEDIT = -miphoneos-version-min=3.0
126 LD_SYSROOT = -syslibroot $(IOS_SDK)
127 LD_NEW_LINKEDIT = -ios_version_min 4.0
128 else
129 FILEARCH = $(ARCH)
130 endif
131
132 ifeq ($(ARCH),arm64)
133 LDFLAGS := -syslibroot $(IOS_SDK)
134 CC = $(shell xcrun --sdk iphoneos.internal -find clang) -arch ${ARCH} -ccc-install-dir ${LD_PATH} -miphoneos-version-min=9.0 -isysroot $(IOS_SDK)
135 CXX = $(shell xcrun --sdk iphoneos.internal -find clang++) -arch ${ARCH} -ccc-install-dir ${LD_PATH} -miphoneos-version-min=9.0 -isysroot $(IOS_SDK)
136 VERSION_NEW_LINKEDIT = -miphoneos-version-min=7.0
137 VERSION_OLD_LINKEDIT = -miphoneos-version-min=3.0
138 LD_SYSROOT = -syslibroot $(IOS_SDK)
139 LD_NEW_LINKEDIT = -ios_version_min 7.0
140 OTOOL = $(shell xcrun --sdk iphoneos.internal -find otool)
141 else
142 FILEARCH = $(ARCH)
143 endif
144
145 RM = rm
146 RMFLAGS = -rf
147
148 # utilites for Makefiles
149 PASS_IFF = ${MYDIR}/pass-iff-exit-zero.pl
150 PASS_IFF_SUCCESS = ${PASS_IFF}
151 PASS_IFF_EMPTY = ${MYDIR}/pass-iff-no-stdin.pl
152 PASS_IFF_STDIN = ${MYDIR}/pass-iff-stdin.pl
153 FAIL_IFF = ${MYDIR}/fail-iff-exit-zero.pl
154 FAIL_IFF_SUCCESS = ${FAIL_IFF}
155 PASS_IFF_ERROR = ${MYDIR}/pass-iff-exit-non-zero.pl
156 FAIL_IF_ERROR = ${MYDIR}/fail-if-exit-non-zero.pl
157 FAIL_IF_SUCCESS = ${MYDIR}/fail-if-exit-zero.pl
158 FAIL_IF_EMPTY = ${MYDIR}/fail-if-no-stdin.pl
159 FAIL_IF_STDIN = ${MYDIR}/fail-if-stdin.pl
160 PASS_IFF_GOOD_MACHO = ${PASS_IFF} ${MACHOCHECK}
161 FAIL_IF_BAD_MACHO = ${FAIL_IF_ERROR} ${MACHOCHECK}
162 FAIL_IF_BAD_OBJ = ${FAIL_IF_ERROR} ${OBJECTDUMP} >/dev/null