summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdrian Thurston <thurston@colm.net>2021-12-06 22:14:00 -0800
committerAdrian Thurston <thurston@colm.net>2021-12-11 11:18:08 -0800
commit4e5cb4f242c001e0937bf90f0e7c96fa64e2befe (patch)
tree9a40e0b82d77a305bfa165f88907105870e357fd
parent04aa160534d62c33b631ef02fe9e202e4e2be045 (diff)
downloadcolm-4e5cb4f242c001e0937bf90f0e7c96fa64e2befe.tar.gz
if buildDir is not set with -B, try to find a default
When running from the build directory, if one forgets to give -B, and colm was previously installed at the current prefix, colm programs will build against the installed version, not the local source tree. This won't be immediately obvious and could lead to confusion during development. To prevent this, try to find the buildDir if one is not given. The tests can continue to specify the buildDir with -B, which is the most safe way. The buildDir is defaulted by testing the buildDir known at compile time against LD_LIBRARY_PATH. Libtool on ubuntu 20.04 will place the buildDir at the head of LD_LIBRARY_PATH. It seems likely that it would do this on all systems, making it a seemingly good test.
-rw-r--r--configure.ac2
-rw-r--r--src/Makefile.am3
-rw-r--r--src/main.cc19
3 files changed, 22 insertions, 2 deletions
diff --git a/configure.ac b/configure.ac
index 532d636d..9124b8a9 100644
--- a/configure.ac
+++ b/configure.ac
@@ -375,7 +375,7 @@ AC_ARG_WITH(crack,
SED_SUBST="$SED_SUBST -e 's|@CRACK_BIN@|${CRACK_BIN}|g'"
AC_SUBST(CRACK_BIN)
-
+
dnl Skip bootstrap process and build using an existing version of colm. Allows us to
dnl break colm without breaking the build of colm.
dnl
diff --git a/src/Makefile.am b/src/Makefile.am
index 09da4c47..895a46d6 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -53,7 +53,8 @@ endif
common_CFLAGS = \
-Wall \
-DINCLUDEDIR='"$(includedir)"' \
- -DLIBDIR='"$(libdir)"'
+ -DLIBDIR='"$(libdir)"' \
+ -DABS_TOP_BUILDDIR='"$(abs_top_builddir)"'
libprog_a_SOURCES = \
buffer.h bytecode.h colm.h debug.h dotgen.h fsmcodegen.h fsmgraph.h \
diff --git a/src/main.cc b/src/main.cc
index 317f3bce..482fb4a4 100644
--- a/src/main.cc
+++ b/src/main.cc
@@ -683,11 +683,30 @@ bool readCheck( const char *fn )
return result;
}
+void defaultBuildDir()
+{
+ if ( buildDir != 0 )
+ return;
+
+ const char *ldlp = getenv("LD_LIBRARY_PATH");
+ if ( ldlp != 0 ) {
+ size_t len_atbd = strlen(ABS_TOP_BUILDDIR);
+
+ if ( strlen(ldlp) > len_atbd &&
+ memcmp( ldlp, ABS_TOP_BUILDDIR "/", len_atbd+1) == 0 )
+ {
+ buildDir = ABS_TOP_BUILDDIR;
+ }
+ }
+}
+
/* Main, process args and call yyparse to start scanning input. */
int main(int argc, const char **argv)
{
processArgs( argc, argv );
+ defaultBuildDir();
+
if ( verbose )
gblActiveRealm = 0xffffffff;