summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVictor Westerhuis <victor@westerhu.is>2021-12-04 01:06:27 +0100
committerVictor Westerhuis <victor@westerhu.is>2021-12-04 01:18:06 +0100
commitbb487b1368b65a1f30fe3a59fd0c7d84bdcc483b (patch)
tree0fe93911a53c24f812173ce74cb72075090b4298
parent7e3709188833f72ca7a0808942d3a9da6464675f (diff)
downloadcolm-bb487b1368b65a1f30fe3a59fd0c7d84bdcc483b.tar.gz
Honor CC and CFLAGS environment variables
This makes it easier to use a cross-compiler, for example.
-rw-r--r--Makefile.am2
-rw-r--r--src/main.cc19
2 files changed, 17 insertions, 4 deletions
diff --git a/Makefile.am b/Makefile.am
index 0eb09cb4..aae162ef 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -24,3 +24,5 @@ SUBDIRS = src doc test
dist_doc_DATA = colm.vim
EXTRA_DIST = colm.vim sedsubst
ACLOCAL_AMFLAGS = -I m4
+
+export CC CFLAGS
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