cmMakefileLibraryTargetGenerator.cxx 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616
  1. /*=========================================================================
  2. Program: CMake - Cross-Platform Makefile Generator
  3. Module: $RCSfile$
  4. Language: C++
  5. Date: $Date$
  6. Version: $Revision$
  7. Copyright (c) 2002 Kitware, Inc., Insight Consortium. All rights reserved.
  8. See Copyright.txt or http://www.cmake.org/HTML/Copyright.html for details.
  9. This software is distributed WITHOUT ANY WARRANTY; without even
  10. the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  11. PURPOSE. See the above copyright notices for more information.
  12. =========================================================================*/
  13. #include "cmMakefileLibraryTargetGenerator.h"
  14. #include "cmGeneratedFileStream.h"
  15. #include "cmGlobalGenerator.h"
  16. #include "cmLocalUnixMakefileGenerator3.h"
  17. #include "cmMakefile.h"
  18. #include "cmSourceFile.h"
  19. #include "cmTarget.h"
  20. #include "cmake.h"
  21. #include <memory> // auto_ptr
  22. //----------------------------------------------------------------------------
  23. void cmMakefileLibraryTargetGenerator::WriteRuleFiles()
  24. {
  25. // create the build.make file and directory, put in the common blocks
  26. this->CreateRuleFile();
  27. // write rules used to help build object files
  28. this->WriteCommonCodeRules();
  29. // write in rules for object files and custom commands
  30. this->WriteTargetBuildRules();
  31. // write the per-target per-language flags
  32. this->WriteTargetLanguageFlags();
  33. // Write the dependency generation rule.
  34. this->WriteTargetDependRules();
  35. // write the link rules
  36. // Write the rule for this target type.
  37. switch(this->Target->GetType())
  38. {
  39. case cmTarget::STATIC_LIBRARY:
  40. this->WriteStaticLibraryRules();
  41. break;
  42. case cmTarget::SHARED_LIBRARY:
  43. this->WriteSharedLibraryRules(false);
  44. if(this->Target->NeedRelinkBeforeInstall())
  45. {
  46. // Write rules to link an installable version of the target.
  47. this->WriteSharedLibraryRules(true);
  48. }
  49. break;
  50. case cmTarget::MODULE_LIBRARY:
  51. this->WriteModuleLibraryRules(false);
  52. if(this->Target->NeedRelinkBeforeInstall())
  53. {
  54. // Write rules to link an installable version of the target.
  55. this->WriteModuleLibraryRules(true);
  56. }
  57. break;
  58. default:
  59. // If language is not known, this is an error.
  60. cmSystemTools::Error("Unknown Library Type");
  61. break;
  62. }
  63. // Write the requires target.
  64. this->WriteTargetRequiresRules();
  65. // Write clean target
  66. this->WriteTargetCleanRules();
  67. // close the streams
  68. this->CloseFileStreams();
  69. }
  70. //----------------------------------------------------------------------------
  71. void cmMakefileLibraryTargetGenerator::WriteStaticLibraryRules()
  72. {
  73. const char* linkLanguage =
  74. this->Target->GetLinkerLanguage(this->GlobalGenerator);
  75. std::string linkRuleVar = "CMAKE_";
  76. if (linkLanguage)
  77. {
  78. linkRuleVar += linkLanguage;
  79. }
  80. linkRuleVar += "_CREATE_STATIC_LIBRARY";
  81. std::string extraFlags;
  82. this->LocalGenerator->AppendFlags
  83. (extraFlags,this->Target->GetProperty("STATIC_LIBRARY_FLAGS"));
  84. this->WriteLibraryRules(linkRuleVar.c_str(), extraFlags.c_str(), false);
  85. }
  86. //----------------------------------------------------------------------------
  87. void cmMakefileLibraryTargetGenerator::WriteSharedLibraryRules(bool relink)
  88. {
  89. const char* linkLanguage =
  90. this->Target->GetLinkerLanguage(this->GlobalGenerator);
  91. std::string linkRuleVar = "CMAKE_";
  92. if (linkLanguage)
  93. {
  94. linkRuleVar += linkLanguage;
  95. }
  96. linkRuleVar += "_CREATE_SHARED_LIBRARY";
  97. std::string extraFlags;
  98. this->LocalGenerator->AppendFlags
  99. (extraFlags, this->Target->GetProperty("LINK_FLAGS"));
  100. std::string linkFlagsConfig = "LINK_FLAGS_";
  101. linkFlagsConfig +=
  102. cmSystemTools::UpperCase(this->LocalGenerator->ConfigurationName.c_str());
  103. this->LocalGenerator->AppendFlags
  104. (extraFlags, this->Target->GetProperty(linkFlagsConfig.c_str()));
  105. this->LocalGenerator->AddConfigVariableFlags
  106. (extraFlags, "CMAKE_SHARED_LINKER_FLAGS",
  107. this->LocalGenerator->ConfigurationName.c_str());
  108. if(this->Makefile->IsOn("WIN32") && !(this->Makefile->IsOn("CYGWIN")
  109. || this->Makefile->IsOn("MINGW")))
  110. {
  111. const std::vector<cmSourceFile*>& sources =
  112. this->Target->GetSourceFiles();
  113. for(std::vector<cmSourceFile*>::const_iterator i = sources.begin();
  114. i != sources.end(); ++i)
  115. {
  116. if((*i)->GetSourceExtension() == "def")
  117. {
  118. extraFlags += " ";
  119. extraFlags +=
  120. this->Makefile->GetSafeDefinition("CMAKE_LINK_DEF_FILE_FLAG");
  121. extraFlags +=
  122. this->Convert((*i)->GetFullPath().c_str(),
  123. cmLocalGenerator::START_OUTPUT,
  124. cmLocalGenerator::MAKEFILE);
  125. }
  126. }
  127. }
  128. this->WriteLibraryRules(linkRuleVar.c_str(), extraFlags.c_str(), relink);
  129. }
  130. //----------------------------------------------------------------------------
  131. void cmMakefileLibraryTargetGenerator::WriteModuleLibraryRules(bool relink)
  132. {
  133. const char* linkLanguage =
  134. this->Target->GetLinkerLanguage(this->GlobalGenerator);
  135. std::string linkRuleVar = "CMAKE_";
  136. if (linkLanguage)
  137. {
  138. linkRuleVar += linkLanguage;
  139. }
  140. linkRuleVar += "_CREATE_SHARED_MODULE";
  141. std::string extraFlags;
  142. this->LocalGenerator->AppendFlags(extraFlags,
  143. this->Target->GetProperty("LINK_FLAGS"));
  144. std::string linkFlagsConfig = "LINK_FLAGS_";
  145. linkFlagsConfig +=
  146. cmSystemTools::UpperCase(this->LocalGenerator->ConfigurationName.c_str());
  147. this->LocalGenerator->AppendFlags
  148. (extraFlags, this->Target->GetProperty(linkFlagsConfig.c_str()));
  149. this->LocalGenerator->AddConfigVariableFlags
  150. (extraFlags, "CMAKE_MODULE_LINKER_FLAGS",
  151. this->LocalGenerator->ConfigurationName.c_str());
  152. // TODO: .def files should be supported here also.
  153. this->WriteLibraryRules(linkRuleVar.c_str(), extraFlags.c_str(), relink);
  154. }
  155. //----------------------------------------------------------------------------
  156. void cmMakefileLibraryTargetGenerator::WriteLibraryRules
  157. (const char* linkRuleVar, const char* extraFlags, bool relink)
  158. {
  159. // TODO: Merge the methods that call this method to avoid
  160. // code duplication.
  161. std::vector<std::string> commands;
  162. std::string relPath = this->LocalGenerator->GetHomeRelativeOutputPath();
  163. std::string objTarget;
  164. // Build list of dependencies.
  165. std::vector<std::string> depends;
  166. for(std::vector<std::string>::const_iterator obj = this->Objects.begin();
  167. obj != this->Objects.end(); ++obj)
  168. {
  169. objTarget = relPath;
  170. objTarget += *obj;
  171. depends.push_back(objTarget);
  172. }
  173. // Add dependencies on targets that must be built first.
  174. this->AppendTargetDepends(depends);
  175. // Add a dependency on the rule file itself.
  176. this->LocalGenerator->AppendRuleDepend(depends,
  177. this->BuildFileNameFull.c_str());
  178. for(std::vector<std::string>::const_iterator obj
  179. = this->ExternalObjects.begin();
  180. obj != this->ExternalObjects.end(); ++obj)
  181. {
  182. depends.push_back(*obj);
  183. }
  184. // Get the language to use for linking this library.
  185. const char* linkLanguage =
  186. this->Target->GetLinkerLanguage(this->GlobalGenerator);
  187. // Make sure we have a link language.
  188. if(!linkLanguage)
  189. {
  190. cmSystemTools::Error("Cannot determine link language for target \"",
  191. this->Target->GetName(), "\".");
  192. return;
  193. }
  194. // Create set of linking flags.
  195. std::string linkFlags;
  196. this->LocalGenerator->AppendFlags(linkFlags, extraFlags);
  197. // Construct the name of the library.
  198. std::string targetName;
  199. std::string targetNameSO;
  200. std::string targetNameReal;
  201. std::string targetNameImport;
  202. this->Target->GetLibraryNames(
  203. targetName, targetNameSO, targetNameReal, targetNameImport,
  204. this->LocalGenerator->ConfigurationName.c_str());
  205. // Construct the full path version of the names.
  206. std::string outpath = this->LocalGenerator->LibraryOutputPath;
  207. if(outpath.length() == 0)
  208. {
  209. outpath = this->Makefile->GetStartOutputDirectory();
  210. outpath += "/";
  211. }
  212. if(relink)
  213. {
  214. outpath = this->Makefile->GetStartOutputDirectory();
  215. outpath += cmake::GetCMakeFilesDirectory();
  216. outpath += "/CMakeRelink.dir";
  217. cmSystemTools::MakeDirectory(outpath.c_str());
  218. outpath += "/";
  219. }
  220. std::string targetFullPath = outpath + targetName;
  221. std::string targetFullPathPDB =
  222. outpath + this->Target->GetName() + std::string(".pdb");
  223. std::string targetFullPathSO = outpath + targetNameSO;
  224. std::string targetFullPathReal = outpath + targetNameReal;
  225. std::string targetFullPathImport = outpath + targetNameImport;
  226. // Construct the output path version of the names for use in command
  227. // arguments.
  228. std::string targetOutPathPDB =
  229. this->Convert(targetFullPathPDB.c_str(),cmLocalGenerator::FULL,
  230. cmLocalGenerator::MAKEFILE);
  231. std::string targetOutPath =
  232. this->Convert(targetFullPath.c_str(),cmLocalGenerator::START_OUTPUT,
  233. cmLocalGenerator::MAKEFILE);
  234. std::string targetOutPathSO =
  235. this->Convert(targetFullPathSO.c_str(),cmLocalGenerator::START_OUTPUT,
  236. cmLocalGenerator::MAKEFILE);
  237. std::string targetOutPathReal =
  238. this->Convert(targetFullPathReal.c_str(),cmLocalGenerator::START_OUTPUT,
  239. cmLocalGenerator::MAKEFILE);
  240. std::string targetOutPathImport =
  241. this->Convert(targetFullPathImport.c_str(),cmLocalGenerator::START_OUTPUT,
  242. cmLocalGenerator::MAKEFILE);
  243. // Add the link message.
  244. std::string buildEcho = "Linking ";
  245. buildEcho += linkLanguage;
  246. const char* forbiddenFlagVar = 0;
  247. switch(this->Target->GetType())
  248. {
  249. case cmTarget::STATIC_LIBRARY:
  250. buildEcho += " static library ";
  251. break;
  252. case cmTarget::SHARED_LIBRARY:
  253. forbiddenFlagVar = "_CREATE_SHARED_LIBRARY_FORBIDDEN_FLAGS";
  254. buildEcho += " shared library ";
  255. break;
  256. case cmTarget::MODULE_LIBRARY:
  257. forbiddenFlagVar = "_CREATE_SHARED_MODULE_FORBIDDEN_FLAGS";
  258. buildEcho += " shared module ";
  259. break;
  260. default:
  261. buildEcho += " library ";
  262. break;
  263. }
  264. buildEcho += targetOutPath.c_str();
  265. this->LocalGenerator->AppendEcho(commands, buildEcho.c_str(),
  266. cmLocalUnixMakefileGenerator3::EchoLink);
  267. // Construct a list of files associated with this library that may
  268. // need to be cleaned.
  269. std::vector<std::string> libCleanFiles;
  270. {
  271. std::string cleanStaticName;
  272. std::string cleanSharedName;
  273. std::string cleanSharedSOName;
  274. std::string cleanSharedRealName;
  275. std::string cleanImportName;
  276. this->Target->GetLibraryCleanNames(
  277. cleanStaticName,
  278. cleanSharedName,
  279. cleanSharedSOName,
  280. cleanSharedRealName,
  281. cleanImportName,
  282. this->LocalGenerator->ConfigurationName.c_str());
  283. std::string cleanFullStaticName = outpath + cleanStaticName;
  284. std::string cleanFullSharedName = outpath + cleanSharedName;
  285. std::string cleanFullSharedSOName = outpath + cleanSharedSOName;
  286. std::string cleanFullSharedRealName = outpath + cleanSharedRealName;
  287. std::string cleanFullImportName = outpath + cleanImportName;
  288. libCleanFiles.push_back
  289. (this->Convert(cleanFullStaticName.c_str(),cmLocalGenerator::START_OUTPUT,
  290. cmLocalGenerator::UNCHANGED));
  291. if(cleanSharedRealName != cleanStaticName)
  292. {
  293. libCleanFiles.push_back(this->Convert(cleanFullSharedRealName.c_str(),
  294. cmLocalGenerator::START_OUTPUT,
  295. cmLocalGenerator::UNCHANGED));
  296. }
  297. if(cleanSharedSOName != cleanStaticName &&
  298. cleanSharedSOName != cleanSharedRealName)
  299. {
  300. libCleanFiles.push_back(this->Convert(cleanFullSharedSOName.c_str(),
  301. cmLocalGenerator::START_OUTPUT,
  302. cmLocalGenerator::UNCHANGED));
  303. }
  304. if(cleanSharedName != cleanStaticName &&
  305. cleanSharedName != cleanSharedSOName &&
  306. cleanSharedName != cleanSharedRealName)
  307. {
  308. libCleanFiles.push_back(this->Convert(cleanFullSharedName.c_str(),
  309. cmLocalGenerator::START_OUTPUT,
  310. cmLocalGenerator::UNCHANGED));
  311. }
  312. if(!cleanImportName.empty() &&
  313. cleanImportName != cleanStaticName &&
  314. cleanImportName != cleanSharedSOName &&
  315. cleanImportName != cleanSharedRealName &&
  316. cleanImportName != cleanSharedName)
  317. {
  318. libCleanFiles.push_back(this->Convert(cleanFullImportName.c_str(),
  319. cmLocalGenerator::START_OUTPUT,
  320. cmLocalGenerator::UNCHANGED));
  321. }
  322. }
  323. // Add a command to remove any existing files for this library.
  324. std::vector<std::string> commands1;
  325. this->LocalGenerator->AppendCleanCommand(commands1, libCleanFiles,
  326. *this->Target, "target");
  327. this->LocalGenerator->CreateCDCommand
  328. (commands1,
  329. this->Makefile->GetStartOutputDirectory(),
  330. this->Makefile->GetHomeOutputDirectory());
  331. commands.insert(commands.end(), commands1.begin(), commands1.end());
  332. commands1.clear();
  333. // Add the pre-build and pre-link rules building but not when relinking.
  334. if(!relink)
  335. {
  336. this->LocalGenerator
  337. ->AppendCustomCommands(commands, this->Target->GetPreBuildCommands());
  338. this->LocalGenerator
  339. ->AppendCustomCommands(commands, this->Target->GetPreLinkCommands());
  340. }
  341. // Open the link script if it will be used.
  342. bool useLinkScript = false;
  343. std::string linkScriptName;
  344. std::auto_ptr<cmGeneratedFileStream> linkScriptStream;
  345. if(this->GlobalGenerator->GetUseLinkScript() &&
  346. (this->Target->GetType() == cmTarget::STATIC_LIBRARY ||
  347. this->Target->GetType() == cmTarget::SHARED_LIBRARY ||
  348. this->Target->GetType() == cmTarget::MODULE_LIBRARY))
  349. {
  350. useLinkScript = true;
  351. linkScriptName = this->TargetBuildDirectoryFull;
  352. if(relink)
  353. {
  354. linkScriptName += "/relink.txt";
  355. }
  356. else
  357. {
  358. linkScriptName += "/link.txt";
  359. }
  360. std::auto_ptr<cmGeneratedFileStream> lss(
  361. new cmGeneratedFileStream(linkScriptName.c_str()));
  362. linkScriptStream = lss;
  363. }
  364. std::vector<std::string> link_script_commands;
  365. // Construct the main link rule.
  366. std::string linkRule = this->Makefile->GetRequiredDefinition(linkRuleVar);
  367. if(useLinkScript)
  368. {
  369. cmSystemTools::ExpandListArgument(linkRule, link_script_commands);
  370. std::string link_command = "$(CMAKE_COMMAND) -E cmake_link_script ";
  371. link_command += this->Convert(linkScriptName.c_str(),
  372. cmLocalGenerator::START_OUTPUT,
  373. cmLocalGenerator::SHELL);
  374. link_command += " --verbose=$(VERBOSE)";
  375. commands1.push_back(link_command);
  376. }
  377. else
  378. {
  379. cmSystemTools::ExpandListArgument(linkRule, commands1);
  380. }
  381. this->LocalGenerator->CreateCDCommand
  382. (commands1,
  383. this->Makefile->GetStartOutputDirectory(),
  384. this->Makefile->GetHomeOutputDirectory());
  385. commands.insert(commands.end(), commands1.begin(), commands1.end());
  386. // Add a rule to create necessary symlinks for the library.
  387. if(targetOutPath != targetOutPathReal)
  388. {
  389. std::string symlink = "$(CMAKE_COMMAND) -E cmake_symlink_library ";
  390. symlink += targetOutPathReal;
  391. symlink += " ";
  392. symlink += targetOutPathSO;
  393. symlink += " ";
  394. symlink += targetOutPath;
  395. commands1.clear();
  396. commands1.push_back(symlink);
  397. this->LocalGenerator->CreateCDCommand(commands1,
  398. this->Makefile->GetStartOutputDirectory(),
  399. this->Makefile->GetHomeOutputDirectory());
  400. commands.insert(commands.end(), commands1.begin(), commands1.end());
  401. }
  402. // Add the post-build rules when building but not when relinking.
  403. if(!relink)
  404. {
  405. this->LocalGenerator->
  406. AppendCustomCommands(commands, this->Target->GetPostBuildCommands());
  407. }
  408. // Collect up flags to link in needed libraries.
  409. cmOStringStream linklibs;
  410. this->LocalGenerator->OutputLinkLibraries(linklibs, *this->Target, relink);
  411. // Construct object file lists that may be needed to expand the
  412. // rule.
  413. std::string variableName;
  414. std::string variableNameExternal;
  415. this->WriteObjectsVariable(variableName, variableNameExternal);
  416. std::string buildObjs;
  417. if(useLinkScript)
  418. {
  419. this->WriteObjectsString(buildObjs);
  420. }
  421. else
  422. {
  423. buildObjs = "$(";
  424. buildObjs += variableName;
  425. buildObjs += ") $(";
  426. buildObjs += variableNameExternal;
  427. buildObjs += ")";
  428. }
  429. std::string cleanObjs = "$(";
  430. cleanObjs += variableName;
  431. cleanObjs += ")";
  432. cmLocalGenerator::RuleVariables vars;
  433. vars.TargetPDB = targetOutPathPDB.c_str();
  434. vars.Language = linkLanguage;
  435. vars.Objects = buildObjs.c_str();
  436. std::string objdir = cmake::GetCMakeFilesDirectoryPostSlash();
  437. objdir += this->Target->GetName();
  438. objdir += ".dir";
  439. vars.ObjectDir = objdir.c_str();
  440. vars.Target = targetOutPathReal.c_str();
  441. std::string linkString = linklibs.str();
  442. vars.LinkLibraries = linkString.c_str();
  443. vars.ObjectsQuoted = buildObjs.c_str();
  444. vars.TargetSOName= targetNameSO.c_str();
  445. vars.LinkFlags = linkFlags.c_str();
  446. // Compute the directory portion of the install_name setting.
  447. std::string install_name_dir;
  448. if(this->Target->GetType() == cmTarget::SHARED_LIBRARY)
  449. {
  450. // Select whether to generate an install_name directory for the
  451. // install tree or the build tree.
  452. const char* config = this->LocalGenerator->ConfigurationName.c_str();
  453. if(this->Target->GetPropertyAsBool("BUILD_WITH_INSTALL_RPATH"))
  454. {
  455. install_name_dir =
  456. this->Target->GetInstallNameDirForInstallTree(config);
  457. }
  458. else
  459. {
  460. install_name_dir =
  461. this->Target->GetInstallNameDirForBuildTree(config);
  462. }
  463. // Set the rule variable replacement value.
  464. if(install_name_dir.empty())
  465. {
  466. vars.TargetInstallNameDir = "";
  467. }
  468. else
  469. {
  470. // Convert to a path for the native build tool.
  471. install_name_dir =
  472. this->LocalGenerator->Convert(install_name_dir.c_str(),
  473. cmLocalGenerator::FULL,
  474. cmLocalGenerator::SHELL, false);
  475. // The Convert method seems to strip trailing slashes, which should
  476. // probably be fixed. Since the only platform supporting install_name
  477. // right now uses forward slashes just add one.
  478. install_name_dir += "/";
  479. vars.TargetInstallNameDir = install_name_dir.c_str();
  480. }
  481. }
  482. std::string langFlags;
  483. this->LocalGenerator
  484. ->AddLanguageFlags(langFlags, linkLanguage,
  485. this->LocalGenerator->ConfigurationName.c_str());
  486. // remove any language flags that might not work with the
  487. // particular os
  488. if(forbiddenFlagVar)
  489. {
  490. this->RemoveForbiddenFlags(forbiddenFlagVar,
  491. linkLanguage, langFlags);
  492. }
  493. vars.LanguageCompileFlags = langFlags.c_str();
  494. // Expand placeholders in the commands.
  495. this->LocalGenerator->TargetImplib = targetOutPathImport;
  496. if(useLinkScript)
  497. {
  498. for(std::vector<std::string>::iterator i = link_script_commands.begin();
  499. i != link_script_commands.end(); ++i)
  500. {
  501. this->LocalGenerator->ExpandRuleVariables(*i, vars);
  502. }
  503. }
  504. else
  505. {
  506. for(std::vector<std::string>::iterator i = commands.begin();
  507. i != commands.end(); ++i)
  508. {
  509. this->LocalGenerator->ExpandRuleVariables(*i, vars);
  510. }
  511. }
  512. this->LocalGenerator->TargetImplib = "";
  513. // Optionally convert the build rule to use a script to avoid long
  514. // command lines in the make shell.
  515. if(useLinkScript)
  516. {
  517. for(std::vector<std::string>::iterator cmd = link_script_commands.begin();
  518. cmd != link_script_commands.end(); ++cmd)
  519. {
  520. // Do not write out empty commands or commands beginning in the
  521. // shell no-op ":".
  522. if(!cmd->empty() && (*cmd)[0] != ':')
  523. {
  524. (*linkScriptStream) << *cmd << "\n";
  525. }
  526. }
  527. }
  528. // Write the build rule.
  529. this->LocalGenerator->WriteMakeRule(*this->BuildFileStream, 0,
  530. targetFullPathReal.c_str(),
  531. depends, commands, false);
  532. // The symlink names for the target should depend on the real target
  533. // so if the target version changes it rebuilds and recreates the
  534. // symlinks.
  535. if(targetFullPathSO != targetFullPathReal)
  536. {
  537. depends.clear();
  538. commands.clear();
  539. depends.push_back(targetFullPathReal.c_str());
  540. this->LocalGenerator->WriteMakeRule(*this->BuildFileStream, 0,
  541. targetFullPathSO.c_str(),
  542. depends, commands, false);
  543. }
  544. if(targetFullPath != targetFullPathSO)
  545. {
  546. depends.clear();
  547. commands.clear();
  548. depends.push_back(targetFullPathSO.c_str());
  549. this->LocalGenerator->WriteMakeRule(*this->BuildFileStream, 0,
  550. targetFullPath.c_str(),
  551. depends, commands, false);
  552. }
  553. // Write the main driver rule to build everything in this target.
  554. this->WriteTargetDriverRule(targetFullPath.c_str(), relink);
  555. // Clean all the possible library names and symlinks and object files.
  556. this->CleanFiles.insert(this->CleanFiles.end(),
  557. libCleanFiles.begin(),libCleanFiles.end());
  558. this->CleanFiles.insert(this->CleanFiles.end(),
  559. this->Objects.begin(),
  560. this->Objects.end());
  561. }