forked from mobiruby/BridgeSupport
-
Notifications
You must be signed in to change notification settings - Fork 6
/
Makefile
273 lines (234 loc) · 10.2 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
##
# Makefile for BridgeSupport
##
ifdef RC_ProjectName
Project = $(RC_ProjectName)
else # !RC_ProjectName
Project = BridgeSupport
endif
include $(MAKEFILEPATH)/CoreOS/ReleaseControl/Common.make
# Override defaults
PWD = $(shell pwd)
DEF_DSTROOT = $(PWD)/DSTROOT
DSTROOT = $(DEF_DSTROOT)
OBJROOT = $(PWD)/OBJROOT
SRCROOT = $(PWD)
DEF_SYMROOT = $(PWD)/SYMROOT
SYMROOT = $(DEF_SYMROOT)
DESTDIR = /
RC_ARCHS = x86_64
ORDERED_ARCHS = $(filter %64,$(RC_ARCHS)) $(filter-out %64,$(RC_ARCHS))
RC_CFLAGS = $(foreach arch,$(RC_ARCHS),-arch $(arch)) -pipe
DEVELOPER_DIR = $(shell xcode-select -p)
SDKROOT = $(DEVELOPER_DIR)/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk
RSYNC = /usr/bin/rsync -rlpt
RUBY = ruby
ifneq ("$(wildcard /usr/local/bin/gcc-4.2)","")
CC = gcc-4.2
CXX = g++-4.2
else
CC = cc
CXX = c++
endif
# Use files to represent whether a directory exist, avoiding problems with
# the modification date of a directory changing. To avoid cluttering up
# the DSTROOT and SYMROOT with these files, we make them in the OBJROOT.
MADEFILE = .made
DSTROOT_MADE = $(OBJROOT)/.DSTROOT$(MADEFILE)
OBJROOT_MADE = $(OBJROOT)/$(MADEFILE)
SYMROOT_MADE = $(OBJROOT)/.SYMROOT$(MADEFILE)
USR_BIN = $(DSTROOT)/usr/bin
DTDS = $(DSTROOT)/System/Library/DTDs
ifeq ($(RC_ProjectName),BridgeSupport_ext)
BS_LIBS = $(OBJROOT)/BridgeSupport
else # !BridgeSupport_ext
BS_LIBS = $(DSTROOT)/System/Library/BridgeSupport
endif # !BridgeSupport_ext
BS_INCLUDE = $(BS_LIBS)/include
BS_RUBY := $(BS_LIBS)/ruby-$(shell $(RUBY) -e 'puts RUBY_VERSION.sub(/^(\d+\.\d+)(\..*)?$$/, "\\1")')
RUBYLIB = $(BS_RUBY)
LIBSYSTEM_HEADERS = $(SDKROOT)/usr/include/asl.h $(SDKROOT)/usr/include/notify*.h $(SDKROOT)/usr/include/copyfile.h $(SDKROOT)/usr/include/sandbox.h $(SDKROOT)/usr/include/launch.h $(SDKROOT)/usr/include/CommonCrypto/*.h
ifneq ($(realpath $(SDKROOT)/usr/include/objc/NSObjCRuntime.h),"")
LIBSYSTEM_HEADERS += $(SDKROOT)/usr/include/objc/NSObjCRuntime.h
endif
# For the Apple build system, we split into two separate projects:
# BridgeSupport_ext - build extension and save in /usr/local/BridgeSupport
# BridgeSupport - install extension and use it to build everything else
ifeq ($(RC_XBS),YES)
ifeq ($(RC_ProjectName),BridgeSupport_ext)
build:: start_build build_extension save_extension finish_build
else # !BridgeSupport_ext
build:: start_build install_extension build_files install_additional_files finish_build
endif # !BridgeSupport_ext
else # !RC_XBS
build:: start_build build_extension build_files install_additional_files finish_build
endif # !RC_XBS
.PHONY: start_build build_extension build_files install_additional_files finish_build save_extension install_extension
start_build:
@/bin/echo -n '*** Started Building $(Project): ' && date
finish_build:
@/bin/echo -n '*** Finished Building $(Project): ' && date
$(DSTROOT_MADE): $(OBJROOT_MADE)
$(MKDIR) $(DSTROOT)
$(TOUCH) $@
$(OBJROOT_MADE):
$(MKDIR) $(OBJROOT)
$(TOUCH) $@
$(SYMROOT_MADE): $(OBJROOT_MADE)
$(MKDIR) $(SYMROOT)
$(TOUCH) $@
# Subdirectories
CLANG_VERS = clang-801
CLANG_BRANCH = tags/RELEASE_801/final
CLANG_DIR = $(OBJROOT)/$(CLANG_VERS)
SWIG_DIR = $(OBJROOT)/swig
CLANG_DIR_MADE = $(CLANG_DIR)/$(MADEFILE)
$(CLANG_DIR_MADE): $(OBJROOT_MADE)
mkdir -p $(OBJROOT)
# cd $(OBJROOT) && git clone https://github.com/llvm-mirror/llvm.git $(CLANG_VERS) && cd $(CLANG_DIR) && git checkout -b $(CLANG_BRANCH) origin/$(CLANG_BRANCH)
# cd $(CLANG_DIR)/tools && git clone https://github.com/llvm-mirror/clang.git && cd $(CLANG_DIR)/tools/clang && git checkout -b $(CLANG_BRANCH) origin/$(CLANG_BRANCH)
# cd $(CLANG_DIR)/projects && git clone https://github.com/llvm-mirror/compiler-rt.git && cd $(CLANG_DIR)/projects/compiler-rt && git checkout -b $(CLANG_BRANCH) origin/$(CLANG_BRANCH)
cd $(OBJROOT) && svn co http://llvm.org/svn/llvm-project/llvm/$(CLANG_BRANCH) $(CLANG_VERS)
cd $(CLANG_DIR)/tools && svn co http://llvm.org/svn/llvm-project/cfe/$(CLANG_BRANCH) clang
cd $(CLANG_DIR)/tools/clang && patch -p0 < $(SRCROOT)/clang.patch
cd $(SRCROOT)
$(TOUCH) $@
SWIG_DIR_MADE = $(SWIG_DIR)/$(MADEFILE)
$(SWIG_DIR_MADE): $(OBJROOT_MADE)
cd $(SRCROOT)/swig && CLANGHOME=$(CLANGROOT) $(RUBY) extconf.rb && cd $(SRCROOT)
$(RSYNC) $(SRCROOT)/swig $(OBJROOT)
$(TOUCH) $@
ifeq ($(words $(RC_ARCHS)),1)
CLANGROOT = $(CLANG_DIR)/darwin-$(RC_ARCHS)/ROOT
else
CLANGROOT = $(OBJROOT)/ROOT
ARCHIVE_DIR = lib
ARCHIVE_LIST = $(OBJROOT)/archive_list
COPY_DIRS = bin include
endif
CLANGROOT_MADE = $(CLANGROOT)/$(MADEFILE)
CLANG_PREFIX = /usr
$(CLANGROOT_MADE): $(CLANG_DIR_MADE)
@/bin/echo -n '*** Started Building $(CLANG_VERS): ' && date
@set -x && \
for arch in $(RC_ARCHS); do \
$(RMDIR) $(CLANG_DIR)/darwin-$$arch && \
$(MKDIR) $(CLANG_DIR)/darwin-$$arch && \
(cd $(CLANG_DIR)/darwin-$$arch && \
$(MKDIR) ROOT && \
env MACOSX_DEPLOYMENT_TARGET=10.9 CC="$(CC) -arch $$arch" CXX="$(CXX) -arch $$arch" cmake ../ -G "Unix Makefiles" -DCMAKE_BUILD_TYPE=Release -DLLVM_TARGETS_TO_BUILD="X86" && \
env MACOSX_DEPLOYMENT_TARGET=10.9 CC="$(CC) -arch $$arch" CXX="$(CXX) -arch $$arch" make -j$(shell sysctl -n hw.ncpu) && \
$(MKDIR) $(CLANG_DIR)/darwin-$$arch/ROOT && \
make install DESTDIR=$(CLANG_DIR)/darwin-$$arch/ROOT) || exit 1; \
done
ifneq ($(words $(RC_ARCHS)),1)
$(MKDIR) $(CLANGROOT)$(CLANG_PREFIX)
cd $(CLANG_DIR)/darwin-$(firstword $(ORDERED_ARCHS))/ROOT$(CLANG_PREFIX) && $(RSYNC) $(COPY_DIRS) $(CLANGROOT)$(CLANG_PREFIX)
cd $(CLANG_DIR)/darwin-$(firstword $(ORDERED_ARCHS))/ROOT$(CLANG_PREFIX)/$(ARCHIVE_DIR) && ls *.a > $(ARCHIVE_LIST)
$(MKDIR) $(CLANGROOT)$(CLANG_PREFIX)/$(ARCHIVE_DIR)
@set -x && \
for a in `cat $(ARCHIVE_LIST)`; do \
$(LIPO) -create -output $(CLANGROOT)$(CLANG_PREFIX)/$(ARCHIVE_DIR)/$$a $(foreach arch,$(RC_ARCHS),-arch $(arch) $(CLANG_DIR)/darwin-$(arch)/ROOT$(CLANG_PREFIX)/$(ARCHIVE_DIR)/$$a) && \
$(RANLIB) $(CLANGROOT)$(CLANG_PREFIX)/$(ARCHIVE_DIR)/$$a || exit 1; \
done
endif
@/bin/echo -n '*** Finished Building $(CLANG_VERS): ' && date
$(TOUCH) $@
# Remove the $(BS_RUBY_MADE) file if you want bridgesupportparser.bundle remade
# or if bridgesupport.rb has been modified
BS_RUBY_MADE = $(OBJROOT)/.BS_RUBY$(MADEFILE)
$(BS_RUBY_MADE): $(CLANGROOT_MADE) $(SWIG_DIR_MADE) $(DSTROOT_MADE) $(SYMROOT_MADE)
@/bin/echo -n '*** Started Building bridgesupport.bundle: ' && date
@set -x && \
cd $(SWIG_DIR) && \
make LLVM-CONFIG=$(CLANGROOT)$(CLANG_PREFIX)/local/bin/llvm-config RC_CFLAGS='$(RC_CFLAGS)' && \
$(MKDIR) $(BS_RUBY) && \
$(RSYNC) bridgesupportparser.bundle* $(SYMROOT) && \
$(RSYNC) bridgesupportparser.bundle $(BS_RUBY) && \
$(STRIP) -x $(BS_RUBY)/bridgesupportparser.bundle && \
$(RSYNC) bridgesupportparser.rb $(BS_RUBY)
$(TOUCH) $@
BS_INCLUDE_MADE = $(OBJROOT)/.BS_INCLUDE$(MADEFILE)
$(BS_INCLUDE_MADE): $(DSTROOT_MADE)
$(INSTALL_DIRECTORY) $(BS_INCLUDE)
$(INSTALL_FILE) $(SRCROOT)/include/_BS_bool.h $(BS_INCLUDE)
@/bin/echo -n '*** Finished Building bridgesupport.bundle: ' && date
$(TOUCH) $@
build_extension: $(BS_RUBY_MADE) $(BS_INCLUDE_MADE)
SAVE_DIR = /usr/local/BridgeSupport/extension
save_extension: $(DSTROOT_MADE)
$(INSTALL_DIRECTORY) $(DSTROOT)$(SAVE_DIR)
ditto $(BS_LIBS) $(DSTROOT)$(SAVE_DIR)
install_extension: $(DSTROOT_MADE)
$(INSTALL_DIRECTORY) $(BS_LIBS)
ditto $(SAVE_DIR) $(BS_LIBS)
SYSTEM_BS = Frameworks/System.framework/Versions/B/Resources/BridgeSupport
SYSTEM_BRIDGESUPPORT = $(DSTROOT)/System/Library/$(SYSTEM_BS)
# Remove the $(LIBSYSTEM_BRIDGESUPPORT) file if you want the .bridgesupport
# files rebuilt. You will need to remove the corresponding .bridgesupport file
# (or the entire .framework directory) in $(DSTROOT)/System/Library/Frameworks,
# to get build.rb to rebuild it.
LIBSYSTEM_BRIDGESUPPORT = $(BS_LIBS)/libSystem.bridgesupport
LIBSYSTEM_XML = libSystem.xml
LIBSYSTEM_EXCEPTION = $(shell plat=`ruby -e 'puts "exceptions-\#{RUBY_PLATFORM}/$(LIBSYSTEM_XML)"'` && if [ -f "$$plat" ]; then echo "$$plat"; else echo "exceptions/$(LIBSYSTEM_XML)"; fi)
$(LIBSYSTEM_BRIDGESUPPORT):
@/bin/echo -n '*** Started Building .bridgesupport files: ' && date
# TODO : generate BridgeSupport files in each system library frameworks
# DSTROOT='$(DSTROOT)' RUBYLIB='$(RUBYLIB)' $(RUBY) build.rb
RUBYLIB='$(RUBYLIB)' $(RUBY) gen_bridge_metadata.rb -c '-isysroot $(SDKROOT) -I$(SDKROOT)/usr/include/CommonCrypto -I$(SDKROOT)/usr/include/objc' -e $(LIBSYSTEM_EXCEPTION) -o $@ $(LIBSYSTEM_HEADERS)
$(INSTALL_DIRECTORY) $(SYSTEM_BRIDGESUPPORT)
$(LN) -fs `echo $(SYSTEM_BS) | sed 's,[^/]*,..,g'`/BridgeSupport/libSystem.bridgesupport $(SYSTEM_BRIDGESUPPORT)/System.bridgesupport
@/bin/echo -n '*** Finished Building .bridgesupport files: ' && date
build_files: $(LIBSYSTEM_BRIDGESUPPORT)
BRIDGESUPPORT_5 = $(DSTROOT)$(MANDIR)/man5/BridgeSupport.5
$(BRIDGESUPPORT_5): $(DSTROOT_MADE)
$(MKDIR) $(USR_BIN)
$(INSTALL_PROGRAM) gen_bridge_metadata.rb $(USR_BIN)/gen_bridge_metadata
$(CHMOD) +x $(USR_BIN)/gen_bridge_metadata
$(MKDIR) $(DTDS)
$(CP) BridgeSupport.dtd $(DTDS)
$(MKDIR) $(DSTROOT)$(MANDIR)/man1
$(INSTALL_FILE) $(SRCROOT)/gen_bridge_metadata.1 $(DSTROOT)$(MANDIR)/man1/gen_bridge_metadata.1
$(MKDIR) $(DSTROOT)$(MANDIR)/man5
$(INSTALL_FILE) $(SRCROOT)/BridgeSupport.5 $@
install_additional_files: $(BRIDGESUPPORT_5)
ifeq ($(RC_XBS),YES) # Apple build system
# make binary submission verifier happy
# install_source::
# @set -x && \
# cd $(SRCROOT) && \
# $(TAR) -xjof $(CLANG_TARBALL) && \
# find $(CLANG_VERS) -name \*.a -delete -print && \
# $(RM) $(CLANG_TARBALL) && \
# $(TAR) -cjf $(CLANG_TARBALL) $(CLANG_VERS) && \
# $(RMDIR) $(CLANG_VERS)
else # normal make targets
install::
ifneq ($(DESTDIR),/)
$(MKDIR) $(DESTDIR)
endif
$(PERL) $(SRCROOT)/tar-chown-root.pl $(DSTROOT) | $(TAR) -xpf - -C $(DESTDIR)
clean::
ifeq ($(DSTROOT),$(DEF_DSTROOT))
$(_v) $(RMDIR) "$(DSTROOT)" || true
endif
ifeq ($(SYMROOT),$(DEF_SYMROOT))
$(_v) $(RMDIR) "$(SYMROOT)" || true
endif
endif #
build_bridgesupport:
DSTROOT='$(DSTROOT)' RUBYLIB='$(RUBYLIB)' $(RUBY) build.rb
update_exceptions:
$(RUBY) build.rb --update-exceptions
sort_exceptions:
for i in `ls exceptions/*.xml`; do $(RUBY) sort.rb $$i | xmllint -format - > $$i.new; mv $$i.new $$i; done
# recompile C++ in swig dir & rebuild DSTROOT
rebuild:
rm -rf $(BS_INCLUDE_MADE)
rm -rf $(BS_RUBY_MADE)
rm -rf $(DSTROOT_MADE)
rm -rf $(SYMROOT_MADE)
rm -rf $(SWIG_DIR)
rm -rf $(DSTROOT)
rm -rf $(SYMROOT)
make