2005-08-03 05:28:08 +00:00
#!/usr/bin/perl
# Generate make dependency rules for asn1 files
# Jelmer Vernooij <jelmer@samba.org> 2005
2007-04-22 11:28:12 +00:00
# Stefan Metzmacher <metze@samba.org> 2007
2005-08-03 05:28:08 +00:00
# GPL
use File::Basename ;
my $ file = shift ;
my $ prefix = shift ;
2007-01-10 01:51:35 +00:00
my $ dirname = shift ;
2006-11-07 06:59:56 +00:00
my $ options = join ( ' ' , @ ARGV ) ;
2005-12-19 23:13:12 +00:00
my $ x_file ;
my @ x_files = ( ) ;
my $ c_file ;
my @ c_files = ( ) ;
2007-01-10 01:51:35 +00:00
my $ o_file ;
my @ o_files = ( ) ;
2007-04-22 11:28:12 +00:00
my $ import ;
my @ imports = ( ) ;
my $ dep ;
my @ deps = ( ) ;
2005-08-03 05:28:08 +00:00
$ basename = basename ( $ file ) ;
2005-08-09 03:04:47 +00:00
if ( not defined $ options ) {
$ options = "" ;
}
2005-08-03 05:28:08 +00:00
my $ header = "$dirname/$prefix.h" ;
2006-03-19 15:59:12 +00:00
print "$header: $file bin/asn1_compile\n" ;
2005-08-03 05:28:08 +00:00
print "\t\@echo \"Compiling ASN1 file $file\"\n" ;
2007-01-15 13:28:09 +00:00
print "\t\@\$(builddir)/heimdal_build/asn1_compile_wrapper.sh \$(srcdir) \$(builddir) $dirname bin/asn1_compile $file $prefix $options\n\n" ;
2005-08-03 05:28:08 +00:00
open ( IN , $ file ) or die ( "Can't open $file: $!" ) ;
2007-04-22 11:28:12 +00:00
my @ lines = <IN> ;
close ( IN ) ;
foreach my $ line ( @ lines ) {
if ( $ line =~ /^([\w]+[\w\-]+)(\s+OBJECT IDENTIFIER)?\s*::=/ ) {
2005-08-03 05:28:08 +00:00
my $ output = $ 1 ;
$ output =~ s/-/_/g ;
2005-08-08 22:14:40 +00:00
$ c_file = "$dirname/asn1_$output.c" ;
$ x_file = "$dirname/asn1_$output.x" ;
2007-01-10 01:51:35 +00:00
$ o_file = "$dirname/asn1_$output.o" ;
2005-08-08 22:14:40 +00:00
print "$x_file: $header\n" ;
print "$c_file: $dirname/asn1_$output.x\n" ;
print "\t\@cp $x_file $c_file\n\n" ;
push @ x_files , $ x_file ;
push @ c_files , $ c_file ;
2007-01-10 01:51:35 +00:00
push @ o_files , $ o_file ;
2007-04-22 11:28:12 +00:00
} elsif ( $ line =~ /^(\s*IMPORT)([\w\,\s])*(\s+FROM\s+)([\w]+[\w\-]+);/ ) {
$ import = $ line ;
chomp $ import ;
push @ imports , $ import ;
$ import = undef ;
} elsif ( $ line =~ /^(\s*IMPORT).*/ ) {
$ import = $ line ;
chomp $ import ;
} elsif ( defined ( $ import ) and ( $ line =~ /;/ ) ) {
$ import . = $ line ;
chomp $ import ;
push @ imports , $ import ;
$ import = undef ;
} elsif ( defined ( $ import ) ) {
$ import . = $ line ;
chomp $ import ;
2005-08-03 05:28:08 +00:00
}
}
2007-04-22 11:28:12 +00:00
foreach $ import ( @ imports ) {
next unless ( $ import =~ /^(\s*IMPORT)([\w\,\s])*(\s+FROM\s+)([\w]+[\w\-]+);/ ) ;
my @ froms = split ( /\s+FROM\s+/ , $ import ) ;
foreach my $ from ( @ froms ) {
next if ( $ from =~ /^(\s*IMPORT).*/ ) ;
if ( $ from =~ /^(\w+)/ ) {
my $ f = $ 1 ;
$ dep = 'HEIMDAL_' . uc ( $ f ) . '_ASN1' ;
push @ deps , $ dep ;
}
}
}
unshift @ deps , "HEIMDAL_HEIM_ASN1" unless grep /HEIMDAL_HEIM_ASN1/ , @ deps ;
my $ depstr = join ( ' ' , @ deps ) ;
2007-01-10 01:51:35 +00:00
print '[SUBSYSTEM::HEIMDAL_' . uc ( $ prefix ) . ']' . "\n" ;
2007-04-21 23:12:45 +00:00
print "CFLAGS = -Iheimdal_build -Iheimdal/lib/roken -I$dirname\n" ;
2007-01-10 01:51:35 +00:00
print "OBJ_FILES = " ;
foreach $ o_file ( @ o_files ) {
2007-01-15 13:28:09 +00:00
print "\\\n\t$o_file" ;
2007-01-10 01:51:35 +00:00
}
2007-04-22 11:28:12 +00:00
print "\nPUBLIC_DEPENDENCIES = $depstr\n\n" ;
2007-01-10 01:51:35 +00:00
2006-03-18 23:51:55 +00:00
print "clean:: \n" ;
2007-01-15 13:28:09 +00:00
print "\t\@echo \"Deleting ASN1 output files generated from $file\"\n" ;
print "\t\@rm -f $header\n" ;
2005-08-08 22:14:40 +00:00
foreach $ c_file ( @ c_files ) {
2007-01-15 13:28:09 +00:00
print "\t\@rm -f $c_file\n" ;
2005-08-08 22:14:40 +00:00
}
foreach $ x_file ( @ x_files ) {
2007-01-15 13:28:09 +00:00
print "\t\@rm -f $x_file\n" ;
2005-08-08 22:14:40 +00:00
}
2007-01-15 13:28:09 +00:00
print "\t\@rm -f $dirname/$prefix\_files\n" ;
print "\t\@rm -f $dirname/$prefix\.h\n" ;
print "\n" ;