aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/tools/swig/swig_lib.cpp
blob: 75b98501e88e43f767ce6aea0ce8d09f260f1422 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define _STR(a) #a
#define STR(a) _STR(a)

static const char* ArcadiaRoot() {
    const char* root = getenv("ARCADIA_ROOT_DISTBUILD");
    return root ? root : STR(ARCADIA_ROOT);
}

#ifdef _MSC_VER
static int setenv(const char* name, const char* value, int overwrite) {
    return (overwrite || !getenv(name)) ? _putenv_s(name, value) : 0;
}
#endif

static void InitSwigLib() {
    const char* root = ArcadiaRoot();
    const char* lib = STR(SWIG_LIB_ARCPATH);
    char* s = new char[strlen(root) + 1 + strlen(lib) + 1];
    sprintf(s, "%s/%s", root, lib);
    setenv("SWIG_LIB", s, false);
    delete[] s;
}

static int initSwigLib = (InitSwigLib(), 0);