s4:heimdal: import lorikeet-heimdal-200906080040 (commit 904d0124b46eed7a8ad6e5b73e89...
[amitay/samba.git] / source4 / heimdal_build / asn1_deps.pl
1 #!/usr/bin/perl
2 # Generate make dependency rules for asn1 files
3 # Jelmer Vernooij <jelmer@samba.org> 2005
4 # Andrew Bartlett <abartlet@samba.org> 2006
5 # Stefan Metzmacher <metze@samba.org> 2007
6 # GPL
7
8 use File::Basename;
9
10 my $file = shift;
11 my $prefix = shift;
12 my $dirname = shift;
13 my $options = join(' ', @ARGV);
14 my $x_file;
15 my @x_files = ();
16 my $c_file;
17 my @c_files = ();
18 my $o_file;
19 my @o_files = ();
20 my $import;
21 my @imports = ();
22 my $dep;
23 my @deps = ();
24
25 $basename = basename($file);
26 if (not defined $options) {
27     $options = "";
28 }
29
30 my $header = "$dirname/$prefix.h";
31 my $headerx = "$dirname/$prefix.hx";
32
33 print "basics:: $header\n";
34 print "$header: $headerx\n";
35 print "\t\@cp $headerx $header\n";
36 print "$headerx: \$(heimdalsrcdir)/$file \$(ASN1C)\n";
37 print "\t\@echo \"Compiling ASN1 file \$(heimdalsrcdir)/$file\"\n";
38 print "\t\@\$(heimdalbuildsrcdir)/asn1_compile_wrapper.sh \$(builddir) $dirname \$(ASN1C) \$(call abspath,\$(heimdalsrcdir)/$file) $prefix $options\n\n";
39
40 open(IN,"heimdal/$file") or die("Can't open heimdal/$file: $!");
41 my @lines = <IN>;
42 close(IN);
43 foreach my $line (@lines) {
44         if ($line =~ /^([\w]+[\w\-]+)(\s+OBJECT IDENTIFIER)?\s*::=/) {
45                 my $output = $1;
46                 $output =~ s/-/_/g;
47                 $c_file = "$dirname/asn1_$output.c";
48                 $x_file = "$dirname/asn1_$output.x";
49                 $o_file = "$dirname/asn1_$output.o";
50                 print "$x_file: $header\n";
51                 print "$c_file: $dirname/asn1_$output.x\n";
52                 print "\t\@echo \"#include \\\"config.h\\\"\" > $c_file && cat $x_file >> $c_file\n\n";
53                 push @x_files, $x_file;
54                 push @c_files, $c_file;
55                 push @o_files, $o_file;
56         } elsif ($line =~ /^(\s*IMPORT)([\w\,\s])*(\s+FROM\s+)([\w]+[\w\-]+);/) {
57                 $import = $line;
58                 chomp $import;
59                 push @imports, $import;
60                 $import = undef;
61         } elsif ($line =~ /^(\s*IMPORT).*/) {
62                 $import = $line;
63                 chomp $import;
64         } elsif (defined($import) and ($line =~ /;/)) {
65                 $import .= $line;
66                 chomp $import;
67                 push @imports, $import;
68                 $import = undef;
69         } elsif (defined($import)) {
70                 $import .= $line;
71                 chomp $import;
72         }
73 }
74
75 foreach $import (@imports) {
76         next unless ($import =~ /^(\s*IMPORT)([\w\,\s])*(\s+FROM\s+)([\w]+[\w\-]+);/);
77
78         my @froms = split (/\s+FROM\s+/, $import);
79         foreach my $from (@froms) {
80                 next if ($from =~ /^(\s*IMPORT).*/);
81                 if ($from =~ /^(\w+)/) {
82                         my $f = $1;
83                         $dep = 'HEIMDAL_'.uc($f).'_ASN1';
84                         push @deps, $dep;
85                 }
86         }
87 }
88
89 unshift @deps, "HEIMDAL_HEIM_ASN1" unless grep /HEIMDAL_HEIM_ASN1/, @deps;
90 my $depstr = join(' ', @deps);
91
92 print '[SUBSYSTEM::HEIMDAL_'.uc($prefix).']'."\n";
93 print "CFLAGS = -Iheimdal_build -Iheimdal/lib/roken -I$dirname\n";
94 print "PUBLIC_DEPENDENCIES = $depstr\n\n";
95
96 print "HEIMDAL_".uc($prefix)."_OBJ_FILES = ";
97 foreach $o_file (@o_files) {
98     print "\\\n\t$o_file";
99 }
100
101 print "\n\n";
102
103 print "clean:: \n";
104 print "\t\@echo \"Deleting ASN1 output files generated from $file\"\n";
105 print "\t\@rm -f $header\n";
106 foreach $c_file (@c_files) {
107     print "\t\@rm -f $c_file\n";
108 }
109 foreach $x_file (@x_files) {
110     print "\t\@rm -f $x_file\n";
111 }
112 print "\t\@rm -f $dirname/$prefix\_files\n";
113 print "\t\@rm -f $dirname/$prefix\.h\n";
114 print "\n";