Skip to content

Commit

Permalink
Support more linker versions in Makefile
Browse files Browse the repository at this point in the history
Changes the way LLVM & Clang object files are detected & extracted in
the default Makefile to handle a wider variety of linker `-t` output formats.
  • Loading branch information
Jcd1230 committed Jul 22, 2021
1 parent ca92b10 commit 14874ec
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 29 deletions.
21 changes: 17 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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


Expand Down
25 changes: 0 additions & 25 deletions src/unpacklibraries.lua

This file was deleted.

0 comments on commit 14874ec

Please sign in to comment.