diff --git a/wrapper/programs/osxcross-man.cpp b/wrapper/programs/osxcross-man.cpp index ae1f148..26659f6 100644 --- a/wrapper/programs/osxcross-man.cpp +++ b/wrapper/programs/osxcross-man.cpp @@ -33,22 +33,54 @@ namespace osxcross { int man(int argc, char **argv, Target &target) { std::string SDKPath; - target.getSDKPath(SDKPath); - std::string manpath = SDKPath + "/usr/share/man"; - if (!dirExists(manpath)) { - err << "directory '" << manpath << "' does not exist" << err.endl(); + if (!target.getSDKPath(SDKPath)) + return 1; + + std::vector manpaths; + + manpaths.push_back(SDKPath + "/usr/share/man"); + manpaths.push_back(std::string(target.execpath) + "/../share/man"); + + unsetenv("MANPATH"); + + for (const std::string &manpath : manpaths) + if (dirExists(manpath)) + concatEnvVariable("MANPATH", manpath); + + if (!getenv("MANPATH")) { + err << "cannot find man pages!" << err.endl(); return 1; } std::vector args; - args.push_back(const_cast("man")); - args.push_back(const_cast("--manpath")); - args.push_back(const_cast(manpath.c_str())); + // All the const violation here doesn't matter, + // the arguments won't be modified - for (int i = 1; i < argc; ++i) - args.push_back(argv[i]); + args.push_back(const_cast("man")); + + for (int i = 1; i < argc; ++i) { + char *arg = argv[i]; + + // Rewrite gcc to -gcc for compatibility + // with other man pages + + constexpr const char *GCCManPages[] = { "gcc", "g++", "cpp", "gcov" }; + + for (const char *mp : GCCManPages) { + if (!strcmp(mp, arg)) { + std::string *str = new std::string; // Intentionally "leaked" + target.getDefaultTriple(*str); + str->append("-"); + str->append(arg); + arg = const_cast(str->c_str()); + break; + } + } + + args.push_back(arg); + } args.push_back(nullptr);