diff options
author | Chris Lattner <sabre@nondot.org> | 2010-06-08 16:52:24 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2010-06-08 16:52:24 +0000 |
commit | 30fdc8d841c9d24ac5f3d452b6ece84ee0ac991c (patch) | |
tree | f70013106f6a461a14abcd71c65f48a95a2979a6 /lldb/scripts | |
parent | 312c4c799da215b337f790fda330f70c4aa757cf (diff) | |
download | bcm5719-llvm-30fdc8d841c9d24ac5f3d452b6ece84ee0ac991c.tar.gz bcm5719-llvm-30fdc8d841c9d24ac5f3d452b6ece84ee0ac991c.zip |
Initial checkin of lldb code from internal Apple repo.
llvm-svn: 105619
Diffstat (limited to 'lldb/scripts')
-rwxr-xr-x | lldb/scripts/Python/build-swig-Python.sh | 127 | ||||
-rw-r--r-- | lldb/scripts/Python/edit-swig-python-wrapper-file.py | 58 | ||||
-rwxr-xr-x | lldb/scripts/Python/finish-swig-Python-LLDB.sh | 45 | ||||
-rw-r--r-- | lldb/scripts/build-llvm.pl | 409 | ||||
-rwxr-xr-x | lldb/scripts/build-swig-wrapper-classes.sh | 85 | ||||
-rwxr-xr-x | lldb/scripts/checkpoint-llvm.pl | 101 | ||||
-rwxr-xr-x | lldb/scripts/finish-swig-wrapper-classes.sh | 71 | ||||
-rwxr-xr-x | lldb/scripts/install-lldb.sh | 59 | ||||
-rw-r--r-- | lldb/scripts/lldb.swig | 149 | ||||
-rwxr-xr-x | lldb/scripts/sed-sources | 252 |
10 files changed, 1356 insertions, 0 deletions
diff --git a/lldb/scripts/Python/build-swig-Python.sh b/lldb/scripts/Python/build-swig-Python.sh new file mode 100755 index 00000000000..9dc4b991c4a --- /dev/null +++ b/lldb/scripts/Python/build-swig-Python.sh @@ -0,0 +1,127 @@ +#!/bin/sh + +# build-swig-Python.sh + + +debug_flag=$1 + +if [ -n "$debug_flag" -a "$debug_flag" == "-debug" ] +then + Debug=1 +else + Debug=0 +fi + + +HEADER_FILES="${SRCROOT}/include/lldb/lldb-types.h"\ +" ${SRCROOT}/include/lldb/API/SBAddress.h"\ +" ${SRCROOT}/include/lldb/API/SBBlock.h"\ +" ${SRCROOT}/include/lldb/API/SBBreakpoint.h"\ +" ${SRCROOT}/include/lldb/API/SBBreakpointLocation.h"\ +" ${SRCROOT}/include/lldb/API/SBBroadcaster.h"\ +" ${SRCROOT}/include/lldb/API/SBCommandContext.h"\ +" ${SRCROOT}/include/lldb/API/SBCommandInterpreter.h"\ +" ${SRCROOT}/include/lldb/API/SBCommandReturnObject.h"\ +" ${SRCROOT}/include/lldb/API/SBCompileUnit.h"\ +" ${SRCROOT}/include/lldb/API/SBDebugger.h"\ +" ${SRCROOT}/include/lldb/API/SBError.h"\ +" ${SRCROOT}/include/lldb/API/SBEvent.h"\ +" ${SRCROOT}/include/lldb/API/SBFrame.h"\ +" ${SRCROOT}/include/lldb/API/SBFunction.h"\ +" ${SRCROOT}/include/lldb/API/SBLineEntry.h"\ +" ${SRCROOT}/include/lldb/API/SBListener.h"\ +" ${SRCROOT}/include/lldb/API/SBModule.h"\ +" ${SRCROOT}/include/lldb/API/SBProcess.h"\ +" ${SRCROOT}/include/lldb/API/SBSourceManager.h"\ +" ${SRCROOT}/include/lldb/API/SBStringList.h"\ +" ${SRCROOT}/include/lldb/API/SBSymbol.h"\ +" ${SRCROOT}/include/lldb/API/SBSymbolContext.h"\ +" ${SRCROOT}/include/lldb/API/SBTarget.h"\ +" ${SRCROOT}/include/lldb/API/SBThread.h"\ +" ${SRCROOT}/include/lldb/API/SBType.h"\ +" ${SRCROOT}/include/lldb/API/SBValue.h" + + +if [ $Debug == 1 ] +then + echo "Header files are:" + echo ${HEADER_FILES} +fi + +NeedToUpdate=0 + +swig_output_file=${SCRIPT_INPUT_FILE_1} + +if [ ! -f $swig_output_file ] +then + NeedToUpdate=1 + if [ $Debug == 1 ] + then + echo "Failed to find LLDBWrapPython.cpp" + fi +fi + +if [ $NeedToUpdate == 0 ] +then + for hdrfile in ${HEADER_FILES} + do + if [ $hdrfile -nt $swig_output_file ] + then + NeedToUpdate=1 + if [ $Debug == 1 ] + then + echo "${hdrfile} is newer than ${swig_output_file}" + echo "swig file will need to be re-built." + fi + fi + done +fi + +framework_python_dir="${CONFIGURATION_BUILD_DIR}/LLDB.framework/Versions/A/Resources/Python" + +if [ ! -L "${framework_python_dir}/_lldb.so" ] +then + NeedToUpdate=1 +fi + +if [ ! -f "${framework_python_dir}/lldb.py" ] +then + NeedToUpdate=1 +fi + + +if [ $NeedToUpdate == 0 ] +then + echo "Everything is up-to-date." + exit 0 +else + echo "SWIG needs to be re-run." +fi + + +# Build the SWIG C++ wrapper file for Python. + +swig -c++ -shadow -python -I"${SRCROOT}/include" -I./. -outdir "${CONFIGURATION_BUILD_DIR}" -o "${SCRIPT_INPUT_FILE_1}" "${SCRIPT_INPUT_FILE_0}" + +# Edit the C++ wrapper file that SWIG generated for Python. There are two +# global string replacements needed, which the following script file takes +# care of. It reads in 'LLDBWrapPython.cpp' and generates +# 'LLDBWrapPython.cpp.edited'. + +# The need for this has been eliminated by fixing the namespace qualifiers on return types. +# Leaving this here for now, just in case... +# +#if [ -f "${SRCROOT}/scripts/Python/edit-swig-python-wrapper-file.py" ] +#then +# python "${SRCROOT}/scripts/Python/edit-swig-python-wrapper-file.py" +#fi + +# +# Now that we've got a C++ file we're happy with (hopefully), rename the +# edited file and move it to the appropriate places. +# + +if [ -f "${SCRIPT_INPUT_FILE_1}.edited" ] +then + mv "${SCRIPT_INPUT_FILE_1}.edited" "${SCRIPT_INPUT_FILE_1}" +fi diff --git a/lldb/scripts/Python/edit-swig-python-wrapper-file.py b/lldb/scripts/Python/edit-swig-python-wrapper-file.py new file mode 100644 index 00000000000..a8c43239471 --- /dev/null +++ b/lldb/scripts/Python/edit-swig-python-wrapper-file.py @@ -0,0 +1,58 @@ +# +# edit-swig-python-wrapper-file.py +# +# This script performs some post-processing editing on the C++ file that +# SWIG generates for python, after running on 'lldb.swig'. In +# particular, the types SWIGTYPE_p_SBThread and SWIGTYPE_p_SBTarget are +# being used, when the types that *should* be used are +# SWIGTYPE_p_lldb__SBThread and SWIGTYPE_p_lldb__SBTarget. +# This script goes through the C++ file SWIG generated, reading it in line +# by line and doing a search-and-replace for these strings. +# + + +import os + +full_input_name = os.environ["SCRIPT_INPUT_FILE_1"]; +full_output_name = full_input_name + ".edited" + +try: + f_in = open (full_input_name, 'r') +except IOError: + print "Error: Unable to open file for reading: " + full_input_name +else: + try: + f_out = open (full_output_name, 'w') + except IOError: + print "Error: Unable to open file for writing: " + full_output_name + else: + target_typedef_found = False + thread_typedef_found = False + + try: + line = f_in.readline() + except IOError: + print "Error occurred while reading file." + else: + while line: + # + # + if (line.find ("SWIGTYPE_p_SBTarget")): + if (line.find ("define") < 0): + line = line.replace ("SWIGTYPE_p_SBTarget", + "SWIGTYPE_p_lldb__SBTarget") + if (line.find ("SWIGTYPE_p_SBThread")): + if (line.find ("define") < 0): + line = line.replace ("SWIGTYPE_p_SBThread", + "SWIGTYPE_p_lldb__SBThread") + f_out.write (line) + try: + line = f_in.readline() + except IOError: + print "Error occurred while reading file." + + try: + f_in.close() + f_out.close() + except: + print "Error occurred while closing files" diff --git a/lldb/scripts/Python/finish-swig-Python-LLDB.sh b/lldb/scripts/Python/finish-swig-Python-LLDB.sh new file mode 100755 index 00000000000..293a8b18c66 --- /dev/null +++ b/lldb/scripts/Python/finish-swig-Python-LLDB.sh @@ -0,0 +1,45 @@ +#! /bin/sh + +# finish-swig-Python.sh +# +# For the Python script interpreter (external to liblldb) to be able to import +# and use the lldb module, there must be a "_lldb.so" in the framework +# resources directory. Here we make a symlink called "_lldb.so" that just +# points to the executable in the LLDB.framework and copy over the needed +# .py files. + +if [ ! -d "${TARGET_BUILD_DIR}/LLDB.framework" ] +then + echo "Error: Unable to find LLDB.framework" >&2 + exit 1 +fi + +# Make the Python directory down in the framework if it doesn't already exist +framework_python_dir="${TARGET_BUILD_DIR}/LLDB.framework/Versions/A/Resources/Python" +if [ ! -d "${framework_python_dir}" ] +then + mkdir -p "${framework_python_dir}" +fi + +# Make the symlink that the script bridge for Python will need in the Python +# framework directory +if [ ! -L "${framework_python_dir}/_lldb.so" ] +then + cd "${framework_python_dir}" + ln -s "../../LLDB" _lldb.so +fi + +# Copy the python module (lldb.py) that was generated by SWIG +# over to the framework Python directory +if [ -f "${CONFIGURATION_BUILD_DIR}/lldb.py" ] +then + cp "${CONFIGURATION_BUILD_DIR}/lldb.py" "${framework_python_dir}" +fi + +# Copy the embedded interpreter script over to the framework Python directory +if [ -f "${SRCROOT}/source/Interpreter/embedded_interpreter.py" ] +then + cp "${SRCROOT}/source/Interpreter/embedded_interpreter.py" "${framework_python_dir}" +fi + +exit 0 diff --git a/lldb/scripts/build-llvm.pl b/lldb/scripts/build-llvm.pl new file mode 100644 index 00000000000..3adfc11996f --- /dev/null +++ b/lldb/scripts/build-llvm.pl @@ -0,0 +1,409 @@ +#!/usr/bin/perl + +# This script will take a number ($ENV{SCRIPT_INPUT_FILE_COUNT}) of static archive files +# and pull them apart into object files. These object files will be placed in a directory +# named the same as the archive itself without the extension. Each object file will then +# get renamed to start with the archive name and a '-' character (for archive.a(object.o) +# the object file would becomde archive-object.o. Then all object files are re-made into +# a single static library. This can help avoid name collisions when different archive +# files might contain object files with the same name. + +use strict; +use File::Basename; +use File::Glob ':glob'; +use List::Util qw[min max]; + +our $llvm_dstroot = $ENV{SCRIPT_INPUT_FILE_0}; + +our $libedis_outfile = $ENV{SCRIPT_OUTPUT_FILE_0}; +our ($libedis_basename, $libedis_dirname) = fileparse ($libedis_outfile); +our @libedis_slices; # Skinny mach-o slices for libEnhancedDisassembly.dylib + +our $llvm_clang_outfile = $ENV{SCRIPT_OUTPUT_FILE_1}; +our ($llvm_clang_basename, $llvm_clang_dirname) = fileparse ($llvm_clang_outfile); +our @llvm_clang_slices; # paths to the single architecture static libraries (archives) + +our $llvm_configuration = $ENV{LLVM_CONFIGURATION}; + +our $llvm_revision = "'{2010-06-01T13:00}'"; +our $llvm_source_dir = "$ENV{SRCROOT}"; +our $cc = "$ENV{DEVELOPER_BIN_DIR}/gcc-4.2"; +our $cxx = "$ENV{DEVELOPER_BIN_DIR}/g++-4.2"; +our @archs = split (/\s+/, $ENV{ARCHS}); + +our @archive_files = ( + "$llvm_configuration/lib/libplugin_llvmc_Base.a", + "$llvm_configuration/lib/libplugin_llvmc_Clang.a", + "$llvm_configuration/lib/libclangAnalysis.a", + "$llvm_configuration/lib/libclangAST.a", + "$llvm_configuration/lib/libclangBasic.a", + "$llvm_configuration/lib/libclangCodeGen.a", + "$llvm_configuration/lib/libclangFrontend.a", + "$llvm_configuration/lib/libclangDriver.a", + "$llvm_configuration/lib/libclangIndex.a", + "$llvm_configuration/lib/libclangLex.a", + "$llvm_configuration/lib/libclangRewrite.a", + "$llvm_configuration/lib/libclangParse.a", + "$llvm_configuration/lib/libclangSema.a", + "$llvm_configuration/lib/libCompilerDriver.a", + "$llvm_configuration/lib/libEnhancedDisassembly.a", + "$llvm_configuration/lib/libLLVMAnalysis.a", + "$llvm_configuration/lib/libLLVMArchive.a", + "$llvm_configuration/lib/libLLVMARMAsmParser.a", + "$llvm_configuration/lib/libLLVMARMAsmPrinter.a", + "$llvm_configuration/lib/libLLVMARMCodeGen.a", + "$llvm_configuration/lib/libLLVMARMDisassembler.a", + "$llvm_configuration/lib/libLLVMARMInfo.a", + "$llvm_configuration/lib/libLLVMAsmParser.a", + "$llvm_configuration/lib/libLLVMAsmPrinter.a", + "$llvm_configuration/lib/libLLVMBitReader.a", + "$llvm_configuration/lib/libLLVMBitWriter.a", + "$llvm_configuration/lib/libLLVMCodeGen.a", + "$llvm_configuration/lib/libLLVMCore.a", + "$llvm_configuration/lib/libLLVMExecutionEngine.a", + "$llvm_configuration/lib/libLLVMInstCombine.a", + "$llvm_configuration/lib/libLLVMInstrumentation.a", + "$llvm_configuration/lib/libLLVMipa.a", + "$llvm_configuration/lib/libLLVMInterpreter.a", + "$llvm_configuration/lib/libLLVMipo.a", + "$llvm_configuration/lib/libLLVMJIT.a", + "$llvm_configuration/lib/libLLVMLinker.a", + "$llvm_configuration/lib/libLLVMMC.a", + "$llvm_configuration/lib/libLLVMMCParser.a", + "$llvm_configuration/lib/libLLVMScalarOpts.a", + "$llvm_configuration/lib/libLLVMSelectionDAG.a", + "$llvm_configuration/lib/libLLVMSupport.a", + "$llvm_configuration/lib/libLLVMSystem.a", + "$llvm_configuration/lib/libLLVMTarget.a", + "$llvm_configuration/lib/libLLVMTransformUtils.a", + "$llvm_configuration/lib/libLLVMX86AsmParser.a", + "$llvm_configuration/lib/libLLVMX86AsmPrinter.a", + "$llvm_configuration/lib/libLLVMX86CodeGen.a", + "$llvm_configuration/lib/libLLVMX86Disassembler.a", + "$llvm_configuration/lib/libLLVMX86Info.a", + "$llvm_configuration/lib/libclangChecker.a" +); + +if (-l $llvm_dstroot) +{ + print "Using standard LLVM build directory...\n"; + # LLVM in the "lldb" root is a symlink which indicates we are using a + # standard LLVM build directory where everything is built into the + # same folder + create_single_llvm_arhive_for_arch ($llvm_dstroot, 0); + my $llvm_dstroot_archive = "$llvm_dstroot/$llvm_clang_basename"; + push @llvm_clang_slices, $llvm_dstroot_archive; + create_dstroot_file ($llvm_clang_basename, $llvm_clang_dirname, \@llvm_clang_slices, $llvm_clang_basename); + my $llvm_dstroot_edis = "$llvm_dstroot/$llvm_configuration/lib/libEnhancedDisassembly.dylib"; + if (-f $llvm_dstroot_edis) + { + push @libedis_slices, $llvm_dstroot_edis; + create_dstroot_file ($libedis_basename, $libedis_dirname, \@libedis_slices, $libedis_basename); + } + exit 0; +} + + +if ($ENV{CONFIGURATION} eq "Debug" or $ENV{CONFIGURATION} eq "Release") +{ + # Check for an old llvm source install (not the minimal zip based + # install by looking for a .svn file in the llvm directory + chomp(my $llvm_zip_md5 = `md5 -q $ENV{SRCROOT}/llvm.zip`); + my $llvm_zip_md5_file = "$ENV{SRCROOT}/llvm/$llvm_zip_md5"; + if (!-e "$llvm_zip_md5_file") + { + print "Updating LLVM to use checkpoint from: '$ENV{SRCROOT}/llvm.zip'...\n"; + if (-d "$ENV{SRCROOT}/llvm") + { + do_command ("cd '$ENV{SRCROOT}' && rm -rf llvm", "removing old llvm repository", 1); + } + do_command ("cd '$ENV{SRCROOT}' && unzip -q llvm.zip && touch '$llvm_zip_md5_file'", "expanding llvm.zip", 1); + } + + # We use the stuff in "lldb/llvm" for non B&I builds + if (!-e $libedis_outfile) + { + print "Copying '$ENV{SRCROOT}/llvm/$libedis_basename' to '$libedis_outfile'...\n"; + do_command ("cp '$ENV{SRCROOT}/llvm/$libedis_basename' '$libedis_outfile'", "copying libedis", 1); + } + exit 0; +} + +# If our output file already exists then we need not generate it again. +if (-e $llvm_clang_outfile and -e $libedis_outfile) +{ + exit 0; +} + + +# Get our options + +our $debug = 1; + +sub parallel_guess +{ + my $cpus = `sysctl -n hw.availcpu`; + chomp ($cpus); + my $memsize = `sysctl -n hw.memsize`; + chomp ($memsize); + my $max_cpus_by_memory = int($memsize / (750 * 1024 * 1024)); + return min($max_cpus_by_memory, $cpus); +} +sub build_llvm +{ + #my $extra_svn_options = $debug ? "" : "--quiet"; + my $svn_options = "--quiet --revision $llvm_revision"; + if (-d "$llvm_source_dir/llvm") + { + print "Using existing llvm sources in: '$llvm_source_dir/llvm'\n"; + # print "Updating llvm to revision $llvm_revision\n"; + # do_command ("cd '$llvm_source_dir/llvm' && svn update $svn_options", "updating llvm from repository", 1); + # print "Updating clang to revision $llvm_revision\n"; + # do_command ("cd '$llvm_source_dir/llvm/tools/clang' && svn update $svn_options", "updating clang from repository", 1); + } + else + { + print "Checking out llvm sources from revision $llvm_revision...\n"; + do_command ("cd '$llvm_source_dir' && svn co $svn_options http://llvm.org/svn/llvm-project/llvm/trunk llvm", "checking out llvm from repository", 1); + print "Checking out clang sources from revision $llvm_revision...\n"; + do_command ("cd '$llvm_source_dir/llvm/tools' && svn co $svn_options http://llvm.org/svn/llvm-project/cfe/trunk clang", "checking out clang from repository", 1); + print "Removing the llvm/test directory...\n"; + do_command ("cd '$llvm_source_dir' && rm -rf llvm/test", "removing test directory", 1); + } + + # Make the llvm build directory + my $arch_idx = 0; + foreach my $arch (@archs) + { + my $llvm_dstroot_arch = "${llvm_dstroot}/${arch}"; + + # if the arch destination root exists we have already built it + my $do_configure = 0; + my $do_make = 0; + + my $llvm_dstroot_arch_archive = "$llvm_dstroot_arch/$llvm_clang_basename"; + print "LLVM architecture root for ${arch} exists at '$llvm_dstroot_arch'..."; + if (-e $llvm_dstroot_arch) + { + print "YES\n"; + $do_configure = !-e "$llvm_dstroot_arch/config.log"; + + # dstroot for llvm build exists, make sure all .a files are built + for my $llvm_lib (@archive_files) + { + if (!-e "$llvm_dstroot_arch/$llvm_lib") + { + print "missing archive: '$llvm_dstroot_arch/$llvm_lib'\n"; + $do_make = 1; + } + } + if (!-e $llvm_dstroot_arch_archive) + { + $do_make = 1; + } + } + else + { + print "NO\n"; + do_command ("mkdir -p '$llvm_dstroot_arch'", "making llvm build directory '$llvm_dstroot_arch'", 1); + $do_configure = 1; + $do_make = 1; + } + + # If this is the first architecture, then make a symbolic link + # for any header files that get generated. + if ($arch_idx == 0) + { + if (!-l "$llvm_dstroot/llvm") + { + do_command ("cd $llvm_dstroot && ln -s './${arch}' llvm"); + } + } + + if ($do_configure) + { + # Build llvm and clang + print "Configuring clang ($arch) in '$llvm_dstroot_arch'...\n"; + my $lldb_configuration_options = ''; + $llvm_configuration eq 'Release' and $lldb_configuration_options .= '--enable-optimized'; + do_command ("cd '$llvm_dstroot_arch' && '$llvm_source_dir/llvm/configure' $lldb_configuration_options --enable-targets=x86,x86_64,arm --build=$arch-apple-darwin10 CC=\"$cc -arch $arch\" CXX=\"$cxx -arch $arch\"", + "configuring llvm build", 1); + } + + if ($do_make) + { + # Build llvm and clang + my $num_cpus = parallel_guess(); + print "Building clang using $num_cpus cpus ($arch)...\n"; + do_command ("cd '$llvm_dstroot_arch' && make -j$num_cpus clang-only VERBOSE=1 PROJECT_NAME='llvm'", "making llvm and clang", 1); + do_command ("cd '$llvm_dstroot_arch' && make -j$num_cpus tools-only VERBOSE=1 PROJECT_NAME='llvm' EDIS_VERSION=1", "making libedis", 1); + # Combine all .o files from a bunch of static libraries from llvm + # and clang into a single .a file. + create_single_llvm_arhive_for_arch ($llvm_dstroot_arch, 1); + } + + -f "$llvm_dstroot_arch_archive" and push @llvm_clang_slices, "$llvm_dstroot_arch_archive"; + -f "$llvm_dstroot_arch/$llvm_configuration/lib/libEnhancedDisassembly.dylib" and push @libedis_slices, "$llvm_dstroot_arch/$llvm_configuration/lib/libEnhancedDisassembly.dylib"; + ++$arch_idx; + } + + # Combine all skinny slices of the LLVM/Clang combined archive + create_dstroot_file ($llvm_clang_basename, $llvm_clang_dirname, \@llvm_clang_slices, $llvm_clang_basename); + + if (scalar(@libedis_slices)) + { + # Combine all skinny slices of the libedis in SYMROOT + create_dstroot_file ($libedis_basename, $libedis_dirname, \@libedis_slices, $libedis_basename); + + # Make dSYM for libedis in SYMROOT + do_command ("cd '$libedis_dirname' && dsymutil $libedis_basename", "making libedis dSYM", 1); + + # strip debug symbols from libedis and copy into DSTROOT + -d "$ENV{DSTROOT}/Developer/usr/lib" or do_command ("mkdir -p '$ENV{DSTROOT}/Developer/usr/lib'", "Making directory '$ENV{DSTROOT}/Developer/usr/lib'", 1); + do_command ("cd '$libedis_dirname' && strip -Sx -o '$ENV{DSTROOT}/Developer/usr/lib/$libedis_basename' '$libedis_outfile'", "Stripping libedis and copying to DSTROOT", 1); + } +} + +sub create_dstroot_file +{ + my $file = shift; + my $dir = shift; + my $fullpath = "$dir/$file"; # The path to the file to create + my $slice_aref = shift; # Array containing one or more skinny files that will be combined into $fullpath + my $what = shift; # Text describing the $fullpath + + print "create_dstroot_file file = '$file', dir = '$dir', slices = (" . join (', ', @$slice_aref) . ") for what = '$what'\n"; + + if (-d $dir) + { + if (@$slice_aref > 0) + { + print "Creating and installing $what into '$fullpath'...\n"; + my $lipo_command = "lipo -output '$fullpath' -create"; + foreach (@$slice_aref) { $lipo_command .= " '$_'"; } + do_command ($lipo_command, "creating $what universal output file", 1); + } + + + if (!-e $fullpath) + { + # die "error: '$fullpath' is missing\n"; + } + } + else + { + die "error: directory '$dir' doesn't exist to receive file '$file'\n"; + } +} +#---------------------------------------------------------------------- +# quote the path if needed and realpath it if the -r option was +# specified +#---------------------------------------------------------------------- +sub finalize_path +{ + my $path = shift; + # Realpath all paths that don't start with "/" + $path =~ /^[^\/]/ and $path = abs_path($path); + + # Quote the path if asked to, or if there are special shell characters + # in the path name + my $has_double_quotes = $path =~ /["]/; + my $has_single_quotes = $path =~ /[']/; + my $needs_quotes = $path =~ /[ \$\&\*'"]/; + if ($needs_quotes) + { + # escape and double quotes in the path + $has_double_quotes and $path =~ s/"/\\"/g; + $path = "\"$path\""; + } + return $path; +} + +sub do_command +{ + my $cmd = shift; + my $description = @_ ? shift : "command"; + my $die_on_fail = @_ ? shift : undef; + $debug and print "% $cmd\n"; + system ($cmd); + if ($? == -1) + { + $debug and printf ("error: %s failed to execute: $!\n", $description); + $die_on_fail and $? and exit(1); + return $?; + } + elsif ($? & 127) + { + $debug and printf("error: %s child died with signal %d, %s coredump\n", + $description, + ($? & 127), + ($? & 128) ? 'with' : 'without'); + $die_on_fail and $? and exit(1); + return $?; + } + else + { + my $exit = $? >> 8; + if ($exit) + { + $debug and printf("error: %s child exited with value %d\n", $description, $exit); + $die_on_fail and exit(1); + } + return $exit; + } +} + +sub create_single_llvm_arhive_for_arch +{ + my $arch_dstroot = shift; + my $split_into_objects = shift; + my @object_dirs; + my $object_dir; + my $tmp_dir = $arch_dstroot; + my $arch_output_file = "$arch_dstroot/$llvm_clang_basename"; + -e $arch_output_file and return; + my $files = "$arch_dstroot/files.txt"; + open (FILES, ">$files") or die "Can't open $! for writing...\n"; + + for my $path (@archive_files) + { + my $archive_fullpath = finalize_path ("$arch_dstroot/$path"); + if (-e $archive_fullpath) + { + if ($split_into_objects) + { + my ($archive_file, $archive_dir, $archive_ext) = fileparse($archive_fullpath, ('.a')); + + $object_dir = "$tmp_dir/$archive_file"; + push @object_dirs, $object_dir; + + do_command ("cd '$tmp_dir'; mkdir '$archive_file'; cd '$archive_file'; ar -x $archive_fullpath"); + + my @objects = bsd_glob("$object_dir/*.o"); + + foreach my $object (@objects) + { + my ($o_file, $o_dir) = fileparse($object); + my $new_object = "$object_dir/${archive_file}-$o_file"; + print FILES "$new_object\n"; + do_command ("mv '$object' '$new_object'"); + } + } + else + { + # just add the .a files into the file list + print FILES "$archive_fullpath\n"; + } + } + } + close (FILES); + do_command ("libtool -static -o '$arch_output_file' -filelist '$files'"); + + foreach $object_dir (@object_dirs) + { + do_command ("rm -rf '$object_dir'"); + } + do_command ("rm -rf '$files'"); +} + +build_llvm(); diff --git a/lldb/scripts/build-swig-wrapper-classes.sh b/lldb/scripts/build-swig-wrapper-classes.sh new file mode 100755 index 00000000000..3d1cf74344f --- /dev/null +++ b/lldb/scripts/build-swig-wrapper-classes.sh @@ -0,0 +1,85 @@ +#!/bin/sh + +# build-swig-wrapper-classes.sh +# +# For each scripting language liblldb supports, we need to create the +# appropriate Script Bridge wrapper classes for that language so that +# users can call Script Bridge functions from within the script interpreter. +# +# We use SWIG to help create the appropriate wrapper classes/functions for +# the scripting language. In some cases the file generated by SWIG may +# need some tweaking before it is completely ready to use. + +debug_flag=$1 + +if [ -n "$debug_flag" -a "$debug_flag" == "-debug" ] +then + Debug=1 +else + Debug=0 +fi + +# +# Verify that 'lldb.swig' exists. +# + +if [ ! -f ${SRCROOT}/scripts/lldb.swig ] +then + echo Error: unable to find file 'lldb.swig' >&2 + exit 1 +fi + +if [ $Debug == 1 ] +then + echo "Found lldb.swig file" +fi + +# +# For each scripting language, make sure the build script for that language +# exists, and if so, call it. +# +# For now the only language we support is Python, but we expect this to +# change. + +languages="Python" +cwd=${SRCROOT}/scripts + +for curlang in $languages +do + if [ $Debug == 1 ] + then + echo "Current language is $curlang" + fi + + if [ ! -d "$cwd/$curlang" ] + then + echo "Error: unable to find $curlang script sub-dirctory" >&2 + continue + else + + if [ $Debug == 1 ] + then + echo "Found $curlang sub-directory" + fi + + cd $cwd/$curlang + + filename="./build-swig-${curlang}.sh" + + if [ ! -f $filename ] + then + echo "Error: unable to find swig build script for $curlang: $filename" >&2 + continue + else + + if [ $Debug == 1 ] + then + echo "Found $curlang build script." + echo "Executing $curlang build script..." + fi + + ./build-swig-${curlang}.sh + fi + fi +done + diff --git a/lldb/scripts/checkpoint-llvm.pl b/lldb/scripts/checkpoint-llvm.pl new file mode 100755 index 00000000000..5c1293b0f33 --- /dev/null +++ b/lldb/scripts/checkpoint-llvm.pl @@ -0,0 +1,101 @@ +#!/usr/bin/perl + +# This script should be pointed to a valid llvm.build folder that +# was created using the "build-llvm.pl" shell script. It will create +# a new llvm.zip file that can be checked into the respository +# at lldb/llvm.zip + +use strict; +use Cwd 'abs_path'; +use File::Basename; +use File::Temp qw/ tempfile tempdir /; +our $debug = 1; + + +sub do_command +{ + my $cmd = shift; + my $description = @_ ? shift : "command"; + my $die_on_fail = @_ ? shift : undef; + $debug and print "% $cmd\n"; + system ($cmd); + if ($? == -1) + { + $debug and printf ("error: %s failed to execute: $!\n", $description); + $die_on_fail and $? and exit(1); + return $?; + } + elsif ($? & 127) + { + $debug and printf("error: %s child died with signal %d, %s coredump\n", + $description, + ($? & 127), + ($? & 128) ? 'with' : 'without'); + $die_on_fail and $? and exit(1); + return $?; + } + else + { + my $exit = $? >> 8; + if ($exit) + { + $debug and printf("error: %s child exited with value %d\n", $description, $exit); + $die_on_fail and exit(1); + } + return $exit; + } +} + +if (@ARGV == 4) +{ + my $llvm_source_dir = abs_path(shift @ARGV); # The llvm source that contains full llvm and clang sources + my $llvm_build_dir = abs_path(shift @ARGV); # The llvm build directory that contains headers and + my $lldb_build_dir = abs_path(shift @ARGV); # the build directory that contains the fat libEnhancedDisassembly.dylib + my $llvm_zip_file = abs_path(shift @ARGV); + + printf("LLVM sources : '%s'\n", $llvm_source_dir); + printf("LLVM build : '%s'\n", $llvm_build_dir); + printf("LLDB build : '%s'\n", $lldb_build_dir); + printf("LLVM zip file: '%s'\n", $llvm_zip_file); + + -e $llvm_build_dir or die "LLVM build directory doesn't exist: '$llvm_build_dir': $!\n"; + -l "$llvm_build_dir/llvm" || die "Couldn't find llvm symlink '$llvm_build_dir/llvm': $!\n"; + + my $temp_dir = tempdir( CLEANUP => 1 ); + print "temp dir = '$temp_dir'\n"; + my $llvm_checkpoint_dir = "$temp_dir/llvm"; + mkdir "$llvm_checkpoint_dir" or die "Couldn't make 'llvm' in '$temp_dir'\n"; + + my @rsync_src_dst_paths = + ( + "$llvm_source_dir/include", "$llvm_checkpoint_dir", + "$llvm_source_dir/tools/clang/include", "$llvm_checkpoint_dir/tools/clang", + "$llvm_build_dir/llvm/include", "$llvm_checkpoint_dir", + "$llvm_build_dir/llvm/tools/clang/include", "$llvm_checkpoint_dir/tools/clang", + ); + + while (@rsync_src_dst_paths) + { + my $rsync_src = shift @rsync_src_dst_paths; + my $rsync_dst = shift @rsync_src_dst_paths; + print "rsync_src = '$rsync_src'\n"; + print "rsync_dst = '$rsync_dst'\n"; + if (-e $rsync_src) + { + my ($rsync_dst_file, $rsync_dst_dir) = fileparse ($rsync_dst); + print "rsync_dst_dir = '$rsync_dst_dir'\n"; + -e $rsync_dst_dir or do_command ("mkdir -p '$rsync_dst_dir'"); + do_command ("rsync -amvC --exclude='*.tmp' --exclude='*.txt' --exclude='*.TXT' --exclude='*.td' --exclude='\.dir' --exclude=Makefile '$rsync_src' '$rsync_dst'"); + } + } + + do_command ("cp '$llvm_build_dir/libllvmclang.a' '$llvm_checkpoint_dir'", "Copying libllvmclang.a", 1); + do_command ("cp '$lldb_build_dir/libEnhancedDisassembly.dylib' '$llvm_checkpoint_dir'", "Copying libEnhancedDisassembly.dylib", 1); + do_command ("rm -rf '$llvm_zip_file'", "Removing old llvm checkpoint file '$llvm_zip_file'", 1); + do_command ("(cd '$temp_dir' ; zip -r '$llvm_zip_file' 'llvm')", "Zipping llvm checkpoint directory '$llvm_checkpoint_dir' to '$llvm_zip_file'", 1); +} +else +{ + print "USAGE\n\tcheckpoint-llvm.pl <llvm-sources> <llvm-build> <lldb-build> <llvm-zip>\n\n"; + print "EXAMPLE\n\tcd lldb\n\t./scripts/checkpoint-llvm.pl llvm build/lldb.build/BuildAndIntegration/LLDB.build/DerivedSources/llvm.build build/BuildAndIntegration llvm.zip\n"; +} diff --git a/lldb/scripts/finish-swig-wrapper-classes.sh b/lldb/scripts/finish-swig-wrapper-classes.sh new file mode 100755 index 00000000000..5d9713d06a2 --- /dev/null +++ b/lldb/scripts/finish-swig-wrapper-classes.sh @@ -0,0 +1,71 @@ +#! /bin/sh + +# finish-swig-wrapper-classes.sh +# +# For each scripting language liblldb supports, we need to create the +# appropriate Script Bridge wrapper classes for that language so that +# users can call Script Bridge functions from within the script interpreter. +# +# We use SWIG to create a C++ file containing the appropriate wrapper classes +# and funcitons for each scripting language, before liblldb is built (thus +# the C++ file can be compiled into liblldb. In some cases, additional work +# may need to be done after liblldb has been compiled, to make the scripting +# language stuff fully functional. Any such post-processing is handled through +# the shell scripts called here. + +debug_flag=$1 + +if [ -n "$debug_flag" -a "$debug_flag" == "-debug" ] +then + Debug=1 +else + Debug=0 +fi + + +# +# For each scripting language, see if a post-processing script for that +# language exists, and if so, call it. +# +# For now the only language we support is Python, but we expect this to +# change. + +languages="Python" +cwd=${SRCROOT}/scripts + +for curlang in $languages +do + if [ $Debug == 1 ] + then + echo "Current language is $curlang" + fi + + if [ ! -d "$cwd/$curlang" ] + then + echo "error: unable to find $curlang script sub-dirctory" >&2 + continue + else + + if [ $Debug == 1 ] + then + echo "Found $curlang sub-directory" + fi + + cd $cwd/$curlang + + filename="./finish-swig-${curlang}-${TARGET_NAME}.sh" + + if [ -f $filename ] + then + if [ $Debug == 1 ] + then + echo "Found $curlang post-processing script for ${TARGET_NAME}" + echo "Executing $curlang post-processing script..." + fi + + ./finish-swig-${curlang}-${TARGET_NAME}.sh + fi + fi +done + +exit 0 diff --git a/lldb/scripts/install-lldb.sh b/lldb/scripts/install-lldb.sh new file mode 100755 index 00000000000..0ba4e7c5ee2 --- /dev/null +++ b/lldb/scripts/install-lldb.sh @@ -0,0 +1,59 @@ +#!/bin/sh + + +# This script will install the files from a "Debug" or "Release" build +# directory into the developer folder specified. + +NUM_EXPECTED_ARGS=2 + +PROGRAM=`basename $0` + +if [ $# -ne $NUM_EXPECTED_ARGS ]; then + echo This script will install the files from a 'Debug' or 'Release' build directory into the developer folder specified. + echo "usage: $PROGRAM <BUILD_DIR> <DEVELOPER_DIR>"; + echo "example: $PROGRAM ./Debug /Developer" + echo "example: $PROGRAM /build/Release /Xcode4" + exit 1; +fi + +BUILD_DIR=$1 +DEVELOPER_DIR=$2 + +if [ -d $BUILD_DIR ]; then + if [ -d $DEVELOPER_DIR ]; then + if [ -e "$BUILD_DIR/debugserver" ]; then + echo Updating "$DEVELOPER_DIR/usr/bin/debugserver" + sudo rm -rf "$DEVELOPER_DIR/usr/bin/debugserver" + sudo cp "$BUILD_DIR/debugserver" "$DEVELOPER_DIR/usr/bin/debugserver" + fi + + if [ -e "$BUILD_DIR/lldb" ]; then + echo Updating "$DEVELOPER_DIR/usr/bin/lldb" + sudo rm -rf "$DEVELOPER_DIR/usr/bin/lldb" + sudo cp "$BUILD_DIR/lldb" "$DEVELOPER_DIR/usr/bin/lldb" + fi + + if [ -e "$BUILD_DIR/libEnhancedDisassembly.dylib" ]; then + echo Updating "$DEVELOPER_DIR/usr/lib/libEnhancedDisassembly.dylib" + sudo rm -rf "$DEVELOPER_DIR/usr/lib/libEnhancedDisassembly.dylib" + sudo cp "$BUILD_DIR/libEnhancedDisassembly.dylib" "$DEVELOPER_DIR/usr/lib/libEnhancedDisassembly.dylib" + fi + + if [ -d "$BUILD_DIR/LLDB.framework" ]; then + echo Updating "$DEVELOPER_DIR/Library/PrivateFrameworks/LLDB.framework" + sudo rm -rf "$DEVELOPER_DIR/Library/PrivateFrameworks/LLDB.framework" + sudo cp -r "$BUILD_DIR/LLDB.framework" "$DEVELOPER_DIR/Library/PrivateFrameworks/LLDB.framework" + elif [ -e "$BUILD_DIR/LLDB.framework" ]; then + echo BUILD_DIR path to LLDB.framework is not a directory: "$BUILD_DIR/LLDB.framework" + exit 2; + fi + + else + echo DEVELOPER_DIR must be a directory: "$DEVELOPER_DIR" + exit 3; + fi + +else + echo BUILD_DIR must be a directory: "$BUILD_DIR" + exit 4; +fi diff --git a/lldb/scripts/lldb.swig b/lldb/scripts/lldb.swig new file mode 100644 index 00000000000..d9fd05b8488 --- /dev/null +++ b/lldb/scripts/lldb.swig @@ -0,0 +1,149 @@ +/* + lldb.swig + + Created by Caroline Tice 1/18/2010 + + This is the input file for SWIG, to create the appropriate C++ wrappers and + functions for various scripting languages, to enable them to call the + liblldb Script Bridge functions. + +*/ + +/* The name of the module to be created. */ + +%module lldb + +%typemap(in) lldb::ReturnStatus { + $1 = (int) $input; +} + +%typemap(freearg) lldb::ReturnStatus { +} + +%typemap(out) lldb::ReturnStatus { + $result = SWIG_From_unsigned_SS_int(static_cast< unsigned int >($1)); +} + +/* Typemap definitions, to allow SWIG to properly handle 'char**' data types. */ + +%typemap(in) char ** { + /* Check if is a list */ + if (PyList_Check($input)) { + int size = PyList_Size($input); + int i = 0; + $1 = (char **) malloc((size+1) * sizeof(char)); + for (i = 0; i < size; i++) { + PyObject *o = PyList_GetItem($input,i); + if (PyString_Check(o)) + $1[i] = PyString_AsString(PyList_GetItem($input,i)); + else { + PyErr_SetString(PyExc_TypeError,"list must contain strings"); + free($1); + return NULL; + } + } + $1[i] = 0; + } else { + PyErr_SetString(PyExc_TypeError,"not a list"); + return NULL; + } +} + +%typemap(freearg) char** { + free((char *) $1); +} + +%typemap(out) char** { + int len; + int i; + len = 0; + while ($1[len]) len++; + $result = PyList_New(len); + for (i = 0; i < len; i++) { + PyList_SetItem($result, i, PyString_FromString($1[i])); + } +} + + +/* The liblld header files to be included. */ + +%{ +#include "lldb/lldb-types.h" +#include "lldb/API/SBAddress.h" +#include "lldb/API/SBBlock.h" +#include "lldb/API/SBBreakpoint.h" +#include "lldb/API/SBBreakpointLocation.h" +#include "lldb/API/SBBroadcaster.h" +#include "lldb/API/SBCommandContext.h" +#include "lldb/API/SBCommandInterpreter.h" +#include "lldb/API/SBCommandReturnObject.h" +#include "lldb/API/SBCompileUnit.h" +#include "lldb/API/SBDebugger.h" +#include "lldb/API/SBError.h" +#include "lldb/API/SBEvent.h" +#include "lldb/API/SBFrame.h" +#include "lldb/API/SBFunction.h" +#include "lldb/API/SBLineEntry.h" +#include "lldb/API/SBListener.h" +#include "lldb/API/SBModule.h" +#include "lldb/API/SBProcess.h" +#include "lldb/API/SBSourceManager.h" +#include "lldb/API/SBStringList.h" +#include "lldb/API/SBSymbol.h" +#include "lldb/API/SBSymbolContext.h" +#include "lldb/API/SBTarget.h" +#include "lldb/API/SBThread.h" +#include "lldb/API/SBType.h" +#include "lldb/API/SBValue.h" +using namespace lldb; +using namespace lldb_private; +%} + +/* Various liblldb typedefs that SWIG needs to know about. */ + +%{ +typedef unsigned int uint32_t; +typedef unsigned long long uint64_t; +typedef int int32_t; +typedef int32_t pid_t; +typedef uint32_t tid_t; +typedef uint64_t addr_t; +%} + +typedef unsigned int uint32_t; +typedef unsigned long long uint64_t; +typedef int int32_t; +typedef int32_t pid_t; +typedef uint32_t tid_t; +typedef uint64_t addr_t; + + +%include "lldb/API/SBAddress.h" +%include "lldb/API/SBBlock.h" +%include "lldb/API/SBBreakpoint.h" +%include "lldb/API/SBBreakpointLocation.h" +%include "lldb/API/SBBroadcaster.h" +%include "lldb/API/SBCommandContext.h" +%include "lldb/API/SBCommandInterpreter.h" +%include "lldb/API/SBCommandReturnObject.h" +%include "lldb/API/SBCompileUnit.h" +%include "lldb/API/SBDebugger.h" +%include "lldb/API/SBError.h" +%include "lldb/API/SBEvent.h" +%include "lldb/API/SBFrame.h" +%include "lldb/API/SBFunction.h" +%include "lldb/API/SBLineEntry.h" +%include "lldb/API/SBListener.h" +%include "lldb/API/SBModule.h" +%include "lldb/API/SBProcess.h" +%include "lldb/API/SBSourceManager.h" +%include "lldb/API/SBStringList.h" +%include "lldb/API/SBSymbol.h" +%include "lldb/API/SBSymbolContext.h" +%include "lldb/API/SBTarget.h" +%include "lldb/API/SBThread.h" +%include "lldb/API/SBType.h" +%include "lldb/API/SBValue.h" +%include "lldb/lldb-types.h" + + diff --git a/lldb/scripts/sed-sources b/lldb/scripts/sed-sources new file mode 100755 index 00000000000..f678ee27551 --- /dev/null +++ b/lldb/scripts/sed-sources @@ -0,0 +1,252 @@ +#!/usr/bin/perl + +use strict; +use File::Find; +use File::Temp qw/ tempfile tempdir /; +use Getopt::Std; +use Pod::Usage; +use Text::Tabs; + +=head1 NAME + +B<sed-sources> -- Performs multiple sed commands on files with the ability to expand or unexpand tabs. + +=head1 SYNOPSIS + +B<sed-sources> [options] [file dir ...] + +=head1 DESCRIPTION + +Performs multiple sed commands (modify builtin %seds hash) on source files +or any sources in directories. If no arguments are given, STDIN will be used +as the source. If source files or directories are specified as arguments, +all files will be transformed and overwritten with new versions. Use the B<-p> +option to preview changes to STDOUT, or use the B<-b> option to make a backup +or the original files. + +=head1 OPTIONS + +=over + +=item B<-b> + +Backup original source file by appending ".bak" before overwriting with the +newly transformed file. + +=item B<-g> + +Display verbose debug logging. + +=item B<-e> + +Expand tabs to spaces (in addition to doing sed substitutions). + +=item B<-u> + +Unexpand spaces to tabs (in addition to doing sed substitutions). + +=item B<-p> + +Preview changes to STDOUT without modifying original source files. + +=item B<-r> + +Skip variants when doing multiple files (no _profile or _debug variants). + +=item B<-t N> + +Set the number of spaces per tab (default is 4) to use when expanding or +unexpanding. + +=back + +=head1 EXAMPLES + +# Recursively process all source files in the current working directory +# and and subdirectories and also expand tabs to spaces. All source files +# will be overwritten with the newly transformed source files. + +% sed-sources -e $cwd + +# Recursively process all source files in the current working directory +# and and subdirectories and also unexpand spaces to tabs and preview the +# results to STDOUT + +% sed-sources -p -u $cwd + +# Same as above except use 8 spaces per tab. + +% sed-sources -p -u -t8 $cwd + +=cut + + +our $opt_b = 0; # Backup original file? +our $opt_g = 0; # Verbose debug output? +our $opt_e = 0; # Expand tabs to spaces? +our $opt_h = 0; # Show help? +our $opt_m = 0; # Show help manpage style? +our $opt_p = 0; # Preview changes to STDOUT? +our $opt_t = 4; # Number of spaces per tab? +our $opt_u = 0; # Unexpand spaces to tabs? +getopts('eghmpt:u'); + +$opt_m and show_manpage(); +$opt_h and help(); + +our %seds = ( + '\s+$' => "\n", # Get rid of spaces at the end of a line + '^\s+$' => "\n", # Get rid spaces on lines that are all spaces + '^\s*//\s*[Cc]opyright.*$' => '//', # Get rid of all copyright lines +); + + +sub show_manpage { exit pod2usage( verbose => 2 ); }; +sub help { exit pod2usage( verbose => 3, noperldoc => 1 ); }; + + +#---------------------------------------------------------------------- +# process_opened_file_handle +#---------------------------------------------------------------------- +sub process_opened_file_handle +{ + my $in_fh = shift; + my $out_fh = shift; + + # Set the number of spaces per tab for expand/unexpand + $tabstop = $opt_t; + + while (my $line = <$in_fh>) + { + foreach my $key (keys %seds) + { + my $value = $seds{"$key"}; + $line =~ s/$key/$value/g; + } + if ($opt_e) { + print $out_fh expand $line; + } elsif ($opt_u) { + print $out_fh unexpand $line; + } else { + print $out_fh $line; + } + } +} + +#---------------------------------------------------------------------- +# process_file +#---------------------------------------------------------------------- +sub process_file +{ + my $in_path = shift; + if (-T $in_path) + { + my $out_fh; + my $out_path; + if ($opt_p) + { + # Preview to STDOUT + $out_fh = *STDOUT; + print "#---------------------------------------------------------------------- \n"; + print "# BEGIN: '$in_path'\n"; + print "#---------------------------------------------------------------------- \n"; + } + else + { + ($out_fh, $out_path) = tempfile(); + $opt_g and print "temporary for '$in_path' is '$out_path'\n"; + } + open (IN, "<$in_path") or die "error: can't open '$in_path' for reading: $!"; + process_opened_file_handle (*IN, $out_fh); + + + # Close our input file + close (IN); + + if ($opt_p) + { + print "#---------------------------------------------------------------------- \n"; + print "# END: '$in_path'\n"; + print "#---------------------------------------------------------------------- \n"; + print "\n\n"; + } + else + { + # Close the output file if it wasn't STDOUT + close ($out_fh); + + # Backup file if requested + if ($opt_b) + { + my $backup_command = "cp '$in_path' '$in_path.bak'"; + $opt_g and print "\% $backup_command\n"; + system ($backup_command); + } + + # Copy temp file over original + my $copy_command = "cp '$out_path' '$in_path'"; + $opt_g and print "\% $copy_command\n"; + system ($copy_command); + } + } +} + +our @valid_extensions = ( "h", "cpp", "c", "m", "mm" ); + +#---------------------------------------------------------------------- +# find_callback +#---------------------------------------------------------------------- +sub find_callback +{ + my $file = $_; + my $fullpath = $File::Find::name; + + foreach my $ext (@valid_extensions) + { + my $ext_regex = "\\.$ext\$"; + if ($fullpath =~ /$ext_regex/i) + { + print "processing: '$fullpath'\n"; + process_file ($fullpath); + return; + } + } + print " ignoring: '$fullpath'\n"; +} + + +#---------------------------------------------------------------------- +# main +#---------------------------------------------------------------------- +sub main +{ + if (@ARGV == 0) + { + # no args, take from STDIN and put to STDOUT + process_opened_file_handle (*STDIN, *STDOUT); + } + else + { + # Got args, any files we run into parse them, any directories + # we run into, search them for files + my $path; + foreach $path (@ARGV) + { + if (-f $path) + { + print "processing: '$path'\n"; + process_file ($path); + } + else + { + print " searching: '$path'\n"; + find(\&find_callback, $path); + } + } + } +} + + + +# call the main function +main();
\ No newline at end of file |