
$projectName = shift;
$projectType = shift;

# Define the symbol that other frameworks will hook onto us by
if ($projectType eq "Framework" ) {
    print "void __${projectName}_frameworkReferenceSymbol(){}\n";
} 

# Get the rest of the arguments as framework names, ignoring NeXT frameworks
#print STDERR "ARGV = " . join(":", @ARGV) . "\n";
@frameworks = grep(!/^(CodeFabRuntime|Foundation|System|AppKit|EOInterface|EOAccess|EOControl|WebObjects|SybaseEOAdaptor|InterfaceBuilder|ProjectBuilder).*/, @ARGV);
#print STDERR "Referencing frameworks " . join(":", @frameworks) . "\n";

# Get rid of NeXT frameworks

# Declare the frameworks we (might) reference
foreach $fw (@frameworks) {
    print "extern void * __" .$fw . "_frameworkReferenceSymbol;\n";
}

# Reference any MAF frameworks we need
print "static void *_frameworkRefs[] = {\n";
print "	&_frameworkRefs,\n";  # Add a reference to our symbol to avoid warnings

foreach $fw (@frameworks) {
    print "	& __${fw}_frameworkReferenceSymbol,\n";
}

# Make it so we don't have to drop the comma on the last framework
# and close out the list of references
print "	(void *)0\n";
print "};\n";
print "\n";

if ($projectType eq "Framework") {
  # Add a class to our framework with a +dllSillinessForNTsBenefit method
  # NT must have a static reference into each and every framework used
  # bummer, eh?  conveniently, we can simply create a bogon class
  # that contains a bogon method that has static references to
  # at least one symbol from all frameworks.
    
    print "#import <Foundation/NSObject.h>\n";
    print "#import <Foundation/NSString.h>\n";
    
    foreach $fw (@frameworks, $projectName) {
	print "\@interface __${fw}__referenceClass : NSObject {} \@end\n";
    }
    
    # Reference the classes in other frameworks
    
    print "\@implementation __${projectName}__referenceClass\n";
    print "+ (void) dllSillinessForNTsBenefit;\n";
    print "{\n";
    print "    NSLog(\@\"-- Initializing $projectType '$projectName' --\");\n";
    foreach $fw (@frameworks) {
	print "    [__${fw}__referenceClass self];\n";
    }
    print "}\n\@end\n";
}

