blob: f92a4ef77ad60753075300bea96e45f973c14cd6 [file] [log] [blame]
Eric Beckmann82998502017-07-17 21:35:12 +00001//===- llvm-mt.cpp - Merge .manifest files ---------------------*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===---------------------------------------------------------------------===//
9//
10// Merge .manifest files. This is intended to be a platform-independent port
11// of Microsoft's mt.exe.
12//
13//===---------------------------------------------------------------------===//
14
15#include "llvm/Option/Arg.h"
16#include "llvm/Option/ArgList.h"
17#include "llvm/Option/Option.h"
18#include "llvm/Support/Error.h"
19#include "llvm/Support/ManagedStatic.h"
20#include "llvm/Support/Path.h"
21#include "llvm/Support/PrettyStackTrace.h"
22#include "llvm/Support/Process.h"
23#include "llvm/Support/Signals.h"
24#include "llvm/Support/raw_ostream.h"
25
26#include <system_error>
27
28using namespace llvm;
29
30namespace {
31
32enum ID {
33 OPT_INVALID = 0, // This is not an option ID.
34#define OPTION(PREFIX, NAME, ID, KIND, GROUP, ALIAS, ALIASARGS, FLAGS, PARAM, \
35 HELPTEXT, METAVAR, VALUES) \
36 OPT_##ID,
37#include "Opts.inc"
38#undef OPTION
39};
40
41#define PREFIX(NAME, VALUE) const char *const NAME[] = VALUE;
42#include "Opts.inc"
43#undef PREFIX
44
45static const opt::OptTable::Info InfoTable[] = {
46#define OPTION(PREFIX, NAME, ID, KIND, GROUP, ALIAS, ALIASARGS, FLAGS, PARAM, \
47 HELPTEXT, METAVAR, VALUES) \
48{ \
49 PREFIX, NAME, HELPTEXT, \
50 METAVAR, OPT_##ID, opt::Option::KIND##Class, \
51 PARAM, FLAGS, OPT_##GROUP, \
52 OPT_##ALIAS, ALIASARGS, VALUES},
53#include "Opts.inc"
54#undef OPTION
55};
56
57class CvtResOptTable : public opt::OptTable {
58public:
59 CvtResOptTable() : OptTable(InfoTable, true) {}
60};
61
62static ExitOnError ExitOnErr;
63} // namespace
64
65LLVM_ATTRIBUTE_NORETURN void reportError(Twine Msg) {
66 errs() << "llvm-mt error: " << Msg << "\n";
67 exit(1);
68}
69
Eric Beckmann21c7e9e2017-07-18 01:13:10 +000070int main(int argc, const char *argv[]) {
Eric Beckmann7828c8852017-07-17 23:36:13 +000071 errs() << "very start\n";
72 for (int i = 0; i < argc; i++ ) {
73 errs() << argv[i] << "\n";
74 }
75
Eric Beckmann82998502017-07-17 21:35:12 +000076 CvtResOptTable T;
77 unsigned MAI, MAC;
Eric Beckmann21c7e9e2017-07-18 01:13:10 +000078 ArrayRef<const char *> ArgsArr = makeArrayRef(argv + 1, argc);
Eric Beckmann82998502017-07-17 21:35:12 +000079 opt::InputArgList InputArgs = T.ParseArgs(ArgsArr, MAI, MAC);
80
Eric Beckmann7828c8852017-07-17 23:36:13 +000081 errs() << "after\n";
Eric Beckmann4bf5dac2017-07-17 22:46:10 +000082 for (int i = 0; i < argc; i++ ) {
83 errs() << argv[i] << "\n";
84 }
85
Eric Beckmann82998502017-07-17 21:35:12 +000086 for (auto &Arg : InputArgs) {
Eric Beckmann4bf5dac2017-07-17 22:46:10 +000087 errs() << "found option: " << Arg->getOption().getName() << "\n";
Eric Beckmann82998502017-07-17 21:35:12 +000088 if (Arg->getOption().matches(OPT_unsupported)) {
89 outs() << "llvm-mt: ignoring unsupported '" << Arg->getOption().getName()
90 << "' option\n";
Eric Beckmann4bf5dac2017-07-17 22:46:10 +000091 errs() << "llvm-mt: ignoring unsupported '" << Arg->getOption().getName()
92 << "' option\n";
Eric Beckmann82998502017-07-17 21:35:12 +000093 }
94 }
95
96 if (InputArgs.hasArg(OPT_help)) {
97 T.PrintHelp(outs(), "mt", "Manifest Tool", false);
98 return 0;
99 }
100
101 std::vector<std::string> InputFiles = InputArgs.getAllArgValues(OPT_manifest);
102
103 if (InputFiles.size() == 0) {
104 reportError("no input file specified");
105 }
106
107 StringRef OutputFile;
108
109 if (InputArgs.hasArg(OPT_out)) {
110 OutputFile = InputArgs.getLastArgValue(OPT_out);
111 } else if (InputFiles.size() == 1) {
112 OutputFile = InputFiles[0];
113 } else {
114 reportError("no output file specified");
115 }
116
117 return 0;
118}