Makefile: added nice variable
[senf.git] / Makefile
index 89b9254..acbd708 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -1,7 +1,22 @@
 #----------------------------------------------------------------------
 # Some SCONS shortcuts
 #----------------------------------------------------------------------
-SCONS=scons
+CONCURRENCY_LEVEL ?= $(shell grep process /proc/cpuinfo | wc -l)
+
+ifdef nice
+  SCONS_ARGS += CXX='nice -n $(nice) g++'
+endif
+ifdef final
+  SCONS_ARGS += "final="$(final)
+endif
+ifdef debug
+  SCONS_ARGS += "debug="$(debug)
+endif
+ifdef profile
+  SCONS_ARGS += "profile="$(profile)
+endif
+
+SCONS=scons -j $(CONCURRENCY_LEVEL) $(SCONS_ARGS)
 
 default: build
 
@@ -10,45 +25,63 @@ build:
 
 clean:
        $(SCONS) --clean all
+       find ./ -name \*.gcno | xargs rm -f
+       find ./ -name \*.gcda | xargs rm -f
+       find ./ -name \*.gcov | xargs rm -f
+       rm -f test_coverage.info
+       rm -rf /doc/test_coverage
 
-all_docs all_tests:
+all_docs all_tests all:
        $(SCONS) $@
+       
+%/test %/doc:
+       $(SCONS) $@
+
+%/build:
+       $(SCONS) $*
 
 #----------------------------------------------------------------------
-# Subversion stuff
+# remote compile targets
 #----------------------------------------------------------------------
-SVN_REVISION = $(shell svnversion)
-
-svn_version:
-       @echo $(SVN_REVISION)
+all@% all_docs@% all_tests@% build@%:
+       ssh $* "cd `pwd` && $(MAKE) SCONS_ARGS=\"$(SCONS_ARGS)\" $(firstword $(subst @, ,$@))"
 
+       
 #----------------------------------------------------------------------
-# Building SENF requires some debian packages
+# test coverage
 #----------------------------------------------------------------------
-DEB_BASE   = scons build-essential binutils-dev
-DEB_BOOST  = libboost-dev libboost-test-dev
-DEB_BOOST += libboost-date-time-dev libboost-regex-dev libboost-thread-dev
-DEB_DOC    = doxygen dia tidy xsltproc graphviz
-
-prerequisites:
-       aptitude install $(DEB_BASE) $(DEB_BOOST) $(DEB_DOC)
+test_coverage:
+       $(SCONS) debug=1 EXTRA_CCFLAGS="-fprofile-arcs -ftest-coverage" EXTRA_LIBS="gcov" all_tests
+       ln -s ../../boost/ include/senf/  # ugly work-around
+       lcov --directory . --capture --output-file /tmp/test_coverage.info --base-directory .
+#      lcov --output-file /tmp/test_coverage.info.tmp --extract test_coverage.info \*/senf/\*
+       lcov --output-file test_coverage.info --remove /tmp/test_coverage.info \*/include/\*
+       genhtml --output-directory doc/test_coverage --title "all_tests" test_coverage.info
+       rm /tmp/test_coverage.info
+       rm include/senf/boost
 
 #----------------------------------------------------------------------
-# Debian package info
+# Subversion stuff
 #----------------------------------------------------------------------
-PKG_NAME=senf-dev
-PKG_ARCH=i386
-PKG_VERS=0.0.$(SVN_REVISION)-1
-PKG_FILE = $(PKG_NAME)-$(PKG_VERS)_$(PKG_ARCH).deb
+svn_version:
+       @svnversion
 
 #----------------------------------------------------------------------
-# Debian package structure
+# Building SENF requires some debian packages
 #----------------------------------------------------------------------
-DEB_TOP = ./debian
-DEB_CTL = $(DEB_TOP)/DEBIAN
-DEB_LIB = $(DEB_TOP)/usr/lib/senf
-DEB_INC = $(DEB_TOP)/usr/include/senf
-DEB_DOC = $(DEB_TOP)/usr/share/doc/senf
+DEB_BASE   = build-essential
+
+# This line parses the 'Build-Depends' entry from debian/control
+DEB_SENF   = $(shell perl -an -F'[:,]' -e '                                    \
+                        BEGIN{ $$,=" " }                                       \
+                        $$P=0 if /^\S/;                                        \
+                        map {s/\(.*\)//} @F;                                   \
+                        print @F if $$P;                                       \
+                        if (/^Build-Depends:/) { print @F[1..$$\#F]; $$P=1 }'  \
+                    debian/control | xargs echo)
+
+prerequisites:
+       aptitude install $(DEB_BASE) $(DEB_SENF)
 
 package:
        $(SCONS) deb