Skip to content

Commit

Permalink
build: Add a generated Version.inc file instead of duplicating inform…
Browse files Browse the repository at this point in the history
…ation.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@106863 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
ddunbar committed Jun 25, 2010
1 parent b24e199 commit a510767
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 12 deletions.
17 changes: 17 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,23 @@ string(REGEX MATCH "[0-9]+\\.[0-9]+(\\.[0-9]+)?" CLANG_VERSION
${CLANG_VERSION_DATA})
message(STATUS "Clang version: ${CLANG_VERSION}")

string(REGEX REPLACE "([0-9]+)\\.[0-9]+(\\.[0-9]+)?" "\\1" CLANG_VERSION_MAJOR
${CLANG_VERSION})
string(REGEX REPLACE "[0-9]+\\.([0-9]+)(\\.[0-9]+)?" "\\1" CLANG_VERSION_MINOR
${CLANG_VERSION})
if (${CLANG_VERSION} MATCHES "[0-9]+\\.[0-9]+\\.[0-9]+")
set(CLANG_HAS_VERSION_PATCHLEVEL 1)
string(REGEX REPLACE "[0-9]+\\.[0-9]+\\.([0-9]+)" "\\1" CLANG_VERSION_PATCHLEVEL
${CLANG_VERSION})
else()
set(CLANG_HAS_VERSION_PATCHLEVEL 0)
endif()

# Configure the Version.inc file.
configure_file(
${CMAKE_CURRENT_SOURCE_DIR}/include/clang/Basic/Version.inc.in
${CMAKE_CURRENT_BINARY_DIR}/include/clang/Basic/Version.inc)

# Add appropriate flags for GCC
if (CMAKE_COMPILER_IS_GNUCXX)
# FIXME: Turn off exceptions, RTTI:
Expand Down
7 changes: 6 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ CPP.Flags += -I$(PROJ_SRC_DIR)/$(CLANG_LEVEL)/include -I$(PROJ_OBJ_DIR)/$(CLANG_
ifdef CLANG_VENDOR
CPP.Flags += -DCLANG_VENDOR='"$(CLANG_VENDOR) "'
endif
ifdef CLANG_VERSION
CPP.Flags += \
-DCLANG_VERSION='"$(CLANG_VERSION)"'
-DCLANG_VERSION='"$(CLANG_VERSION)"'
endif

# Disable -fstrict-aliasing. Darwin disables it by default (and LLVM doesn't
# work with it enabled with GCC), Clang/llvm-gc don't support it yet, and newer
Expand Down Expand Up @@ -74,7 +79,7 @@ report::

clean::
@ $(MAKE) -C test clean

libs-only: all

tags::
Expand Down
26 changes: 24 additions & 2 deletions include/clang/Basic/Makefile
Original file line number Diff line number Diff line change
@@ -1,16 +1,29 @@
CLANG_LEVEL := ../../..
BUILT_SOURCES = DiagnosticAnalysisKinds.inc DiagnosticASTKinds.inc \
BUILT_SOURCES = \
DiagnosticAnalysisKinds.inc DiagnosticASTKinds.inc \
DiagnosticCommonKinds.inc DiagnosticDriverKinds.inc \
DiagnosticFrontendKinds.inc DiagnosticLexKinds.inc \
DiagnosticParseKinds.inc DiagnosticSemaKinds.inc \
DiagnosticGroups.inc AttrList.inc arm_neon.inc
DiagnosticGroups.inc AttrList.inc arm_neon.inc \
Version.inc

TABLEGEN_INC_FILES_COMMON = 1

include $(CLANG_LEVEL)/Makefile

INPUT_TDS = $(wildcard $(PROJ_SRC_DIR)/Diagnostic*.td)

CLANG_VERSION := $(shell cat $(PROJ_SRC_DIR)/../../../VER)
CLANG_VERSION_COMPONENTS := $(subst ., ,$(CLANG_VERSION))
CLANG_VERSION_MAJOR := $(word 1,$(CLANG_VERSION_COMPONENTS))
CLANG_VERSION_MINOR := $(word 2,$(CLANG_VERSION_COMPONENTS))
CLANG_VERSION_PATCHLEVEL := $(word 3,$(CLANG_VERSION_COMPONENTS))
ifeq ($(CLANG_VERSION_PATCHLEVEL),)
CLANG_HAS_VERSION_PATCHLEVEL := 0
else
CLANG_HAS_VERSION_PATCHLEVEL := 1
endif

$(ObjDir)/Diagnostic%Kinds.inc.tmp : Diagnostic.td Diagnostic%Kinds.td $(TBLGEN) $(ObjDir)/.dir
$(Echo) "Building Clang $(patsubst Diagnostic%Kinds.inc.tmp,%,$(@F)) diagnostic tables with tblgen"
$(Verb) $(TableGen) -gen-clang-diags-defs -clang-component=$(patsubst Diagnostic%Kinds.inc.tmp,%,$(@F)) -o $(call SYSPATH, $@) $<
Expand All @@ -27,3 +40,12 @@ $(ObjDir)/AttrList.inc.tmp : Attr.td $(TBLGEN) $(ObjDir)/.dir
$(ObjDir)/arm_neon.inc.tmp : arm_neon.td $(TBLGEN) $(ObjDir)/.dir
$(Echo) "Building Clang arm_neon.inc with tblgen"
$(Verb) $(TableGen) -gen-arm-neon-sema -o $(call SYSPATH, $@) $<

$(ObjDir)/Version.inc.tmp : Version.inc.in $(PROJ_SRC_DIR)/../../../VER $(ObjDir)/.dir
$(Echo) "Updating Clang version info."
$(Verb)sed -e "s#@CLANG_VERSION@#$(CLANG_VERSION)#g" \
-e "s#@CLANG_VERSION_MAJOR@#$(CLANG_VERSION_MAJOR)#g" \
-e "s#@CLANG_VERSION_MINOR@#$(CLANG_VERSION_MINOR)#g" \
-e "s#@CLANG_VERSION_PATCHLEVEL@#$(CLANG_VERSION_PATCHLEVEL)#g" \
-e "s#@CLANG_HAS_VERSION_PATCHLEVEL@#$(CLANG_HAS_VERSION_PATCHLEVEL)#g" \
$< > $@
10 changes: 1 addition & 9 deletions include/clang/Basic/Version.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,7 @@

#include "llvm/ADT/StringRef.h"

/// \brief Clang major version
#define CLANG_VERSION_MAJOR 2

// FIXME: Updates to this file must also update CMakeLists.txt and VER.
/// \brief Clang minor version
#define CLANG_VERSION_MINOR 0

/// \brief Clang patchlevel version
// #define CLANG_VERSION_PATCHLEVEL 1
#include "clang/Basic/Version.inc"

/// \brief Helper macro for CLANG_VERSION_STRING.
#define CLANG_MAKE_VERSION_STRING2(X) #X
Expand Down
6 changes: 6 additions & 0 deletions include/clang/Basic/Version.inc.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#define CLANG_VERSION @CLANG_VERSION@
#define CLANG_VERSION_MAJOR @CLANG_VERSION_MAJOR@
#define CLANG_VERSION_MINOR @CLANG_VERSION_MINOR@
#if @CLANG_HAS_VERSION_PATCHLEVEL@
#define CLANG_VERSION_PATCHLEVEL @CLANG_VERSION_PATCHLEVEL@
#endif

0 comments on commit a510767

Please sign in to comment.