\FF\D8\FF\E0\00JFIF\00\00\00d\00d\00\00\FF\FE\00\border bs:0 bc:#000000 ps:0 pc:#ffffff es:0 ec:#000000 ck:feee6c715d26fd9f38b0ca4278c05026\FF\DB\00C\00P7<F<2PFAFZUP_xxnnx\F5\AF\B9\91\C8\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\DB\00CUZZxix‚\EB\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\C0\00\00b\00d\00\FF\C4\00\00\00\00\00\00\00\00\00\00\00\00\00\00\FF\C4\00\00\00\00\00\00\00\00\00\00\001A!Q\FF\C4\00\00\00\00\00\00\00\00\00\00\00\00\00\FF\C4\00\00\00\00\00\00\00\00\00\00!1AQ\FF\DA\00\00\00?\00\F6\00\00\00\00\00\00\00\00\00\00\A0\00\00\C5\CF\F8\E7Ó\FCjD~\B9^\AD\%\B3]\D8cs-\BBs,-\A0\00"\80\00%\B83rÏ^K~F\A4ea\00E\00\C6\EE=u\B1\9B\D1\00@\00r\BE8\F9:\FE5#.M\00\E7\CB\C9q\CBq\D6\F2\BE\B7\C7>\C9n5×\D6?\BDê\9Ds\EBp\9F[`8m\B7)o\B5\E8\E6I\99\FE3]]A2\BA\8Cw\D6E\93\\DEv\C8\009\F2\F1NI?uc\\F5\EA\96k\xN<~buv\EA\C8\D7	\8B\84\CEcxI\BBg\AE\9E=\D6+n\EC\80\C8A\8C\AE\EB\CF\D5\DA\E9"2\A4\B9j5\EB\F3W\B63\96\B30Yu\DA\FC8\ED\DF\E7Ms\FB\F1\8E\B3\FA\EA\E8\E6(\883zs\F2_\8DFk\8Bh
\00\8C\DCw\D3R\B5+6X\BA\B2\C4j\AB0\B4\FCMw\C2I\8E\9B\E3\A9~9u\FA\D3l\80\C8%p\EE\FDn2€
\00$\FEj\C4e\A9\DB\~\95\A7\A5\80EK\BB\8DDsP\00@@AD'k\CF\E8\DB\D2(\80\9AK\D3\85\D6lb\F2\BA\8C*\80\00)\95
59\A3R:\F3\CE"\B6\80\88\00\00i1u4ê\E9\F2á\A6\A2\FACM\93WMb*\E0*\00\00\00\00\00(\A8\80\00\00\80\00\00\00\00\00\00\00\00\00\FF\D9<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>C///</title>
</head>
#!/usr/bin/env ruby
#  Phusion Passenger - https://www.phusionpassenger.com/
#  Copyright (c) 2010-2025 Asynchronous B.V.
#
#  "Passenger", "Phusion Passenger" and "Union Station" are registered
#  trademarks of Asynchronous B.V.
#
#  Permission is hereby granted, free of charge, to any person obtaining a copy
#  of this software and associated documentation files (the "Software"), to deal
#  in the Software without restriction, including without limitation the rights
#  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
#  copies of the Software, and to permit persons to whom the Software is
#  furnished to do so, subject to the following conditions:
#
#  The above copyright notice and this permission notice shall be included in
#  all copies or substantial portions of the Software.
#
#  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
#  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
#  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
#  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
#  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
#  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
#  THE SOFTWARE.

