From adc34616ee2da59bd3d57ee59b2d5934e97f396f Mon Sep 17 00:00:00 2001
From: Zuzana Baranova <xbaranov@fi.muni.cz>
Date: Mon, 2 Apr 2018 13:46:52 +0000
Subject: [PATCH] tools: Better mimic gcc in file naming so that divcc can work
 with CMake.

---
 tools/divcc.cpp | 15 +++++++++++++--
 1 file changed, 13 insertions(+), 2 deletions(-)

diff --git a/tools/divcc.cpp b/tools/divcc.cpp
index 8371b4cf0..aa3a5532c 100644
--- a/tools/divcc.cpp
+++ b/tools/divcc.cpp
@@ -226,6 +226,8 @@ std::unique_ptr< llvm::Module > llvmExtract( std::vector< std::pair< std::string
         }
 
         auto bc = llvm::object::IRObjectFile::findBitcodeInMemBuffer( (*buf.get()).getMemBufferRef() );
+        if ( !bc ) std::cerr << "No .llvmbc section found in file " << file.second << "." << std::endl;
+
         std::unique_ptr< llvm::Module > m = std::move( llvm::parseBitcodeFile( bc.get(), *clang.context().get()).get() );
         m->setTargetTriple( "x86_64-unknown-none-elf" );
         verifyModule( *m );
@@ -260,6 +262,7 @@ int main( int argc, char **argv )
         auto po = cc::parseOpts( opts );
 
         using brick::fs::joinPath;
+        using brick::fs::absolutePrefix;
         using divine::cc::includeDir;
 
         po.opts.insert( po.opts.end(), {
@@ -296,8 +299,16 @@ int main( int argc, char **argv )
             {
                 std::string ifn = srcFile.get< cc::File >().name;
                 std::string ofn = brick::fs::dropExtension( ifn );
-                if ( po.outputFile != "" ) ofn += ".temp";
-                ofn += ".o";
+                auto abs = absolutePrefix( ofn );
+                ofn = abs.second;
+                if ( po.outputFile != "" && po.toObjectOnly )
+                    ofn = po.outputFile;
+                else
+                {
+                    if ( po.outputFile != "" )
+                        ofn += ".temp";
+                    ofn += ".o";
+                }
 
                 if ( isType( ifn, FileType::Obj ) || isType( ifn, FileType::Archive ) )
                     ofn = ifn;
-- 
GitLab