#!/usr/local/bin/ruby
#
#
# arirang Makefile for Ruby 1.8x and Ruby 1.9x
# tested on *BSD, Linux, Mac OS X Lion
#
# maybe other systems required  -L#{$libdir} variable.
#
# ruby extconf.rb
# make
# ./arirang
#
require 'mkmf'
libruby = CONFIG['RUBY_SO_NAME']

makefile =  "all: arirang\n"
makefile += "exec_prefix = /usr/local\n"
makefile += "CC=         cc\n"
makefile += "CFLAGS+=-Wall -pedantic\n"
makefile += "TARGET=     arirang\n"
makefile += "SRCS=       arirang.c grabhead.c rule.c screen.c report.c arissl.c ariruby.c proxy.c debug.c\n"
makefile += "OBJS=       $(SRCS:.c=.o)\n\n"

makefile += ".c.o:\n"

if RUBY_VERSION =~ /1.9/ then
    makefile += "	$(CC) $(CFLAGS) -c $< -I #{$topdir} -I #{$topdir}/#{RUBY_PLATFORM} -DRUBY_19\n\n"
else
    makefile += "	$(CC) $(CFLAGS) -c $< -I #{$topdir} \n\n"
end

makefile += "$(TARGET) : $(OBJS)\n"
#makefile += "  $(CC) $(CFLAGS) -o $(TARGET) $(OBJS) -L#{$LIBPATH} -lssl -lcrypto -l#{libruby} \n\n\n"

if RUBY_PLATFORM =~ /linux/ then
    makefile += "	$(CC) $(CFLAGS) -o $(TARGET) $(OBJS) -L#{$libdir} -lssl -lcrypto -l#{libruby} -lresolv\n\n\n"
elsif RUBY_PLATFORM =~ /darwin/ then
    makefile += "	$(CC) $(CFLAGS) -o $(TARGET) $(OBJS) -lssl -lcrypto -l#{libruby} -lresolv\n\n\n"
else
    makefile += "	$(CC) $(CFLAGS) -o $(TARGET) $(OBJS) -L#{$libdir} -lssl -lcrypto -l#{libruby} \n\n\n"
end


makefile += "clean:\n"
makefile += "	rm -f *.core core $(OBJS)\n"
makefile += "	rm -f $(TARGET) \n"

File.open("Makefile", "w") do |fd|
    fd.write(makefile)
end

