Reid Spencer | 65e731d | 2004-09-06 19:06:27 +0000 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | ##===- utils/countloc.sh - Counts Lines Of Code --------------*- Script -*-===## |
| 3 | # |
| 4 | # The LLVM Compiler Infrastructure |
| 5 | # |
Chris Lattner | 3060910 | 2007-12-29 20:37:13 +0000 | [diff] [blame] | 6 | # This file is distributed under the University of Illinois Open Source |
| 7 | # License. See LICENSE.TXT for details. |
Reid Spencer | 65e731d | 2004-09-06 19:06:27 +0000 | [diff] [blame] | 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 | # |
Reid Spencer | ca7592a | 2006-08-14 18:49:05 +0000 | [diff] [blame] | 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. |
Reid Spencer | 65e731d | 2004-09-06 19:06:27 +0000 | [diff] [blame] | 18 | # |
Reid Spencer | 181e65d | 2004-09-20 08:09:36 +0000 | [diff] [blame] | 19 | # Note that the implementation is based on llvmdo. See that script for more |
| 20 | # details. |
| 21 | ##===----------------------------------------------------------------------===## |
| 22 | |
Reid Spencer | ca7592a | 2006-08-14 18:49:05 +0000 | [diff] [blame] | 23 | if test $# -gt 1 ; then |
| 24 | if test "$1" = "-topdir" ; then |
| 25 | TOPDIR="$2" |
| 26 | shift; shift; |
| 27 | else |
| 28 | TOPDIR=`llvm-config --src-root` |
| 29 | fi |
| 30 | fi |
| 31 | |
Reid Spencer | 65e731d | 2004-09-06 19:06:27 +0000 | [diff] [blame] | 32 | if test -d "$TOPDIR" ; then |
| 33 | cd $TOPDIR |
Reid Spencer | ca7592a | 2006-08-14 18:49:05 +0000 | [diff] [blame] | 34 | ./utils/llvmdo -topdir "$TOPDIR" -dirs "include lib tools test utils examples" -code-only wc -l | awk '\ |
Reid Spencer | 65e731d | 2004-09-06 19:06:27 +0000 | [diff] [blame] | 35 | BEGIN { loc=0; } \ |
| 36 | { loc += $1; } \ |
| 37 | END { print loc; }' |
| 38 | else |
Reid Spencer | ca7592a | 2006-08-14 18:49:05 +0000 | [diff] [blame] | 39 | echo "Can't find LLVM top directory" |
Reid Spencer | 65e731d | 2004-09-06 19:06:27 +0000 | [diff] [blame] | 40 | fi |