ESSENTIALS = [
  "boost/*regex*",
  "boost/algorithm/string",
  "boost/atomic",
  "boost/bind",
  "boost/chrono*",
  "boost/config*",
  "boost/container",
  "boost/core",
  "boost/cstdint.hpp",
  "boost/date_time",
  "boost/date_time/date_formatting_limited.hpp",
  "boost/date_time/gregorian/formatters_limited.hpp",
  "boost/detail/fenv.hpp",
  "boost/detail/reference_content.hpp",
  "boost/foreach.hpp",
  "boost/function",
  "boost/integer*",
  "boost/intrusive",
  "boost/move",
  "boost/mpl",
  "boost/non_type.hpp",
  "boost/none*",
  "boost/optional",
  "boost/optional.hpp",
  "boost/parameter",
  "boost/pool",
  "boost/predef",
  "boost/predef/other/endian.h",
  "boost/preprocessor",
  "boost/preprocessor/stringize.hpp",
  "boost/random*",
  "boost/ratio*",
  "boost/smart_ptr/detail/atomic_count*",
  "boost/smart_ptr/detail/sp_counted_*",
  "boost/smart_ptr/detail/spinlock*",
  "boost/system/config.hpp",
  "boost/system/detail/error_code.ipp",
  "boost/thread",
  "boost/type_traits",
  "boost/type_traits/detail/*",
  "boost/type_traits/make_signed.hpp",
  "boost/typeof",
  "boost/unordered*",
  "boost/utility",
  "libs/chrono/src",
  "libs/random/src",
  "libs/regex/src",
  "libs/system/src",
  "libs/thread/src",
]
EXCLUDE = [
  "libs/thread/src/win32/*",
  "libs/regex/src/w32_regex_traits.cpp",
  "libs/regex/src/fileiter.cpp",
  "libs/regex/src/icu.cpp",
  "libs/regex/src/usinstances.cpp",
  "boost/atomic/detail/windows.hpp",
  "boost/regex/icu.hpp",
]
PROGRAM_SOURCE = %q(
  #include <boost/aligned_storage.hpp>
  #include <boost/atomic.hpp>
  #include <boost/bind/bind.hpp>
  #include <boost/chrono.hpp>
  #include <boost/circular_buffer.hpp>
  #include <boost/config.hpp>
  #include <boost/container/small_vector.hpp>
  #include <boost/container/vector.hpp>
  #include <boost/core/noncopyable.hpp>
  #include <boost/cstdint.hpp>
  #include <boost/current_function.hpp>
  #include <boost/date_time/posix_time/posix_time.hpp>
  #include <boost/date_time/posix_time/posix_time_types.hpp>
  #include <boost/enable_shared_from_this.hpp>
  #include <boost/foreach.hpp>
  #include <boost/function.hpp>
  #include <boost/intrusive_ptr.hpp>
  #include <boost/make_shared.hpp>
  #include <boost/move/core.hpp>
  #include <boost/move/move.hpp>
  #include <boost/move/utility.hpp>
  #include <boost/noncopyable.hpp>
  #include <boost/nondet_random.hpp>
  #include <boost/pointer_cast.hpp>
  #include <boost/pool/object_pool.hpp>
  #include <boost/predef.h>
  #include <boost/predef/other/endian.h>
  #include <boost/preprocessor/stringize.hpp>
  #include <boost/random/random_device.hpp>
  #include <boost/random/uniform_int_distribution.hpp>
  #include <boost/ref.hpp>
  #include <boost/regex.hpp>
  #include <boost/scoped_array.hpp>
  #include <boost/scoped_ptr.hpp>
  #include <boost/shared_array.hpp>
  #include <boost/shared_ptr.hpp>
  #include <boost/smart_ptr/intrusive_ref_counter.hpp>
  #include <boost/static_assert.hpp>
  #include <boost/system/error_code.hpp>
  #include <boost/system/system_error.hpp>
  #include <boost/thread.hpp>
  #include <boost/thread/condition_variable.hpp>
  #include <boost/thread/mutex.hpp>
  #include <boost/thread/once.hpp>
  #include <boost/thread/tss.hpp>
  #include <boost/typeof/typeof.hpp>
  #include <boost/version.hpp>
  #include <boost/weak_ptr.hpp>
// Included despite not used in Passenger
  #include <boost/thread/thread_time.hpp>
  #include <boost/cregex.hpp>
  #include <boost/pointer_cast.hpp>
)

