From c5d0b2a87290e2df91fde20b21ac3ff44dec3e3b Mon Sep 17 00:00:00 2001 From: Alex Lin Date: Thu, 4 Jun 2015 13:17:53 -0500 Subject: [PATCH] /usr/lib64/llvm/clang/3.4.2 not found Modified the makefile for ICG to be able to use clang from yum, fink, and manual installs. Removed the requirement for copying the clang friendly header files into Trick. However Trick will be expecting the clang header files to be in it's search path. refs #40 --- .../Interface_Code_Gen/FieldDescription.cpp | 2 +- .../Interface_Code_Gen/HeaderSearchDirs.cpp | 29 ++----- .../Interface_Code_Gen/HeaderSearchDirs.hh | 4 - .../codegen/Interface_Code_Gen/main.cpp | 25 ++---- .../codegen/Interface_Code_Gen/makefile | 80 +++++++------------ 5 files changed, 41 insertions(+), 99 deletions(-) diff --git a/trick_source/codegen/Interface_Code_Gen/FieldDescription.cpp b/trick_source/codegen/Interface_Code_Gen/FieldDescription.cpp index 5809dfe0..08ee6d91 100644 --- a/trick_source/codegen/Interface_Code_Gen/FieldDescription.cpp +++ b/trick_source/codegen/Interface_Code_Gen/FieldDescription.cpp @@ -430,7 +430,7 @@ std::ostream & operator << (std::ostream & os , FieldDescription & fdes ) { os << " bitfield_word_offset = " << fdes.bitfield_word_offset << std::endl ; os << " num_dims = " << fdes.num_dims << std::endl ; os << " array_sizes =" ; - for( unsigned int ii ; ii < 8 ; ii++ ) { + for( unsigned int ii = 0 ; ii < 8 ; ii++ ) { os << " " << fdes.array_sizes[ii] ; } os << std::endl ; diff --git a/trick_source/codegen/Interface_Code_Gen/HeaderSearchDirs.cpp b/trick_source/codegen/Interface_Code_Gen/HeaderSearchDirs.cpp index 72e01a75..3e842375 100644 --- a/trick_source/codegen/Interface_Code_Gen/HeaderSearchDirs.cpp +++ b/trick_source/codegen/Interface_Code_Gen/HeaderSearchDirs.cpp @@ -32,22 +32,19 @@ void HeaderSearchDirs::AddCompilerBuiltInSearchDirs () { const bool IsFramework = false; const bool IsSysRootRelative = true; -#ifdef __linux // Add clang specific include directory first. Only required on linux systems. :( + // This is so that ICG will find clang friendly headers first. gcc headers cause + // all kinds of problems. On macs all headers are clang friendly. +#if __linux std::stringstream icg_dir ; - icg_dir << std::string(getenv("TRICK_HOME")) << "/trick_source/codegen/Interface_Code_Gen/lib/clang/" ; + //icg_dir << std::string(getenv("TRICK_HOME")) << "/libexec/trick/lib/clang/" ; + icg_dir << LLVM_HOME << "/lib/clang/" ; icg_dir << __clang_major__ << "." << __clang_minor__ ; -#if (__clang_major__ == 3) && (__clang_minor__ >= 4) #ifdef __clang_patchlevel__ icg_dir << "." << __clang_patchlevel__ ; -#endif #endif icg_dir << "/include" ; -#if (__clang_major__ == 3) && (__clang_minor__ >= 3) hso.AddPath(icg_dir.str() , clang::frontend::System, IsFramework, IsSysRootRelative); -#else - hso.AddPath(icg_dir.str() , clang::frontend::System, IsUserSupplied, IsFramework, IsSysRootRelative); -#endif #endif fp = popen("${TRICK_HOME}/bin/trick-gte TRICK_CPPC" , "r") ; @@ -79,11 +76,7 @@ void HeaderSearchDirs::AddCompilerBuiltInSearchDirs () { //std::cout << "dir = " << dir << std::endl ; if ( resolved_path != NULL ) { //std::cout << "gcc resolved_path = " << resolved_path << std::endl ; -#if (__clang_major__ == 3) && (__clang_minor__ >= 3) hso.AddPath(resolved_path , clang::frontend::System, IsFramework, IsSysRootRelative); -#else - hso.AddPath(resolved_path , clang::frontend::System, IsUserSupplied, IsFramework, IsSysRootRelative); -#endif free(resolved_path) ; } } else if ( !strncmp( line, "#include <...>", 14 )) { @@ -103,11 +96,7 @@ void HeaderSearchDirs::AddUserSearchDirs ( std::vector & include_di char * resolved_path = almostRealPath(include_dirs[ii].c_str()) ; if ( resolved_path != NULL ) { //std::cout << "adding resolved_path = " << resolved_path << std::endl ; -#if (__clang_major__ == 3) && (__clang_minor__ >= 3) hso.AddPath(resolved_path , clang::frontend::Angled, false, true); -#else - hso.AddPath(resolved_path , clang::frontend::Angled, true, false, true); -#endif // Add the path as a system path as well for those included files that are erroneously in <> } } @@ -120,21 +109,13 @@ void HeaderSearchDirs::AddTrickSearchDirs () { if ( trick_home != NULL ) { std::string temp_dir = std::string(trick_home) + "/include/trick" ; char * resolved_path = almostRealPath(temp_dir.c_str() ) ; -#if (__clang_major__ == 3) && (__clang_minor__ >= 3) hso.AddPath(resolved_path , clang::frontend::Quoted, false, true); -#else - hso.AddPath(resolved_path , clang::frontend::Quoted, true, false, true); -#endif trick_include_dir = std::string(resolved_path) ; free(resolved_path) ; temp_dir = std::string(trick_home) + "/trick_source" ; resolved_path = almostRealPath(temp_dir.c_str() ) ; -#if (__clang_major__ == 3) && (__clang_minor__ >= 3) hso.AddPath(resolved_path , clang::frontend::Quoted, false, true); -#else - hso.AddPath(resolved_path , clang::frontend::Quoted, true, false, true); -#endif trick_source_dir = std::string(resolved_path) ; free(resolved_path) ; } diff --git a/trick_source/codegen/Interface_Code_Gen/HeaderSearchDirs.hh b/trick_source/codegen/Interface_Code_Gen/HeaderSearchDirs.hh index fe6c60e1..eb45dd76 100644 --- a/trick_source/codegen/Interface_Code_Gen/HeaderSearchDirs.hh +++ b/trick_source/codegen/Interface_Code_Gen/HeaderSearchDirs.hh @@ -7,11 +7,7 @@ #include #include "clang/Lex/HeaderSearch.h" -#if (__clang_major__ == 3) && (__clang_minor__ >= 3) #include "clang/Lex/HeaderSearchOptions.h" -#else -#include "clang/Frontend/HeaderSearchOptions.h" -#endif #include "clang/Lex/Preprocessor.h" /** diff --git a/trick_source/codegen/Interface_Code_Gen/main.cpp b/trick_source/codegen/Interface_Code_Gen/main.cpp index 5cfe2925..5e95a7eb 100644 --- a/trick_source/codegen/Interface_Code_Gen/main.cpp +++ b/trick_source/codegen/Interface_Code_Gen/main.cpp @@ -62,7 +62,7 @@ Most of the main program is pieced together from examples on the web. We are doi */ int main( int argc , char * argv[] ) { -#if (__clang_major__ == 3) && (__clang_minor__ >= 5) +#if (__clang_major__ >= 6) || ((__clang_major__ == 3) && (__clang_minor__ >= 5)) clang::TargetOptions to; #elif (__clang_major__ == 3) && (__clang_minor__ >= 3) clang::TargetOptions * to = new clang::TargetOptions() ; @@ -85,11 +85,7 @@ int main( int argc , char * argv[] ) { return 0 ; } -#if (__clang_major__ == 3) && (__clang_minor__ >= 3) ci.createDiagnostics(); -#else - ci.createDiagnostics(0,NULL); -#endif clang::DiagnosticOptions & diago = ci.getDiagnosticOpts() ; diago.ShowColors = 1 ; ci.getDiagnostics().setIgnoreAllWarnings(true) ; @@ -102,14 +98,10 @@ int main( int argc , char * argv[] ) { ci.getLangOpts().CXXExceptions = true ; // Activate C++11 parsing -#if (__clang_major__ == 3) && (__clang_minor__ >= 3) ci.getLangOpts().CPlusPlus11 = true ; -#else - ci.getLangOpts().CPlusPlus0x = true ; -#endif // Set the default target architecture -#if (__clang_major__ == 3) && (__clang_minor__ >= 5) +#if (__clang_major__ >= 6) || (__clang_major__ == 3) && (__clang_minor__ >= 5) to.Triple = llvm::sys::getDefaultTargetTriple(); #elif (__clang_major__ == 3) && (__clang_minor__ >= 3) to->Triple = llvm::sys::getDefaultTargetTriple(); @@ -117,7 +109,7 @@ int main( int argc , char * argv[] ) { to.Triple = llvm::sys::getDefaultTargetTriple(); #endif -#if (__clang_major__ == 3) && (__clang_minor__ >= 5) +#if (__clang_major__ >= 6) || (__clang_major__ == 3) && (__clang_minor__ >= 5) std::shared_ptr shared_to = std::make_shared(to) ; clang::TargetInfo *pti = clang::TargetInfo::CreateTargetInfo(ci.getDiagnostics(), shared_to); #else @@ -128,7 +120,7 @@ int main( int argc , char * argv[] ) { // Create all of the necessary managers. ci.createFileManager(); ci.createSourceManager(ci.getFileManager()); -#if (__clang_major__ == 3) && (__clang_minor__ >= 5) +#if (__clang_major__ >= 6) || (__clang_major__ == 3) && (__clang_minor__ >= 5) ci.createPreprocessor(clang::TU_Complete); #else ci.createPreprocessor(); @@ -151,12 +143,7 @@ int main( int argc , char * argv[] ) { // Add our comment saver as a comment handler in the preprocessor CommentSaver cs(ci.getSourceManager()) ; -#if (__clang_major__ == 3) && (__clang_minor__ >= 3) pp.addCommentHandler(&cs) ; -#else - pp.AddCommentHandler(&cs) ; -#endif - PrintAttributes pa( attr_version, hsd, cs, ci, force, sim_services_flag) ; @@ -165,7 +152,7 @@ int main( int argc , char * argv[] ) { // Tell the compiler to use our ICGASTconsumer ICGASTConsumer *astConsumer = new ICGASTConsumer(ci, hsd, cs, pa); -#if (__clang_major__ == 3) && (__clang_minor__ >= 6) +#if (__clang_major__ >= 6) || ((__clang_major__ == 3) && (__clang_minor__ >= 6)) std::unique_ptr unique_ast(astConsumer) ; ci.setASTConsumer(std::move(unique_ast)); #else @@ -186,7 +173,7 @@ int main( int argc , char * argv[] ) { // Open up the input file and parse it. const clang::FileEntry *pFile = ci.getFileManager().getFile(input_file_full_path); -#if (__clang_major__ == 3) && (__clang_minor__ >= 5) +#if (__clang_major__ >= 6) || ((__clang_major__ == 3) && (__clang_minor__ >= 5)) ci.getSourceManager().setMainFileID(ci.getSourceManager().createFileID(pFile, clang::SourceLocation(), clang::SrcMgr::C_User)); #else ci.getSourceManager().createMainFileID(pFile); diff --git a/trick_source/codegen/Interface_Code_Gen/makefile b/trick_source/codegen/Interface_Code_Gen/makefile index 115a31cb..147cefc9 100644 --- a/trick_source/codegen/Interface_Code_Gen/makefile +++ b/trick_source/codegen/Interface_Code_Gen/makefile @@ -2,20 +2,15 @@ # The config_${HOST_TYPE}.mk file provides LLVM_HOME include ${TRICK_HOME}/share/trick/makefiles/Makefile.common -RTTIFLAG := -fno-rtti -LLVM_VERSION := $(shell $(LLVM_HOME)/bin/$(LLVM_CONFIG) --version) -ifneq ($(LLVM_HOME),) CC := $(shell $(LLVM_HOME)/bin/$(LLVM_CONFIG) --bindir)/clang CXX := $(shell $(LLVM_HOME)/bin/$(LLVM_CONFIG) --bindir)/clang++ -CXXFLAGS := $(shell $(LLVM_HOME)/bin/$(LLVM_CONFIG) --cxxflags) -I$(shell $(LLVM_HOME)/bin/$(LLVM_CONFIG) --includedir) $(RTTIFLAG) -g -O0 -LLVMLIBDIR := -L$(shell $(LLVM_HOME)/bin/$(LLVM_CONFIG) --libdir) -endif -LLVMLDFLAGS := $(shell $(LLVM_HOME)/bin/$(LLVM_CONFIG) --ldflags) -OBJ_DIR := object_$(TRICK_HOST_CPU) +CXXFLAGS := -I${LLVM_HOME}/include -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -fno-rtti -CLANG_VERSION := $(shell $(LLVM_HOME)/bin/$(LLVM_CONFIG) --version) CLANG_MINOR_GTEQ5 := $(shell expr `$(LLVM_HOME)/bin/$(LLVM_CONFIG) --version | cut -f2 -d. ` \>= 5 ) -CLANG_LIBDIR := $(shell $(LLVM_HOME)/bin/$(LLVM_CONFIG) --libdir) + +LLVMLDFLAGS := $(shell $(LLVM_HOME)/bin/$(LLVM_CONFIG) --ldflags) + +OBJ_DIR := object_$(TRICK_HOST_CPU) ifeq ($(IS_CC_CLANG), 0) CXXFLAGS += -DGCC_MAJOR=$(GCC_MAJOR) -DGCC_MINOR=$(GCC_MINOR) @@ -31,53 +26,39 @@ UNITS_CONV_SRC = ${TRICK_HOME}/trick_source/trick_utils/units/src/units_conv.c UNITS_CONV_INCLUDE = -I${TRICK_HOME}/include UNITS_CONV_OBJ = $(OBJ_DIR)/units_conv.o +CLANGLIBS = \ + -lclangFrontend \ + -lclangDriver \ + -lclangSerialization \ + -lclangParse \ + -lclangSema \ + -lclangAnalysis \ + -lclangEdit \ + -lclangAST \ + -lclangLex \ + -lclangBasic \ + +ifeq ($(TRICK_HOST_TYPE),Linux) +CLANGLIBS += $(shell $(LLVM_HOME)/bin/$(LLVM_CONFIG) --libs) ifeq ($(CLANG_MINOR_GTEQ5),1) -LLVMLDFLAGS += $(shell $(LLVM_HOME)/bin/$(LLVM_CONFIG) --system-libs) +CXXFLAGS += -std=c++11 +CLANGLIBS += $(shell $(LLVM_HOME)/bin/$(LLVM_CONFIG) --system-libs) +endif endif -ifeq ($(CLANG_VERSION),3.1) -CLANGLIBS = \ - -lclangFrontend \ - -lclangDriver \ - -lclangSerialization \ - -lclangParse \ - -lclangSema \ - -lclangAnalysis \ - -lclangRewrite \ - -lclangEdit \ - -lclangAST \ - -lclangLex \ - -lclangBasic \ - -lLLVMMC \ - -lLLVMSupport -else -CLANGLIBS = \ - -lclangFrontend \ - -lclangDriver \ - -lclangSerialization \ - -lclangParse \ - -lclangSema \ - -lclangAnalysis \ - -lclangEdit \ - -lclangAST \ - -lclangLex \ - -lclangBasic \ - $(shell $(LLVM_HOME)/bin/$(LLVM_CONFIG) --libs) +ifeq ($(TRICK_HOST_TYPE),Darwin) +CXXFLAGS += -std=c++11 +CLANGLIBS += -lLLVMOption -lLLVMMCParser -lLLVMBitReader -lLLVMMC -lLLVMSupport $(shell $(LLVM_HOME)/bin/$(LLVM_CONFIG) --system-libs) endif -all: $(ICG) lib/clang/$(LLVM_VERSION) +all: $(ICG) $(ICG): $(OBJECTS) $(UNITS_CONV_OBJ) - $(CXX) -o $@ $(OBJECTS) $(UNITS_CONV_OBJ) $(LLVMLIBDIR) $(CLANGLIBS) $(LLVMLDFLAGS) - -lib/clang: - mkdir -p $@ - -lib/clang/$(LLVM_VERSION): | lib/clang - cp -r $(CLANG_LIBDIR)/clang/$(LLVM_VERSION) lib/clang + $(CXX) -o $@ $(OBJECTS) $(UNITS_CONV_OBJ) $(LLVMLDFLAGS) $(CLANGLIBS) # Only FieldDescription.cpp includes the units conversion header. $(OBJ_DIR)/FieldDescription.o : CXXFLAGS += $(UNITS_CONV_INCLUDE) +$(OBJ_DIR)/HeaderSearchDirs.o : CXXFLAGS += -DLLVM_HOME=\"${LLVM_HOME}\" $(OBJ_DIR)/main.o : CXXFLAGS += $(UNITS_CONV_INCLUDE) $(OBJECTS): $(OBJ_DIR)/%.o : %.cpp @@ -91,8 +72,5 @@ $(OBJECTS) $(UNITS_CONV_OBJ) : | $(OBJ_DIR) $(OBJ_DIR): mkdir -p $(OBJ_DIR) -# if an LLVM_HOME is not specified, then ICG cannot be rebuilt... don't delete it clean: -ifneq ($(LLVM_HOME),) - -rm -rf $(OBJ_DIR) $(ICG) lib -endif + rm -rf $(OBJ_DIR) $(ICG)