diff --git a/bin/trick-ify b/bin/trick-ify index af071b8e..fc0a187f 100755 --- a/bin/trick-ify +++ b/bin/trick-ify @@ -3,10 +3,11 @@ $my_path = $0 ; $my_path =~ s/trick-ify// ; -$source_dir = "." ; # Base path to build lib from. Default to working directory +$source_dir = "." ; # Base path to build header from. Default to working directory +$header_dir = "." ; # Base path to build source from. Default to working directory $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 -$make_S_source = 0 ; # Whether to generate a S_source +$build_s_source = 0 ; # Whether to generate a S_source $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) @@ -21,14 +22,25 @@ foreach $argnum (0 .. $#ARGV) } $arg = $ARGV[$argnum] ; - if($arg eq "-d") # Set source directory + 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 "-R") # Rebuild S_source { - $make_S_source = 1 ; + $build_s_source = 1 ; } elsif($arg eq "-t") # Build trick artifacts only { @@ -65,6 +77,7 @@ foreach $argnum (0 .. $#ARGV) else { print "Unrecognized argument: $arg\n" ; + exit 1 ; } } @@ -72,6 +85,7 @@ foreach $argnum (0 .. $#ARGV) $ENV{'TRICKIFY_CXX_FLAGS'} = "-I $source_dir" ; #TODO: Test with multiple dirs passed in at once $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 ; @@ -85,20 +99,46 @@ elsif ( $build_type eq so ) $ENV{'TRICKIFY_BUILD_TYPE'} = SHARED ; } -print "BUILD INFO: - $ENV{'TRICKIFY_SOURCE'} - source_dir = $source_dir - trickify_make_args = $trickify_make_args - trickify_make_path = $trickify_make_path - make_S_source = $make_S_source - full_build = $full_build - name = $name - build_type = $build_type\n" ; - #Build the S_source.hh $make_s_source = "python3 $my_path../share/trick/makefiles/build_trickify_S_source_hh.py" ; print(`$make_s_source`) ; +#Build source file list, only if trickifying the entire library +if($full_build) +{ + #$make_obj_list = "python3 $my_path../share/trick/makefiles/build_trickify_obj_list.py" ; + #print(`$make_obj_list`) ; + $make_src_list = "python3 $my_path../share/trick/makefiles/build_trickify_src_list.py" ; + print(`$make_src_list`) ; +} +else +{ + #open (fh, ">", "trickify_obj_list") ; + #close (fh) ; + open (fh, ">", "trickify_src_list") ; + close (fh) ; +} + +open (fh, "<", "trickify_src_list") ; +@src_files ; +while ($line = <$fh>) +{ + chomp $line ; + print $line AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA; + push @src_files, $line ; +} +close (fh) ; + #Build trickify call $trickify_make_call = "make $trickify_make_args -f $trickify_make_path" ; print(`$trickify_make_call`) ; + +print "TRICKIFY BUILD INFO: + header_dir = $header_dir + source_dir = $source_dir + 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\n" ; diff --git a/share/trick/makefiles/build_trickify.py b/share/trick/makefiles/build_trickify.py new file mode 100644 index 00000000..ffaa69c3 --- /dev/null +++ b/share/trick/makefiles/build_trickify.py @@ -0,0 +1,42 @@ +from pathlib import Path +import os + +def_header_ext = ["h", "hh", "hpp", "H", "hxx", "h++"] +def_src_ext = ["cpp", "c"] + +def find_files_by_extension(loc, ext): + path = Path(loc) + files = list(path.rglob(f'*.{ext}')) + return files + +def build_S_source(): + loc = "" + if "TRICKIFY_HEADER" in os.environ: + loc = os.getenv("TRICKIFY_HEADER") + + s_source = open("S_source.hh", 'w') + for ext in def_header_ext: + files = find_files_by_extension(loc, ext) + for i in range(len(files)): + s_source.write('#include "' + str(files[i]) + '"\n') + +def build_obj_list(): + loc = "" + if "TRICKIFY_SOURCE" in os.environ: + loc = os.getenv("TRICKIFY_SOURCE") + + files = find_files_by_extension(loc, "o") + s_source = open("trickify_obj_list", 'w') + for i in range(len(files)): + s_source.write(str(files[i]) + '\n') + +def build_src_list(): + loc = "" + if "TRICKIFY_SOURCE" in os.environ: + loc = os.getenv("TRICKIFY_SOURCE") + + for ext in def_src_ext: + files = find_files_by_extension(loc, ext) + s_source = open("trickify_src_list", 'w') + for i in range(len(files)): + s_source.write(str(files[i]) + '\n') diff --git a/share/trick/makefiles/build_trickify_S_source_hh.py b/share/trick/makefiles/build_trickify_S_source_hh.py index a698f03b..92242d43 100644 --- a/share/trick/makefiles/build_trickify_S_source_hh.py +++ b/share/trick/makefiles/build_trickify_S_source_hh.py @@ -1,18 +1,10 @@ -from pathlib import Path import os -def_ext = ["h", "hh", "hpp", "H", "hxx", "h++"] +path = "" +if "TRICK_HOME" in os.environ: + path = os.getenv("TRICK_HOME") +path += "/share/trick/makefiles/build_trickify.py" -loc = "" -if "TRICKIFY_SOURCE" in os.environ: - loc = os.getenv("TRICKIFY_SOURCE") +exec(open(path).read()) -def find_files_by_extension(loc, ext): - path = Path(loc) - files = list(path.rglob(f'*.{ext}')) - return files - -files = find_files_by_extension(loc, "hh") -s_source = open("S_source.hh", 'w') -for i in range(len(files)): - s_source.write('#include "' + str(files[i]) + '"\n') +build_S_source() diff --git a/share/trick/makefiles/build_trickify_obj_list.py b/share/trick/makefiles/build_trickify_obj_list.py new file mode 100644 index 00000000..0fa24786 --- /dev/null +++ b/share/trick/makefiles/build_trickify_obj_list.py @@ -0,0 +1,10 @@ +import os + +path = "" +if "TRICK_HOME" in os.environ: + path = os.getenv("TRICK_HOME") +path += "/share/trick/makefiles/build_trickify.py" + +exec(open(path).read()) + +build_obj_list() diff --git a/share/trick/makefiles/build_trickify_src_list.py b/share/trick/makefiles/build_trickify_src_list.py new file mode 100644 index 00000000..164733d6 --- /dev/null +++ b/share/trick/makefiles/build_trickify_src_list.py @@ -0,0 +1,10 @@ +import os + +path = "" +if "TRICK_HOME" in os.environ: + path = os.getenv("TRICK_HOME") +path += "/share/trick/makefiles/build_trickify.py" + +exec(open(path).read()) + +build_src_list() diff --git a/share/trick/makefiles/trickify.mk b/share/trick/makefiles/trickify.mk index bc97aaa8..ffd88e83 100644 --- a/share/trick/makefiles/trickify.mk +++ b/share/trick/makefiles/trickify.mk @@ -107,8 +107,8 @@ include $(dir $(lastword $(MAKEFILE_LIST)))Makefile.common BUILD_DIR := $(dir $(MAKE_OUT)) PY_LINK_LIST := $(BUILD_DIR)trickify_py_link_list IO_LINK_LIST := $(BUILD_DIR)trickify_io_link_list -SRC_LINK_LIST := -LINK_LISTS := @$(IO_LINK_LIST) @$(PY_LINK_LIST) $(SRC_LINK_LIST) +SRC_LINK_LIST := trickify_obj_list +LINK_LISTS := @$(IO_LINK_LIST) @$(PY_LINK_LIST) @$(SRC_LINK_LIST) ifneq ($(wildcard $(BUILD_DIR)),) SWIG_OBJECTS := $(shell cat $(PY_LINK_LIST)) IO_OBJECTS := $(shell cat $(IO_LINK_LIST)) diff --git a/test/SIM_trickified/trickified_project/testing/testing.cpp b/test/SIM_trickified/trickified_project/testing/testing.cpp new file mode 100644 index 00000000..6d67eb5d --- /dev/null +++ b/test/SIM_trickified/trickified_project/testing/testing.cpp @@ -0,0 +1,3 @@ +#include "testing.hh" + +test_class::test_class() : a(1), b(2), c(3) { print();print();print();print();print(); } diff --git a/test/SIM_trickified/trickified_project/testing/testing.hh b/test/SIM_trickified/trickified_project/testing/testing.hh new file mode 100644 index 00000000..3bc95fc0 --- /dev/null +++ b/test/SIM_trickified/trickified_project/testing/testing.hh @@ -0,0 +1,19 @@ +#include + +class test_class +{ + public: + + test_class(); + + void print() + { + int i = 0 ; + std::cout << "Printing Test Class: " << a+i << ", " << b+i << ", " << c+i << std::endl ; + i++ ; + } + + int a; + int b; + int c; +}; diff --git a/test/SIM_trickified/trickified_project/testing/testing_main.cpp b/test/SIM_trickified/trickified_project/testing/testing_main.cpp new file mode 100644 index 00000000..f51da2aa --- /dev/null +++ b/test/SIM_trickified/trickified_project/testing/testing_main.cpp @@ -0,0 +1,11 @@ +#include "testing.hh" + +int main() +{ + test_class test ; + std::cout << test.a << ", " << test.b << ", " << test.c << std::endl ; + test.print() ; + + return 0 ; + +} diff --git a/test/SIM_trickified/trickified_project/trickified/Makefile b/test/SIM_trickified/trickified_project/trickified/Makefile index 8f8f110c..4bad006d 100644 --- a/test/SIM_trickified/trickified_project/trickified/Makefile +++ b/test/SIM_trickified/trickified_project/trickified/Makefile @@ -9,7 +9,8 @@ export TRICKIFY_CXX_FLAGS := -I $(PROJECT_HOME)/include -I $(TRICK_HOME)/include all: #@$(MAKE) -s -f $(TRICK_HOME)/share/trick/makefiles/trickify.mk - @trick-ify -d "/users/plherrin/trick/test/SIM_trickified/trickified_project/include" -b a -n trickified_myproject + #@trick-ify -h "/users/plherrin/trick/test/SIM_trickified/trickified_project/include" -b a -n trickified_myproject + @trick-ify -d "/users/plherrin/trick/test/SIM_trickified/trickified_project/testing" -b a -n trickified_myproject clean: @rm -rf build python trick $(TRICKIFY_OBJECT_NAME) diff --git a/test/SIM_trickified/trickified_project/trickified/S_source.hh b/test/SIM_trickified/trickified_project/trickified/S_source.hh index 62d7a586..cef5a8e0 100644 --- a/test/SIM_trickified/trickified_project/trickified/S_source.hh +++ b/test/SIM_trickified/trickified_project/trickified/S_source.hh @@ -1,2 +1 @@ -#include "/users/plherrin/trick/test/SIM_trickified/trickified_project/include/Bar.hh" -#include "/users/plherrin/trick/test/SIM_trickified/trickified_project/include/Foo.hh" +#include "/users/plherrin/trick/test/SIM_trickified/trickified_project/testing/testing.hh"