@@ -63,6 +63,44 @@ class ObjcopyOptTable : public opt::OptTable {
6363 ObjcopyOptTable () : OptTable(ObjcopyInfoTable) {}
6464};
6565
66+ enum InstallNameToolID {
67+ INSTALL_NAME_TOOL_INVALID = 0 , // This is not an option ID.
68+ #define OPTION (PREFIX, NAME, ID, KIND, GROUP, ALIAS, ALIASARGS, FLAGS, PARAM, \
69+ HELPTEXT, METAVAR, VALUES) \
70+ INSTALL_NAME_TOOL_##ID,
71+ #include " InstallNameToolOpts.inc"
72+ #undef OPTION
73+ };
74+
75+ #define PREFIX (NAME, VALUE ) \
76+ const char *const INSTALL_NAME_TOOL_##NAME[] = VALUE;
77+ #include " InstallNameToolOpts.inc"
78+ #undef PREFIX
79+
80+ static const opt::OptTable::Info InstallNameToolInfoTable[] = {
81+ #define OPTION (PREFIX, NAME, ID, KIND, GROUP, ALIAS, ALIASARGS, FLAGS, PARAM, \
82+ HELPTEXT, METAVAR, VALUES) \
83+ {INSTALL_NAME_TOOL_##PREFIX, \
84+ NAME, \
85+ HELPTEXT, \
86+ METAVAR, \
87+ INSTALL_NAME_TOOL_##ID, \
88+ opt::Option::KIND##Class, \
89+ PARAM, \
90+ FLAGS, \
91+ INSTALL_NAME_TOOL_##GROUP, \
92+ INSTALL_NAME_TOOL_##ALIAS, \
93+ ALIASARGS, \
94+ VALUES},
95+ #include " InstallNameToolOpts.inc"
96+ #undef OPTION
97+ };
98+
99+ class InstallNameToolOptTable : public opt ::OptTable {
100+ public:
101+ InstallNameToolOptTable () : OptTable(InstallNameToolInfoTable) {}
102+ };
103+
66104enum StripID {
67105 STRIP_INVALID = 0 , // This is not an option ID.
68106#define OPTION (PREFIX, NAME, ID, KIND, GROUP, ALIAS, ALIASARGS, FLAGS, PARAM, \
@@ -752,6 +790,57 @@ parseObjcopyOptions(ArrayRef<const char *> ArgsArr,
752790 return std::move (DC);
753791}
754792
793+ // ParseInstallNameToolOptions returns the config and sets the input arguments.
794+ // If a help flag is set then ParseInstallNameToolOptions will print the help
795+ // messege and exit.
796+ Expected<DriverConfig>
797+ parseInstallNameToolOptions (ArrayRef<const char *> ArgsArr) {
798+ DriverConfig DC;
799+ CopyConfig Config;
800+ InstallNameToolOptTable T;
801+ unsigned MissingArgumentIndex, MissingArgumentCount;
802+ llvm::opt::InputArgList InputArgs =
803+ T.ParseArgs (ArgsArr, MissingArgumentIndex, MissingArgumentCount);
804+
805+ if (InputArgs.size () == 0 ) {
806+ printHelp (T, errs (), " llvm-install-name-tool" );
807+ exit (1 );
808+ }
809+
810+ if (InputArgs.hasArg (INSTALL_NAME_TOOL_help)) {
811+ printHelp (T, outs (), " llvm-install-name-tool" );
812+ exit (0 );
813+ }
814+
815+ if (InputArgs.hasArg (INSTALL_NAME_TOOL_version)) {
816+ outs () << " llvm-install-name-tool, compatible with cctools "
817+ " install_name_tool\n " ;
818+ cl::PrintVersionMessage ();
819+ exit (0 );
820+ }
821+
822+ for (auto Arg : InputArgs.filtered (INSTALL_NAME_TOOL_add_rpath))
823+ Config.RPathToAdd .push_back (Arg->getValue ());
824+
825+ SmallVector<StringRef, 2 > Positional;
826+ for (auto Arg : InputArgs.filtered (INSTALL_NAME_TOOL_UNKNOWN))
827+ return createStringError (errc::invalid_argument, " unknown argument '%s'" ,
828+ Arg->getAsString (InputArgs).c_str ());
829+ for (auto Arg : InputArgs.filtered (INSTALL_NAME_TOOL_INPUT))
830+ Positional.push_back (Arg->getValue ());
831+ if (Positional.empty ())
832+ return createStringError (errc::invalid_argument, " no input file specified" );
833+ if (Positional.size () > 1 )
834+ return createStringError (
835+ errc::invalid_argument,
836+ " llvm-install-name-tool expects a single input file" );
837+ Config.InputFilename = Positional[0 ];
838+ Config.OutputFilename = Positional[0 ];
839+
840+ DC.CopyConfigs .push_back (std::move (Config));
841+ return std::move (DC);
842+ }
843+
755844// ParseStripOptions returns the config and sets the input arguments. If a
756845// help flag is set then ParseStripOptions will print the help messege and
757846// exit.
0 commit comments