Jan Tattermusch | 7897ae9 | 2017-06-07 22:57:36 +0200 | [diff] [blame] | 1 | # Copyright 2015 gRPC authors. |
nnoble | 097ef9b | 2014-12-01 17:06:10 -0800 | [diff] [blame] | 2 | # |
Jan Tattermusch | 7897ae9 | 2017-06-07 22:57:36 +0200 | [diff] [blame] | 3 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | # you may not use this file except in compliance with the License. |
| 5 | # You may obtain a copy of the License at |
nnoble | 097ef9b | 2014-12-01 17:06:10 -0800 | [diff] [blame] | 6 | # |
Jan Tattermusch | 7897ae9 | 2017-06-07 22:57:36 +0200 | [diff] [blame] | 7 | # http://www.apache.org/licenses/LICENSE-2.0 |
nnoble | 097ef9b | 2014-12-01 17:06:10 -0800 | [diff] [blame] | 8 | # |
Jan Tattermusch | 7897ae9 | 2017-06-07 22:57:36 +0200 | [diff] [blame] | 9 | # Unless required by applicable law or agreed to in writing, software |
| 10 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | # See the License for the specific language governing permissions and |
| 13 | # limitations under the License. |
nnoble | 097ef9b | 2014-12-01 17:06:10 -0800 | [diff] [blame] | 14 | |
J. Martin | 18e8b14 | 2017-02-23 18:52:46 -0600 | [diff] [blame] | 15 | require 'etc' |
nnoble | 097ef9b | 2014-12-01 17:06:10 -0800 | [diff] [blame] | 16 | require 'mkmf' |
| 17 | |
| 18 | LIBDIR = RbConfig::CONFIG['libdir'] |
| 19 | INCLUDEDIR = RbConfig::CONFIG['includedir'] |
| 20 | |
| 21 | HEADER_DIRS = [ |
Tim Emiola | e2860c5 | 2015-01-16 02:58:41 -0800 | [diff] [blame] | 22 | # Search /opt/local (Mac source install) |
| 23 | '/opt/local/include', |
nnoble | 097ef9b | 2014-12-01 17:06:10 -0800 | [diff] [blame] | 24 | |
Tim Emiola | e2860c5 | 2015-01-16 02:58:41 -0800 | [diff] [blame] | 25 | # Search /usr/local (Source install) |
| 26 | '/usr/local/include', |
nnoble | 097ef9b | 2014-12-01 17:06:10 -0800 | [diff] [blame] | 27 | |
Tim Emiola | e2860c5 | 2015-01-16 02:58:41 -0800 | [diff] [blame] | 28 | # Check the ruby install locations |
| 29 | INCLUDEDIR |
nnoble | 097ef9b | 2014-12-01 17:06:10 -0800 | [diff] [blame] | 30 | ] |
| 31 | |
| 32 | LIB_DIRS = [ |
Tim Emiola | e2860c5 | 2015-01-16 02:58:41 -0800 | [diff] [blame] | 33 | # Search /opt/local (Mac source install) |
| 34 | '/opt/local/lib', |
nnoble | 097ef9b | 2014-12-01 17:06:10 -0800 | [diff] [blame] | 35 | |
Tim Emiola | e2860c5 | 2015-01-16 02:58:41 -0800 | [diff] [blame] | 36 | # Search /usr/local (Source install) |
| 37 | '/usr/local/lib', |
nnoble | 097ef9b | 2014-12-01 17:06:10 -0800 | [diff] [blame] | 38 | |
Tim Emiola | e2860c5 | 2015-01-16 02:58:41 -0800 | [diff] [blame] | 39 | # Check the ruby install locations |
| 40 | LIBDIR |
nnoble | 097ef9b | 2014-12-01 17:06:10 -0800 | [diff] [blame] | 41 | ] |
| 42 | |
Nicolas "Pixel" Noble | d51d121 | 2016-01-31 11:33:19 +0100 | [diff] [blame] | 43 | windows = RUBY_PLATFORM =~ /mingw|mswin/ |
Frank Groeneveld | fbf8128 | 2017-10-12 08:27:14 +0200 | [diff] [blame] | 44 | bsd = RUBY_PLATFORM =~ /bsd/ |
Nicolas "Pixel" Noble | d51d121 | 2016-01-31 11:33:19 +0100 | [diff] [blame] | 45 | |
murgatroid99 | d7e1a10 | 2015-12-18 11:16:16 -0800 | [diff] [blame] | 46 | grpc_root = File.expand_path(File.join(File.dirname(__FILE__), '../../../..')) |
| 47 | |
| 48 | grpc_config = ENV['GRPC_CONFIG'] || 'opt' |
| 49 | |
Nicolas Noble | 86cbe30 | 2016-02-05 15:08:12 -0800 | [diff] [blame] | 50 | ENV['MACOSX_DEPLOYMENT_TARGET'] = '10.7' |
| 51 | |
Nicolas "Pixel" Noble | 791e93e | 2016-03-01 02:48:00 +0100 | [diff] [blame] | 52 | ENV['AR'] = RbConfig::CONFIG['AR'] + ' rcs' |
| 53 | ENV['CC'] = RbConfig::CONFIG['CC'] |
Craig Tiller | 9f3822c | 2017-04-10 15:07:22 -0700 | [diff] [blame] | 54 | ENV['CXX'] = RbConfig::CONFIG['CXX'] |
Nicolas "Pixel" Noble | 791e93e | 2016-03-01 02:48:00 +0100 | [diff] [blame] | 55 | ENV['LD'] = ENV['CC'] |
Nicolas "Pixel" Noble | e7a91a2 | 2016-01-28 07:46:08 +0100 | [diff] [blame] | 56 | |
Nicolas "Pixel" Noble | 791e93e | 2016-03-01 02:48:00 +0100 | [diff] [blame] | 57 | ENV['AR'] = 'libtool -o' if RUBY_PLATFORM =~ /darwin/ |
Nicolas Noble | 2bc107f | 2016-02-02 23:15:22 -0800 | [diff] [blame] | 58 | |
Nicolas "Pixel" Noble | 791e93e | 2016-03-01 02:48:00 +0100 | [diff] [blame] | 59 | ENV['EMBED_OPENSSL'] = 'true' |
| 60 | ENV['EMBED_ZLIB'] = 'true' |
Yuchen Zeng | b1b2115 | 2016-08-12 11:27:30 -0700 | [diff] [blame] | 61 | ENV['EMBED_CARES'] = 'true' |
Nicolas "Pixel" Noble | 791e93e | 2016-03-01 02:48:00 +0100 | [diff] [blame] | 62 | ENV['ARCH_FLAGS'] = RbConfig::CONFIG['ARCH_FLAG'] |
| 63 | ENV['ARCH_FLAGS'] = '-arch i386 -arch x86_64' if RUBY_PLATFORM =~ /darwin/ |
Alexander Polcyn | ebcc6b3 | 2017-12-08 15:39:53 -0800 | [diff] [blame] | 64 | ENV['CPPFLAGS'] = '-DGPR_BACKWARDS_COMPATIBILITY_MODE' |
Nicolas "Pixel" Noble | e7a91a2 | 2016-01-28 07:46:08 +0100 | [diff] [blame] | 65 | |
Nicolas "Pixel" Noble | 791e93e | 2016-03-01 02:48:00 +0100 | [diff] [blame] | 66 | output_dir = File.expand_path(RbConfig::CONFIG['topdir']) |
| 67 | grpc_lib_dir = File.join(output_dir, 'libs', grpc_config) |
| 68 | ENV['BUILDDIR'] = output_dir |
Nicolas "Pixel" Noble | e7a91a2 | 2016-01-28 07:46:08 +0100 | [diff] [blame] | 69 | |
Nicolas "Pixel" Noble | d8b07cb | 2016-05-05 03:55:55 +0200 | [diff] [blame] | 70 | unless windows |
| 71 | puts 'Building internal gRPC into ' + grpc_lib_dir |
J. Martin | 18e8b14 | 2017-02-23 18:52:46 -0600 | [diff] [blame] | 72 | nproc = 4 |
| 73 | nproc = Etc.nprocessors * 2 if Etc.respond_to? :nprocessors |
Frank Groeneveld | fbf8128 | 2017-10-12 08:27:14 +0200 | [diff] [blame] | 74 | make = bsd ? 'gmake' : 'make' |
| 75 | system("#{make} -j#{nproc} -C #{grpc_root} #{grpc_lib_dir}/libgrpc.a CONFIG=#{grpc_config} Q=") |
Nicolas "Pixel" Noble | d8b07cb | 2016-05-05 03:55:55 +0200 | [diff] [blame] | 76 | exit 1 unless $? == 0 |
| 77 | end |
nnoble | 097ef9b | 2014-12-01 17:06:10 -0800 | [diff] [blame] | 78 | |
murgatroid99 | d7e1a10 | 2015-12-18 11:16:16 -0800 | [diff] [blame] | 79 | $CFLAGS << ' -I' + File.join(grpc_root, 'include') |
Nicolas "Pixel" Noble | d51d121 | 2016-01-31 11:33:19 +0100 | [diff] [blame] | 80 | $LDFLAGS << ' ' + File.join(grpc_lib_dir, 'libgrpc.a') unless windows |
murgatroid99 | d7e1a10 | 2015-12-18 11:16:16 -0800 | [diff] [blame] | 81 | if grpc_config == 'gcov' |
| 82 | $CFLAGS << ' -O0 -fprofile-arcs -ftest-coverage' |
| 83 | $LDFLAGS << ' -fprofile-arcs -ftest-coverage -rdynamic' |
murgatroid99 | 51dbf90 | 2015-07-07 16:00:06 -0700 | [diff] [blame] | 84 | end |
| 85 | |
Alexander Polcyn | 38ba85c | 2016-08-29 16:59:23 -0700 | [diff] [blame] | 86 | if grpc_config == 'dbg' |
Alexander Polcyn | d359498 | 2018-04-05 03:12:27 -0700 | [diff] [blame] | 87 | $CFLAGS << ' -O0 -ggdb3' |
Alexander Polcyn | 38ba85c | 2016-08-29 16:59:23 -0700 | [diff] [blame] | 88 | end |
| 89 | |
Nicolas "Pixel" Noble | d355497 | 2016-02-03 02:11:43 +0100 | [diff] [blame] | 90 | $LDFLAGS << ' -Wl,-wrap,memcpy' if RUBY_PLATFORM =~ /linux/ |
| 91 | $LDFLAGS << ' -static' if windows |
Craig Tiller | 4bef7ce | 2016-02-02 08:38:43 -0800 | [diff] [blame] | 92 | |
murgatroid99 | fa0fa18 | 2015-07-07 18:02:00 -0700 | [diff] [blame] | 93 | $CFLAGS << ' -std=c99 ' |
| 94 | $CFLAGS << ' -Wall ' |
| 95 | $CFLAGS << ' -Wextra ' |
| 96 | $CFLAGS << ' -pedantic ' |
murgatroid99 | 0b90c1e | 2015-07-07 17:44:46 -0700 | [diff] [blame] | 97 | |
Nicolas "Pixel" Noble | eade6e0 | 2016-01-29 22:53:31 +0100 | [diff] [blame] | 98 | output = File.join('grpc', 'grpc_c') |
Nicolas "Pixel" Noble | e7a91a2 | 2016-01-28 07:46:08 +0100 | [diff] [blame] | 99 | puts 'Generating Makefile for ' + output |
| 100 | create_makefile(output) |
murgatroid99 | d7e1a10 | 2015-12-18 11:16:16 -0800 | [diff] [blame] | 101 | |
Nicolas "Pixel" Noble | e7a91a2 | 2016-01-28 07:46:08 +0100 | [diff] [blame] | 102 | strip_tool = RbConfig::CONFIG['STRIP'] |
Nicolas Noble | 2bc107f | 2016-02-02 23:15:22 -0800 | [diff] [blame] | 103 | strip_tool = 'strip -x' if RUBY_PLATFORM =~ /darwin/ |
Nicolas "Pixel" Noble | e7a91a2 | 2016-01-28 07:46:08 +0100 | [diff] [blame] | 104 | |
Nicolas "Pixel" Noble | 1723044 | 2016-01-29 01:46:19 +0100 | [diff] [blame] | 105 | if grpc_config == 'opt' |
| 106 | File.open('Makefile.new', 'w') do |o| |
| 107 | o.puts 'hijack: all strip' |
| 108 | o.puts |
| 109 | File.foreach('Makefile') do |i| |
| 110 | o.puts i |
| 111 | end |
| 112 | o.puts |
| 113 | o.puts 'strip:' |
| 114 | o.puts "\t$(ECHO) Stripping $(DLLIB)" |
| 115 | o.puts "\t$(Q) #{strip_tool} $(DLLIB)" |
Nicolas "Pixel" Noble | e7a91a2 | 2016-01-28 07:46:08 +0100 | [diff] [blame] | 116 | end |
Nicolas "Pixel" Noble | 1723044 | 2016-01-29 01:46:19 +0100 | [diff] [blame] | 117 | File.rename('Makefile.new', 'Makefile') |
Nicolas "Pixel" Noble | e7a91a2 | 2016-01-28 07:46:08 +0100 | [diff] [blame] | 118 | end |