chiark / gitweb /
fic gcov use and move it into the Makefile
[elogind.git] / Makefile
index 07f57519ab64c6b1d63f4af01231af7a98b393b5..2017e7be3bf627bc3c2a16d60609db372d8fd301 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -27,6 +27,10 @@ USE_LOG = true
 #  to print the debug messages to syslog)
 DEBUG = false
 
+# compile with gcc's code coverage option
+# (use it with DEBUG, works only with glibc)
+USE_GCOV = false
+
 # include Security-Enhanced Linux support
 USE_SELINUX = false
 
@@ -186,6 +190,11 @@ else
        STRIPCMD = $(STRIP) -s --remove-section=.note --remove-section=.comment
 endif
 
+ifeq ($(strip $(USE_GCOV)),true)
+       CFLAGS += -fprofile-arcs -ftest-coverage
+       LDFLAGS = -fprofile-arcs
+endif
+
 # if our own version of klibc is used, we need to build it
 ifeq ($(strip $(USE_KLIBC)),true)
        KLIBC_INSTALL   = $(PWD)/klibc/.install
@@ -194,6 +203,7 @@ ifeq ($(strip $(USE_KLIBC)),true)
        LD              = $(KLCC)
 else
        CFLAGS          += -Wshadow -Wstrict-prototypes -Wmissing-prototypes -Wmissing-declarations
+       LDFLAGS         += -Wl,-warn-common
 endif
 
 ifeq ($(strip $(USE_SELINUX)),true)
@@ -227,6 +237,7 @@ all: $(KLCC) $(PROGRAMS) $(MAN_PAGES)
                        -C $$target $@; \
        done;
 .PHONY: all
+.DEFAULT: all
 
 # clear implicit rules
 .SUFFIXES:
@@ -288,8 +299,12 @@ ccdv: ccdv.c
 .SILENT: ccdv
 
 clean:
-       -find . \( -not -type d \) -and \( -name '*~' -o -name '*.[oas]' \) -type f -print | xargs rm -f
-       -rm -f core $(PROGRAMS) $(GEN_HEADERS) $(GEN_CONFIGS)
+       - find . \( -not -type d \) -and \( -name '*~' -o -name '*.[oas]' \) -type f -print0 | xargs -0rt rm -f
+       - find -name "*.gcno" -print0 | xargs -0rt rm -f
+       - find -name "*.gcda" -print0 | xargs -0rt rm -f
+       - find -name "*.gcov" -print0 | xargs -0rt rm -f
+       - rm -f udev_gcov.txt
+       - rm -f core $(PROGRAMS) $(GEN_HEADERS) $(GEN_CONFIGS)
        $(MAKE) -C klibc SUBDIRS=klibc clean
        @extras="$(EXTRAS)"; for target in $$extras; do \
                echo $$target; \
@@ -342,7 +357,7 @@ uninstall-man:
        - rm $(mandir)/man8/udevcontrol.8
 .PHONY: uninstall-man
 
-install: install-config install-man all
+install-bin:
        $(INSTALL) -d $(DESTDIR)$(udevdir)
        $(INSTALL_PROGRAM) -D udev $(DESTDIR)$(sbindir)/udev
        $(INSTALL_PROGRAM) -D udevd $(DESTDIR)$(sbindir)/udevd
@@ -361,13 +376,9 @@ endif
                echo $$target; \
                $(MAKE) prefix=$(prefix) -C $$target $@; \
        done;
-.PHONY: install
+.PHONY: install-bin
 
-uninstall: uninstall-man
-       - rm $(configdir)/rules.d/50-udev.rules
-       - rm $(configdir)/udev.conf
-       - rmdir $(configdir)/rules.d
-       - rmdir $(configdir)
+uninstall-bin:
        - rm $(sbindir)/udev
        - rm $(sbindir)/udevd
        - rm $(sbindir)/udevsend
@@ -379,16 +390,48 @@ uninstall: uninstall-man
        - rm $(usrbindir)/udevinfo
        - rm $(usrbindir)/udevtest
        - rm -rf $(udevdb)
-       - rmdir $(udevdir)
        - killall udevd
        @extras="$(EXTRAS)"; for target in $$extras; do \
                echo $$target; \
                $(MAKE) prefix=$(prefix) -C $$target $@; \
        done;
-.PHONY: uninstall-man
+.PHONY: uninstall-bin
+
+install: all install-bin install-config install-man
+.PHONY: install
+
+uninstall: uninstall-bin uninstall-man
+.PHONY: uninstall
 
 test tests: all
        @ cd test && ./udev-test.pl
        @ cd test && ./udevstart-test.pl
 .PHONY: test tests
 
+buildtest:
+       ./test/simple-build-check.sh
+.PHONY: buildtest
+
+gcov-all:
+       $(MAKE) clean all DEBUG=true USE_GCOV=true
+       @echo
+       @echo "binaries built with gcov support."
+       @echo "run the tests and analyze with 'make udev_gcov.txt'"
+.PHONY: gcov-all
+
+# see docs/README-gcov_for_udev
+udev_gcov.txt: $(wildcard *.gcda) $(wildcard *.gcno)
+       for file in `find -maxdepth 1 -name "*.gcno"`; do \
+               name=`basename $$file .gcno`; \
+               echo "################" >> $@; \
+               echo "$$name.c" >> $@; \
+               echo "################" >> $@; \
+               if [ -e "$$name.gcda" ]; then \
+                       gcov -l "$$name.c" >> $@ 2>&1; \
+               else \
+                       echo "code for $$name.c was never executed" >> $@ 2>&1; \
+               fi; \
+               echo >> $@; \
+       done; \
+       echo "view $@ for the result"
+