//-------------------------------------------------------------------------------------------------- static void GenerateComponentLibBuildStatement ( std::ofstream& script, ///< Build script to write to. const model::Component_t* componentPtr, const mk::BuildParams_t& buildParams ) //-------------------------------------------------------------------------------------------------- { std::string rule; // Determine which rules should be used for building the component. if (!componentPtr->cxxSources.empty()) { rule = "LinkCxxLib"; } else if (!componentPtr->cSources.empty()) { rule = "LinkCLib"; } else { // No source files. No library to build. return; } // Create the build statement. script << "build " << componentPtr->lib << ": " << rule; // Includes object files compiled from the component's C/C++ source files. for (auto sourceFile : componentPtr->cSources) { script << " " << GetObjectFile(sourceFile); } for (auto sourceFile : componentPtr->cxxSources) { script << " " << GetObjectFile(sourceFile); } // Also includes all the object files for the auto-generated IPC API client and server // code for the component's required and provided APIs. for (auto apiPtr : componentPtr->clientApis) { script << " $builddir/" << apiPtr->objectFile; } for (auto apiPtr : componentPtr->serverApis) { script << " $builddir/" << apiPtr->objectFile; } // And the object file for the component-specific generated code in _componentMain.c. script << " $builddir/" << componentPtr->workingDir << "/obj/_componentMain.c.o"; // Add implicit dependencies. std::stringstream implicitDependencies; GetSubComponentLibs(implicitDependencies, componentPtr); if (!implicitDependencies.str().empty()) { script << " |" << implicitDependencies.str(); } script << "\n"; // Define the ldFlags variable. GenerateLdFlagsDef(script, componentPtr, buildParams); script << "\n"; }
//-------------------------------------------------------------------------------------------------- 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"; }