diff options
author | Adrian Thurston <thurston@colm.net> | 2021-12-04 09:48:13 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-12-04 09:48:13 -0800 |
commit | 0856b1a230400fc4358ef00fa422db986f685555 (patch) | |
tree | 720500f71252e0f92ca713512bdaf1c673db0fa9 /src | |
parent | c77aceb85139404a602fbd463f631235f99773d9 (diff) | |
parent | 7b2524ec0c036a3aab8e97e77c8a94b3dc12fe82 (diff) | |
download | colm-0856b1a230400fc4358ef00fa422db986f685555.tar.gz |
Merge pull request #138 from viccie30/fix-out-of-tree-build
Some build system fixes
Diffstat (limited to 'src')
-rw-r--r-- | src/CMakeLists.txt | 2 | ||||
-rw-r--r-- | src/Makefile.am | 19 | ||||
-rw-r--r-- | src/codevect.c | 1 | ||||
-rw-r--r-- | src/main.cc | 124 | ||||
-rw-r--r-- | src/rtvector.h | 35 | ||||
-rw-r--r-- | src/version.h.in | 2 |
6 files changed, 49 insertions, 134 deletions
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 c5fb6efa..09da4c47 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -52,13 +52,14 @@ 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 \ 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 \ @@ -135,10 +136,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 +158,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 $@ $< @@ -184,8 +185,7 @@ colm_LDADD = libprog.a -lcolm # with the following additional dependency. CLEANFILES = \ - version.h \ - include/colm \ + colm-wrap \ gen/parse1.c \ gen/if1.h \ gen/if1.cc \ @@ -199,6 +199,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 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 <string.h> #include <stdlib.h> -#include <colm/rtvector.h> #include <colm/pdarun.h> void init_rt_code_vect( struct rt_code_vect *vect ) diff --git a/src/main.cc b/src/main.cc index 8ca395f0..06647497 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,67 +442,49 @@ 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; - } - } + 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++ ) length += strlen( *ip ) + 3; for ( ArgsVector::Iter lp = libraryPaths; lp.lte(); lp++ ) length += strlen( *lp ) + 3; -#define COMPILE_COMMAND_STRING "gcc -Wall -Wwrite-strings" \ - " -g" \ + if ( buildDir != 0 ) + length += strlen( buildDir ) * 3; +#define COMPILE_COMMAND_STRING "%s -Wall -Wwrite-strings" \ + " -g %s" \ " -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, compiler, cflags, + binaryFn, intermedFn, + buildDir, buildDir ); } 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 ); } #undef COMPILE_COMMAND_STRING @@ -518,7 +501,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 +510,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 +604,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 +760,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(); 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 <thurston@colm.net> - * - * 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 */ - 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 |