//-------------------------------------------------------------------------------------------------- static void GenerateLdFlagsDef ( std::ofstream& script, ///< Build script to write the variable definition to. const model::Component_t* componentPtr, const mk::BuildParams_t& buildParams ) //-------------------------------------------------------------------------------------------------- { script << " ldFlags = "; // Add the ldflags from the Component.cdef file. for (auto& arg : componentPtr->ldFlags) { script << " " << arg; } // Add the library output directory to the list of places to search for libraries to link with. script << " -L" << buildParams.libOutputDir; // Set the DT_RUNPATH variable inside the executable's ELF headers to include the expected // on-target runtime locations of the libraries needed. GenerateRunPathLdFlags(script, buildParams.target); // Includes a list of -l directives for all the libraries the component needs. GetDependentLibLdFlags(script, componentPtr); // Link with the standard runtime libs. script << " \"-L$$LEGATO_BUILD/bin/lib\" -llegato -lpthread -lrt -lm\n"; }
//-------------------------------------------------------------------------------------------------- void GetDependentLibLdFlags ( std::ofstream& script, ///< Build script to write the variable definition to. const model::Component_t* componentPtr ) //-------------------------------------------------------------------------------------------------- { for (auto subComponentPtr : componentPtr->subComponents) { // If the component has itself been built into a library, link with that. if (subComponentPtr->lib != "") { script << " \"-L" << path::GetContainingDir(subComponentPtr->lib) << "\""; script << " -l" << path::GetLibShortName(subComponentPtr->lib); } // Link with whatever this component depends on. GetDependentLibLdFlags(script, subComponentPtr); } }
//-------------------------------------------------------------------------------------------------- static void GenerateBuildStatement ( std::ofstream& script, const model::Exe_t* exePtr, const mk::BuildParams_t& buildParams ) //-------------------------------------------------------------------------------------------------- { auto exePath = exePtr->path; if (!path::IsAbsolute(exePath)) { exePath = "$builddir/" + exePath; } script << "build " << exePath << ": " << GetLinkRule(exePtr) << " $builddir/" << exePtr->mainObjectFile; // Link in all the .o files for C/C++ sources. for (auto sourceFile : exePtr->cSources) { script << " " << GetObjectFile(sourceFile); } for (auto sourceFile : exePtr->cxxSources) { script << " " << GetObjectFile(sourceFile); } // Declare the exe's (implicit) dependencies on all the components' shared libraries. if (!exePtr->componentInstances.empty()) { script << " |"; for (auto componentInstancePtr : exePtr->componentInstances) { script << " " << componentInstancePtr->componentPtr->lib; } } script << "\n"; // Define an exe-specific ldFlags variable that adds all the components' and interfaces' // shared libraries to the linker command line. script << " ldFlags =" // Make the executable able to export symbols to dynamic shared libraries that get loaded. // This is needed so the executable can define executable-specific interface name variables // for component libraries to use. " -rdynamic" // Add the library output directory to the list of places to search for libraries to link with. " -L" << buildParams.libOutputDir; // Set the DT_RUNPATH variable inside the executable's ELF headers to include the expected // on-target runtime locations of the libraries needed. GenerateRunPathLdFlags(script, buildParams.target); // Includes a list of -l directives for all the libraries the executable needs. GetDependentLibLdFlags(script, exePtr); // Link with the standard runtime libs. script << " \"-L$$LEGATO_BUILD/bin/lib\" -llegato -lpthread -lrt -ldl -lm"; // Add ldFlags from earlier definition. script << " $ldFlags\n" "\n"; }