aboutsummaryrefslogtreecommitdiffstats
path: root/icetime/icetime.cc
diff options
context:
space:
mode:
authorNathan Rossi <nathan@nathanrossi.com>2018-09-03 22:50:03 +1000
committerNathan Rossi <nathan@nathanrossi.com>2018-09-03 23:11:26 +1000
commitc1c13f3b3e14a392fbfbb63add2d55aa642f6018 (patch)
treec15605b695f68208ed9939c042135fcf1a5f3496 /icetime/icetime.cc
parent3681ade2c7bfb2e4befee1ff6909608752f91d92 (diff)
downloadicestorm-c1c13f3b3e14a392fbfbb63add2d55aa642f6018.tar.gz
icestorm-c1c13f3b3e14a392fbfbb63add2d55aa642f6018.tar.bz2
icestorm-c1c13f3b3e14a392fbfbb63add2d55aa642f6018.zip
icetime: Add support for searching for chipdb relative to binary
Like yosys and arachne-pnr, allow for searching for the desired chipdb file relative to the executing binaries directory. This allows for portable builds of icetime without needing to specify the exact path to the needed chipdb file with the -C arg. In order to support this icetime must be able to get the "proc_self_dirname" path just like yosys and arachne-pnr. As such copy the equivalent code to get this path information. To avoid cluttering the icetime.cc file with this code, place it in a separate iceutil.cc file. Signed-off-by: Nathan Rossi <nathan@nathanrossi.com>
Diffstat (limited to 'icetime/icetime.cc')
-rw-r--r--icetime/icetime.cc33
1 files changed, 9 insertions, 24 deletions
diff --git a/icetime/icetime.cc b/icetime/icetime.cc
index 35ce99a..16ad142 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);
}