trick/bin/trick-ify

239 lines
6.8 KiB
Perl
Executable File

#!/usr/bin/perl
$my_path = $0 ;
$my_path =~ s/trick-ify// ;
$source_dir = "" ; # Base path to build source from
$header_dir = "" ; # Base path to find header files
$source_make_call = "" ; # Make call to build object files
$source_make_args = "" ; # Args to pass into default object make
$trickify_make_args = "" ; # Arguments to pass into the trickify make
$trickify_make_path = "$my_path../share/trick/makefiles/trickify.mk" ; # Path of the trickify make file
$build_s_source = 1 ; # Whether to generate a S_source
$build_trickify_src_list = 1 ; # Whether to generate a trickify_src_list
$build_trickify_obj_list = 1 ; # Whether to generate a trickify_obj_list
$full_build = 1 ; # Whether to build only ICG/Swig artifacts or entire source
$name = "trickified" ; # Name of the library
$build_type = "o" ; # Type of library to be built (o, a , so)
$debug = 0 ; # Debug info flag
$trick_home = $my_path . ".." ; # Trick directory to use for building
$skip_arg = 0 ;
foreach $argnum (0 .. $#ARGV)
{
if($skip_arg)
{
$skip_arg = 0 ;
next ;
}
$arg = $ARGV[$argnum] ;
if($arg eq "-d") # Set both source and header directory
{
$source_dir = $ARGV[$argnum + 1] ;
$header_dir = $source_dir ;
$skip_arg = 1 ;
}
elsif($arg eq "-s") # Set source directory
{
$source_dir = $ARGV[$argnum + 1] ;
$skip_arg = 1 ;
}
elsif($arg eq "-h") # Set header directory
{
$header_dir = $ARGV[$argnum + 1] ;
$skip_arg = 1 ;
}
elsif($arg eq "-ph") # Preserve S_source.hh
{
$build_s_source = 0 ;
}
elsif($arg eq "-ps") # Preserve trickify_src_list
{
$build_trickify_src_list = 0 ;
}
elsif($arg eq "-po") # Preserve trickify_obj_list
{
$build_trickify_obj_list = 0 ;
}
elsif($arg eq "-t") # Build trick artifacts only
{
$full_build = 0 ;
}
elsif($arg eq "-m") # Make call to build object files
{
$source_make_call = $ARGV[$argnum + 1] ;
$skip_arg = 1 ;
}
elsif($arg eq "-ma") # Default make call args to build object files
{
$source_make_args = $ARGV[$argnum + 1] ;
$skip_arg = 1 ;
}
elsif($arg eq "-tm") # Trickify make args
{
$trickify_make_args = $ARGV[$argnum + 1] ;
$skip_arg = 1 ;
}
elsif($arg eq "-tp") # Set trickify make path
{
$trickify_make_path = $ARGV[$argnum + 1] ;
$skip_arg = 1 ;
}
elsif($arg eq "-n") # Set the library name
{
$name = $ARGV[$argnum + 1] ;
$skip_arg = 1 ;
}
elsif($arg eq "-b") # Set library build type
{
$val = $ARGV[$argnum + 1] ;
if( ($val eq "o") or ($val eq "a") or ($val eq "so") )
{
$build_type = $ARGV[$argnum + 1] ;
}
else
{
print "Invalid build type {$val}, valid build types are {o, a, so}\n" ;
exit 1 ;
}
$skip_arg = 1 ;
}
elsif($arg eq "-v") # Verbose, print debug info
{
$debug = 1 ;
}
elsif($arg eq "-th") # Set trick home directory
{
$trick_home = $ARGV[$argnum + 1] ;
$skip_arg = 1 ;
}
else
{
print "Unrecognized argument: $arg\n" ;
exit 1 ;
}
}
if($header_dir eq "")
{
print "Must set a header directory\n" ;
exit 1 ;
}
if($source_dir eq "" and $full_build)
{
print "Must set a source directory\n" ;
exit 1 ;
}
#Set Environment Variables
if ($full_build)
{
$ENV{'FULL_TRICKIFY_BUILD'} = "1" ;
}
my @src_dirs = split ' ', $source_dir ;
$source_dir_arg = "" ;
foreach $dir (@src_dirs)
{
$source_dir_arg .= "-I " . $dir . " ";
}
$ENV{'TRICKIFY_CXX_FLAGS'} = "$source_dir_args -I $trick_home" . "/include" ;
$ENV{'TRICKIFY_OBJECT_NAME'} = "$name.$build_type" ;
$ENV{'TRICKIFY_SOURCE'} = "$source_dir" ;
$ENV{'TRICKIFY_HEADER'} = "$header_dir" ;
if ( $build_type eq o )
{
$ENV{'TRICKIFY_BUILD_TYPE'} = PLO ;
}
elsif ( $build_type eq a )
{
$ENV{'TRICKIFY_BUILD_TYPE'} = STATIC ;
}
elsif ( $build_type eq so )
{
$ENV{'TRICKIFY_BUILD_TYPE'} = SHARED ;
}
#Build the S_source.hh
if ($build_s_source)
{
print "Building S_source.hh\n" ;
$make_s_source = "python3 $my_path../share/trick/pymods/trick/build_trickify_S_source_hh.py" ;
print(`$make_s_source`) ;
}
#Build source file list, only if trickifying the entire library
if ($build_trickify_src_list and $full_build)
{
print "Building trickify_src_list\n" ;
$make_src_list = "python3 $my_path../share/trick/pymods/trick/build_trickify_src_list.py" ;
print(`$make_src_list`) ;
}
#Build array of source files
if ($full_build)
{
open ($fh, "trickify_src_list") or die "Could not open trickify_src_list: $!" ;
@src_files ;
while (my $line = <$fh>)
{
chomp $line ;
push @src_files, $line ;
}
close (fh) ;
}
#Build object files from source file list
if ($full_build)
{
print "Building object files\n" ;
if($source_make_call eq "")
{
foreach $src (@src_files)
{
$file = $src ;
$file =~ s/\Q.cpp\E$// ;
$file =~ s/\Q.c$\E$// ;
$cmd = "g++ $source_make_args -I $trick_home" . "/include -c $src -o $file.o" ;
if($debug)
{
print "Building obj file: $cmd\n" ;
}
print(`$cmd`) ;
}
}
else
{
print(`$source_make_call`) ;
}
}
#Build object file list, only if trickifying the entire library
if($build_trickify_obj_list and $full_build)
{
print "Building trickify_obj_list\n" ;
$make_obj_list = "python3 $my_path../share/trick/pymods/trick/build_trickify_obj_list.py" ;
print(`$make_obj_list`) ;
}
#Build trickify call
print "Begin Trickification...\n" ;
$trickify_make_call = "make $trickify_make_args -f $trickify_make_path" ;
print(`$trickify_make_call`) ;
if($debug) {
print
"TRICKIFY BUILD INFO:
header_dir = $header_dir
source_dir = $source_dir_arg
source_make_call = $source_make_call
trickify_make_args = $trickify_make_args
trickify_make_path = $trickify_make_path
build_s_source = $build_s_source
full_build = $full_build
name = $name
build_type = $build_type
trick_home = $trick_home\n" ;
}