[llvm-commits] [llvm] r143616 - in /llvm/trunk/tools: CMakeLists.txt Makefile llvm-config-2/ llvm-config-2/CMakeLists.txt llvm-config-2/Makefile llvm-config-2/llvm-config.cpp

Wesley Peck peckw at wesleypeck.com
Thu Nov 3 11:51:43 PDT 2011


On Nov 3, 2011, at 12:30 PM, Daniel Dunbar wrote:
> +  for (int i = 1; i != argc; ++i) {
> +    StringRef Arg = argv[i];
> +
> +    if (Arg.startswith("-")) {
> +      HasAnyOption = true;
> +      if (Arg == "--version") {
> +        OS << PACKAGE_VERSION << '\n';
> +      } else if (Arg == "--prefix") {
> +        OS << ActivePrefix << '\n';
> +      } else if (Arg == "--bindir") {
> +        OS << ActiveBinDir << '\n';
> +      } else if (Arg == "--includedir") {
> +        OS << ActiveIncludeDir << '\n';
> +      } else if (Arg == "--libdir") {
> +        OS << ActiveLibDir << '\n';
> +      } else if (Arg == "--cppflags") {
> +        OS << ActiveIncludeOption << ' ' << LLVM_CPPFLAGS << '\n';
> +      } else if (Arg == "--cflags") {
> +        OS << ActiveIncludeOption << ' ' << LLVM_CFLAGS << '\n';
> +      } else if (Arg == "--cxxflags") {
> +        OS << ActiveIncludeOption << ' ' << LLVM_CXXFLAGS << '\n';
> +      } else if (Arg == "--ldflags") {
> +        OS << "-L" << ActiveLibDir << ' ' << LLVM_LDFLAGS
> +           << ' ' << LLVM_SYSTEM_LIBS << '\n';
> +      } else if (Arg == "--libs") {
> +        PrintLibs = true;
> +      } else if (Arg == "--libnames") {
> +        PrintLibNames = true;
> +      } else if (Arg == "--libfiles") {
> +        PrintLibFiles = true;
> +      } else if (Arg == "--components") {
> +        for (unsigned j = 0; j != NumAvailableComponents; ++j) {
> +          if (j)
> +            OS << ' ';
> +          OS << AvailableComponents[j].Name;
> +        }
> +        OS << '\n';
> +      } else if (Arg == "--targets-built") {
> +        bool First = true;
> +        for (TargetRegistry::iterator I = TargetRegistry::begin(),
> +               E = TargetRegistry::end(); I != E; First = false, ++I) {
> +          if (!First)
> +            OS << ' ';
> +          OS << I->getName();
> +        }
> +        OS << '\n';
> +      } else if (Arg == "--host-target") {
> +        OS << LLVM_DEFAULT_TARGET_TRIPLE << '\n';
> +      } else if (Arg == "--build-mode") {
> +        OS << LLVM_BUILDMODE << '\n';
> +      } else if (Arg == "--obj-root") {
> +        OS << LLVM_OBJ_ROOT << '\n';
> +      } else if (Arg == "--src-root") {
> +        OS << LLVM_SRC_ROOT << '\n';
> +      } else {
> +        usage();
> +      }
> +    } else {
> +      Components.push_back(Arg);
> +    }
> +  }
> +
> +  if (!HasAnyOption)
> +    usage();

Just out of curiosity, why not use LLVM's command line parsing library for this? Is is not capable of parsing the required syntax or are you trying to avoid some sort of dependency? It seems like it would be a lot cleaner and easier to maintain than this code.

--
Wesley Peck
University of Kansas
SLDG Laboratory



More information about the llvm-commits mailing list