diff --git a/bin/trick-ify b/bin/trick-ify index f852362e..9e503fc3 100755 --- a/bin/trick-ify +++ b/bin/trick-ify @@ -3,9 +3,10 @@ $my_path = $0 ; $my_path =~ s/trick-ify// ; -$source_dir = "" ; # Base path to build header from. -$header_dir = "" ; # Base path to find header files. +$source_dir = "" ; # Base path to build header 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 @@ -64,6 +65,11 @@ foreach $argnum (0 .. $#ARGV) $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] ; @@ -189,7 +195,7 @@ if ($full_build) $file = $src ; $file =~ s/\Q.cpp\E$// ; $file =~ s/\Q.c$\E$// ; - $cmd = "g++ -I $trick_home" . "/include -c $src -o $file.o" ; + $cmd = "g++ $source_make_args -I $trick_home" . "/include -c $src -o $file.o" ; if($debug) { print "Building obj file: $cmd\n" ; diff --git a/test/SIM_trickified/RUN_test/unit_test.py b/test/SIM_trickified_archive/RUN_test/unit_test.py similarity index 100% rename from test/SIM_trickified/RUN_test/unit_test.py rename to test/SIM_trickified_archive/RUN_test/unit_test.py diff --git a/test/SIM_trickified/S_define b/test/SIM_trickified_archive/S_define similarity index 100% rename from test/SIM_trickified/S_define rename to test/SIM_trickified_archive/S_define diff --git a/test/SIM_trickified/S_overrides.mk b/test/SIM_trickified_archive/S_overrides.mk similarity index 100% rename from test/SIM_trickified/S_overrides.mk rename to test/SIM_trickified_archive/S_overrides.mk diff --git a/test/SIM_trickified/models/Baz.hh b/test/SIM_trickified_archive/models/Baz.hh similarity index 100% rename from test/SIM_trickified/models/Baz.hh rename to test/SIM_trickified_archive/models/Baz.hh diff --git a/test/SIM_trickified/trickified_project/include_bar/Bar.cpp b/test/SIM_trickified_archive/trickified_project/include_bar/Bar.cpp similarity index 100% rename from test/SIM_trickified/trickified_project/include_bar/Bar.cpp rename to test/SIM_trickified_archive/trickified_project/include_bar/Bar.cpp diff --git a/test/SIM_trickified/trickified_project/include_bar/Bar.hh b/test/SIM_trickified_archive/trickified_project/include_bar/Bar.hh similarity index 100% rename from test/SIM_trickified/trickified_project/include_bar/Bar.hh rename to test/SIM_trickified_archive/trickified_project/include_bar/Bar.hh diff --git a/test/SIM_trickified/trickified_project/include_foo/Foo.cpp b/test/SIM_trickified_archive/trickified_project/include_foo/Foo.cpp similarity index 100% rename from test/SIM_trickified/trickified_project/include_foo/Foo.cpp rename to test/SIM_trickified_archive/trickified_project/include_foo/Foo.cpp diff --git a/test/SIM_trickified/trickified_project/include_foo/Foo.hh b/test/SIM_trickified_archive/trickified_project/include_foo/Foo.hh similarity index 100% rename from test/SIM_trickified/trickified_project/include_foo/Foo.hh rename to test/SIM_trickified_archive/trickified_project/include_foo/Foo.hh diff --git a/test/SIM_trickified/trickified_project/trickified/.gitignore b/test/SIM_trickified_archive/trickified_project/trickified/.gitignore similarity index 100% rename from test/SIM_trickified/trickified_project/trickified/.gitignore rename to test/SIM_trickified_archive/trickified_project/trickified/.gitignore diff --git a/test/SIM_trickified_archive/trickified_project/trickified/Makefile b/test/SIM_trickified_archive/trickified_project/trickified/Makefile new file mode 100644 index 00000000..4cf63573 --- /dev/null +++ b/test/SIM_trickified_archive/trickified_project/trickified/Makefile @@ -0,0 +1,15 @@ +LOCAL_DIR := $(abspath $(dir $(lastword $(MAKEFILE_LIST)))) +include $(LOCAL_DIR)/myproject_vars.mk + +all: + @echo MAKE LOCAL_DIR $(LOCAL_DIR) + @trick-ify -d "$(LOCAL_DIR)/../include_bar $(LOCAL_DIR)/../include_foo" -b a -n trickified_myproject -v + +clean: + @rm -rf build python trick $(TRICKIFY_OBJECT_NAME) + @rm -rf $(MYPROJECT_TRICK) + @rm -rf trickify_obj_list + @rm -rf trickify_src_list + @rm -rf S_source.hh + @rm -rf ../include_foo/*.o + @rm -rf ../include_bar/*.o diff --git a/test/SIM_trickified/trickified_project/trickified/myproject.mk b/test/SIM_trickified_archive/trickified_project/trickified/myproject.mk similarity index 100% rename from test/SIM_trickified/trickified_project/trickified/myproject.mk rename to test/SIM_trickified_archive/trickified_project/trickified/myproject.mk diff --git a/test/SIM_trickified_archive/trickified_project/trickified/myproject_vars.mk b/test/SIM_trickified_archive/trickified_project/trickified/myproject_vars.mk new file mode 100644 index 00000000..4454d8a7 --- /dev/null +++ b/test/SIM_trickified_archive/trickified_project/trickified/myproject_vars.mk @@ -0,0 +1,28 @@ +# We know this file's position relative to the root directory of the project, +# and MAKEFILE_LIST will give us the full path to this file no matter where the +# user has installed this project. +export MYPROJECT_HOME := $(abspath $(dir $(lastword $(MAKEFILE_LIST)))/..) + +# Specify include paths for your headers. +MYPROJECT_INCLUDE := -I$(MYPROJECT_HOME)/include_bar -I$(MYPROJECT_HOME)/include_foo + +# Users may set different flags for C and C++, so you should really modify both +# to be safe. +TRICK_CFLAGS += $(MYPROJECT_INCLUDE) $(MYPROJECT_SOURCE) +TRICK_CXXFLAGS += $(MYPROJECT_INCLUDE) $(MYPROJECT_SOURCE) + +export TRICKIFY_OBJECT_NAME := trickified_myproject.a +MYPROJECT_TRICK := $(MYPROJECT_HOME)/trickified/$(TRICKIFY_OBJECT_NAME) + +# Tell Trick the headers and source at this location are part of a +# Trickified project +TRICK_EXT_LIB_DIRS += :$(MYPROJECT_HOME) + +# Tell Trick where to find the Python modules generated by SWIG +TRICK_PYTHON_PATH += :$(MYPROJECT_HOME)/trickified/python + +# Tell SWIG where to find py_*.i files +TRICK_SWIG_FLAGS += -I$(MYPROJECT_HOME)/trickified + +# Link in the Trickified object +TRICK_LDFLAGS += $(MYPROJECT_TRICK) diff --git a/test/SIM_trickified_object/RUN_test/unit_test.py b/test/SIM_trickified_object/RUN_test/unit_test.py new file mode 100644 index 00000000..f74fee0b --- /dev/null +++ b/test/SIM_trickified_object/RUN_test/unit_test.py @@ -0,0 +1,4 @@ +sandbox.foo.i = 5 +assert sandbox.foo.i == 5 +foo = trick.Foo() +trick.stop(10) diff --git a/test/SIM_trickified_object/S_define b/test/SIM_trickified_object/S_define new file mode 100644 index 00000000..f770e2a7 --- /dev/null +++ b/test/SIM_trickified_object/S_define @@ -0,0 +1,21 @@ +#include "sim_objects/default_trick_sys.sm" +##include "Foo.hh" +##include "Bar.hh" +##include "Baz.hh" + +class Sandbox : public Trick::SimObject { + + public: + + Foo foo; + Bar bar; + Baz baz; + + Sandbox() { + (1, "scheduled") foo.foo(); + } + +}; + + +Sandbox sandbox; diff --git a/test/SIM_trickified_object/S_overrides.mk b/test/SIM_trickified_object/S_overrides.mk new file mode 100644 index 00000000..e17d8690 --- /dev/null +++ b/test/SIM_trickified_object/S_overrides.mk @@ -0,0 +1,4 @@ +LOCAL_DIR := $(abspath $(dir $(lastword $(MAKEFILE_LIST)))) + +TRICK_CXXFLAGS += -I$(LOCAL_DIR)/models +include $(CURDIR)/trickified_project/trickified/myproject.mk diff --git a/test/SIM_trickified_object/models/Baz.hh b/test/SIM_trickified_object/models/Baz.hh new file mode 100644 index 00000000..fc91c1b2 --- /dev/null +++ b/test/SIM_trickified_object/models/Baz.hh @@ -0,0 +1,9 @@ +// @trick_parse{everything} + +class Baz { + + public: + int i; + int j; + +}; diff --git a/test/SIM_trickified_object/trickified_project/include_bar/Bar.cpp b/test/SIM_trickified_object/trickified_project/include_bar/Bar.cpp new file mode 100644 index 00000000..55a07a84 --- /dev/null +++ b/test/SIM_trickified_object/trickified_project/include_bar/Bar.cpp @@ -0,0 +1,9 @@ +// @trick_parse{everything} + +#include "Bar.hh" + + +void Bar::add() {} +void Bar::remove() {} +void Bar::restart() {} + diff --git a/test/SIM_trickified_object/trickified_project/include_bar/Bar.hh b/test/SIM_trickified_object/trickified_project/include_bar/Bar.hh new file mode 100644 index 00000000..5c497262 --- /dev/null +++ b/test/SIM_trickified_object/trickified_project/include_bar/Bar.hh @@ -0,0 +1,17 @@ +// @trick_parse{everything} + +#include "trick/Event.hh" + +/** + * Induce an `%import sim_services` statement in this class's Python module by inheriting from a + * Trick class. This allows us to test if `sys.path` contains the correct path to `sim_services.py` + * (and other modules generated during a sim build) for Trickified projects. + */ +class Bar : public Trick::Event { + + int process(long long) {return 0;} + void add(); + void remove(); + void restart(); + +}; diff --git a/test/SIM_trickified_object/trickified_project/include_foo/Foo.cpp b/test/SIM_trickified_object/trickified_project/include_foo/Foo.cpp new file mode 100644 index 00000000..f8c4fe60 --- /dev/null +++ b/test/SIM_trickified_object/trickified_project/include_foo/Foo.cpp @@ -0,0 +1,9 @@ +// @trick_parse{everything} + +#include "Foo.hh" + + + +void Foo::foo() { + std::cout << i++ << '\n'; +} diff --git a/test/SIM_trickified_object/trickified_project/include_foo/Foo.hh b/test/SIM_trickified_object/trickified_project/include_foo/Foo.hh new file mode 100644 index 00000000..a29d0719 --- /dev/null +++ b/test/SIM_trickified_object/trickified_project/include_foo/Foo.hh @@ -0,0 +1,13 @@ +// @trick_parse{everything} + +#include + +class Foo { + + public: + + int i; + + void foo(); + +}; diff --git a/test/SIM_trickified_object/trickified_project/trickified/.gitignore b/test/SIM_trickified_object/trickified_project/trickified/.gitignore new file mode 100644 index 00000000..0259157c --- /dev/null +++ b/test/SIM_trickified_object/trickified_project/trickified/.gitignore @@ -0,0 +1,4 @@ +build +python +trick +*.o diff --git a/test/SIM_trickified/trickified_project/trickified/Makefile b/test/SIM_trickified_object/trickified_project/trickified/Makefile similarity index 87% rename from test/SIM_trickified/trickified_project/trickified/Makefile rename to test/SIM_trickified_object/trickified_project/trickified/Makefile index af59fc55..f087848e 100644 --- a/test/SIM_trickified/trickified_project/trickified/Makefile +++ b/test/SIM_trickified_object/trickified_project/trickified/Makefile @@ -11,3 +11,5 @@ clean: @rm -rf trickify_obj_list @rm -rf trickify_src_list @rm -rf S_source.hh + @rm -rf ../include_foo/*.o + @rm -rf ../include_bar/*.o diff --git a/test/SIM_trickified_object/trickified_project/trickified/myproject.mk b/test/SIM_trickified_object/trickified_project/trickified/myproject.mk new file mode 100644 index 00000000..f2f61e8f --- /dev/null +++ b/test/SIM_trickified_object/trickified_project/trickified/myproject.mk @@ -0,0 +1,14 @@ +LOCAL_DIR := $(abspath $(dir $(lastword $(MAKEFILE_LIST)))) + +include $(LOCAL_DIR)/myproject_vars.mk + +# Append a prerequisite to the $(SWIG_SRC) target. This will build the +# Trickified library along with the sim if it does not already exist. Using +# $(SWIG_SRC) ensures that all Trickified .i files are created before SWIG is +# run on any simulation .i files, which may %import them. Note that this does +# NOT cause the Trickified library to be rebuilt if it already exists, even if +# the Trickified source code has changed. +$(SWIG_SRC): $(MYPROJECT_TRICK) + +$(MYPROJECT_TRICK): + @$(MAKE) -s -C $(MYPROJECT_HOME)/trickified diff --git a/test/SIM_trickified/trickified_project/trickified/myproject_vars.mk b/test/SIM_trickified_object/trickified_project/trickified/myproject_vars.mk similarity index 100% rename from test/SIM_trickified/trickified_project/trickified/myproject_vars.mk rename to test/SIM_trickified_object/trickified_project/trickified/myproject_vars.mk diff --git a/test/SIM_trickified_shared/RUN_test/unit_test.py b/test/SIM_trickified_shared/RUN_test/unit_test.py new file mode 100644 index 00000000..f74fee0b --- /dev/null +++ b/test/SIM_trickified_shared/RUN_test/unit_test.py @@ -0,0 +1,4 @@ +sandbox.foo.i = 5 +assert sandbox.foo.i == 5 +foo = trick.Foo() +trick.stop(10) diff --git a/test/SIM_trickified_shared/S_define b/test/SIM_trickified_shared/S_define new file mode 100644 index 00000000..f770e2a7 --- /dev/null +++ b/test/SIM_trickified_shared/S_define @@ -0,0 +1,21 @@ +#include "sim_objects/default_trick_sys.sm" +##include "Foo.hh" +##include "Bar.hh" +##include "Baz.hh" + +class Sandbox : public Trick::SimObject { + + public: + + Foo foo; + Bar bar; + Baz baz; + + Sandbox() { + (1, "scheduled") foo.foo(); + } + +}; + + +Sandbox sandbox; diff --git a/test/SIM_trickified_shared/S_overrides.mk b/test/SIM_trickified_shared/S_overrides.mk new file mode 100644 index 00000000..e17d8690 --- /dev/null +++ b/test/SIM_trickified_shared/S_overrides.mk @@ -0,0 +1,4 @@ +LOCAL_DIR := $(abspath $(dir $(lastword $(MAKEFILE_LIST)))) + +TRICK_CXXFLAGS += -I$(LOCAL_DIR)/models +include $(CURDIR)/trickified_project/trickified/myproject.mk diff --git a/test/SIM_trickified_shared/models/Baz.hh b/test/SIM_trickified_shared/models/Baz.hh new file mode 100644 index 00000000..fc91c1b2 --- /dev/null +++ b/test/SIM_trickified_shared/models/Baz.hh @@ -0,0 +1,9 @@ +// @trick_parse{everything} + +class Baz { + + public: + int i; + int j; + +}; diff --git a/test/SIM_trickified_shared/trickified_project/include_bar/Bar.cpp b/test/SIM_trickified_shared/trickified_project/include_bar/Bar.cpp new file mode 100644 index 00000000..55a07a84 --- /dev/null +++ b/test/SIM_trickified_shared/trickified_project/include_bar/Bar.cpp @@ -0,0 +1,9 @@ +// @trick_parse{everything} + +#include "Bar.hh" + + +void Bar::add() {} +void Bar::remove() {} +void Bar::restart() {} + diff --git a/test/SIM_trickified_shared/trickified_project/include_bar/Bar.hh b/test/SIM_trickified_shared/trickified_project/include_bar/Bar.hh new file mode 100644 index 00000000..5c497262 --- /dev/null +++ b/test/SIM_trickified_shared/trickified_project/include_bar/Bar.hh @@ -0,0 +1,17 @@ +// @trick_parse{everything} + +#include "trick/Event.hh" + +/** + * Induce an `%import sim_services` statement in this class's Python module by inheriting from a + * Trick class. This allows us to test if `sys.path` contains the correct path to `sim_services.py` + * (and other modules generated during a sim build) for Trickified projects. + */ +class Bar : public Trick::Event { + + int process(long long) {return 0;} + void add(); + void remove(); + void restart(); + +}; diff --git a/test/SIM_trickified_shared/trickified_project/include_foo/Foo.cpp b/test/SIM_trickified_shared/trickified_project/include_foo/Foo.cpp new file mode 100644 index 00000000..f8c4fe60 --- /dev/null +++ b/test/SIM_trickified_shared/trickified_project/include_foo/Foo.cpp @@ -0,0 +1,9 @@ +// @trick_parse{everything} + +#include "Foo.hh" + + + +void Foo::foo() { + std::cout << i++ << '\n'; +} diff --git a/test/SIM_trickified_shared/trickified_project/include_foo/Foo.hh b/test/SIM_trickified_shared/trickified_project/include_foo/Foo.hh new file mode 100644 index 00000000..a29d0719 --- /dev/null +++ b/test/SIM_trickified_shared/trickified_project/include_foo/Foo.hh @@ -0,0 +1,13 @@ +// @trick_parse{everything} + +#include + +class Foo { + + public: + + int i; + + void foo(); + +}; diff --git a/test/SIM_trickified_shared/trickified_project/trickified/.gitignore b/test/SIM_trickified_shared/trickified_project/trickified/.gitignore new file mode 100644 index 00000000..0259157c --- /dev/null +++ b/test/SIM_trickified_shared/trickified_project/trickified/.gitignore @@ -0,0 +1,4 @@ +build +python +trick +*.o diff --git a/test/SIM_trickified_shared/trickified_project/trickified/Makefile b/test/SIM_trickified_shared/trickified_project/trickified/Makefile new file mode 100644 index 00000000..f4013441 --- /dev/null +++ b/test/SIM_trickified_shared/trickified_project/trickified/Makefile @@ -0,0 +1,15 @@ +LOCAL_DIR := $(abspath $(dir $(lastword $(MAKEFILE_LIST)))) +include $(LOCAL_DIR)/myproject_vars.mk + +all: + @echo MAKE LOCAL_DIR $(LOCAL_DIR) + @trick-ify -d "$(LOCAL_DIR)/../include_bar $(LOCAL_DIR)/../include_foo" -b so -n trickified_myproject -v -ma "-fPIC" + +clean: + @rm -rf build python trick $(TRICKIFY_OBJECT_NAME) + @rm -rf $(MYPROJECT_TRICK) + @rm -rf trickify_obj_list + @rm -rf trickify_src_list + @rm -rf S_source.hh + @rm -rf ../include_foo/*.o + @rm -rf ../include_bar/*.o diff --git a/test/SIM_trickified_shared/trickified_project/trickified/myproject.mk b/test/SIM_trickified_shared/trickified_project/trickified/myproject.mk new file mode 100644 index 00000000..f2f61e8f --- /dev/null +++ b/test/SIM_trickified_shared/trickified_project/trickified/myproject.mk @@ -0,0 +1,14 @@ +LOCAL_DIR := $(abspath $(dir $(lastword $(MAKEFILE_LIST)))) + +include $(LOCAL_DIR)/myproject_vars.mk + +# Append a prerequisite to the $(SWIG_SRC) target. This will build the +# Trickified library along with the sim if it does not already exist. Using +# $(SWIG_SRC) ensures that all Trickified .i files are created before SWIG is +# run on any simulation .i files, which may %import them. Note that this does +# NOT cause the Trickified library to be rebuilt if it already exists, even if +# the Trickified source code has changed. +$(SWIG_SRC): $(MYPROJECT_TRICK) + +$(MYPROJECT_TRICK): + @$(MAKE) -s -C $(MYPROJECT_HOME)/trickified diff --git a/test/SIM_trickified_shared/trickified_project/trickified/myproject_vars.mk b/test/SIM_trickified_shared/trickified_project/trickified/myproject_vars.mk new file mode 100644 index 00000000..8f3a556b --- /dev/null +++ b/test/SIM_trickified_shared/trickified_project/trickified/myproject_vars.mk @@ -0,0 +1,28 @@ +# We know this file's position relative to the root directory of the project, +# and MAKEFILE_LIST will give us the full path to this file no matter where the +# user has installed this project. +export MYPROJECT_HOME := $(abspath $(dir $(lastword $(MAKEFILE_LIST)))/..) + +# Specify include paths for your headers. +MYPROJECT_INCLUDE := -I$(MYPROJECT_HOME)/include_bar -I$(MYPROJECT_HOME)/include_foo + +# Users may set different flags for C and C++, so you should really modify both +# to be safe. +TRICK_CFLAGS += $(MYPROJECT_INCLUDE) $(MYPROJECT_SOURCE) +TRICK_CXXFLAGS += $(MYPROJECT_INCLUDE) $(MYPROJECT_SOURCE) + +export TRICKIFY_OBJECT_NAME := trickified_myproject.so +MYPROJECT_TRICK := $(MYPROJECT_HOME)/trickified/$(TRICKIFY_OBJECT_NAME) + +# Tell Trick the headers and source at this location are part of a +# Trickified project +TRICK_EXT_LIB_DIRS += :$(MYPROJECT_HOME) + +# Tell Trick where to find the Python modules generated by SWIG +TRICK_PYTHON_PATH += :$(MYPROJECT_HOME)/trickified/python + +# Tell SWIG where to find py_*.i files +TRICK_SWIG_FLAGS += -I$(MYPROJECT_HOME)/trickified + +# Link in the Trickified object +TRICK_LDFLAGS += $(MYPROJECT_TRICK)