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