1#!/usr/bin/env ruby
2# Copyright (c) 2006-2007, The RubyCocoa Project.
3# All Rights Reserved.
4#
5# RubyCocoa is free software, covered under either the Ruby's license or the 
6# LGPL. See the COPYRIGHT file for more information.
7
8require 'rbconfig'
9
10def show_options
11  puts "Usage:"
12  puts "  #{__FILE__} build [options] <output dir>"
13  puts ""
14  puts "  build  Create the RDoc documentation for the supported frameworks"
15  puts ''
16  puts "Options:"
17  puts "  The extra options only apply to 'build' option and are options passed"
18  puts "  to the actual rdocify_framework.rb script."
19  puts "  These are:"
20  puts "  -v Verbose output."
21  puts "  -f Force the output files to be written even if there were errors during parsing."
22  puts ''
23  puts "Output Dir:"
24  puts "  If a optional output dir is specified,"
25  puts "  the documentation will be generated in that location."
26  puts ""
27  puts "Examples:"
28  puts "  #{__FILE__} build ~/documentation"
29  puts "  #{__FILE__} build -v -f"
30  puts ''
31end
32
33def command( str )
34  $stderr.puts str
35  system str or raise RuntimeError, "'system #{str}' failed"
36end
37
38def ruby( str )
39  command "#{Config::CONFIG["bindir"]}/ruby #{str}"
40end
41
42def rdoc( str )
43  command "#{Config::CONFIG["bindir"]}/rdoc #{str}"
44end
45
46unless ARGV[0].nil?
47  case ARGV[0]
48  when 'build'
49    options = []
50    output_dir = ''
51    
52    # Check if there are any other args
53    if ARGV.length > 1
54      ARGV[1..-1].each do |arg|
55        case arg
56        when '-v'
57          options.push '-v'
58        when '-f'
59          options.push '-f'
60        else
61          output_dir = arg
62        end
63      end
64    end
65    
66    # Get a reference to the output dir and create it if necessary
67    unless output_dir.empty?
68      output_dir = File.expand_path(output_dir)
69      unless File.exist?(output_dir)
70        command "mkdir -p #{output_dir}"
71      end
72    else
73      output_dir = File.join(File.dirname(File.expand_path(__FILE__)), 'doc/')
74    end
75    
76    DOCUMENTATION_PATH =
77      if `sw_vers -productVersion`.strip =~ /^10\.5/
78        '/Developer/Documentation/DocSets/com.apple.ADC_Reference_Library.CoreReference.docset/Contents/Resources/Documents/documentation'
79      else
80        '/Developer/ADC Reference Library/documentation'
81      end
82    SUPPORTED_FRAMEWORKS = ["#{DOCUMENTATION_PATH}/Cocoa/Reference/ApplicationKit/",
83                            "#{DOCUMENTATION_PATH}/Cocoa/Reference/Foundation/",
84                            "#{DOCUMENTATION_PATH}/Cocoa/Reference/WebKit/",
85                            "#{DOCUMENTATION_PATH}/Cocoa/Reference/CoreDataFramework/",
86                            "#{DOCUMENTATION_PATH}/QuickTime/Reference/QTKitFramework/",
87                            "#{DOCUMENTATION_PATH}/UserExperience/Reference/AddressBook/",
88                            "#{DOCUMENTATION_PATH}/AppleApplications/Reference/InstantMessageFrameworkRef/",
89                            "#{DOCUMENTATION_PATH}/GraphicsImaging/Reference/QuartzFramework/"]
90
91    start_time = Time.now
92    
93    # Setup the env
94    ENV['DYLD_FRAMEWORK_PATH'] = File.expand_path('../build/Default')
95    ENV['BRIDGE_SUPPORT_PATH'] = File.expand_path('../bridge-support')
96    
97    # Parse the rdoc for each supported framework
98    SUPPORTED_FRAMEWORKS.each do |f|
99      ruby "-I../../ext/rubycocoa -I../../lib gen_bridge_doc/rdocify_framework.rb #{options.join(' ')} '#{f}' #{output_dir}/ruby"
100    end
101    
102    osx_additions = %w{oc_attachments.rb oc_attachments_appkit.rb oc_types.rb oc_types_appkit.rb ruby_addition.rb}.map do |file|
103      File.expand_path(file, '../src/ruby/osx/objc/')
104    end.join(' ')
105    
106    # Create the rdoc files
107    #system "rdoc  --line-numbers --inline-source --template gen_bridge_doc/allison/allison.rb gen_bridge_doc/output -o doc/html"
108    Dir.chdir "#{output_dir}/ruby" do
109      rdoc ". -o #{output_dir}/html #{osx_additions}"
110      rdoc "--ri . -o #{output_dir}/ri #{osx_additions}"
111    end
112    
113    puts ""
114    puts "Total Cocoa Reference to RDoc processing time: #{Time.now - start_time} seconds"
115  else
116    show_options
117    exit 1
118  end
119else
120  show_options
121  exit 1
122end
123