2 ##===- utils/llvmdo - Counts Lines Of Code -------------------*- Script -*-===##
4 # The LLVM Compiler Infrastructure
6 # This file is distributed under the University of Illinois Open Source
7 # License. See LICENSE.TXT for details.
9 ##===----------------------------------------------------------------------===##
11 # This script is a general purpose "apply" function for the source files in LLVM
12 # It uses "find" to locate all the source files and then applies the user's
13 # command to them. As such, this command is often not used by itself much but
14 # the other find related tools (countloc.sh,llvmgrep,getsrcs.sh,userloc.sh) are
15 # all based on this script. This script defines "what is a source file" in
16 # LLVM and so should be maintained if new directories, new file extensions,
17 # etc. are used in LLVM as it progresses.
20 # llvmdo [-topdir DIR] [-dirs "DIRNAMES..."] [-code-only] PROGRAM ARGS...
22 # The -topdir option allows you to specify the llvm source root directly. If it
23 # is not specified then it will be obtained with llvm-config which must be built
26 # The -dirs argument allows you to specify the set of directories that are
27 # searched. The default list of directories searched is:
28 # include lib tools utils runtime autoconf docs test examples projects
29 # Note that you must use quotes around the list of directory names.
31 # The -code-only option specifies that only those files that are considered
32 # "code" should be visited. HTML documentation is considered code, but things
33 # like README files, etc. are not.
35 # Finally, you simply specify whatever program you want to run against each
36 # file and the arguments to give it. The PROGRAM will be given the file name
37 # as its last argument.
38 ##===----------------------------------------------------------------------===##
40 if test $# -lt 1 ; then
41 echo "Usage: llvmdo [-topdir DIR] [-dirs "DIRNAMES..."] [-code-only] PROGRAM ARGS..."
45 if test "$1" = "-topdir" ; then
49 TOPDIR=`llvm-config --src-root`
52 if test "$1" = "-dirs" ; then
55 elif test -z "$LLVMDO_DIRS" ; then
56 LLVMDO_DIRS="include lib tools utils runtime autoconf docs test examples projects cmake"
59 if test "$1" = "-code-only" ; then
66 if test "$1" = "" ; then
67 echo "Missing program name to run"
72 if test ! -x "$PROGRAM" ; then
73 echo "Can't execute $1"
81 -path docs/doxygen/* -o \
82 -path docs/CommandGuide/html/* -o \
83 -path docs/CommandGuide/man/* -o \
84 -path docs/CommandGuide/ps/* -o \
85 -path docs/CommandGuide/man/* -o \
86 -path docs/HistoricalNotes/* -o \
89 -path lib/Support/bzip2/* -o \
90 -path projects/llvm-test/* \
104 -o -name *.gnuplot' \
129 -o -name check-each-file \
130 -o -name codgen-diff \
131 -o -name llvm-native-gcc \
132 -o -name llvm-native-gxx \
134 -o -path include/llvm/ADT/ilist \
135 -o -path test/\*.ll \
136 -o -path test/Scripts/not \
137 -o -path runtime/\*.ll \
139 if test -z "$CODE_ONLY" ; then
140 files_to_match="$files_to_match \
146 -o -name COPYING.LIB \
160 -o -name aclocal.m4 \
161 -o -name acinclude.m4 \
162 -o -name *LoopSimplifyCrash.ll \
163 -o -name *AST-Remove.ll \
164 -o -name PPCPerfectShuffle.h \
167 if test -d "$TOPDIR" ; then
169 # Have to use the right "find" on a per-platform basis. Most platforms have
170 # Gnu find as "find", but Solaris does not.
172 SunOS) find_prog=gfind ;;
175 # Turn off file name generation (globbing) so that substitution of the
176 # variables doesn't cause the shell to create lists of file names
178 $find_prog $LLVMDO_DIRS -type f \
179 \( $paths_to_ignore \) -prune \
180 -o \( \( $files_to_match \) \! \( $files_to_ignore \) \
181 -exec $PROGRAM "$@" {} \; \)
183 echo "Can't find LLVM top directory in $TOPDIR"