From 14874ecd0c115e6e0bd0ab3ada6f8e2b42f523db Mon Sep 17 00:00:00 2001 From: Jason Dogariu Date: Wed, 21 Jul 2021 18:00:03 -0400 Subject: [PATCH] Support more linker versions in Makefile Changes the way LLVM & Clang object files are detected & extracted in the default Makefile to handle a wider variety of linker `-t` output formats. --- Makefile | 21 +++++++++++++++++---- src/unpacklibraries.lua | 25 ------------------------- 2 files changed, 17 insertions(+), 29 deletions(-) delete mode 100644 src/unpacklibraries.lua diff --git a/Makefile b/Makefile index bfbfc09d..93a891e1 100644 --- a/Makefile +++ b/Makefile @@ -108,7 +108,7 @@ LLVM_LIBRARY_FLAGS += -lclangFrontend -lclangDriver \ -lclangAnalysis \ -lclangEdit -lclangAST -lclangLex -lclangBasic -CLANG_AST_MATCHERS = "80 90 100 110 111" +CLANG_AST_MATCHERS = "80 90 100 110 111 120" ifneq (,$(findstring $(LLVM_VERSION),$(CLANG_AST_MATCHERS))) LLVM_LIBRARY_FLAGS += -lclangASTMatchers endif @@ -229,9 +229,22 @@ release/include/terra/%.h: $(LUAJIT_INCLUDE)/%.h $(LUAJIT_LIB) build/llvm_objects/llvm_list: $(addprefix build/, $(LIBOBJS) $(EXEOBJS)) mkdir -p build/llvm_objects/luajit - $(CXX) -o /dev/null $(addprefix build/, $(LIBOBJS) $(EXEOBJS)) $(LLVM_LIBRARY_FLAGS) $(SUPPORT_LIBRARY_FLAGS) $(LFLAGS) -Wl,-t 2>&1 | egrep "lib(LLVM|clang)" > build/llvm_objects/llvm_list - # extract needed LLVM objects based on a dummy linker invocation - < build/llvm_objects/llvm_list $(LUAJIT) src/unpacklibraries.lua build/llvm_objects + # Extract needed LLVM objects based on a dummy linker invocation: + # - Older linkers output '(libName.a)object.o' per line, + # - Newer versions output just 'libName.a', unless -t is passed twice. + # grep & uniq are used to get just the paths to the static libraries needed. + $(CXX) -o /dev/null $(addprefix build/, $(LIBOBJS) $(EXEOBJS)) $(LLVM_LIBRARY_FLAGS) $(SUPPORT_LIBRARY_FLAGS) $(LFLAGS) -Wl,-t 2>&1 \ + | egrep -o "[^()]*lib(LLVM|clang|Polly).*\.a" \ + | uniq \ + > build/llvm_objects/llvm_list + # Extract all the static libraries to build/llvm_objects/* + cd build/llvm_objects; for lib in $$(cat llvm_list); do \ + DIR=$$(basename $$lib .a); \ + mkdir -p $$DIR; \ + cd $$DIR; \ + ar x $$lib; \ + cd ..; \ + done # include all luajit objects, since the entire lua interface is used in terra diff --git a/src/unpacklibraries.lua b/src/unpacklibraries.lua deleted file mode 100644 index ff884d22..00000000 --- a/src/unpacklibraries.lua +++ /dev/null @@ -1,25 +0,0 @@ -local destination = ... - -local function exe(cmd,...) - cmd = string.format(cmd,...) - local res = { os.execute(cmd) } - if type(res[1]) == 'number' and res[1] ~= 0 or not res[1] then - print('Error during '..cmd..':', table.unpack(res)) - error("command failed: "..cmd) - end -end -local function exists(path) - local f = io.open(path) - if not f then return false end - f:close() - return true -end -for line in io.lines() do - line = line:gsub("[()]"," ") - local archivepath,objectfile = line:match("(%S+)%s+(%S+)") - local archivename = archivepath:match("/([^/]*)%.a$") - if not exists( ("%s/%s/%s"):format(destination,archivename,objectfile) ) then - exe("mkdir -p %s/%s",destination,archivename) - exe("cd %s/%s; ar x %s %s",destination,archivename,archivepath,objectfile) - end -end \ No newline at end of file