Revert Jelmer's CFLAGS commit e2b71a0ecbf10a78a59a8ec6371bdee57b1bfa6c
[ira/wip.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
32 print "$header: \$(heimdalsrcdir)/$file \$(ASN1C)\n";
33 print "\t\@echo \"Compiling ASN1 file \$(heimdalsrcdir)/$file\"\n";
34 print "\t\@\$(heimdalbuildsrcdir)/asn1_compile_wrapper.sh \$(builddir) $dirname \$(ASN1C) \$(abspath \$(heimdalsrcdir)/$file) $prefix $options\n\n";
35
36 open(IN,"heimdal/$file") or die("Can't open heimdal/$file: $!");
37 my @lines = <IN>;
38 close(IN);
39 foreach my $line (@lines) {
40         if ($line =~ /^([\w]+[\w\-]+)(\s+OBJECT IDENTIFIER)?\s*::=/) {
41                 my $output = $1;
42                 $output =~ s/-/_/g;
43                 $c_file = "$dirname/asn1_$output.c";
44                 $x_file = "$dirname/asn1_$output.x";
45                 $o_file = "$dirname/asn1_$output.o";
46                 print "$x_file: $header\n";
47                 print "$c_file: $dirname/asn1_$output.x\n";
48                 print "\t\@echo \"#include \\\"config.h\\\"\" > $c_file && cat $x_file >> $c_file\n\n";
49                 push @x_files, $x_file;
50                 push @c_files, $c_file;
51                 push @o_files, $o_file;
52         } elsif ($line =~ /^(\s*IMPORT)([\w\,\s])*(\s+FROM\s+)([\w]+[\w\-]+);/) {
53                 $import = $line;
54                 chomp $import;
55                 push @imports, $import;
56                 $import = undef;
57         } elsif ($line =~ /^(\s*IMPORT).*/) {
58                 $import = $line;
59                 chomp $import;
60         } elsif (defined($import) and ($line =~ /;/)) {
61                 $import .= $line;
62                 chomp $import;
63                 push @imports, $import;
64                 $import = undef;
65         } elsif (defined($import)) {
66                 $import .= $line;
67                 chomp $import;
68         }
69 }
70
71 foreach $import (@imports) {
72         next unless ($import =~ /^(\s*IMPORT)([\w\,\s])*(\s+FROM\s+)([\w]+[\w\-]+);/);
73
74         my @froms = split (/\s+FROM\s+/, $import);
75         foreach my $from (@froms) {
76                 next if ($from =~ /^(\s*IMPORT).*/);
77                 if ($from =~ /^(\w+)/) {
78                         my $f = $1;
79                         $dep = 'HEIMDAL_'.uc($f).'_ASN1';
80                         push @deps, $dep;
81                 }
82         }
83 }
84
85 unshift @deps, "HEIMDAL_HEIM_ASN1" unless grep /HEIMDAL_HEIM_ASN1/, @deps;
86 my $depstr = join(' ', @deps);
87
88 print '[SUBSYSTEM::HEIMDAL_'.uc($prefix).']'."\n";
89 print "CFLAGS = -Iheimdal_build -Iheimdal/lib/roken -I$dirname\n";
90 print "PUBLIC_DEPENDENCIES = $depstr\n\n";
91
92 print "HEIMDAL_".uc($prefix)."_OBJ_FILES = ";
93 foreach $o_file (@o_files) {
94     print "\\\n\t$o_file";
95 }
96
97 print "\n\n";
98
99 print "clean:: \n";
100 print "\t\@echo \"Deleting ASN1 output files generated from $file\"\n";
101 print "\t\@rm -f $header\n";
102 foreach $c_file (@c_files) {
103     print "\t\@rm -f $c_file\n";
104 }
105 foreach $x_file (@x_files) {
106     print "\t\@rm -f $x_file\n";
107 }
108 print "\t\@rm -f $dirname/$prefix\_files\n";
109 print "\t\@rm -f $dirname/$prefix\.h\n";
110 print "\n";