diff --git a/bindings/terra/.gitignore b/bindings/terra/.gitignore index 1b1efedebf..6ac4a28c90 100644 --- a/bindings/terra/.gitignore +++ b/bindings/terra/.gitignore @@ -1,3 +1,4 @@ *.a *.so *.dylib +link_flags.txt diff --git a/bindings/terra/Makefile b/bindings/terra/Makefile index 45c30aa376..454ef54df6 100644 --- a/bindings/terra/Makefile +++ b/bindings/terra/Makefile @@ -78,6 +78,10 @@ endif CC_FLAGS += -DREALM_ALLOW_MISSING_LLVM_LIBS $(OUTFILE) : LLVM_LIBS= +# Also static-link all application objects +OUTLIB = liblegion_terra_bindings.a +OUTLINK_FLAGS = link_flags.txt + ########################################################################### # # Don't change anything below here diff --git a/language/src/regent/std.t b/language/src/regent/std.t index 8e73b97895..f5df7d0895 100644 --- a/language/src/regent/std.t +++ b/language/src/regent/std.t @@ -3455,6 +3455,8 @@ end function std.start(main_task, extra_setup_thunk) if std.config["pretty"] then os.exit() end + terralib.linklibrary("liblegion_terra.so") + assert(std.is_task(main_task)) local main = std.setup(main_task, extra_setup_thunk) @@ -3476,6 +3478,13 @@ function std.start(main_task, extra_setup_thunk) wrapper() end +local function split(str, sep) + local fields = terralib.newlist() + local pattern = string.format("([^%s]+)", sep) + str:gsub(pattern, function(c) fields:insert(c) end) + return fields +end + function std.saveobj(main_task, filename, filetype, extra_setup_thunk, link_flags) assert(std.is_task(main_task)) local main, names = std.setup(main_task, extra_setup_thunk) @@ -3483,7 +3492,11 @@ function std.saveobj(main_task, filename, filetype, extra_setup_thunk, link_flag local flags = terralib.newlist() if link_flags then flags:insertall(link_flags) end - flags:insertall({"-L" .. lib_dir, "-llegion_terra"}) + flags:insertall({"-L" .. lib_dir, "-llegion_terra_bindings"}) + local legion_flags_cache = io.open(lib_dir .. "/link_flags.txt", "r") + flags:insertall(split(legion_flags_cache:read(), ' ')) + legion_flags_cache:close() + flags:insert('-lstdc++') if filetype ~= nil then terralib.saveobj(filename, filetype, names, flags) else diff --git a/language/src/regent/std_base.t b/language/src/regent/std_base.t index 4ad986ca1e..56cc596789 100644 --- a/language/src/regent/std_base.t +++ b/language/src/regent/std_base.t @@ -25,7 +25,6 @@ base.config, base.args = config.args() -- ## Legion Bindings -- ################# -terralib.linklibrary("liblegion_terra.so") local c = terralib.includecstring([[ #include "legion_c.h" #include "legion_terra.h" diff --git a/runtime/runtime.mk b/runtime/runtime.mk index 96eafdbdeb..f9fc039fe8 100644 --- a/runtime/runtime.mk +++ b/runtime/runtime.mk @@ -581,24 +581,37 @@ endif # Provide build rules unless the user asks us not to ifndef NO_BUILD_RULES + # Provide an all unless the user asks us not to ifndef NO_BUILD_ALL .PHONY: all +ifdef OUTLIB +all: $(OUTFILE) $(OUTLIB) +else all: $(OUTFILE) endif +endif # If we're using CUDA we have to link with nvcc $(OUTFILE) : $(GEN_OBJS) $(GEN_GPU_OBJS) $(SLIB_LEGION) $(SLIB_REALM) @echo "---> Linking objects into one binary: $(OUTFILE)" $(CXX) -o $(OUTFILE) $(GEN_OBJS) $(GEN_GPU_OBJS) $(LD_FLAGS) $(LEGION_LIBS) $(LEGION_LD_FLAGS) $(GASNET_FLAGS) +ifdef OUTLIB +$(OUTLIB) : $(GEN_OBJS) $(GEN_GPU_OBJS) + @echo "---> Linking application objects into a static archive: $(OUTLIB)" + @echo "---> Required link flags stored in $(OUTLINK_FLAGS)" + $(AR) rcs $(OUTLIB) $(GEN_OBJS) $(GEN_GPU_OBJS) + @echo "-llegion -lrealm $(LEGION_LD_FLAGS) $(GASNET_FLAGS)" > $(OUTLINK_FLAGS) +endif + $(SLIB_LEGION) : $(LEGION_OBJS) $(MAPPER_OBJS) rm -f $@ - $(AR) rc $@ $^ + $(AR) rcs $@ $^ $(SLIB_REALM) : $(REALM_OBJS) rm -f $@ - $(AR) rc $@ $^ + $(AR) rcs $@ $^ $(GEN_OBJS) : %.cc.o : %.cc $(CXX) -o $@ -c $< $(CC_FLAGS) $(INC_FLAGS)