From e5c522e2dbee4d5adff14e920d276b21aadbf009 Mon Sep 17 00:00:00 2001 From: Jean Privat Date: Tue, 11 Nov 2014 10:24:30 -0500 Subject: [PATCH] compiler: copy the binary if the outpath is crazy and cannot used in Makefile Signed-off-by: Jean Privat --- src/compiler/abstract_compiler.nit | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/src/compiler/abstract_compiler.nit b/src/compiler/abstract_compiler.nit index 326c885..abfbf3f 100644 --- a/src/compiler/abstract_compiler.nit +++ b/src/compiler/abstract_compiler.nit @@ -315,7 +315,14 @@ class MakefileToolchain var outname = outfile(mainmodule) - var outpath = compile_dir.relpath(outname).escape_to_mk + var real_outpath = compile_dir.relpath(outname) + var outpath = real_outpath.escape_to_mk + if outpath != real_outpath then + # If the name is crazy and need escaping, we will do an indirection + # 1. generate the binary in the .nit_compile dir under an escaped name + # 2. copy the binary at the right place in the `all` goal. + outpath = mainmodule.c_name + end var makename = makefile_name(mainmodule) var makepath = "{compile_dir}/{makename}" var makefile = new OFStream.open(makepath) @@ -348,7 +355,11 @@ class MakefileToolchain makefile.write("ifdef NEED_LIBUNWIND\n\tLDLIBS += -lunwind\nendif\n") - makefile.write("all: {outpath}\n\n") + makefile.write("all: {outpath}\n") + if outpath != real_outpath then + makefile.write("\tcp -- {outpath.escape_to_sh} {real_outpath.escape_to_sh.replace("$","$$")}") + end + makefile.write("\n") var ofiles = new Array[String] var dep_rules = new Array[String] @@ -415,7 +426,10 @@ endif end makefile.write("{outpath}: {dep_rules.join(" ")}\n\t$(CC) $(LDFLAGS) -o {outpath.escape_to_sh} {ofiles.join(" ")} $(LDLIBS) {pkg}\n\n") # Clean - makefile.write("clean:\n\trm {ofiles.join(" ")} 2>/dev/null\n\n") + makefile.write("clean:\n\trm {ofiles.join(" ")} 2>/dev/null\n") + if outpath != real_outpath then + makefile.write("\trm -- {outpath.escape_to_sh} 2>/dev/null\n") + end makefile.close self.toolcontext.info("Generated makefile: {makepath}", 2) -- 1.7.9.5