summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdrian Thurston <thurston@complang.org>2011-06-03 07:30:47 +0000
committerAdrian Thurston <thurston@complang.org>2011-06-03 07:30:47 +0000
commit642d75c057fbb0360692b10f1552fd557b0fb462 (patch)
treec516b26de98e1cbe1424816501483daec2f6589f
parent67cee0221975b384ba910693187823eb15e972d8 (diff)
downloadcolm-642d75c057fbb0360692b10f1552fd557b0fb462.tar.gz
Install the runtime headers.
Improved the check that decides if we are in the source tree VS an installed location. Previously, if there was a / in the path it was assumed to be source. This doesn't work for cases where we specify the full path to the installed location. Now we look for a slash, then for main.cc next to the binary. refs #297.
-rw-r--r--colm/Makefile.am6
-rw-r--r--colm/main.cc35
2 files changed, 32 insertions, 9 deletions
diff --git a/colm/Makefile.am b/colm/Makefile.am
index 40c6379b..93dc5a41 100644
--- a/colm/Makefile.am
+++ b/colm/Makefile.am
@@ -121,7 +121,7 @@ RUNTIME_SRC = \
codevect.c pool.c string.c tree.c bytecode.c
RUNTIME_HDR = \
- bytecode.h config.h debug.h pool.h input.h \
+ bytecode.h config.h defs.h debug.h pool.h input.h \
fsmrun.h pdarun.h map.h tree.h
lib_LIBRARIES = libcolmp.a libcolmd.a
@@ -167,6 +167,10 @@ colm_SOURCES = \
redfsm.cc fsmexec.cc main.cc redbuild.cc closure.cc fsmap.cc \
dotgen.cc pcheck.cc ctinput.cc
+colmincdir = $(includedir)/colm
+
+colminc_HEADERS = $(RUNTIME_HDR)
+
BUILT_SOURCES = \
version.h lmscan.cc lmparse.h lmparse.cc
diff --git a/colm/main.cc b/colm/main.cc
index 6d55643e..e2fe0faf 100644
--- a/colm/main.cc
+++ b/colm/main.cc
@@ -26,6 +26,9 @@
#include <fstream>
#include <unistd.h>
#include <sstream>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <unistd.h>
#include "colm.h"
#include "debug.h"
@@ -269,7 +272,7 @@ void compileOutputCommand( const char *command )
cout << "there was a problem compiling the output" << endl;
}
-void compileOutputPath( const char *argv0 )
+void compileOutputInstalled( const char *argv0 )
{
/* Find the location of the colm program that is executing. */
char *location = strdup( argv0 );
@@ -304,7 +307,7 @@ void compileOutputPath( const char *argv0 )
compileOutputCommand( command );
}
-void compileOutputRelative( const char *argv0 )
+void compileOutputInSource( const char *argv0 )
{
/* Find the location of the colm program that is executing. */
char *location = strdup( argv0 );
@@ -331,12 +334,24 @@ void compileOutputRelative( const char *argv0 )
compileOutputCommand( command );
}
-void compileOutput( const char *argv0 )
+bool inSourceTree( const char *argv0 )
{
- if ( strchr( argv0, '/' ) == 0 )
- compileOutputPath( argv0 );
- else
- compileOutputRelative( argv0 );
+ const char *lastSlash = strrchr( argv0, '/' );
+ if ( lastSlash != 0 ) {
+ int rootLen = lastSlash - argv0 + 1;
+ char *mainPath = new char[rootLen + 16];
+ memcpy( mainPath, argv0, rootLen );
+ strcpy( mainPath + rootLen, "main.cc" );
+
+ struct stat sb;
+ int res = stat( mainPath, &sb );
+ delete[] mainPath;
+
+ if ( res == 0 && S_ISREG( sb.st_mode ) )
+ return true;
+ }
+
+ return false;
}
void process_args( int argc, const char **argv )
@@ -486,7 +501,11 @@ int main(int argc, const char **argv)
if ( outStream != 0 )
delete outStream;
- compileOutput( argv[0] );
+ if ( inSourceTree( argv[0] ) )
+ compileOutputInSource( argv[0] );
+ else
+ compileOutputInstalled( argv[0] );
}
+
return 0;
}