From: Mikko Rasa Date: Sun, 5 Oct 2014 23:49:06 +0000 (+0300) Subject: Don't rely on component type in determining whether to use -fPIC X-Git-Url: http://git.tdb.fi/?p=builder.git;a=commitdiff_plain;h=0f7867524bf87a389ff5d4f9d3290d68a254b693 Don't rely on component type in determining whether to use -fPIC Instead let SharedLibrary set a flag in ObjectFiles and use that. --- diff --git a/source/gnucompiler.cpp b/source/gnucompiler.cpp index 1b05a5c..a86cb59 100644 --- a/source/gnucompiler.cpp +++ b/source/gnucompiler.cpp @@ -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(); diff --git a/source/objectfile.cpp b/source/objectfile.cpp index 732fe14..0536755 100644 --- a/source/objectfile.cpp +++ b/source/objectfile.cpp @@ -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); diff --git a/source/objectfile.h b/source/objectfile.h index 1546a56..48e4482 100644 --- a/source/objectfile.h +++ b/source/objectfile.h @@ -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: diff --git a/source/sharedlibrary.cpp b/source/sharedlibrary.cpp index ae44f2c..305061a 100644 --- a/source/sharedlibrary.cpp +++ b/source/sharedlibrary.cpp @@ -2,6 +2,7 @@ #include #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::const_iterator i=objects.begin(); i!=objects.end(); ++i) + (*i)->set_used_in_shared_library(true); } string SharedLibrary::generate_filename(const Component &comp)