2005-08-03 09:28:08 +04:00
#!/usr/bin/perl
# Generate make dependency rules for asn1 files
# Jelmer Vernooij <jelmer@samba.org> 2005
2009-09-13 04:20:32 +04:00
# Andrew Bartlett <abartlet@samba.org> 2006-2009
2007-04-22 15:28:12 +04:00
# Stefan Metzmacher <metze@samba.org> 2007
2005-08-03 09:28:08 +04:00
# GPL
use File::Basename ;
my $ file = shift ;
my $ prefix = shift ;
2007-01-10 04:51:35 +03:00
my $ dirname = shift ;
2006-11-07 09:59:56 +03:00
my $ options = join ( ' ' , @ ARGV ) ;
2007-04-22 15:28:12 +04:00
my $ import ;
my @ imports = ( ) ;
my $ dep ;
my @ deps = ( ) ;
2005-08-03 09:28:08 +04:00
$ basename = basename ( $ file ) ;
2005-08-09 07:04:47 +04:00
if ( not defined $ options ) {
$ options = "" ;
}
2005-08-03 09:28:08 +04:00
my $ header = "$dirname/$prefix.h" ;
2009-06-08 13:06:16 +04:00
my $ headerx = "$dirname/$prefix.hx" ;
2010-01-12 05:24:33 +03:00
my $ headerpriv = "$dirname/$prefix-priv.h" ;
my $ headerprivx = "$dirname/$prefix-priv.hx" ;
2009-09-13 04:20:32 +04:00
my $ o_file = "$dirname/asn1_$prefix.o" ;
my $ c_file = "$dirname/asn1_$prefix.c" ;
my $ x_file = "$dirname/asn1_$prefix.x" ;
my $ output_file = "$dirname/" . $ prefix . "_asn1_files" ;
2005-08-03 09:28:08 +04:00
2008-08-01 18:53:52 +04:00
print "basics:: $header\n" ;
2009-09-13 04:20:32 +04:00
print "$output_file: \$(heimdalsrcdir)/$file \$(ASN1C)\n" ;
print "\t\@echo \"Compiling ASN1 file \$(heimdalsrcdir)/$file\"\n" ;
2009-09-15 09:48:50 +04:00
print "\t\@\$(heimdalbuildsrcdir)/asn1_compile_wrapper.sh \$(builddir) $dirname \$(ASN1C) \$(call abspath,\$(heimdalsrcdir)/$file) $prefix $options --one-code-file && touch $output_file\n" ;
2009-09-13 04:20:32 +04:00
print "$headerx: $output_file\n" ;
2009-06-08 13:06:16 +04:00
print "$header: $headerx\n" ;
print "\t\@cp $headerx $header\n" ;
2010-01-12 05:24:33 +03:00
print "$headerpriv: $headerprivx\n" ;
print "\t\@cp $headerprivx $headerpriv\n" ;
print "$x_file: $header $headerpriv\n" ;
2009-09-13 04:20:32 +04:00
print "$c_file: $x_file\n" ;
print "\t\@echo \"#include \\\"config.h\\\"\" > $c_file && cat $x_file >> $c_file\n\n" ;
2005-08-03 09:28:08 +04:00
2008-05-27 17:32:44 +04:00
open ( IN , "heimdal/$file" ) or die ( "Can't open heimdal/$file: $!" ) ;
2007-04-22 15:28:12 +04:00
my @ lines = <IN> ;
close ( IN ) ;
foreach my $ line ( @ lines ) {
2009-09-13 04:20:32 +04:00
if ( $ line =~ /^(\s*IMPORT)([\w\,\s])*(\s+FROM\s+)([\w]+[\w\-]+);/ ) {
2007-04-22 15:28:12 +04:00
$ 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 09:28:08 +04:00
}
}
2007-04-22 15:28:12 +04: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 04:51:35 +03:00
print '[SUBSYSTEM::HEIMDAL_' . uc ( $ prefix ) . ']' . "\n" ;
2008-05-31 02:35:55 +04:00
print "CFLAGS = -Iheimdal_build -Iheimdal/lib/roken -I$dirname\n" ;
2008-04-14 18:53:00 +04:00
print "PUBLIC_DEPENDENCIES = $depstr\n\n" ;
print "HEIMDAL_" . uc ( $ prefix ) . "_OBJ_FILES = " ;
2009-09-13 04:20:32 +04:00
print "\\\n\t$o_file" ;
2008-04-14 18:53:00 +04:00
print "\n\n" ;
2007-01-10 04:51:35 +03:00
2006-03-19 02:51:55 +03:00
print "clean:: \n" ;
2007-01-15 16:28:09 +03:00
print "\t\@echo \"Deleting ASN1 output files generated from $file\"\n" ;
2009-09-13 04:20:32 +04:00
print "\t\@rm -f $output_file\n" ;
2007-01-15 16:28:09 +03:00
print "\t\@rm -f $header\n" ;
2009-09-13 04:20:32 +04:00
print "\t\@rm -f $c_file\n" ;
print "\t\@rm -f $x_file\n" ;
2007-01-15 16:28:09 +03:00
print "\t\@rm -f $dirname/$prefix\_files\n" ;
print "\t\@rm -f $dirname/$prefix\.h\n" ;
print "\n" ;