Skip to content

Commit

Permalink
add pkg-config wrapper
Browse files Browse the repository at this point in the history
  • Loading branch information
tpoechtrager committed Sep 27, 2014
1 parent e7b643d commit a8fdaa3
Show file tree
Hide file tree
Showing 6 changed files with 75 additions and 8 deletions.
3 changes: 2 additions & 1 deletion wrapper/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ SRCS= \
programs/osxcross-env.cpp \
programs/osxcross-conf.cpp \
programs/osxcross-cmp.cpp \
programs/sw_vers.cpp
programs/sw_vers.cpp \
programs/pkg-config.cpp

OBJS=$(subst .cpp,.o,$(SRCS))

Expand Down
1 change: 1 addition & 0 deletions wrapper/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ create_wrapper_link osxcross 1
create_wrapper_link osxcross-conf 1
create_wrapper_link osxcross-env 1
create_wrapper_link osxcross-cmp 1
create_wrapper_link pkg-config 1

if [ "$PLATFORM" != "Darwin" ]; then
create_wrapper_link sw_vers 1
Expand Down
2 changes: 1 addition & 1 deletion wrapper/programs/osxcross-conf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ using namespace target;
namespace program {
namespace osxcross {

int conf(const Target &target) {
int conf(Target &target) {
std::string sdkpath;
OSVersion OSXVersionMin = getDefaultMinTarget();
const char *ltopath = getLibLTOPath();
Expand Down
63 changes: 63 additions & 0 deletions wrapper/programs/pkg-config.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/***********************************************************************
* OSXCross Compiler Wrapper *
* Copyright (C) 2014 by Thomas Poechtrager *
* t.poechtrager@gmail.com *
* *
* This program is free software; you can redistribute it and/or *
* modify it under the terms of the GNU General Public License *
* as published by the Free Software Foundation; either version 2 *
* of the License, or (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the Free Software *
* Foundation, Inc., *
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
***********************************************************************/

#include "proginc.h"

#ifndef _WIN32
#include <unistd.h>
#endif

extern char **environ;

using namespace tools;
using namespace target;

namespace program {
namespace osxcross {

int pkg_config(int argc, char **argv) {
(void)argc;

bool execute = false;
std::string varname;
const char *val;

// Map OSXCROSS_PKG_* to PKG_*
for (char **env = environ; *env; ++env) {
char *p = *env;

if (!strncmp(p, "OSXCROSS_PKG", 12)) {
execute = true;
p += 9; // skip OSXCROSS_
val = strchr(p, '=') + 1; // find value offset
varname.assign(p, val - p - 1);
setenv(varname.c_str(), val, 1);
}
}

if (execute && execvp("pkg-config", argv))
std::cerr << "cannot find or execute pkg-config" << std::endl;

return 1;
}

} // namespace osxcross
} // namespace program
2 changes: 1 addition & 1 deletion wrapper/programs/sw_vers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ using namespace target;

namespace program {

int sw_vers(int argc, char **argv, const Target &target) {
int sw_vers(int argc, char **argv, Target &target) {

auto genFakeBuildVer = [](std::string & build)->std::string & {
std::stringstream tmp;
Expand Down
12 changes: 7 additions & 5 deletions wrapper/progs.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ class prog {
public:
typedef int (*f1)();
typedef int (*f2)(int, char **);
typedef int (*f3)(int, char **, const target::Target &);
typedef int (*f4)(const target::Target &);
typedef int (*f3)(int, char **, Target &);
typedef int (*f4)(Target &);

constexpr prog(const char *name, f1 fun)
: name(name), fun1(fun), fun2(), fun3(), fun4(), type(1) {}
Expand All @@ -46,7 +46,7 @@ class prog {
constexpr prog(const char *name, f4 fun)
: name(name), fun1(), fun2(), fun3(), fun4(fun), type(4) {}

void operator()(int argc, char **argv, const Target &target) const {
void operator()(int argc, char **argv, Target &target) const {
switch (type) {
case 1:
exit(fun1());
Expand Down Expand Up @@ -74,13 +74,14 @@ class prog {
int type;
};

int sw_vers(int argc, char **argv, const target::Target &target);
int sw_vers(int argc, char **argv, target::Target &target);

namespace osxcross {
int version();
int env(int argc, char **argv);
int conf(const Target &target);
int conf(Target &target);
int cmp(int argc, char **argv);
int pkg_config(int argc, char **argv);
} // namespace osxcross

static int dummy() { return 0; }
Expand All @@ -91,6 +92,7 @@ constexpr prog programs[] = { { "sw_vers", sw_vers },
{ "osxcross-env", osxcross::env },
{ "osxcross-conf", osxcross::conf },
{ "osxcross-cmp", osxcross::cmp },
{ "pkg-config", osxcross::pkg_config },
{ "wrapper", dummy } };

template <class T> const prog *getprog(const T &name) {
Expand Down

0 comments on commit a8fdaa3

Please sign in to comment.