countloc.sh 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. #!/bin/sh
  2. ##===- utils/countloc.sh - Counts Lines Of Code --------------*- Script -*-===##
  3. #
  4. # The LLVM Compiler Infrastructure
  5. #
  6. # This file is distributed under the University of Illinois Open Source
  7. # License. See LICENSE.TXT for details.
  8. #
  9. ##===----------------------------------------------------------------------===##
  10. #
  11. # This script finds all the source code files in the source code directories
  12. # (excluding certain things), runs "wc -l" on them to get the number of lines in
  13. # each file and then sums up and prints the total with awk.
  14. #
  15. # The script takes one optional option, -topdir, which specifies the top llvm
  16. # source directory. If it is not specified then the llvm-config tool is
  17. # consulted to find top source dir.
  18. #
  19. # Note that the implementation is based on llvmdo. See that script for more
  20. # details.
  21. ##===----------------------------------------------------------------------===##
  22. if test $# -gt 1 ; then
  23. if test "$1" = "-topdir" ; then
  24. TOPDIR="$2"
  25. shift; shift;
  26. else
  27. TOPDIR=`llvm-config --src-root`
  28. fi
  29. fi
  30. if test -d "$TOPDIR" ; then
  31. cd $TOPDIR
  32. ./utils/llvmdo -topdir "$TOPDIR" -dirs "include lib tools test utils examples" -code-only wc -l | awk '\
  33. BEGIN { loc=0; } \
  34. { loc += $1; } \
  35. END { print loc; }'
  36. else
  37. echo "Can't find LLVM top directory"
  38. fi