WHATSNEW: Start release notes for Samba 3.4.11.
[Samba.git] / source4 / heimdal_build / asn1_deps.pl
blob6c4d10d262b9c7c193971c1789ddb6d984c92af5
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
8 use File::Basename;
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 = ();
25 $basename = basename($file);
26 if (not defined $options) {
27 $options = "";
30 my $header = "$dirname/$prefix.h";
32 print "basics:: $header\n";
33 print "$header: \$(heimdalsrcdir)/$file \$(ASN1C)\n";
34 print "\t\@echo \"Compiling ASN1 file \$(heimdalsrcdir)/$file\"\n";
35 print "\t\@\$(heimdalbuildsrcdir)/asn1_compile_wrapper.sh \$(builddir) $dirname \$(ASN1C) \$(call abspath,\$(heimdalsrcdir)/$file) $prefix $options\n\n";
37 open(IN,"heimdal/$file") or die("Can't open heimdal/$file: $!");
38 my @lines = <IN>;
39 close(IN);
40 foreach my $line (@lines) {
41 if ($line =~ /^([\w]+[\w\-]+)(\s+OBJECT IDENTIFIER)?\s*::=/) {
42 my $output = $1;
43 $output =~ s/-/_/g;
44 $c_file = "$dirname/asn1_$output.c";
45 $x_file = "$dirname/asn1_$output.x";
46 $o_file = "$dirname/asn1_$output.o";
47 print "$x_file: $header\n";
48 print "$c_file: $dirname/asn1_$output.x\n";
49 print "\t\@echo \"#include \\\"config.h\\\"\" > $c_file && cat $x_file >> $c_file\n\n";
50 push @x_files, $x_file;
51 push @c_files, $c_file;
52 push @o_files, $o_file;
53 } elsif ($line =~ /^(\s*IMPORT)([\w\,\s])*(\s+FROM\s+)([\w]+[\w\-]+);/) {
54 $import = $line;
55 chomp $import;
56 push @imports, $import;
57 $import = undef;
58 } elsif ($line =~ /^(\s*IMPORT).*/) {
59 $import = $line;
60 chomp $import;
61 } elsif (defined($import) and ($line =~ /;/)) {
62 $import .= $line;
63 chomp $import;
64 push @imports, $import;
65 $import = undef;
66 } elsif (defined($import)) {
67 $import .= $line;
68 chomp $import;
72 foreach $import (@imports) {
73 next unless ($import =~ /^(\s*IMPORT)([\w\,\s])*(\s+FROM\s+)([\w]+[\w\-]+);/);
75 my @froms = split (/\s+FROM\s+/, $import);
76 foreach my $from (@froms) {
77 next if ($from =~ /^(\s*IMPORT).*/);
78 if ($from =~ /^(\w+)/) {
79 my $f = $1;
80 $dep = 'HEIMDAL_'.uc($f).'_ASN1';
81 push @deps, $dep;
86 unshift @deps, "HEIMDAL_HEIM_ASN1" unless grep /HEIMDAL_HEIM_ASN1/, @deps;
87 my $depstr = join(' ', @deps);
89 print '[SUBSYSTEM::HEIMDAL_'.uc($prefix).']'."\n";
90 print "CFLAGS = -Iheimdal_build -Iheimdal/lib/roken -I$dirname\n";
91 print "PUBLIC_DEPENDENCIES = $depstr\n\n";
93 print "HEIMDAL_".uc($prefix)."_OBJ_FILES = ";
94 foreach $o_file (@o_files) {
95 print "\\\n\t$o_file";
98 print "\n\n";
100 print "clean:: \n";
101 print "\t\@echo \"Deleting ASN1 output files generated from $file\"\n";
102 print "\t\@rm -f $header\n";
103 foreach $c_file (@c_files) {
104 print "\t\@rm -f $c_file\n";
106 foreach $x_file (@x_files) {
107 print "\t\@rm -f $x_file\n";
109 print "\t\@rm -f $dirname/$prefix\_files\n";
110 print "\t\@rm -f $dirname/$prefix\.h\n";
111 print "\n";