From d117fced27de17371e60d15a34fd0200d6d2c81a Mon Sep 17 00:00:00 2001
From: midipix <writeonce@midipix.org>
Date: Fri, 22 Apr 2016 04:27:06 -0400
Subject: compile mode: remove .lo object file prior to invoking the compiler.

---
 src/logic/slbt_exec_compile.c | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)

(limited to 'src/logic')

diff --git a/src/logic/slbt_exec_compile.c b/src/logic/slbt_exec_compile.c
index 53de294..4d645d2 100644
--- a/src/logic/slbt_exec_compile.c
+++ b/src/logic/slbt_exec_compile.c
@@ -13,6 +13,21 @@
 #include <slibtool/slibtool.h>
 #include "slibtool_spawn_impl.h"
 
+static int slbt_exec_compile_remove_file(
+	const struct slbt_driver_ctx *	dctx,
+	struct slbt_exec_ctx *		ectx,
+	const char *			target)
+{
+	/* remove target (if any) */
+	if (!(unlink(target)) || (errno == ENOENT))
+		return 0;
+
+	if (!(dctx->cctx->drvflags & SLBT_DRIVER_SILENT))
+		strerror(errno);
+
+	return -1;
+}
+
 int  slbt_exec_compile(
 	const struct slbt_driver_ctx *	dctx,
 	struct slbt_exec_ctx *		ectx)
@@ -30,6 +45,10 @@ int  slbt_exec_compile(
 	else
 		actx = ectx;
 
+	/* remove old .lo wrapper */
+	if (slbt_exec_compile_remove_file(dctx,ectx,ectx->ltobjname))
+		return -1;
+
 	/* .libs directory */
 	if (dctx->cctx->drvflags & SLBT_DRIVER_SHARED) {
 		if ((fdlibs = open(ectx->ldirname,O_DIRECTORY)) >= 0)
-- 
cgit v1.2.3