changeset 3960:a0e6b2575364

scripts: blob2c: add option to define C headers according to -n option
author Pierre Bertin <bertinp17@icloud.com>
date Mon, 11 Jun 2018 14:40:22 +0200
parents bcda75d2c4ff
children 0fbb904b6f08
files scripts/blob2c.pl
diffstat 1 files changed, 16 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/scripts/blob2c.pl	Fri Jun 08 20:52:58 2018 +0200
+++ b/scripts/blob2c.pl	Mon Jun 11 14:40:22 2018 +0200
@@ -3,21 +3,23 @@
 use Getopt::Long;
 use strict;
 
-my ( $help, $name, $align, $section, $size, $output, $input )
-    = ( 0, "blob", 1, undef, 0, "-" );
+my ( $help, $name, $align, $section, $size, $header, $output, $input )
+    = ( 0, "blob", 1, undef, undef, 0, "-" );
 
 Getopt::Long::Configure("no_ignore_case");
 my $r = GetOptions("n=s" => \$name, "a=i" => \$align,
                    "s=s" => \$section, "S" => \$size,
-                   "o=s" => \$output, "h" => \$help);
+                   "H" => \$header, "o=s" => \$output,
+                   "h" => \$help);
 
 if ( $help ) {
-    print STDERR 
+    print STDERR
 "usage: blob2c.pl [ -n symbol_name ] [ -s symbol_section ] blob > output
     -n name      Change symbol name (default = 'blob')
     -a value     Add an alignment attribute on blob variable
     -s name      Change section name (no default (.rodata))
     -S           Also emit a size symbol '<name>_size'
+    -H           Define C headers according to -n option
     -o name      Change section output file name (default stdout)
 ";
     exit 1;
@@ -34,7 +36,12 @@
     open( STDOUT, ">$output" ) or die 'unable to open output file';
 }
 
-print "#include <stdint.h>\n" if ( $size );
+if ( $header ) {
+    print "#ifndef _${name}_H\n";
+    print "#define _${name}_H\n\n";
+}
+
+print "#include <stdint.h>\n\n" if ( $size );
 print "__attribute__((section \"$section\"))\n" if ( defined $section );
 print "__attribute__((aligned ($align)))\n" if ( defined $align );
 print "const unsigned char $name\[\] = {\n";
@@ -54,5 +61,8 @@
     print "const size_t ${name}_size = $tlen;\n"
 }
 
+if ( $header ) {
+    print "\n#endif /* !_${name}_H */\n";
+}
+
 exit 0;
-