lmt_make.pl 1.44 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74
#!/usr/bin/perl

#
# Use this program to automatically create the C table that lists the modules that are going to be
# linked statically to ScriptBasic. Do not edit the created C file, rather maintain one or more
# linkedmodules.def file and create one or more linkedmodules.c file
#

while(1){

exit 0 unless defined($InputFile = shift);
$OutputFile = $InputFile;

$OUTL = <<END;
/* FILE: $OutputFile

This file was automatically created by the program lmt_make.pl

DO NOT EDIT THIS FILE!!!

Rather edit the file $InputFile that is the source 

*/
#include <stdio.h>
#include "basext.h"

END

@ModuleList = ();

unless( open(F,$InputFile) ){
  print "Cannot open $InputFile\n";
  exit 1;
  }

while( <F> ){
  chomp;
  next if /^\s*\#/;
  next if /^\s*$/;
  @words = split /\s+/;
  push @ModuleList, $words[0];
  }


for $module (@ModuleList ){
  $OUTL .= "extern SLFST " . uc($module) ."_SLFST[];\n"
  }

$OUTL .= "MODLIST StaticallyLinkedModules[] ={\n";
for $module (@ModuleList ){
  $OUTL .= "  {\"$module\" , (void *)" . uc($module) . "_SLFST },\n"
  }

close F;
$OUTL .= "  { NULL, NULL },\n";
$OUTL .= "  };\n";

$OutputFile =~ s{def$}{c};

if( open(OUT,$OutputFile) ){
  my @old = <OUT>;
  close OUT;
  $oldfile = join( '' , @old);
  if( $oldfile eq $OUTL ){
    next;
    }
  close OUT;
  }

open(OUT,">$OutputFile") or die "Cannot open output file $OutputFile";
print OUT $OUTL;
close OUT;

}