r20639: Commit part 1 of 2.
[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 # GPL
5
6 use File::Basename;
7
8 my $file = shift;
9 my $prefix = shift;
10 my $dirname = shift;
11 my $options = join(' ', @ARGV);
12 my $x_file;
13 my @x_files = ();
14 my $c_file;
15 my @c_files = ();
16 my $o_file;
17 my @o_files = ();
18
19 $basename = basename($file);
20 if (not defined $options) {
21     $options = "";
22 }
23
24 my $header = "$dirname/$prefix.h";
25
26 print "$header: $file bin/asn1_compile\n";
27 print "\t\@echo \"Compiling ASN1 file $file\"\n";
28 print "\t\@startdir=`pwd` && cd $dirname && " . ' $$startdir/bin/asn1_compile ' . " $options " . '$$startdir/' . "$file $prefix\n\n";
29
30 open(IN,$file) or die("Can't open $file: $!");
31 foreach(<IN>) {
32         if (/^([\w]+[\w\-]+)(\s+OBJECT IDENTIFIER)?\s*::=/) {
33                 my $output = $1;
34                 $output =~ s/-/_/g;
35                 $c_file = "$dirname/asn1_$output.c";
36                 $x_file = "$dirname/asn1_$output.x";
37                 $o_file = "$dirname/asn1_$output.o";
38                 print "$x_file: $header\n";
39                 print "$c_file: $dirname/asn1_$output.x\n";
40                 print "\t\@cp $x_file $c_file\n\n";
41                 push @x_files, $x_file;
42                 push @c_files, $c_file;
43                 push @o_files, $o_file;
44         }
45 }
46 close(IN);
47
48 print '[SUBSYSTEM::HEIMDAL_'.uc($prefix).']'."\n";
49 print "CFLAGS = -Iheimdal_build -I$dirname\n";
50 print "OBJ_FILES = ";
51 foreach $o_file (@o_files) {
52     print "\\\n\t$o_file ";
53 }
54 print "\nPRIVATE_DEPENDENCIES = HEIMDAL_ASN1\n\n";
55
56 print "clean:: \n";
57 print "\t\@echo \"Deleting ASN1 output files generated from $file\"";
58 print "\n\t\@rm -f $header";
59 foreach $c_file (@c_files) {
60     print "\n\t\@rm -f $c_file";
61 }
62 foreach $x_file (@x_files) {
63     print "\n\t\@rm -f $x_file";
64 }
65 print "\n\t\@rm -f $dirname/$prefix\_files";
66 print "\n\t\@rm -f $dirname/$prefix\.h";
67 print "\n\n";