diff options
author | Clifford Wolf <clifford@clifford.at> | 2018-10-30 11:28:34 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-10-30 11:28:34 +0100 |
commit | 90f0e40cb849e076a08bc9b6fdcd05899f88eeae (patch) | |
tree | e78f9e337b2bf890adee7bed1795bf9177819f29 /icetime/icetime.cc | |
parent | 8f738342bc32e4fd0233f52a5282b4a1bfc72ba2 (diff) | |
parent | c1c13f3b3e14a392fbfbb63add2d55aa642f6018 (diff) | |
download | icestorm-90f0e40cb849e076a08bc9b6fdcd05899f88eeae.tar.gz icestorm-90f0e40cb849e076a08bc9b6fdcd05899f88eeae.tar.bz2 icestorm-90f0e40cb849e076a08bc9b6fdcd05899f88eeae.zip |
Merge pull request #184 from nathanrossi/nrossi/portable-chipdb
icetime: Add support for searching for chipdb relative to binary
Diffstat (limited to 'icetime/icetime.cc')
-rw-r--r-- | icetime/icetime.cc | 33 |
1 files changed, 9 insertions, 24 deletions
diff --git a/icetime/icetime.cc b/icetime/icetime.cc index c49e2e2..a5a27a0 100644 --- a/icetime/icetime.cc +++ b/icetime/icetime.cc @@ -38,6 +38,8 @@ #include <emscripten.h> #endif +std::string find_chipdb(std::string config_device); + // add this number of ns as estimate for clock distribution mismatch #define GLOBAL_CLK_DIST_JITTER 0.1 @@ -322,35 +324,18 @@ void read_config() void read_chipdb() { char buffer[1024]; + std::string filepath = chipdbfile; - if (!chipdbfile.empty()) { - snprintf(buffer, 1024, "%s", chipdbfile.c_str()); - } else - if (PREFIX[0] == '~' && PREFIX[1] == '/') { - std::string homedir; -#ifdef _WIN32 - if (getenv("USERPROFILE") != nullptr) { - homedir += getenv("USERPROFILE"); - } - else { - if (getenv("HOMEDRIVE") != nullptr && - getenv("HOMEPATH") != nullptr) { - homedir += getenv("HOMEDRIVE"); - homedir += getenv("HOMEPATH"); - } - } -#else - homedir += getenv("HOME"); -#endif - snprintf(buffer, 1024, "%s%s/share/" CHIPDB_SUBDIR "/chipdb-%s.txt", homedir.c_str(), PREFIX+1, config_device.c_str()); - } else { - snprintf(buffer, 1024, PREFIX "/share/" CHIPDB_SUBDIR "/chipdb-%s.txt", config_device.c_str()); + if (filepath.empty()) + filepath = find_chipdb(config_device); + if (filepath.empty()) { + fprintf(stderr, "Can't find chipdb file for device %s\n", config_device.c_str()); + exit(1); } - FILE *fdb = fopen(buffer, "r"); + FILE *fdb = fopen(filepath.c_str(), "r"); if (fdb == nullptr) { perror("Can't open chipdb file"); - fprintf(stderr, " %s\n", buffer); exit(1); } |