require 'fileutils'
BOOST_DIR = ARGV[0]
Dir.chdir(File.dirname(__FILE__) + "/../src/cxx_supportlib/vendor-modified")

# Run the given command, and abort on error.
def sh(*command)
  puts command.join(" ")
  if !system(*command)
    puts "*** ERROR"
    exit 1
  end
end

def install(source_filename, target_filename)
  dir = File.dirname(target_filename)
  if !File.exist?(dir)
    sh "mkdir", "-p", dir
  end
  command = [ "install", "-m", "u+rw,g+r,o+r", source_filename, target_filename ]
  sh(*command)
end

def copy_boost_files(patterns, exclude = nil)
  patterns.each do |pattern|
    files = Dir["#{BOOST_DIR}/#{pattern}"]
    files -= exclude if exclude
    files.each do |source|
      if File.directory?(source)
        source.slice!(0 .. BOOST_DIR.size)
        copy_boost_files([ "#{source}/*" ], exclude)
      else
        target = source.slice(BOOST_DIR.size + 1 .. source.size - 1)
        if target =~ /^libs\//
          target = "boost/#{target}"
        end
        if !File.exist?(target)
          install(source, target)
        end
      end
    end
  end
end

def copy_essential_files
  exclude = EXCLUDE.flat_map do |pattern|
    Dir["#{BOOST_DIR}/#{pattern}"]
  end
  copy_boost_files(ESSENTIALS, exclude)
end

def prepare
  File.open("test.cpp", "w") do |f|
    f.write(PROGRAM_SOURCE)
  end
end

def cleanup
  FileUtils.rm_rf("boost/atomic/detail/caps_windows.hpp")
  FileUtils.rm_rf("boost/atomic/detail/core_ops_windows.hpp")
  FileUtils.rm_rf("boost/atomic/detail/fence_ops_windows.hpp")
  FileUtils.rm_rf("boost/atomic/detail/ops_windows.hpp")
  FileUtils.rm_rf("boost/atomic/detail/wait_caps_windows.hpp")
  FileUtils.rm_rf("boost/atomic/detail/wait_ops_windows.hpp")
  FileUtils.rm_rf("boost/chrono/detail/inlined/win")
  FileUtils.rm_rf("boost/config/platform/cygwin.hpp")
  FileUtils.rm_rf("boost/config/platform/win32.hpp")
  FileUtils.rm_rf("boost/core/detail/sp_win32_sleep.hpp")
  FileUtils.rm_rf("boost/smart_ptr/detail/atomic_count_win32.hpp")
  FileUtils.rm_rf("boost/smart_ptr/detail/sp_counted_base_w32.hpp")
  FileUtils.rm_rf("boost/smart_ptr/detail/spinlock_w32.hpp")
  FileUtils.rm_rf("boost/src/win32")
  FileUtils.rm_rf("boost/thread/win32")
  File.unlink("test.cpp") rescue nil
end

# Compile PROGRAM_SOURCE and copy whatever missing header files the compiler needs.
def copy_dependencies(cflags)
  if RUBY_PLATFORM =~ /darwin/
    openssl_path = `brew --prefix openssl`.strip
  else
    openssl_path = '/usr/include/openssl'
  end

  loop do
    compiler_output = `c++ test.cpp -c -I#{openssl_path}/include -I. -I.. #{cflags.join(" ")} 2>&1`
    File.unlink('test.o') if File.exist?('test.o')
    missing_headers = compiler_output.lines.
      grep(/(error: .*: No such file|fatal error: '.*' file not found)/).
      reject { |s| s =~ /\/usr\/include\// }.
      map do |line|
        if line =~ /error: (.*): No such file/
          file = $1
        elsif line =~ /fatal error: '(.*)' file not found/
          file = $1
        else
          abort "Bug"
        end

        if file =~ /^boost\//
          file
        else
          line =~ /(.*?):/
          source = $1
          File.dirname(source) + "/" + file
        end
      end
    missing_headers.each do |header|
      install("#{BOOST_DIR}/#