]> git.tdb.fi Git - builder.git/commitdiff
Don't rely on component type in determining whether to use -fPIC
authorMikko Rasa <tdb@tdb.fi>
Sun, 5 Oct 2014 23:49:06 +0000 (02:49 +0300)
committerMikko Rasa <tdb@tdb.fi>
Sun, 5 Oct 2014 23:50:05 +0000 (02:50 +0300)
Instead let SharedLibrary set a flag in ObjectFiles and use that.

source/gnucompiler.cpp
source/objectfile.cpp
source/objectfile.h
source/sharedlibrary.cpp

index 1b05a5cb6e99b459ff9f4f3ea3a63f3a8378295f..a86cb59d0567b06f4e88c07a72e2ddbd4dd17d49 100644 (file)
@@ -151,7 +151,7 @@ Task *GnuCompiler::run(const Target &target) const
        }
        if(binfo.threads && architecture->get_system()!="windows" && architecture->get_system()!="darwin")
                argv.push_back("-pthread");
-       if((comp.get_type()==Component::LIBRARY || comp.get_type()==Component::MODULE) && architecture->get_system()!="windows")
+       if(object.is_used_in_shared_library() && architecture->get_system()!="windows")
                argv.push_back("-fPIC");
 
        const Architecture &native_arch = builder.get_native_arch();
index 732fe142400f72159f2f800407c16d6287fce10d..0536755bb26788354d5e147e021f38fe64d0af36 100644 (file)
@@ -11,7 +11,8 @@ using namespace Msp;
 
 ObjectFile::ObjectFile(Builder &b, const Component &c, SourceFile &s):
        FileTarget(b, c.get_package(), generate_target_path(c, s.get_path())),
-       source(s)
+       source(s),
+       used_in_shlib(false)
 {
        component = &c;
        add_dependency(source);
@@ -37,6 +38,11 @@ FS::Path ObjectFile::generate_target_path(const Component &comp, const FS::Path
        return temp_dir/(FS::basepart(fn)+".o");
 }
 
+void ObjectFile::set_used_in_shared_library(bool u)
+{
+       used_in_shlib = u;
+}
+
 void ObjectFile::collect_build_info(BuildInfo &binfo) const
 {
        Target::collect_build_info(binfo);
index 1546a56bea3b5b83b1d48a5c5ed532f9315595e4..48e4482d7ab4a153f251724d02f4f855c01c218c 100644 (file)
@@ -12,6 +12,7 @@ class ObjectFile: public FileTarget
 {
 private:
        SourceFile &source;
+       bool used_in_shlib;
 
 public:
        ObjectFile(Builder &, const Component &, SourceFile &);
@@ -22,6 +23,9 @@ public:
        virtual const char *get_type() const { return "ObjectFile"; }
        SourceFile &get_source() const { return source; }
 
+       void set_used_in_shared_library(bool);
+       bool is_used_in_shared_library() const { return used_in_shlib; }
+
        virtual void collect_build_info(BuildInfo &) const;
 
 private:
index ae44f2cd5751701dff67a5e18dc29183960adb6b..305061a02c5bd7c617ad8c4b8febb57d4ddd8197 100644 (file)
@@ -2,6 +2,7 @@
 #include <msp/strings/format.h>
 #include "builder.h"
 #include "component.h"
+#include "objectfile.h"
 #include "sharedlibrary.h"
 #include "sourcepackage.h"
 
@@ -48,6 +49,9 @@ SharedLibrary::SharedLibrary(Builder &b, const Component &c, const list<ObjectFi
 
                install_filename = soname;
        }
+
+       for(list<ObjectFile *>::const_iterator i=objects.begin(); i!=objects.end(); ++i)
+               (*i)->set_used_in_shared_library(true);
 }
 
 string SharedLibrary::generate_filename(const Component &comp)