--- ./ext/ruby_http_parser/extconf.rb 2022-04-18 19:41:59.313000000 +0000 +++ ./ext/ruby_http_parser/extconf.rb 2022-04-18 20:21:08.161000000 +0000 @@ -1,3 +1,5 @@ +#!/usr/bin/ruby + require 'mkmf' # check out code if it hasn't been already @@ -10,12 +12,21 @@ end # mongrel and http-parser both define http_parser_(init|execute), so we # rename functions in http-parser before using them. -vendor_dir = File.expand_path('../vendor/http-parser/', __FILE__) src_dir = File.expand_path('../', __FILE__) -%w[ http_parser.c http_parser.h ].each do |file| - File.open(File.join(src_dir, "ryah_#{file}"), 'w'){ |f| - f.write File.read(File.join(vendor_dir, file)).gsub('http_parser', 'ryah_http_parser') - } +if find_library("http_parser", "http_parser_init") && find_header("http_parser.h") + File.open("ryah_http_parser.h", "w+") do |f| + f.puts('#include "http_parser.h"') + [nil, :settings, :type, :execute, :init].each do |name| + f.puts("#define #{["ryah_http_parser", name].compact.join("_")} #{["http_parser", name].compact.join("_")}") + end + end +else + vendor_dir = File.expand_path('../vendor/http-parser/', __FILE__) + %w[ http_parser.c http_parser.h ].each do |file| + File.open(File.join(src_dir, "ryah_#{file}"), 'w'){ |f| + f.write File.read(File.join(vendor_dir, file)).gsub('http_parser', 'ryah_http_parser') + } + end end $CFLAGS << " -I\"#{src_dir}\""