citrun

watch C/C++ source code execute
Log | Files | Refs | LICENSE

commit 6c802f6367d41c866c2b95e39cc680b552ae9e53
parent b2397ed443c5d0fa1ff88f56ffaab7f6f965568c
Author: Kyle Milz <kyle@0x30.net>
Date:   Wed, 21 Dec 2016 16:34:00 -0700

add configure script

Diffstat:
DJamrules | 135-------------------------------------------------------------------------------
AJamrules.in | 70++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
DREADME | 20--------------------
Aconfigure | 36++++++++++++++++++++++++++++++++++++
Msrc/Jamfile | 82+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++----------
5 files changed, 178 insertions(+), 165 deletions(-)

diff --git a/Jamrules b/Jamrules @@ -1,135 +0,0 @@ -# -# Knowing the absolute path to citrun resources is necessary because: -# - instrumented programs must be linked to the runtime library -# - the PATH compiler interception mechanism needs to remove itself from PATH -# -# If PREFIX is set we're building a package, so trust that will be the final -# (after installation) location. -# -if $(PREFIX) { - echo ...build C It Run (Release) on $(OS)... ; - CITRUN_SHARE = $(PREFIX)/share/citrun ; -} -else { - echo ...build C It Run (Debug) on $(OS)... ; - #CITRUN_SHARE = "`readlink -f $(TOP)/src`" ; - CITRUN_SHARE = "`cd $(TOP)/src && pwd`" ; - CFLAGS += -Wall -g ; -} - -CCFLAGS += $(CFLAGS) ; -C++FLAGS += -std=c++11 -fno-exceptions -fno-rtti $(CFLAGS) ; -LINKFLAGS += $(LDFLAGS) ; - -CLANG_LIBS = - -lclangAST - -lclangAnalysis - -lclangBasic - -lclangDriver - -lclangEdit - -lclangFrontend - -lclangFrontendTool - -lclangLex - -lclangParse - -lclangRewrite - -lclangRewriteFrontend - -lclangSema - -lclangSerialization - -lclangTooling ; - -if $(OS) = OPENBSD { - C++ = eg++ ; - - PKG_CONFIG_LIBS = gl glfw3 glew freetype2 ; - LINKLIBS on citrun-inst += -Wl,--start-group $(CLANG_LIBS) -Wl,--end-group ; -} - -if $(OS) = MACOSX { - PKG_CONFIG_LIBS = glfw3 glew freetype2 ; - LINKLIBS on citrun-gl = -framework OpenGL ; - LINKLIBS on citrun-inst = $(CLANG_LIBS) ; -} - -if $(OS) = LINUX { - # llvm version is 3.5 on Debian, which is too old. - PKG_CONFIG_LIBS = gl glfw3 glew freetype2 ; - LINKLIBS on citrun-gl = -lbsd ; - LINKLIBS on citrun-inst = -lbsd ; - LINKLIBS on citrun-inst += -Wl,--start-group $(CLANG_LIBS) -Wl,--end-group ; -} - -actions StaticAnalysis -{ - export CITRUN_SA=1 - scan-build -o html --use-c++=eg++ jam -j4 - # scan-build -o html -v --use-c++=eg++ jam -j4 -} - -actions TestCoverage -{ - set -e - CFLAGS="-coverage -ggdb" LDFLAGS="-coverage" jam -j4 - - # Roll libgcov.a into libcitrun.a. - ar -M < t/libcitrun_gcov.mri - - prove - # prove tt - - gcov -o src src/lib.c - egcov -r src/*.cc -} - -StaticAnalysis static-analysis ; -TestCoverage test-coverage ; - -if $(CITRUN_SA) { - # scan-build sets these expecting us to pick up the new values. - CC = $(CC) ; - C++ = $(CXX) ; -} - -# Link with the c++ compiler so that the matching c++ runtime library gets added -# automatically. -LINK on citrun-inst citrun-term citrun-gl citrun-gltest = $(C++) ; - -rule Stringize -{ - MakeLocate $(1) : $(LOCATE_SOURCE) ; - SEARCH on $(2) = $(SEARCH_SOURCE) ; - Depends $(1) : $(2) ; - Clean clean : $(1) ; -} - -actions Stringize -{ - # Quote the entire original source file and put it in the destination. - sed -e ' s/\\/\\\\/g; s/"/\\"/g; s/^/"/; s/$/\\n"/; ' < $(>) > $(<) - echo ";" >> $(<) - - # Add the declaration to the start of the file. - sed -e '1s/^/static const char *$(1:B) = /' -i.bak $(<) - rm $(<).bak -} - -actions ReplaceTokens -{ - sed -e s,%CITRUN_SHARE%,$(CITRUN_SHARE), -i.bak $(<) ; - rm $(<).bak -} - -rule InstallSyms -{ - Depends install : $(PREFIX)/share/citrun/$(>) ; - MakeLocate $(PREFIX)/share/citrun/$(>) : $(<) ; - - for i in $(>) - { - SymLink $(PREFIX)/share/citrun/$(i) ; - } -} - -actions SymLink -{ - $(RM) $(<) && $(LN) -s ../../bin/citrun-inst $(<) ; -} diff --git a/Jamrules.in b/Jamrules.in @@ -0,0 +1,70 @@ +# +# Knowing the absolute path to citrun resources is necessary because: +# - instrumented programs must be linked to the runtime library +# - the PATH compiler interception mechanism needs to remove itself from PATH +# +# If PREFIX is set we're building a package, so trust that will be the final +# (after installation) location. +# +if $(PREFIX) { + echo ...build C It Run (Release) on $(OS)... ; + CITRUN_SHARE = $(PREFIX)/share/citrun ; +} +else { + echo ...build C It Run (Debug) on $(OS)... ; + #CITRUN_SHARE = "`readlink -f $(TOP)/src`" ; + CITRUN_SHARE = "`cd $(TOP)/src && pwd`" ; + CFLAGS += -Wall -g ; +} + +CCFLAGS += $(CFLAGS) ; +C++FLAGS += -std=c++11 -fno-exceptions -fno-rtti $(CFLAGS) ; +LINKFLAGS += $(LDFLAGS) ; + +if $(OS) = OPENBSD { + C++ = eg++ ; + LDGROUP_START = -Wl,--start-group ; + LDGROUP_END = -Wl,--end-group ; +} + +if $(OS) = MACOSX { + LINKLIBS on citrun-gl = -framework OpenGL ; +} + +if $(OS) = LINUX { + LINKLIBS on citrun-gl = -lbsd ; + LINKLIBS on citrun-inst = -lbsd ; + LDGROUP_START = -Wl,--start-group ; + LDGROUP_END = -Wl,--end-group ; +} + +actions StaticAnalysis +{ + export CITRUN_SA=1 + scan-build -o html --use-c++=eg++ jam -j4 + # scan-build -o html -v --use-c++=eg++ jam -j4 +} + +actions TestCoverage +{ + set -e + CFLAGS="-coverage -ggdb" LDFLAGS="-coverage" jam -j4 + + # Roll libgcov.a into libcitrun.a. + ar -M < t/libcitrun_gcov.mri + + prove + # prove tt + + gcov -o src src/lib.c + egcov -r src/*.cc +} + +StaticAnalysis static-analysis ; +TestCoverage test-coverage ; + +if $(CITRUN_SA) { + # scan-build sets these expecting us to pick up the new values. + CC = $(CC) ; + C++ = $(CXX) ; +} diff --git a/README b/README @@ -1,20 +0,0 @@ -░█▀▀░░░▀█▀░▀█▀░░░█▀▄░█░█░█▀█ -░█░░░░░░█░░░█░░░░█▀▄░█░█░█░█ -░▀▀▀░░░▀▀▀░░▀░░░░▀░▀░▀▀▀░▀░▀ - -Build dependencies: -- C++11 capable compiler -- Curses -- DejaVu Sans Mono -- GLEW -- GLFW -- FreeType2 -- Jam -- LLVM and Clang > 3.7 -- OpenGLES >= 2.0 - -Compile: -$ jam - -Run the tests with any TAP harness: -$ prove diff --git a/configure b/configure @@ -0,0 +1,36 @@ +#!/bin/sh -eu +# +# ░█▀▀░░░▀█▀░▀█▀░░░█▀▄░█░█░█▀█ +# ░█░░░░░░█░░░█░░░░█▀▄░█░█░█░█ +# ░▀▀▀░░░▀▀▀░░▀░░░░▀░▀░▀▀▀░▀░▀ +# +# Creates Jamrules from Jamrules.in and output from this script. +# +type pkg-config +type llvm-config + +# stuff still not accounted for: +# - C++11 capable compiler +# - Curses +# - DejaVu Sans Mono +# - Jam +# - LLVM and Clang > 3.7 +# - OpenGLES >= 2.0 + +gl_pkgs="osmesa glfw3 glew freetype2" +pkg-config --exists $gl_pkgs + +cp Jamrules.in Jamrules +cat <<EOF >> Jamrules + +# Automatically generated on `date` +GL_CFLAGS = "`pkg-config --cflags glfw3 glew freetype2`" ; +GL_LIBS = "`pkg-config --libs glfw3 glew freetype2`" ; +GLTEST_LIBS = "`pkg-config --libs osmesa`" ; +INST_CFLAGS = "`llvm-config --cxxflags`" ; +INST_LDFLAGS = "`llvm-config --ldflags`" ; +INST_LIBS = "`llvm-config --libs bitreader mcparser transformutils option`" ; +INST_LIBS += "`llvm-config --system-libs`" ; +EOF + +echo ">> Jamrules created. Now run \`jam\` to build" diff --git a/src/Jamfile b/src/Jamfile @@ -1,5 +1,50 @@ SubDir TOP src ; +# Do a string replacement on the first argument. +actions ReplaceTokens +{ + sed -e s,%CITRUN_SHARE%,$(CITRUN_SHARE), -i.bak $(<) ; + rm $(<).bak +} + +# Quote an entire file and add a variable declaration prefixing the string. +rule Stringize +{ + MakeLocate $(1) : $(LOCATE_SOURCE) ; + SEARCH on $(2) = $(SEARCH_SOURCE) ; + Depends $(1) : $(2) ; + Clean clean : $(1) ; +} + +actions Stringize +{ + # Quote the entire original source file and put it in the destination. + sed -e ' s/\\/\\\\/g; s/"/\\"/g; s/^/"/; s/$/\\n"/; ' < $(>) > $(<) + echo ";" >> $(<) + + # Add the declaration to the start of the file. + sed -e '1s/^/static const char *$(1:B) = /' -i.bak $(<) + rm $(<).bak +} + +# Create installation directories and setup quirky ../../citrun-inst links. +rule InstallSyms +{ + Depends install : $(PREFIX)/share/citrun/$(>) ; + MakeLocate $(PREFIX)/share/citrun/$(>) : $(<) ; + + for i in $(>) + { + SymLink $(PREFIX)/share/citrun/$(i) ; + } +} + +# Used by InstallSyms +actions SymLink +{ + $(RM) $(<) && $(LN) -s ../../bin/citrun-inst $(<) ; +} + # # libcitrun.a # @@ -18,7 +63,7 @@ ReplaceTokens citrun-wrap ; # # citrun-term # -LINKLIBS on citrun-term += -lcurses ; +#LINKLIBS on citrun-term += -lcurses ; # XXX: Not the main focus right now. # Main citrun-term : term_main.cc ; @@ -43,13 +88,12 @@ Stringize demo_atlas_glsl.h : demo_atlas.glsl ; Stringize demo_vshader_glsl.h : demo_vshader.glsl ; Stringize demo_fshader_glsl.h : demo_fshader.glsl ; -ObjectC++Flags gl_main.cc gl_testmain.cc $(GL_SRCS) : - `pkg-config $(PKG_CONFIG_LIBS) --cflags` ; +ObjectC++Flags gl_main.cc gl_testmain.cc $(GL_SRCS) : $(GL_CFLAGS) ; -LINKLIBS on citrun-gl citrun-gltest += -lm `pkg-config $(PKG_CONFIG_LIBS) --libs` ; +LINKLIBS on citrun-gl citrun-gltest += -lm $(GL_LIBS) ; LinkLibraries citrun-gl citrun-gltest : gl_common libglyphy ; -LINKLIBS on citrun-gltest += -lOSMesa ; +LINKLIBS on citrun-gltest += $(GLTEST_LIBS) ; Main citrun-gl : gl_main.cc ; Main citrun-gltest : gl_testmain.cc ; @@ -63,18 +107,36 @@ INST_SRCS = inst_action.cc inst_visitor.cc ; +CLANG_LIBS = + -lclangAST + -lclangAnalysis + -lclangBasic + -lclangDriver + -lclangEdit + -lclangFrontend + -lclangFrontendTool + -lclangLex + -lclangParse + -lclangRewrite + -lclangRewriteFrontend + -lclangSema + -lclangSerialization + -lclangTooling ; + Stringize lib_h.h : lib.h ; -ObjectC++Flags $(INST_SRCS) : `llvm-config --cxxflags` ; +ObjectC++Flags $(INST_SRCS) : $(INST_CFLAGS) ; ObjectDefines $(INST_SRCS) : CITRUN_SHARE=\\\"$(CITRUN_SHARE)\\\" ; -LINKFLAGS on citrun-inst = $(LINKFLAGS) `llvm-config --ldflags` ; - -LLVM_LIBS = bitreader mcparser transformutils option ; -LINKLIBS on citrun-inst += `llvm-config --libs $(LLVM_LIBS) --system-libs` ; +LINKFLAGS on citrun-inst = $(LINKFLAGS) $(INST_LDFLAGS) ; +LINKLIBS on citrun-inst += $(LDGROUP_START) $(CLANG_LIBS) $(LDGROUP_END) $(INST_LIBS) ; Main citrun-inst : $(INST_SRCS) ; +# Link with the c++ compiler so that the matching c++ runtime library gets added +# automatically. +LINK on citrun-inst citrun-term citrun-gl citrun-gltest = $(C++) ; + # # install #