From 882a94938aae254aac05e061043f4c06851ea7fc Mon Sep 17 00:00:00 2001 From: Victor Westerhuis Date: Thu, 2 Dec 2021 16:59:21 +0100 Subject: Delete automatic detection of running in-source This cannot work reliably when using a separate build dir. Instead, add a new switch to specify the build directory explicitly. Use libtool to build the output, defaulting to statically linking libcolm. --- src/main.cc | 101 +++++++++++------------------------------------------------- 1 file changed, 18 insertions(+), 83 deletions(-) (limited to 'src') diff --git a/src/main.cc b/src/main.cc index 8ca395f0..2ceb7cf3 100644 --- a/src/main.cc +++ b/src/main.cc @@ -78,6 +78,7 @@ const char *binaryFn = 0; const char *exportHeaderFn = 0; const char *exportCodeFn = 0; const char *commitCodeFn = 0; +const char *buildDir = 0; const char *objectName = "colm_object"; bool exportCode = false; bool hostAdapters = true; @@ -441,60 +442,31 @@ void runOutputProgram() /* We shall never return here! */ } -void compileOutput( const char *argv0, const bool inSource, char *srcLocation ) +void compileOutput() { - /* Find the location of the colm program that is executing. */ - char *location = strdup( argv0 ); - char *last; int length = 1024 + strlen( intermedFn ) + strlen( binaryFn ); - if ( inSource ) { - last = strrchr( location, '/' ); - assert( last != 0 ); - last[0] = 0; - length += 3 * strlen( location ); - } - else { - last = location + strlen( location ) - 1; - while ( true ) { - if ( last == location ) { - last[0] = '.'; - last[1] = 0; - break; - } - if ( *last == '/' ) { - last[0] = 0; - break; - } - last -= 1; - } - } for ( ArgsVector::Iter af = additionalCodeFiles; af.lte(); af++ ) length += strlen( *af ) + 2; for ( ArgsVector::Iter ip = includePaths; ip.lte(); ip++ ) length += strlen( *ip ) + 3; for ( ArgsVector::Iter lp = libraryPaths; lp.lte(); lp++ ) length += strlen( *lp ) + 3; + if ( buildDir != 0 ) + length += strlen( buildDir ) * 3; #define COMPILE_COMMAND_STRING "gcc -Wall -Wwrite-strings" \ " -g" \ " -o %s" \ " %s" char *command = new char[length]; - if ( inSource ) { + if ( buildDir != 0 ) { sprintf( command, + "%s/libtool --tag=CC --mode=link " COMPILE_COMMAND_STRING - " -I%s/../aapl" - " -I%s/include" - " -L%s" -#if defined(LINK_STATIC) - " %s/libcolm.a", -#elif defined(LINK_SHARED) - " %s/libcolm.so", -#else -# error "must enabled at least one of shared or static libs" -#endif - - binaryFn, intermedFn, srcLocation, - srcLocation, location, location ); + " -I%s/src/include" + " -static" + " %s/src/libcolm.la", + buildDir, binaryFn, intermedFn, + buildDir, buildDir ); } else { sprintf( command, @@ -518,7 +490,7 @@ void compileOutput( const char *argv0, const bool inSource, char *srcLocation ) strcat( command, *lp ); } - if ( !inSource ) + if ( buildDir == 0 ) strcat( command, " -lcolm" ); if( !compileOutputCommand( command ) && run ) @@ -527,46 +499,9 @@ void compileOutput( const char *argv0, const bool inSource, char *srcLocation ) delete[] command; } -bool inSourceTree( const char *argv0, char *&location ) -{ - const char *lastSlash = strrchr( argv0, '/' ); - if ( lastSlash != 0 ) { - /* Take off the file name. */ - int rootLen = lastSlash - argv0; - - /* Create string for dir. */ - char *mainPath = new char[rootLen + 16]; - memcpy( mainPath, argv0, rootLen ); - mainPath[rootLen] = 0; - - /* If built using ldconfig then there will be a .libs dir. */ - lastSlash = strrchr( mainPath, '/' ); - if ( lastSlash != 0 ) { - if ( strlen( lastSlash ) >= 6 && memcmp( lastSlash, "/.libs", 7 ) == 0 ) { - rootLen = lastSlash - mainPath; - mainPath[rootLen] = 0; - } - } - - strcpy( mainPath + rootLen, "/main.cc" ); - - struct stat sb; - int res = stat( mainPath, &sb ); - if ( res == 0 && S_ISREG( sb.st_mode ) ) { - mainPath[rootLen] = 0; - location = mainPath; - return true; - } - - delete[] mainPath; - } - - return false; -} - void processArgs( int argc, const char **argv ) { - ParamCheck pc( "p:cD:e:x:I:L:vdliro:S:M:vHh?-:sVa:m:b:E:", argc, argv ); + ParamCheck pc( "p:cD:e:x:I:L:vdliro:S:M:vHh?-:sVa:m:b:E:B:", argc, argv ); while ( pc.check() ) { switch ( pc.state ) { @@ -658,6 +593,9 @@ void processArgs( int argc, const char **argv ) case 'm': commitCodeFn = pc.parameterArg; break; + case 'B': + buildDir = pc.parameterArg; + break; case 'E': { const char *eq = strchr( pc.parameterArg, '=' ); @@ -811,11 +749,8 @@ int main(int argc, const char **argv) if ( outStream != 0 ) delete outStream; - if ( !gblLibrary ) { - char *location = 0; - bool inSource = inSourceTree( argv[0], location ); - compileOutput( argv[0], inSource, location ); - } + if ( !gblLibrary ) + compileOutput(); if ( exportHeaderFn != 0 ) { openExports(); -- cgit v1.2.1 From 044bd51df6b7a87d97e6d5e12c940c7ec8492880 Mon Sep 17 00:00:00 2001 From: Victor Westerhuis Date: Thu, 2 Dec 2021 19:12:43 +0100 Subject: Move version.h generation to config.status This means that automake makes sure it's remade when configure{,.ac} or version.h.in change. Also don't delete it in clean, but do delete it in distclean, like any file configured by config.status. --- src/Makefile.am | 1 - src/version.h.in | 2 ++ 2 files changed, 2 insertions(+), 1 deletion(-) create mode 100644 src/version.h.in (limited to 'src') diff --git a/src/Makefile.am b/src/Makefile.am index c5fb6efa..d6c2a32f 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -184,7 +184,6 @@ colm_LDADD = libprog.a -lcolm # with the following additional dependency. CLEANFILES = \ - version.h \ include/colm \ gen/parse1.c \ gen/if1.h \ diff --git a/src/version.h.in b/src/version.h.in new file mode 100644 index 00000000..753ae55b --- /dev/null +++ b/src/version.h.in @@ -0,0 +1,2 @@ +#undef VERSION +#undef PUBDATE -- cgit v1.2.1 From 29879d74ae4ec35e452d9fd34d8718378f19a821 Mon Sep 17 00:00:00 2001 From: Victor Westerhuis Date: Fri, 3 Dec 2021 14:00:09 +0100 Subject: Remove empty header src/rtvector.h This header has been empty since 2010. It is not installed, so it does not change the installation. --- src/CMakeLists.txt | 2 +- src/Makefile.am | 2 +- src/codevect.c | 1 - src/rtvector.h | 35 ----------------------------------- 4 files changed, 2 insertions(+), 38 deletions(-) delete mode 100644 src/rtvector.h (limited to 'src') diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 3d855523..651df849 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -56,7 +56,7 @@ add_library(libprog buffer.h bytecode.h colm.h debug.h dotgen.h fsmcodegen.h fsmgraph.h input.h keyops.h map.h compiler.h parsetree.h pcheck.h pdacodegen.h pdagraph.h pdarun.h pool.h redbuild.h - redfsm.h rtvector.h tree.h global.h colm.h parser.h cstring.h + redfsm.h tree.h global.h colm.h parser.h cstring.h internal.h resolve.cc lookup.cc synthesis.cc parsetree.cc fsmstate.cc fsmbase.cc fsmattach.cc fsmmin.cc diff --git a/src/Makefile.am b/src/Makefile.am index d6c2a32f..d4678334 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -58,7 +58,7 @@ libprog_a_SOURCES = \ buffer.h bytecode.h colm.h debug.h dotgen.h fsmcodegen.h fsmgraph.h \ input.h keyops.h map.h compiler.h \ parsetree.h pcheck.h pdacodegen.h pdagraph.h pdarun.h pool.h redbuild.h \ - redfsm.h rtvector.h tree.h version.h global.h colm.h parser.h cstring.h \ + redfsm.h tree.h version.h global.h colm.h parser.h cstring.h \ internal.h \ \ resolve.cc lookup.cc synthesis.cc parsetree.cc \ diff --git a/src/codevect.c b/src/codevect.c index 50b86336..e206371b 100644 --- a/src/codevect.c +++ b/src/codevect.c @@ -23,7 +23,6 @@ #include #include -#include #include void init_rt_code_vect( struct rt_code_vect *vect ) diff --git a/src/rtvector.h b/src/rtvector.h deleted file mode 100644 index e15d3f2a..00000000 --- a/src/rtvector.h +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright 2002-2018 Adrian Thurston - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to - * deal in the Software without restriction, including without limitation the - * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or - * sell copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -#ifndef _COLM_RTVECTOR_H -#define _COLM_RTVECTOR_H - -#ifdef __cplusplus -extern "C" { -#endif - -#ifdef __cplusplus -} -#endif - -#endif /* _COLM_RT_VECTOR_H */ - -- cgit v1.2.1 From c411d029734122fb6de8be8326ba803438c775e0 Mon Sep 17 00:00:00 2001 From: Victor Westerhuis Date: Fri, 3 Dec 2021 14:25:18 +0100 Subject: Move src/include/colm generation to config.status The list of linked headers comes from RUNTIME_HDR in src/Makefile.am. Also don't delete it in clean, but do delete it in distclean, like any file configured by config.status. --- src/Makefile.am | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/Makefile.am b/src/Makefile.am index d4678334..9ec58595 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -184,7 +184,6 @@ colm_LDADD = libprog.a -lcolm # with the following additional dependency. CLEANFILES = \ - include/colm \ gen/parse1.c \ gen/if1.h \ gen/if1.cc \ @@ -198,6 +197,9 @@ CLEANFILES = \ gen/bootstrap2.pack \ gen/bootstrap3.pack +distclean-local: + -rm -rf include + EXTRA_DIST = prog.lm colm.lm loadfinal.cc colm-wrap.sh colm-wrap: colm-wrap.sh -- cgit v1.2.1 From cb0dc1bcb82a9ff4e623a49d05a52ae1f63d0626 Mon Sep 17 00:00:00 2001 From: Victor Westerhuis Date: Fri, 3 Dec 2021 14:28:39 +0100 Subject: Make colm executable buildable in out-of-tree build --- src/Makefile.am | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/Makefile.am b/src/Makefile.am index 9ec58595..ca2d6829 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -135,10 +135,10 @@ bootstrap1_LDADD = libprog.a libcolm.la # and thus generates the sources used in the colm binary. # -gen/bootstrap2.pack: $(builddir)/colm-wrap bootstrap1$(EXEEXT) colm.lm +gen/bootstrap2.pack: colm.lm $(builddir)/colm-wrap bootstrap1$(EXEEXT) mkdir -p gen $(builddir)/colm-wrap -w bootstrap1 -o $@ \ - -c -p gen/parse2.c -e gen/if2.h -x gen/if2.cc colm.lm + -c -p gen/parse2.c -e gen/if2.h -x gen/if2.cc $< gen/parse2.c: gen/bootstrap2.pack $(builddir)/colm-wrap -o $@ $< @@ -157,10 +157,10 @@ bootstrap2_LDADD = libprog.a libcolm.la endif -gen/bootstrap3.pack: $(WRAP_PARSE_3_WITH) $(BUILD_PARSE_3_WITH) prog.lm colm.lm +gen/bootstrap3.pack: prog.lm colm.lm $(WRAP_PARSE_3_WITH) $(BUILD_PARSE_3_WITH) mkdir -p gen $(WRAP_PARSE_3_WITH) -w $(BUILD_PARSE_3_WITH) -o $@ \ - -c -p gen/parse3.c -e gen/if3.h -x gen/if3.cc prog.lm + -c -p gen/parse3.c -e gen/if3.h -x gen/if3.cc -I$(srcdir) $< gen/parse3.c: gen/bootstrap3.pack $(WRAP_PARSE_3_WITH) -o $@ $< -- cgit v1.2.1 From 7e3709188833f72ca7a0808942d3a9da6464675f Mon Sep 17 00:00:00 2001 From: Victor Westerhuis Date: Fri, 3 Dec 2021 23:56:32 +0100 Subject: Clean up more Everything built by make should be cleaned up by make clean, according to the automake manual. --- src/Makefile.am | 1 + 1 file changed, 1 insertion(+) (limited to 'src') diff --git a/src/Makefile.am b/src/Makefile.am index ca2d6829..6953a93c 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -184,6 +184,7 @@ colm_LDADD = libprog.a -lcolm # with the following additional dependency. CLEANFILES = \ + colm-wrap \ gen/parse1.c \ gen/if1.h \ gen/if1.cc \ -- cgit v1.2.1 From bb487b1368b65a1f30fe3a59fd0c7d84bdcc483b Mon Sep 17 00:00:00 2001 From: Victor Westerhuis Date: Sat, 4 Dec 2021 01:06:27 +0100 Subject: Honor CC and CFLAGS environment variables This makes it easier to use a cross-compiler, for example. --- src/main.cc | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/main.cc b/src/main.cc index 2ceb7cf3..3a1db38c 100644 --- a/src/main.cc +++ b/src/main.cc @@ -444,7 +444,16 @@ void runOutputProgram() void compileOutput() { - int length = 1024 + strlen( intermedFn ) + strlen( binaryFn ); + const char *compiler = getenv( "CC" ); + if ( compiler == 0 ) + compiler = "gcc"; + + const char *cflags = getenv( "CFLAGS" ); + if ( cflags == 0 ) + cflags = ""; + + int length = 1024 + strlen( compiler ) + strlen( cflags ) + + strlen( intermedFn ) + strlen( binaryFn ); for ( ArgsVector::Iter af = additionalCodeFiles; af.lte(); af++ ) length += strlen( *af ) + 2; for ( ArgsVector::Iter ip = includePaths; ip.lte(); ip++ ) @@ -453,8 +462,8 @@ void compileOutput() length += strlen( *lp ) + 3; if ( buildDir != 0 ) length += strlen( buildDir ) * 3; -#define COMPILE_COMMAND_STRING "gcc -Wall -Wwrite-strings" \ - " -g" \ +#define COMPILE_COMMAND_STRING "%s -Wall -Wwrite-strings" \ + " -g %s" \ " -o %s" \ " %s" char *command = new char[length]; @@ -465,7 +474,8 @@ void compileOutput() " -I%s/src/include" " -static" " %s/src/libcolm.la", - buildDir, binaryFn, intermedFn, + buildDir, compiler, cflags, + binaryFn, intermedFn, buildDir, buildDir ); } else { @@ -474,6 +484,7 @@ void compileOutput() " -I" PREFIX "/include" " -L" PREFIX "/lib" " -Wl,-rpath," PREFIX "/lib", + compiler, cflags, binaryFn, intermedFn ); } #undef COMPILE_COMMAND_STRING -- cgit v1.2.1 From 7b2524ec0c036a3aab8e97e77c8a94b3dc12fe82 Mon Sep 17 00:00:00 2001 From: Victor Westerhuis Date: Sat, 4 Dec 2021 01:26:36 +0100 Subject: Honor includedir and libdir settings They are usually direct subdirectories of the prefix, but they can be different, for example in Debian's multiarch scheme. --- src/Makefile.am | 3 ++- src/main.cc | 6 +++--- 2 files changed, 5 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/Makefile.am b/src/Makefile.am index 6953a93c..09da4c47 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -52,7 +52,8 @@ endif common_CFLAGS = \ -Wall \ - -DPREFIX='"$(prefix)"' + -DINCLUDEDIR='"$(includedir)"' \ + -DLIBDIR='"$(libdir)"' 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 3a1db38c..06647497 100644 --- a/src/main.cc +++ b/src/main.cc @@ -481,9 +481,9 @@ void compileOutput() else { sprintf( command, COMPILE_COMMAND_STRING - " -I" PREFIX "/include" - " -L" PREFIX "/lib" - " -Wl,-rpath," PREFIX "/lib", + " -I" INCLUDEDIR + " -L" LIBDIR + " -Wl,-rpath," LIBDIR, compiler, cflags, binaryFn, intermedFn ); } -- cgit v1.2.1