cmLocalUnixMakefileGenerator.cxx 95 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844
  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 "cmGlobalGenerator.h"
  14. #include "cmLocalUnixMakefileGenerator.h"
  15. #include "cmMakefile.h"
  16. #include "cmSystemTools.h"
  17. #include "cmSourceFile.h"
  18. #include "cmMakeDepend.h"
  19. #include "cmCacheManager.h"
  20. #include "cmGeneratedFileStream.h"
  21. #include <cmsys/RegularExpression.hxx>
  22. #include <stdio.h>
  23. cmLocalUnixMakefileGenerator::cmLocalUnixMakefileGenerator()
  24. {
  25. m_WindowsShell = false;
  26. m_IncludeDirective = "include";
  27. m_MakefileVariableSize = 0;
  28. m_IgnoreLibPrefix = false;
  29. }
  30. cmLocalUnixMakefileGenerator::~cmLocalUnixMakefileGenerator()
  31. {
  32. }
  33. void cmLocalUnixMakefileGenerator::Generate(bool fromTheTop)
  34. {
  35. // suppoirt override in output directories
  36. if (m_Makefile->GetDefinition("LIBRARY_OUTPUT_PATH"))
  37. {
  38. m_LibraryOutputPath = m_Makefile->GetDefinition("LIBRARY_OUTPUT_PATH");
  39. if(m_LibraryOutputPath.size())
  40. {
  41. if(m_LibraryOutputPath[m_LibraryOutputPath.size() -1] != '/')
  42. {
  43. m_LibraryOutputPath += "/";
  44. }
  45. if(!cmSystemTools::MakeDirectory(m_LibraryOutputPath.c_str()))
  46. {
  47. cmSystemTools::Error("Error failed create "
  48. "LIBRARY_OUTPUT_PATH directory:",
  49. m_LibraryOutputPath.c_str());
  50. }
  51. m_Makefile->AddLinkDirectory(m_LibraryOutputPath.c_str());
  52. }
  53. }
  54. if (m_Makefile->GetDefinition("EXECUTABLE_OUTPUT_PATH"))
  55. {
  56. m_ExecutableOutputPath =
  57. m_Makefile->GetDefinition("EXECUTABLE_OUTPUT_PATH");
  58. if(m_ExecutableOutputPath.size())
  59. {
  60. if(m_ExecutableOutputPath[m_ExecutableOutputPath.size() -1] != '/')
  61. {
  62. m_ExecutableOutputPath += "/";
  63. }
  64. if(!cmSystemTools::MakeDirectory(m_ExecutableOutputPath.c_str()))
  65. {
  66. cmSystemTools::Error("Error failed to create "
  67. "EXECUTABLE_OUTPUT_PATH directory:",
  68. m_ExecutableOutputPath.c_str());
  69. }
  70. m_Makefile->AddLinkDirectory(m_ExecutableOutputPath.c_str());
  71. }
  72. }
  73. if (!fromTheTop)
  74. {
  75. // Generate depends
  76. cmMakeDepend md;
  77. md.SetMakefile(m_Makefile);
  78. md.GenerateMakefileDependencies();
  79. this->ProcessDepends(md);
  80. }
  81. // output the makefile fragment
  82. std::string dest = m_Makefile->GetStartOutputDirectory();
  83. dest += "/Makefile";
  84. this->OutputMakefile(dest.c_str(), !fromTheTop);
  85. }
  86. void
  87. cmLocalUnixMakefileGenerator::AddDependenciesToSourceFile(cmDependInformation const *info,
  88. cmSourceFile *i,
  89. std::set<cmDependInformation const*> *visited)
  90. {
  91. // add info to the visited set
  92. visited->insert(info);
  93. // add this dependency and the recurse
  94. // now recurse with info's dependencies
  95. for(cmDependInformation::DependencySet::const_iterator d =
  96. info->m_DependencySet.begin();
  97. d != info->m_DependencySet.end(); ++d)
  98. {
  99. if (visited->find(*d) == visited->end())
  100. {
  101. if((*d)->m_FullPath != "")
  102. {
  103. i->GetDepends().push_back((*d)->m_FullPath);
  104. }
  105. this->AddDependenciesToSourceFile(*d,i,visited);
  106. }
  107. }
  108. }
  109. void cmLocalUnixMakefileGenerator::ProcessDepends(const cmMakeDepend &md)
  110. {
  111. // Now create cmDependInformation objects for files in the directory
  112. cmTargets &tgts = m_Makefile->GetTargets();
  113. for(cmTargets::iterator l = tgts.begin(); l != tgts.end(); l++)
  114. {
  115. std::vector<cmSourceFile*> &classes = l->second.GetSourceFiles();
  116. for(std::vector<cmSourceFile*>::iterator i = classes.begin();
  117. i != classes.end(); ++i)
  118. {
  119. if(!(*i)->GetPropertyAsBool("HEADER_FILE_ONLY"))
  120. {
  121. // get the depends
  122. const cmDependInformation *info =
  123. md.GetDependInformationForSourceFile(*(*i));
  124. // Delete any hints from the source file's dependencies.
  125. (*i)->GetDepends().erase((*i)->GetDepends().begin(), (*i)->GetDepends().end());
  126. // Now add the real dependencies for the file.
  127. if (info)
  128. {
  129. // create visited set
  130. std::set<cmDependInformation const*> visited;
  131. this->AddDependenciesToSourceFile(info,*i, &visited);
  132. }
  133. }
  134. }
  135. }
  136. }
  137. // This is where CMakeTargets.make is generated
  138. void cmLocalUnixMakefileGenerator::OutputMakefile(const char* file,
  139. bool withDepends)
  140. {
  141. // Create sub directories fro aux source directories
  142. std::vector<std::string>& auxSourceDirs =
  143. m_Makefile->GetAuxSourceDirectories();
  144. if( auxSourceDirs.size() )
  145. {
  146. // For the case when this is running as a remote build
  147. // on unix, make the directory
  148. for(std::vector<std::string>::iterator i = auxSourceDirs.begin();
  149. i != auxSourceDirs.end(); ++i)
  150. {
  151. if(i->c_str()[0] != '/')
  152. {
  153. std::string dir = m_Makefile->GetCurrentOutputDirectory();
  154. if(dir.size() && dir[dir.size()-1] != '/')
  155. {
  156. dir += "/";
  157. }
  158. dir += *i;
  159. cmSystemTools::MakeDirectory(dir.c_str());
  160. }
  161. else
  162. {
  163. cmSystemTools::MakeDirectory(i->c_str());
  164. }
  165. }
  166. }
  167. // Create a stream that writes to a temporary file
  168. // then does a copy at the end. This is to allow users
  169. // to hit control-c during the make of the makefile
  170. cmGeneratedFileStream tempFile(file);
  171. tempFile.SetAlwaysCopy(true);
  172. std::ostream& fout = tempFile.GetStream();
  173. if(!fout)
  174. {
  175. cmSystemTools::Error("Error can not open for write: ", file);
  176. return;
  177. }
  178. fout << "# CMAKE generated Makefile, DO NOT EDIT!\n"
  179. << "# Generated by \"" << m_GlobalGenerator->GetName() << "\""
  180. << " Generator, CMake Version "
  181. << cmMakefile::GetMajorVersion() << "."
  182. << cmMakefile::GetMinorVersion() << "\n"
  183. << "# Generated from the following files:\n# "
  184. << m_Makefile->GetHomeOutputDirectory() << "/CMakeCache.txt\n";
  185. std::vector<std::string> lfiles = m_Makefile->GetListFiles();
  186. // sort the array
  187. std::sort(lfiles.begin(), lfiles.end(), std::less<std::string>());
  188. // remove duplicates
  189. std::vector<std::string>::iterator new_end =
  190. std::unique(lfiles.begin(), lfiles.end());
  191. lfiles.erase(new_end, lfiles.end());
  192. for(std::vector<std::string>::const_iterator i = lfiles.begin();
  193. i != lfiles.end(); ++i)
  194. {
  195. fout << "# " << i->c_str() << "\n";
  196. }
  197. fout << "\n\n";
  198. if(!m_Makefile->IsOn("CMAKE_VERBOSE_MAKEFILE"))
  199. {
  200. fout << "# Suppresses display of executed commands\n";
  201. fout << ".SILENT:\n";
  202. }
  203. fout << "# disable some common implicit rules to speed things up\n";
  204. fout << ".SUFFIXES:\n";
  205. fout << ".SUFFIXES:.hpuxmakemusthaverule\n";
  206. // create a make variable with all of the sources for this Makefile
  207. // for depend purposes.
  208. fout << "CMAKE_MAKEFILE_SOURCES = ";
  209. for(std::vector<std::string>::const_iterator i = lfiles.begin();
  210. i != lfiles.end(); ++i)
  211. {
  212. fout << " " << cmSystemTools::ConvertToOutputPath(i->c_str());
  213. }
  214. // Add the cache to the list
  215. std::string cacheFile = m_Makefile->GetHomeOutputDirectory();
  216. cacheFile += "/CMakeCache.txt";
  217. fout << " " << cmSystemTools::ConvertToOutputPath(cacheFile.c_str());
  218. fout << "\n\n\n";
  219. this->OutputMakeVariables(fout);
  220. std::string checkCache = m_Makefile->GetHomeOutputDirectory();
  221. checkCache += "/cmake.check_cache";
  222. checkCache = cmSystemTools::ConvertToOutputPath(checkCache.c_str());
  223. // Set up the default target as the VERY first target, so that make with no arguments will run it
  224. this->
  225. OutputMakeRule(fout,
  226. "Default target executed when no arguments are given to make, first make sure cmake.depends exists, cmake.check_depends is up-to-date, check the sources, then build the all target",
  227. "default_target",
  228. checkCache.c_str(),
  229. "$(MAKE) $(MAKESILENT) cmake.depends",
  230. "$(MAKE) $(MAKESILENT) cmake.check_depends",
  231. "$(MAKE) $(MAKESILENT) -f cmake.check_depends",
  232. "$(MAKE) $(MAKESILENT) all");
  233. this->OutputTargetRules(fout);
  234. this->OutputDependLibs(fout);
  235. this->OutputTargets(fout);
  236. this->OutputSubDirectoryRules(fout);
  237. std::string dependName = m_Makefile->GetStartOutputDirectory();
  238. dependName += "/cmake.depends";
  239. if(withDepends)
  240. {
  241. std::ofstream dependout(dependName.c_str());
  242. if(!dependout)
  243. {
  244. cmSystemTools::Error("Error can not open for write: ", dependName.c_str());
  245. return;
  246. }
  247. dependout << "# .o dependencies in this directory." << std::endl;
  248. std::string checkDepend = m_Makefile->GetStartOutputDirectory();
  249. checkDepend += "/cmake.check_depends";
  250. std::ofstream checkdependout(checkDepend.c_str());
  251. if(!checkdependout)
  252. {
  253. cmSystemTools::Error("Error can not open for write: ", checkDepend.c_str());
  254. return;
  255. }
  256. checkdependout << "# This file is used as a tag file, that all sources depend on. If a source changes, then the rule to rebuild this file will cause cmake.depends to be rebuilt." << std::endl;
  257. // if there were any depends output, then output the check depends
  258. // information inot checkdependout
  259. if(this->OutputObjectDepends(dependout))
  260. {
  261. this->OutputCheckDepends(checkdependout);
  262. }
  263. else
  264. {
  265. checkdependout << "all:\n\t@echo cmake.depends is up-to-date\n";
  266. }
  267. }
  268. this->OutputCustomRules(fout);
  269. this->OutputMakeRules(fout);
  270. this->OutputInstallRules(fout);
  271. // only add the depend include if the depend file exists
  272. if(cmSystemTools::FileExists(dependName.c_str()))
  273. {
  274. fout << m_IncludeDirective << " cmake.depends\n";
  275. }
  276. }
  277. #if defined(_WIN32) && ! defined(__CYGWIN__)
  278. std::string cmLocalUnixMakefileGenerator::GetOutputExtension(const char* s)
  279. {
  280. std::string sourceExtension = s;
  281. if(sourceExtension == "def")
  282. {
  283. return "";
  284. }
  285. if(sourceExtension == "ico" || sourceExtension == "rc2")
  286. {
  287. return "";
  288. }
  289. if(sourceExtension == "rc")
  290. {
  291. return ".res";
  292. }
  293. return ".obj";
  294. }
  295. #else
  296. std::string cmLocalUnixMakefileGenerator::GetOutputExtension(const char*)
  297. {
  298. return ".o";
  299. }
  300. #endif
  301. std::string cmLocalUnixMakefileGenerator::GetFullTargetName(const char* n,
  302. const cmTarget& t)
  303. {
  304. const char* targetPrefix = t.GetProperty("PREFIX");
  305. const char* targetSuffix = t.GetProperty("SUFFIX");
  306. const char* prefixVar = 0;
  307. const char* suffixVar = 0;
  308. switch(t.GetType())
  309. {
  310. case cmTarget::STATIC_LIBRARY:
  311. prefixVar = "CMAKE_STATIC_LIBRARY_PREFIX";
  312. suffixVar = "CMAKE_STATIC_LIBRARY_SUFFIX";
  313. break;
  314. case cmTarget::SHARED_LIBRARY:
  315. prefixVar = "CMAKE_SHARED_LIBRARY_PREFIX";
  316. suffixVar = "CMAKE_SHARED_LIBRARY_SUFFIX";
  317. break;
  318. case cmTarget::MODULE_LIBRARY:
  319. prefixVar = "CMAKE_SHARED_MODULE_PREFIX";
  320. suffixVar = "CMAKE_SHARED_MODULE_SUFFIX";
  321. break;
  322. case cmTarget::EXECUTABLE:
  323. case cmTarget::WIN32_EXECUTABLE:
  324. targetSuffix = cmSystemTools::GetExecutableExtension();
  325. case cmTarget::UTILITY:
  326. case cmTarget::INSTALL_FILES:
  327. case cmTarget::INSTALL_PROGRAMS:
  328. break;
  329. }
  330. // if there is no prefix on the target use the cmake definition
  331. if(!targetPrefix && prefixVar)
  332. {
  333. targetPrefix = this->GetSafeDefinition(prefixVar);
  334. }
  335. // if there is no suffix on the target use the cmake definition
  336. if(!targetSuffix && suffixVar)
  337. {
  338. targetSuffix = this->GetSafeDefinition(suffixVar);
  339. }
  340. std::string name = targetPrefix?targetPrefix:"";
  341. name += n;
  342. name += targetSuffix?targetSuffix:"";
  343. return name;
  344. }
  345. // Output the rules for any targets
  346. void cmLocalUnixMakefileGenerator::OutputTargetRules(std::ostream& fout)
  347. {
  348. // for each target add to the list of targets
  349. fout << "TARGETS = ";
  350. const cmTargets &tgts = m_Makefile->GetTargets();
  351. // list libraries first
  352. for(cmTargets::const_iterator l = tgts.begin();
  353. l != tgts.end(); l++)
  354. {
  355. if (l->second.IsInAll())
  356. {
  357. if((l->second.GetType() == cmTarget::STATIC_LIBRARY) ||
  358. (l->second.GetType() == cmTarget::SHARED_LIBRARY) ||
  359. (l->second.GetType() == cmTarget::MODULE_LIBRARY))
  360. {
  361. std::string path = m_LibraryOutputPath;
  362. path += this->GetFullTargetName(l->first.c_str(), l->second);
  363. fout << " \\\n"
  364. << cmSystemTools::ConvertToOutputPath(path.c_str());
  365. }
  366. }
  367. }
  368. // executables
  369. for(cmTargets::const_iterator l = tgts.begin();
  370. l != tgts.end(); l++)
  371. {
  372. if ((l->second.GetType() == cmTarget::EXECUTABLE ||
  373. l->second.GetType() == cmTarget::WIN32_EXECUTABLE) &&
  374. l->second.IsInAll())
  375. {
  376. std::string path = m_ExecutableOutputPath;
  377. path += this->GetFullTargetName(l->first.c_str(), l->second);
  378. fout << " \\\n" << cmSystemTools::ConvertToOutputPath(path.c_str());
  379. }
  380. }
  381. // list utilities last
  382. for(cmTargets::const_iterator l = tgts.begin();
  383. l != tgts.end(); l++)
  384. {
  385. if (l->second.GetType() == cmTarget::UTILITY &&
  386. l->second.IsInAll())
  387. {
  388. fout << " \\\n" << l->first.c_str();
  389. }
  390. }
  391. fout << "\n\n";
  392. // get the classes from the source lists then add them to the groups
  393. for(cmTargets::const_iterator l = tgts.begin();
  394. l != tgts.end(); l++)
  395. {
  396. std::vector<cmSourceFile*> classes = l->second.GetSourceFiles();
  397. if (classes.begin() != classes.end())
  398. {
  399. fout << this->CreateMakeVariable(l->first.c_str(), "_SRC_OBJS") << " = ";
  400. for(std::vector<cmSourceFile*>::iterator i = classes.begin();
  401. i != classes.end(); i++)
  402. {
  403. if(!(*i)->GetPropertyAsBool("HEADER_FILE_ONLY") &&
  404. !(*i)->GetCustomCommand())
  405. {
  406. std::string outExt(
  407. this->GetOutputExtension((*i)->GetSourceExtension().c_str()));
  408. if(outExt.size())
  409. {
  410. fout << "\\\n"
  411. << cmSystemTools::ConvertToOutputPath((*i)->GetSourceName().c_str())
  412. << outExt.c_str() << " ";
  413. }
  414. }
  415. }
  416. fout << "\n\n";
  417. fout << this->CreateMakeVariable(l->first.c_str(), "_SRC_OBJS_QUOTED") << " = ";
  418. for(std::vector<cmSourceFile*>::iterator i = classes.begin();
  419. i != classes.end(); i++)
  420. {
  421. if(!(*i)->GetPropertyAsBool("HEADER_FILE_ONLY") &&
  422. !(*i)->GetCustomCommand())
  423. {
  424. std::string outExt(this->GetOutputExtension((*i)->GetSourceExtension().c_str()));
  425. if(outExt.size())
  426. {
  427. fout << "\\\n\"" << cmSystemTools::ConvertToOutputPath((*i)->GetSourceName().c_str())
  428. << outExt.c_str() << "\" ";
  429. }
  430. }
  431. }
  432. fout << "\n\n";
  433. }
  434. }
  435. fout << "CLEAN_OBJECT_FILES = ";
  436. for(cmTargets::const_iterator l = tgts.begin();
  437. l != tgts.end(); l++)
  438. {
  439. std::vector<cmSourceFile*> classes = l->second.GetSourceFiles();
  440. if (classes.begin() != classes.end())
  441. {
  442. fout << "$(" << this->CreateMakeVariable(l->first.c_str(), "_SRC_OBJS")
  443. << ") ";
  444. }
  445. }
  446. fout << "\n\n";
  447. const char * qt_files = m_Makefile->GetDefinition("GENERATED_QT_FILES");
  448. if (qt_files != NULL &&
  449. strlen(m_Makefile->GetDefinition("GENERATED_QT_FILES"))>0)
  450. {
  451. fout << "GENERATED_QT_FILES = ";
  452. fout << qt_files;
  453. fout << "\n\n";
  454. }
  455. }
  456. /**
  457. * Output the linking rules on a command line. For executables,
  458. * targetLibrary should be a NULL pointer. For libraries, it should point
  459. * to the name of the library. This will not link a library against itself.
  460. */
  461. void cmLocalUnixMakefileGenerator::OutputLinkLibraries(std::ostream& fout,
  462. const char* targetLibrary,
  463. const cmTarget &tgt)
  464. {
  465. // Try to emit each search path once
  466. std::set<std::string> emitted;
  467. // Embed runtime search paths if possible and if required.
  468. bool outputRuntime = true;
  469. std::string runtimeFlag;
  470. std::string runtimeSep;
  471. std::vector<std::string> runtimeDirs;
  472. bool cxx = tgt.HasCxx();
  473. if(!cxx )
  474. {
  475. // if linking a c executable use the C runtime flag as cc
  476. // may not be the same program that creates shared libaries
  477. // and may have different flags
  478. runtimeFlag = this->GetSafeDefinition("CMAKE_SHARED_LIBRARY_RUNTIME_FLAG");
  479. runtimeSep = this->GetSafeDefinition("CMAKE_SHARED_LIBRARY_RUNTIME_FLAG_SEP");
  480. }
  481. else
  482. {
  483. runtimeFlag = this->GetSafeDefinition("CMAKE_SHARED_LIBRARY_RUNTIME_CXX_FLAG");
  484. runtimeSep = this->GetSafeDefinition("CMAKE_SHARED_LIBRARY_RUNTIME_CXX_FLAG_SEP");
  485. }
  486. // concatenate all paths or no?
  487. bool runtimeConcatenate = ( runtimeSep!="" );
  488. if(runtimeFlag == "" || m_Makefile->IsOn("CMAKE_SKIP_RPATH") )
  489. {
  490. outputRuntime = false;
  491. }
  492. // Some search paths should never be emitted
  493. emitted.insert("");
  494. emitted.insert("/usr/lib");
  495. std::string libPathFlag = m_Makefile->GetDefinition("CMAKE_LIBRARY_PATH_FLAG");
  496. std::string libLinkFlag = this->GetSafeDefinition("CMAKE_LINK_LIBRARY_FLAG");
  497. // collect all the flags needed for linking libraries
  498. std::string linkLibs;
  499. // Flags to link an executable to shared libraries.
  500. if( tgt.GetType() == cmTarget::EXECUTABLE)
  501. {
  502. if(cxx)
  503. {
  504. linkLibs = this->GetSafeDefinition("CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS");
  505. }
  506. else
  507. {
  508. linkLibs = this->GetSafeDefinition("CMAKE_SHARED_LIBRARY_LINK_FLAGS");
  509. }
  510. linkLibs += " ";
  511. }
  512. const std::vector<std::string>& libdirs = tgt.GetLinkDirectories();
  513. for(std::vector<std::string>::const_iterator libDir = libdirs.begin();
  514. libDir != libdirs.end(); ++libDir)
  515. {
  516. std::string libpath = this->ConvertToOutputForExisting(libDir->c_str());
  517. if(emitted.insert(libpath).second)
  518. {
  519. std::string::size_type pos = libDir->find(libPathFlag.c_str());
  520. if((pos == std::string::npos || pos > 0)
  521. && libDir->find("${") == std::string::npos)
  522. {
  523. linkLibs += libPathFlag;
  524. if(outputRuntime)
  525. {
  526. runtimeDirs.push_back( libpath );
  527. }
  528. }
  529. linkLibs += libpath;
  530. linkLibs += " ";
  531. }
  532. }
  533. std::string linkSuffix = this->GetSafeDefinition("CMAKE_LINK_LIBRARY_SUFFIX");
  534. std::string regexp = ".*\\";
  535. regexp += linkSuffix;
  536. regexp += "$";
  537. cmsys::RegularExpression hasSuffix(regexp.c_str());
  538. std::string librariesLinked;
  539. const cmTarget::LinkLibraries& libs = tgt.GetLinkLibraries();
  540. for(cmTarget::LinkLibraries::const_iterator lib = libs.begin();
  541. lib != libs.end(); ++lib)
  542. {
  543. // Don't link the library against itself!
  544. if(targetLibrary && (lib->first == targetLibrary)) continue;
  545. // don't look at debug libraries
  546. if (lib->second == cmTarget::DEBUG) continue;
  547. // skip zero size library entries, this may happen
  548. // if a variable expands to nothing.
  549. if (lib->first.size() == 0) continue;
  550. // if it is a full path break it into -L and -l
  551. cmsys::RegularExpression reg("([ \t]*\\-l)|([ \t]*\\-framework)|(\\${)");
  552. if(lib->first.find('/') != std::string::npos
  553. && !reg.find(lib->first))
  554. {
  555. std::string dir, file;
  556. cmSystemTools::SplitProgramPath(lib->first.c_str(),
  557. dir, file);
  558. std::string libpath = this->ConvertToOutputForExisting(dir.c_str());
  559. if(emitted.insert(libpath).second)
  560. {
  561. linkLibs += libPathFlag;
  562. linkLibs += libpath;
  563. linkLibs += " ";
  564. if(outputRuntime)
  565. {
  566. runtimeDirs.push_back( libpath );
  567. }
  568. }
  569. cmsys::RegularExpression libname("^lib([^/]*)(\\.so|\\.lib|\\.dll|\\.sl|\\.a|\\.dylib).*");
  570. cmsys::RegularExpression libname_noprefix("([^/]*)(\\.so|\\.lib|\\.dll|\\.sl|\\.a|\\.dylib).*");
  571. std::cout << "file is " << file << "\n";
  572. if(libname.find(file))
  573. {
  574. // Library had "lib" prefix.
  575. librariesLinked += libLinkFlag;
  576. file = libname.match(1);
  577. // if ignore libprefix is on,
  578. // then add the lib prefix back into the name
  579. if(m_IgnoreLibPrefix)
  580. {
  581. std::cout << "m_IgnoreLibPrefix\n";
  582. file = "lib" + file;
  583. }
  584. librariesLinked += file;
  585. if(linkSuffix.size() && !hasSuffix.find(file))
  586. {
  587. librariesLinked += linkSuffix;
  588. }
  589. librariesLinked += " ";
  590. }
  591. else if(libname_noprefix.find(file))
  592. {
  593. // Library had no "lib" prefix.
  594. librariesLinked += libLinkFlag;
  595. file = libname_noprefix.match(1);
  596. librariesLinked += file;
  597. if(linkSuffix.size() && !hasSuffix.find(file))
  598. {
  599. librariesLinked += linkSuffix;
  600. }
  601. librariesLinked += " ";
  602. }
  603. else
  604. {
  605. // Error parsing the library name. Just use the full path.
  606. // The linker will give an error if it is invalid.
  607. librariesLinked += lib->first;
  608. librariesLinked += " ";
  609. }
  610. }
  611. // not a full path, so add -l name
  612. else
  613. {
  614. if(!reg.find(lib->first))
  615. {
  616. librariesLinked += libLinkFlag;
  617. }
  618. librariesLinked += lib->first;
  619. if(linkSuffix.size() && !hasSuffix.find(lib->first))
  620. {
  621. librariesLinked += linkSuffix;
  622. }
  623. librariesLinked += " ";
  624. }
  625. }
  626. linkLibs += librariesLinked;
  627. fout << linkLibs;
  628. if(outputRuntime && runtimeDirs.size()>0)
  629. {
  630. // For the runtime search directories, do a "-Wl,-rpath,a:b:c" or
  631. // a "-R a -R b -R c" type link line
  632. fout << runtimeFlag;
  633. std::vector<std::string>::iterator itr = runtimeDirs.begin();
  634. fout << *itr;
  635. ++itr;
  636. for( ; itr != runtimeDirs.end(); ++itr )
  637. {
  638. if(runtimeConcatenate)
  639. {
  640. fout << runtimeSep << *itr;
  641. }
  642. else
  643. {
  644. fout << " " << runtimeFlag << *itr;
  645. }
  646. }
  647. fout << " ";
  648. }
  649. if(m_Makefile->GetDefinition("CMAKE_STANDARD_LIBRARIES"))
  650. {
  651. fout << m_Makefile->GetDefinition("CMAKE_STANDARD_LIBRARIES") << " ";
  652. }
  653. }
  654. std::string cmLocalUnixMakefileGenerator::CreatePreBuildRules(
  655. const cmTarget &target, const char* /* targetName */)
  656. {
  657. std::string customRuleCode = "";
  658. bool initNext = false;
  659. for (std::vector<cmCustomCommand>::const_iterator cr =
  660. target.GetPreBuildCommands().begin();
  661. cr != target.GetPreBuildCommands().end(); ++cr)
  662. {
  663. cmCustomCommand cc(*cr);
  664. cc.ExpandVariables(*m_Makefile);
  665. if(initNext)
  666. {
  667. customRuleCode += "\n\t";
  668. }
  669. else
  670. {
  671. initNext = true;
  672. }
  673. std::string command = cmSystemTools::ConvertToOutputPath(cc.GetCommand().c_str());
  674. customRuleCode += command + " " + cc.GetArguments();
  675. }
  676. return customRuleCode;
  677. }
  678. std::string cmLocalUnixMakefileGenerator::CreatePreLinkRules(
  679. const cmTarget &target, const char* /* targetName */)
  680. {
  681. std::string customRuleCode = "";
  682. bool initNext = false;
  683. for (std::vector<cmCustomCommand>::const_iterator cr =
  684. target.GetPreLinkCommands().begin();
  685. cr != target.GetPreLinkCommands().end(); ++cr)
  686. {
  687. cmCustomCommand cc(*cr);
  688. cc.ExpandVariables(*m_Makefile);
  689. if(initNext)
  690. {
  691. customRuleCode += "\n\t";
  692. }
  693. else
  694. {
  695. initNext = true;
  696. }
  697. std::string command = cmSystemTools::ConvertToOutputPath(cc.GetCommand().c_str());
  698. customRuleCode += command + " " + cc.GetArguments();
  699. }
  700. return customRuleCode;
  701. }
  702. std::string cmLocalUnixMakefileGenerator::CreatePostBuildRules(
  703. const cmTarget &target, const char* /* targetName */)
  704. {
  705. std::string customRuleCode = "";
  706. bool initNext = false;
  707. for (std::vector<cmCustomCommand>::const_iterator cr =
  708. target.GetPostBuildCommands().begin();
  709. cr != target.GetPostBuildCommands().end(); ++cr)
  710. {
  711. cmCustomCommand cc(*cr);
  712. cc.ExpandVariables(*m_Makefile);
  713. if(initNext)
  714. {
  715. customRuleCode += "\n\t";
  716. }
  717. else
  718. {
  719. initNext = true;
  720. }
  721. std::string command = cmSystemTools::ConvertToOutputPath(cc.GetCommand().c_str());
  722. customRuleCode += command + " " + cc.GetArguments();
  723. }
  724. return customRuleCode;
  725. }
  726. struct RuleVariables
  727. {
  728. const char* replace;
  729. const char* lookup;
  730. };
  731. static RuleVariables ruleReplaceVars[] =
  732. {
  733. {"<CMAKE_SHARED_LIBRARY_CREATE_CXX_FLAGS>", "CMAKE_SHARED_LIBRARY_CREATE_CXX_FLAGS"},
  734. {"<CMAKE_SHARED_MODULE_CREATE_CXX_FLAGS>", "CMAKE_SHARED_MODULE_CREATE_CXX_FLAGS"},
  735. {"<CMAKE_SHARED_MODULE_C_FLAGS>", "CMAKE_SHARED_MODULE_C_FLAGS"},
  736. {"<CMAKE_SHARED_MODULE_CXX_FLAGS>", "CMAKE_SHARED_MODULE_CXX_FLAGS"},
  737. {"<CMAKE_SHARED_LIBRARY_C_FLAGS>", "CMAKE_SHARED_LIBRARY_C_FLAGS"},
  738. {"<CMAKE_SHARED_LIBRARY_CXX_FLAGS>", "CMAKE_SHARED_LIBRARY_CXX_FLAGS"},
  739. {"<CMAKE_CXX_LINK_FLAGS>", "CMAKE_CXX_LINK_FLAGS"},
  740. {"<CMAKE_SHARED_LIBRARY_CREATE_C_FLAGS>", "CMAKE_SHARED_LIBRARY_CREATE_C_FLAGS"},
  741. {"<CMAKE_SHARED_MODULE_CREATE_C_FLAGS>", "CMAKE_SHARED_MODULE_CREATE_C_FLAGS"},
  742. {"<CMAKE_C_LINK_FLAGS>", "CMAKE_C_LINK_FLAGS"},
  743. {"<CMAKE_AR>", "CMAKE_AR"},
  744. {"<CMAKE_RANLIB>", "CMAKE_RANLIB"},
  745. {0, 0}
  746. };
  747. void
  748. cmLocalUnixMakefileGenerator::ExpandRuleVariables(std::string& s,
  749. const char* objects,
  750. const char* target,
  751. const char* linkLibs,
  752. const char* source,
  753. const char* object,
  754. const char* flags,
  755. const char* objectsquoted,
  756. const char* targetBase,
  757. const char* linkFlags)
  758. {
  759. std::string cxxcompiler = this->ConvertToOutputForExisting(
  760. this->GetSafeDefinition("CMAKE_CXX_COMPILER"));
  761. std::string ccompiler = this->ConvertToOutputForExisting(
  762. this->GetSafeDefinition("CMAKE_C_COMPILER"));
  763. cmSystemTools::ReplaceString(s, "<CMAKE_CXX_COMPILER>", cxxcompiler.c_str());
  764. cmSystemTools::ReplaceString(s, "<CMAKE_C_COMPILER>", ccompiler.c_str());
  765. if(linkFlags)
  766. {
  767. cmSystemTools::ReplaceString(s, "<LINK_FLAGS>", linkFlags);
  768. }
  769. if(flags)
  770. {
  771. cmSystemTools::ReplaceString(s, "<FLAGS>", flags);
  772. }
  773. if(source)
  774. {
  775. cmSystemTools::ReplaceString(s, "<SOURCE>", source);
  776. }
  777. if(object)
  778. {
  779. cmSystemTools::ReplaceString(s, "<OBJECT>", object);
  780. }
  781. if(objects)
  782. {
  783. cmSystemTools::ReplaceString(s, "<OBJECTS>", objects);
  784. }
  785. if(objectsquoted)
  786. {
  787. cmSystemTools::ReplaceString(s, "<OBJECTS_QUOTED>", objectsquoted);
  788. }
  789. if(target)
  790. {
  791. cmSystemTools::ReplaceString(s, "<TARGET>", target);
  792. }
  793. if(targetBase)
  794. {
  795. // special case for quoted paths with spaces
  796. // if you see <TARGET_BASE>.lib then put the .lib inside
  797. // the quotes, same for .dll
  798. if((strlen(targetBase) > 1) && targetBase[0] == '\"')
  799. {
  800. std::string base = targetBase;
  801. base[base.size()-1] = '.';
  802. std::string baseLib = base + "lib\"";
  803. std::string baseDll = base + "dll\"";
  804. cmSystemTools::ReplaceString(s, "<TARGET_BASE>.lib", baseLib.c_str());
  805. cmSystemTools::ReplaceString(s, "<TARGET_BASE>.dll", baseDll.c_str());
  806. }
  807. cmSystemTools::ReplaceString(s, "<TARGET_BASE>", targetBase);
  808. }
  809. if(linkLibs)
  810. {
  811. cmSystemTools::ReplaceString(s, "<LINK_LIBRARIES>", linkLibs);
  812. }
  813. RuleVariables* rv = ruleReplaceVars;
  814. while(rv->replace)
  815. {
  816. cmSystemTools::ReplaceString(s, rv->replace,
  817. this->GetSafeDefinition(rv->lookup));
  818. rv++;
  819. }
  820. }
  821. void cmLocalUnixMakefileGenerator::OutputLibraryRule(std::ostream& fout,
  822. const char* name,
  823. const cmTarget &t,
  824. const char* prefix,
  825. const char* suffix,
  826. const char* createVariable,
  827. const char* comment,
  828. const char* linkFlags
  829. )
  830. {
  831. // create the library name
  832. std::string targetNameBase = prefix;
  833. targetNameBase += name;
  834. std::string targetName = prefix;
  835. targetName += name;
  836. targetName += suffix;
  837. // create the target full path name
  838. std::string targetFullPath = m_LibraryOutputPath + targetName;
  839. std::string targetBaseFullPath = m_LibraryOutputPath + targetNameBase;
  840. targetBaseFullPath =
  841. cmSystemTools::ConvertToOutputPath(targetBaseFullPath.c_str());
  842. targetFullPath = cmSystemTools::ConvertToOutputPath(targetFullPath.c_str());
  843. // get the objects that are used to link this library
  844. std::string objs = "$(" + this->CreateMakeVariable(name, "_SRC_OBJS") + ") ";
  845. std::string objsQuoted = "$(" + this->CreateMakeVariable(name, "_SRC_OBJS_QUOTED") + ") ";
  846. // create a variable with the objects that this library depends on
  847. std::string depend = objs + " $("
  848. + this->CreateMakeVariable(name, "_DEPEND_LIBS") + ")";
  849. // collect up the build rules
  850. std::vector<std::string> rules;
  851. std::string command = "$(RM) " + targetFullPath;
  852. rules.push_back(command);
  853. rules.push_back(m_Makefile->GetDefinition(createVariable));
  854. // expand multi-command semi-colon separated lists
  855. // of commands into separate commands
  856. std::vector<std::string> commands;
  857. // collect custom commands for this target and add them to the list
  858. std::string customCommands = this->CreatePreBuildRules(t, name);
  859. if(customCommands.size() > 0)
  860. {
  861. commands.push_back(customCommands);
  862. }
  863. // collect custom commands for this target and add them to the list
  864. customCommands = this->CreatePreLinkRules(t, name);
  865. if(customCommands.size() > 0)
  866. {
  867. commands.push_back(customCommands);
  868. }
  869. cmSystemTools::ExpandList(rules, commands);
  870. // collect custom commands for this target and add them to the list
  871. customCommands = this->CreatePostBuildRules(t, name);
  872. if(customCommands.size() > 0)
  873. {
  874. commands.push_back(customCommands);
  875. }
  876. // collect up the link libraries
  877. cmOStringStream linklibs;
  878. this->OutputLinkLibraries(linklibs, name, t);
  879. for(std::vector<std::string>::iterator i = commands.begin();
  880. i != commands.end(); ++i)
  881. {
  882. this->ExpandRuleVariables(*i,
  883. objs.c_str(),
  884. targetFullPath.c_str(),
  885. linklibs.str().c_str(),
  886. 0, 0, 0, objsQuoted.c_str(),
  887. targetBaseFullPath.c_str(),
  888. linkFlags);
  889. }
  890. this->OutputMakeRule(fout, comment,
  891. targetFullPath.c_str(),
  892. depend.c_str(),
  893. commands);
  894. }
  895. void cmLocalUnixMakefileGenerator::OutputSharedLibraryRule(std::ostream& fout,
  896. const char* name,
  897. const cmTarget &t)
  898. {
  899. const char* createRule;
  900. if(t.HasCxx())
  901. {
  902. createRule = "CMAKE_CXX_CREATE_SHARED_LIBRARY";
  903. }
  904. else
  905. {
  906. createRule = "CMAKE_C_CREATE_SHARED_LIBRARY";
  907. }
  908. std::string buildType = this->GetSafeDefinition("CMAKE_BUILD_TYPE");
  909. buildType = cmSystemTools::UpperCase(buildType);
  910. std::string linkFlags = this->GetSafeDefinition("CMAKE_SHARED_LINKER_FLAGS");
  911. linkFlags += " ";
  912. if(buildType.size())
  913. {
  914. std::string build = "CMAKE_SHARED_LINKER_FLAGS_";
  915. build += buildType;
  916. linkFlags += this->GetSafeDefinition(build.c_str());
  917. linkFlags += " ";
  918. }
  919. #ifdef _WIN32
  920. const std::vector<cmSourceFile*>& sources = t.GetSourceFiles();
  921. for(std::vector<cmSourceFile*>::const_iterator i = sources.begin();
  922. i != sources.end(); ++i)
  923. {
  924. if((*i)->GetSourceExtension() == "def")
  925. {
  926. linkFlags += this->GetSafeDefinition("CMAKE_LINK_DEF_FILE_FLAG");
  927. linkFlags += cmSystemTools::ConvertToOutputPath((*i)->GetFullPath().c_str());
  928. linkFlags += " ";
  929. }
  930. }
  931. #endif
  932. const char* targetPrefix = t.GetProperty("PREFIX");
  933. if(!targetPrefix)
  934. {
  935. targetPrefix = this->GetSafeDefinition("CMAKE_SHARED_LIBRARY_PREFIX");
  936. }
  937. const char* targetSuffix = t.GetProperty("SUFFIX");
  938. if(!targetSuffix)
  939. {
  940. targetSuffix = this->GetSafeDefinition("CMAKE_SHARED_LIBRARY_SUFFIX");
  941. }
  942. const char* targetLinkFlags = t.GetProperty("LINK_FLAGS");
  943. if(targetLinkFlags)
  944. {
  945. linkFlags += targetLinkFlags;
  946. linkFlags += " ";
  947. }
  948. this->OutputLibraryRule(fout, name, t,
  949. targetPrefix,
  950. targetSuffix,
  951. createRule,
  952. "shared library",
  953. linkFlags.c_str());
  954. }
  955. void cmLocalUnixMakefileGenerator::OutputModuleLibraryRule(std::ostream& fout,
  956. const char* name,
  957. const cmTarget &t)
  958. {
  959. const char* createRule;
  960. if(t.HasCxx())
  961. {
  962. createRule = "CMAKE_CXX_CREATE_SHARED_MODULE";
  963. }
  964. else
  965. {
  966. createRule = "CMAKE_C_CREATE_SHARED_MODULE";
  967. }
  968. std::string buildType = this->GetSafeDefinition("CMAKE_BUILD_TYPE");
  969. buildType = cmSystemTools::UpperCase(buildType);
  970. std::string linkFlags = this->GetSafeDefinition("CMAKE_MODULE_LINKER_FLAGS");
  971. linkFlags += " ";
  972. if(buildType.size())
  973. {
  974. std::string build = "CMAKE_MODULE_LINKER_FLAGS_";
  975. build += buildType;
  976. linkFlags += this->GetSafeDefinition(build.c_str());
  977. linkFlags += " ";
  978. }
  979. const char* targetPrefix = t.GetProperty("PREFIX");
  980. if(!targetPrefix)
  981. {
  982. targetPrefix = this->GetSafeDefinition("CMAKE_SHARED_MODULE_PREFIX");
  983. }
  984. const char* targetSuffix = t.GetProperty("SUFFIX");
  985. if(!targetSuffix)
  986. {
  987. targetSuffix = this->GetSafeDefinition("CMAKE_SHARED_MODULE_SUFFIX");
  988. }
  989. const char* targetLinkFlags = t.GetProperty("LINK_FLAGS");
  990. if(targetLinkFlags)
  991. {
  992. linkFlags += targetLinkFlags;
  993. linkFlags += " ";
  994. }
  995. this->OutputLibraryRule(fout, name, t,
  996. targetPrefix,
  997. targetSuffix,
  998. createRule,
  999. "shared module",
  1000. linkFlags.c_str());
  1001. }
  1002. void cmLocalUnixMakefileGenerator::OutputStaticLibraryRule(std::ostream& fout,
  1003. const char* name,
  1004. const cmTarget &t)
  1005. {
  1006. const char* createRule;
  1007. if(t.HasCxx())
  1008. {
  1009. createRule = "CMAKE_CXX_CREATE_STATIC_LIBRARY";
  1010. }
  1011. else
  1012. {
  1013. createRule = "CMAKE_C_CREATE_STATIC_LIBRARY";
  1014. }
  1015. const char* targetPrefix = t.GetProperty("PREFIX");
  1016. if(!targetPrefix)
  1017. {
  1018. targetPrefix = this->GetSafeDefinition("CMAKE_STATIC_LIBRARY_PREFIX");
  1019. }
  1020. const char* targetSuffix = t.GetProperty("SUFFIX");
  1021. if(!targetSuffix)
  1022. {
  1023. targetSuffix = this->GetSafeDefinition("CMAKE_STATIC_LIBRARY_SUFFIX");
  1024. }
  1025. std::string linkFlags;
  1026. const char* targetLinkFlags = t.GetProperty("LINK_FLAGS");
  1027. if(targetLinkFlags)
  1028. {
  1029. linkFlags += targetLinkFlags;
  1030. linkFlags += " ";
  1031. }
  1032. this->OutputLibraryRule(fout, name, t,
  1033. targetPrefix,
  1034. targetSuffix,
  1035. createRule,
  1036. "static library",
  1037. linkFlags.c_str());
  1038. }
  1039. void cmLocalUnixMakefileGenerator::OutputExecutableRule(std::ostream& fout,
  1040. const char* name,
  1041. const cmTarget &t)
  1042. {
  1043. std::string linkFlags;
  1044. std::string buildType = this->GetSafeDefinition("CMAKE_BUILD_TYPE");
  1045. buildType = cmSystemTools::UpperCase(buildType);
  1046. std::string flags;
  1047. // Construct the full path to the executable that will be generated.
  1048. std::string target = m_ExecutableOutputPath;
  1049. if(target.length() == 0)
  1050. {
  1051. target = m_Makefile->GetCurrentOutputDirectory();
  1052. if(target.size() && target[target.size()-1] != '/')
  1053. {
  1054. target += "/";
  1055. }
  1056. }
  1057. target += name;
  1058. target += cmSystemTools::GetExecutableExtension();
  1059. target = cmSystemTools::ConvertToOutputPath(target.c_str());
  1060. std::string objs = "$(" + this->CreateMakeVariable(name, "_SRC_OBJS") + ") ";
  1061. std::string depend = "$(";
  1062. depend += this->CreateMakeVariable(name, "_SRC_OBJS")
  1063. + ") $(" + this->CreateMakeVariable(name, "_DEPEND_LIBS") + ")";
  1064. std::vector<std::string> rules;
  1065. linkFlags += this->GetSafeDefinition("CMAKE_EXE_LINKER_FLAGS");
  1066. linkFlags += " ";
  1067. if(buildType.size())
  1068. {
  1069. std::string build = "CMAKE_EXE_LINKER_FLAGS_";
  1070. build += buildType;
  1071. linkFlags += this->GetSafeDefinition(build.c_str());
  1072. linkFlags += " ";
  1073. }
  1074. if(t.HasCxx())
  1075. {
  1076. rules.push_back(m_Makefile->GetDefinition("CMAKE_CXX_LINK_EXECUTABLE"));
  1077. flags += this->GetSafeDefinition("CMAKE_CXX_FLAGS");
  1078. flags += " ";
  1079. flags += this->GetSafeDefinition("CMAKE_SHARED_LIBRARY_CXX_FLAGS");
  1080. flags += " ";
  1081. }
  1082. else
  1083. {
  1084. rules.push_back(m_Makefile->GetDefinition("CMAKE_C_LINK_EXECUTABLE"));
  1085. flags += this->GetSafeDefinition("CMAKE_C_FLAGS");
  1086. flags += " ";
  1087. flags += this->GetSafeDefinition("CMAKE_SHARED_LIBRARY_C_FLAGS");
  1088. flags += " ";
  1089. }
  1090. cmOStringStream linklibs;
  1091. this->OutputLinkLibraries(linklibs, 0, t);
  1092. std::string comment = "executable";
  1093. std::vector<std::string> commands;
  1094. std::string customCommands = this->CreatePreBuildRules(t, name);
  1095. if(customCommands.size() > 0)
  1096. {
  1097. commands.push_back(customCommands.c_str());
  1098. }
  1099. customCommands = this->CreatePreLinkRules(t, name);
  1100. if(customCommands.size() > 0)
  1101. {
  1102. commands.push_back(customCommands.c_str());
  1103. }
  1104. cmSystemTools::ExpandList(rules, commands);
  1105. customCommands = this->CreatePostBuildRules(t, name);
  1106. if(customCommands.size() > 0)
  1107. {
  1108. commands.push_back(customCommands.c_str());
  1109. }
  1110. if(cmSystemTools::IsOn(m_Makefile->GetDefinition("BUILD_SHARED_LIBS")))
  1111. {
  1112. linkFlags += this->GetSafeDefinition("CMAKE_SHARED_BUILD_CXX_FLAGS");
  1113. linkFlags += " ";
  1114. }
  1115. if(t.GetType() == cmTarget::WIN32_EXECUTABLE)
  1116. {
  1117. linkFlags += this->GetSafeDefinition("CMAKE_CREATE_WIN32_EXE");
  1118. linkFlags += " ";
  1119. }
  1120. else
  1121. {
  1122. linkFlags += this->GetSafeDefinition("CMAKE_CREATE_CONSOLE_EXE");
  1123. linkFlags += " ";
  1124. }
  1125. const char* targetLinkFlags = t.GetProperty("LINK_FLAGS");
  1126. if(targetLinkFlags)
  1127. {
  1128. linkFlags += targetLinkFlags;
  1129. linkFlags += " ";
  1130. }
  1131. for(std::vector<std::string>::iterator i = commands.begin();
  1132. i != commands.end(); ++i)
  1133. {
  1134. this->ExpandRuleVariables(*i,
  1135. objs.c_str(),
  1136. target.c_str(),
  1137. linklibs.str().c_str(),
  1138. 0,
  1139. 0,
  1140. flags.c_str(),
  1141. 0,
  1142. 0,
  1143. linkFlags.c_str());
  1144. }
  1145. this->OutputMakeRule(fout,
  1146. comment.c_str(),
  1147. target.c_str(),
  1148. depend.c_str(),
  1149. commands);
  1150. // If there is no executable output path, add a rule with the
  1151. // relative path to the executable. This is necessary for
  1152. // try-compile to work in this case.
  1153. if(m_ExecutableOutputPath.length() == 0)
  1154. {
  1155. target = name;
  1156. target += cmSystemTools::GetExecutableExtension();
  1157. target = cmSystemTools::ConvertToOutputPath(target.c_str());
  1158. this->OutputMakeRule(fout,
  1159. comment.c_str(),
  1160. target.c_str(),
  1161. depend.c_str(),
  1162. commands);
  1163. }
  1164. }
  1165. void cmLocalUnixMakefileGenerator::OutputUtilityRule(std::ostream& fout,
  1166. const char* name,
  1167. const cmTarget &t)
  1168. {
  1169. const char* cc = 0;
  1170. std::string customCommands = this->CreatePreBuildRules(t, name);
  1171. std::string customCommands2 = this->CreatePreLinkRules(t, name);
  1172. if(customCommands2.size() > 0)
  1173. {
  1174. customCommands += customCommands2;
  1175. }
  1176. customCommands2 = this->CreatePostBuildRules(t, name);
  1177. if(customCommands2.size() > 0)
  1178. {
  1179. customCommands += customCommands2;
  1180. }
  1181. if(customCommands.size() > 0)
  1182. {
  1183. cc = customCommands.c_str();
  1184. }
  1185. std::string comment = "Utility";
  1186. std::string depends;
  1187. depends = "$(" + this->CreateMakeVariable(name, "_DEPEND_LIBS") + ")";
  1188. std::string replaceVars;
  1189. const std::vector<cmCustomCommand> &ccs = t.GetPostBuildCommands();
  1190. for(std::vector<cmCustomCommand>::const_iterator i = ccs.begin();
  1191. i != ccs.end(); ++i)
  1192. {
  1193. const std::vector<std::string> & dep = i->GetDepends();
  1194. for(std::vector<std::string>::const_iterator d = dep.begin();
  1195. d != dep.end(); ++d)
  1196. {
  1197. depends += " \\\n";
  1198. replaceVars = *d;
  1199. m_Makefile->ExpandVariablesInString(replaceVars);
  1200. depends += cmSystemTools::ConvertToOutputPath(replaceVars.c_str());
  1201. }
  1202. }
  1203. this->OutputMakeRule(fout, comment.c_str(), name,
  1204. depends.c_str(), cc);
  1205. }
  1206. void cmLocalUnixMakefileGenerator::OutputTargets(std::ostream& fout)
  1207. {
  1208. // for each target
  1209. const cmTargets &tgts = m_Makefile->GetTargets();
  1210. for(cmTargets::const_iterator l = tgts.begin();
  1211. l != tgts.end(); l++)
  1212. {
  1213. switch(l->second.GetType())
  1214. {
  1215. case cmTarget::STATIC_LIBRARY:
  1216. this->OutputStaticLibraryRule(fout, l->first.c_str(), l->second);
  1217. break;
  1218. case cmTarget::SHARED_LIBRARY:
  1219. this->OutputSharedLibraryRule(fout, l->first.c_str(), l->second);
  1220. break;
  1221. case cmTarget::MODULE_LIBRARY:
  1222. this->OutputModuleLibraryRule(fout, l->first.c_str(), l->second);
  1223. break;
  1224. case cmTarget::EXECUTABLE:
  1225. case cmTarget::WIN32_EXECUTABLE:
  1226. this->OutputExecutableRule(fout, l->first.c_str(), l->second);
  1227. break;
  1228. case cmTarget::UTILITY:
  1229. this->OutputUtilityRule(fout, l->first.c_str(), l->second);
  1230. break;
  1231. // This is handled by the OutputCustomRules method
  1232. case cmTarget::INSTALL_FILES:
  1233. // This is handled by the OutputInstallRules method
  1234. case cmTarget::INSTALL_PROGRAMS:
  1235. // This is handled by the OutputInstallRules method
  1236. break;
  1237. }
  1238. }
  1239. }
  1240. // For each target that is an executable or shared library, generate
  1241. // the "<name>_DEPEND_LIBS" variable listing its library dependencies.
  1242. void cmLocalUnixMakefileGenerator::OutputDependLibs(std::ostream& fout)
  1243. {
  1244. // Build a set of libraries that will be linked into any target in
  1245. // this directory.
  1246. std::set<std::string> used;
  1247. // for each target
  1248. const cmTargets &tgts = m_Makefile->GetTargets();
  1249. for(cmTargets::const_iterator l = tgts.begin();
  1250. l != tgts.end(); l++)
  1251. {
  1252. // Each dependency should only be emitted once per target.
  1253. std::set<std::string> emitted;
  1254. if ((l->second.GetType() == cmTarget::SHARED_LIBRARY)
  1255. || (l->second.GetType() == cmTarget::MODULE_LIBRARY)
  1256. || (l->second.GetType() == cmTarget::STATIC_LIBRARY)
  1257. || (l->second.GetType() == cmTarget::EXECUTABLE)
  1258. || (l->second.GetType() == cmTarget::UTILITY)
  1259. || (l->second.GetType() == cmTarget::WIN32_EXECUTABLE))
  1260. {
  1261. fout << this->CreateMakeVariable(l->first.c_str(), "_DEPEND_LIBS") << " = ";
  1262. // A library should not depend on itself!
  1263. emitted.insert(l->first);
  1264. // for static libraries do not depend on other libraries
  1265. if(l->second.GetType() != cmTarget::STATIC_LIBRARY)
  1266. {
  1267. // Now, look at all link libraries specific to this target.
  1268. const cmTarget::LinkLibraries& tlibs = l->second.GetLinkLibraries();
  1269. for(cmTarget::LinkLibraries::const_iterator lib = tlibs.begin();
  1270. lib != tlibs.end(); ++lib)
  1271. {
  1272. // Record that this library was used.
  1273. used.insert(lib->first);
  1274. // Don't emit the same library twice for this target.
  1275. if(emitted.insert(lib->first).second)
  1276. {
  1277. // Output this dependency.
  1278. this->OutputLibDepend(fout, lib->first.c_str());
  1279. }
  1280. }
  1281. }
  1282. // for all targets depend on utilities
  1283. // Now, look at all utilities specific to this target.
  1284. const std::set<cmStdString>& tutils = l->second.GetUtilities();
  1285. for(std::set<cmStdString>::const_iterator util = tutils.begin();
  1286. util != tutils.end(); ++util)
  1287. {
  1288. // Record that this utility was used.
  1289. used.insert(*util);
  1290. // Don't emit the same utility twice for this target.
  1291. if(emitted.insert(*util).second)
  1292. {
  1293. // Output this dependency.
  1294. this->OutputExeDepend(fout, util->c_str());
  1295. }
  1296. }
  1297. fout << "\n";
  1298. }
  1299. }
  1300. fout << "\n";
  1301. // Loop over the libraries used and make sure there is a rule to
  1302. // build them in this makefile. If the library is in another
  1303. // directory, add a rule to jump to that directory and make sure it
  1304. // exists.
  1305. for(std::set<std::string>::const_iterator lib = used.begin();
  1306. lib != used.end(); ++lib)
  1307. {
  1308. // loop over the list of directories that the libraries might
  1309. // be in, looking for an ADD_LIBRARY(lib...) line. This would
  1310. // be stored in the cache
  1311. std::string libPath = *lib + "_CMAKE_PATH";
  1312. const char* cacheValue = m_Makefile->GetDefinition(libPath.c_str());
  1313. // if cache and not the current directory add a rule, to
  1314. // jump into the directory and build for the first time
  1315. if(cacheValue &&
  1316. (!this->SamePath(m_Makefile->GetCurrentOutputDirectory(), cacheValue)))
  1317. {
  1318. // add the correct extension
  1319. std::string ltname = *lib+"_LIBRARY_TYPE";
  1320. const char* libType
  1321. = m_Makefile->GetDefinition(ltname.c_str());
  1322. // if it was a library..
  1323. if (libType)
  1324. {
  1325. std::string library;
  1326. std::string libpath = cacheValue;
  1327. if(libType && std::string(libType) == "SHARED")
  1328. {
  1329. library = this->GetSafeDefinition("CMAKE_SHARED_LIBRARY_PREFIX");
  1330. library += *lib;
  1331. library += this->GetSafeDefinition("CMAKE_SHARED_LIBRARY_SUFFIX");
  1332. }
  1333. else if(libType && std::string(libType) == "MODULE")
  1334. {
  1335. library = this->GetSafeDefinition("CMAKE_SHARED_MODULE_PREFIX");
  1336. library += *lib;
  1337. library += this->GetSafeDefinition("CMAKE_SHARED_MODULE_SUFFIX");
  1338. }
  1339. else if(libType && std::string(libType) == "STATIC")
  1340. {
  1341. library = this->GetSafeDefinition("CMAKE_STATIC_LIBRARY_PREFIX");
  1342. library += *lib;
  1343. library += this->GetSafeDefinition("CMAKE_STATIC_LIBRARY_SUFFIX");
  1344. }
  1345. else
  1346. {
  1347. cmSystemTools::Error("Unknown library type!");
  1348. return;
  1349. }
  1350. if(m_LibraryOutputPath.size())
  1351. {
  1352. libpath = m_LibraryOutputPath;
  1353. }
  1354. else
  1355. {
  1356. libpath += "/";
  1357. }
  1358. libpath += library;
  1359. // put out a rule to build the library if it does not exist
  1360. this->OutputBuildTargetInDir(fout,
  1361. cacheValue,
  1362. library.c_str(),
  1363. libpath.c_str(),
  1364. m_Makefile->
  1365. GetDefinition("LIBRARY_OUTPUT_PATH")
  1366. );
  1367. }
  1368. // something other than a library...
  1369. else
  1370. {
  1371. std::string exepath = cacheValue;
  1372. if(m_ExecutableOutputPath.size())
  1373. {
  1374. exepath = m_ExecutableOutputPath;
  1375. }
  1376. else
  1377. {
  1378. exepath += "/";
  1379. }
  1380. std::string fullName = lib->c_str();
  1381. fullName += cmSystemTools::GetExecutableExtension();
  1382. exepath += fullName;
  1383. this->OutputBuildTargetInDir(fout,
  1384. cacheValue,
  1385. fullName.c_str(),
  1386. exepath.c_str(),
  1387. m_Makefile->
  1388. GetDefinition("EXECUTABLE_OUTPUT_PATH")
  1389. );
  1390. }
  1391. }
  1392. }
  1393. }
  1394. void cmLocalUnixMakefileGenerator::OutputBuildTargetInDirWindows(std::ostream& fout,
  1395. const char* path,
  1396. const char* library,
  1397. const char* fullpath,
  1398. const char* libOutPath)
  1399. {
  1400. const char* makeTarget = library;
  1401. std::string currentDir =
  1402. cmSystemTools::ConvertToOutputPath(m_Makefile->GetCurrentOutputDirectory());
  1403. std::string wpath = this->ConvertToOutputForExisting(path);
  1404. std::string wfullpath = this->ConvertToOutputForExisting(fullpath);
  1405. if(libOutPath && strcmp( libOutPath, "" ) != 0)
  1406. {
  1407. makeTarget = wfullpath.c_str();
  1408. }
  1409. fout << wfullpath
  1410. << ":\n\tcd " << wpath << "\n"
  1411. << "\t$(MAKE) -$(MAKEFLAGS) $(MAKESILENT) cmake.depends\n"
  1412. << "\t$(MAKE) -$(MAKEFLAGS) $(MAKESILENT) cmake.check_depends\n"
  1413. << "\t$(MAKE) -$(MAKEFLAGS) $(MAKESILENT) -f cmake.check_depends\n"
  1414. << "\t$(MAKE) $(MAKESILENT) " << makeTarget
  1415. << "\n\tcd " << currentDir << "\n";
  1416. }
  1417. void cmLocalUnixMakefileGenerator::OutputBuildTargetInDir(std::ostream& fout,
  1418. const char* path,
  1419. const char* library,
  1420. const char* fullpath,
  1421. const char* outputPath)
  1422. {
  1423. if(m_WindowsShell)
  1424. {
  1425. this->OutputBuildTargetInDirWindows(fout, path, library, fullpath, outputPath);
  1426. return;
  1427. }
  1428. const char* makeTarget = library;
  1429. if(outputPath && strcmp( outputPath, "" ) != 0)
  1430. {
  1431. makeTarget = fullpath;
  1432. }
  1433. fout << this->ConvertToOutputForExisting(fullpath)
  1434. << ":\n\tcd " << this->ConvertToOutputForExisting(path)
  1435. << "; $(MAKE) $(MAKESILENT) cmake.depends"
  1436. << "; $(MAKE) $(MAKESILENT) cmake.check_depends"
  1437. << "; $(MAKE) $(MAKESILENT) -f cmake.check_depends"
  1438. << "; $(MAKE) $(MAKESILENT) "
  1439. << cmSystemTools::ConvertToOutputPath(makeTarget) << "\n\n";
  1440. }
  1441. bool cmLocalUnixMakefileGenerator::SamePath(const char* path1, const char* path2)
  1442. {
  1443. if (strcmp(path1, path2) == 0)
  1444. {
  1445. return true;
  1446. }
  1447. #if defined(_WIN32) || defined(__APPLE__)
  1448. return
  1449. cmSystemTools::LowerCase(this->ConvertToOutputForExisting(path1)) ==
  1450. cmSystemTools::LowerCase(this->ConvertToOutputForExisting(path2));
  1451. #else
  1452. return false;
  1453. #endif
  1454. }
  1455. void cmLocalUnixMakefileGenerator::OutputLibDepend(std::ostream& fout,
  1456. const char* name)
  1457. {
  1458. std::string libPath = name;
  1459. libPath += "_CMAKE_PATH";
  1460. const char* cacheValue = m_Makefile->GetDefinition(libPath.c_str());
  1461. if(cacheValue )
  1462. {
  1463. // if there is a cache value, then this is a library that cmake
  1464. // knows how to build, so we can depend on it
  1465. std::string libpath;
  1466. if (!this->SamePath(m_Makefile->GetCurrentOutputDirectory(), cacheValue))
  1467. {
  1468. // if the library is not in the current directory, then get the full
  1469. // path to it
  1470. if(m_LibraryOutputPath.size())
  1471. {
  1472. libpath = m_LibraryOutputPath;
  1473. }
  1474. else
  1475. {
  1476. libpath = cacheValue;
  1477. libpath += "/";
  1478. }
  1479. }
  1480. else
  1481. {
  1482. // library is in current Makefile so use lib as a prefix
  1483. libpath = m_LibraryOutputPath;
  1484. }
  1485. // add the correct extension
  1486. std::string ltname = name;
  1487. ltname += "_LIBRARY_TYPE";
  1488. const char* libType = m_Makefile->GetDefinition(ltname.c_str());
  1489. if(libType && std::string(libType) == "SHARED")
  1490. {
  1491. libpath += this->GetSafeDefinition("CMAKE_SHARED_LIBRARY_PREFIX");
  1492. libpath += name;
  1493. libpath += this->GetSafeDefinition("CMAKE_SHARED_LIBRARY_SUFFIX");
  1494. }
  1495. else if (libType && std::string(libType) == "MODULE")
  1496. {
  1497. libpath += this->GetSafeDefinition("CMAKE_SHARED_MODULE_PREFIX");
  1498. libpath += name;
  1499. libpath += this->GetSafeDefinition("CMAKE_SHARED_MODULE_SUFFIX");
  1500. }
  1501. else if (libType && std::string(libType) == "STATIC")
  1502. {
  1503. libpath += this->GetSafeDefinition("CMAKE_STATIC_LIBRARY_PREFIX");
  1504. libpath += name;
  1505. libpath += this->GetSafeDefinition("CMAKE_STATIC_LIBRARY_SUFFIX");
  1506. }
  1507. fout << cmSystemTools::ConvertToOutputPath(libpath.c_str()) << " ";
  1508. }
  1509. }
  1510. void cmLocalUnixMakefileGenerator::OutputExeDepend(std::ostream& fout,
  1511. const char* name)
  1512. {
  1513. std::string exePath = name;
  1514. exePath += "_CMAKE_PATH";
  1515. const char* cacheValue = m_Makefile->GetDefinition(exePath.c_str());
  1516. if(cacheValue )
  1517. {
  1518. // if there is a cache value, then this is a executable/utility that cmake
  1519. // knows how to build, so we can depend on it
  1520. std::string exepath;
  1521. if (!this->SamePath(m_Makefile->GetCurrentOutputDirectory(), cacheValue))
  1522. {
  1523. // if the exe/utility is not in the current directory, then get the full
  1524. // path to it
  1525. if(m_ExecutableOutputPath.size())
  1526. {
  1527. exepath = m_ExecutableOutputPath;
  1528. }
  1529. else
  1530. {
  1531. exepath = cacheValue;
  1532. exepath += "/";
  1533. }
  1534. }
  1535. else
  1536. {
  1537. // library is in current Makefile
  1538. exepath = m_ExecutableOutputPath;
  1539. }
  1540. // add the library name
  1541. exepath += name;
  1542. // add the correct extension
  1543. exepath += cmSystemTools::GetExecutableExtension();
  1544. fout << cmSystemTools::ConvertToOutputPath(exepath.c_str()) << " ";
  1545. }
  1546. // if it isn't in the cache, it might still be a utility target
  1547. // so check for that
  1548. else
  1549. {
  1550. std::map<cmStdString, cmTarget>& targets = m_Makefile->GetTargets();
  1551. if (targets.find(name) != targets.end())
  1552. {
  1553. fout << name << " ";
  1554. }
  1555. }
  1556. }
  1557. // fix up names of directories so they can be used
  1558. // as targets in makefiles.
  1559. inline std::string FixDirectoryName(const char* dir)
  1560. {
  1561. std::string s = dir;
  1562. // replace ../ with 3 under bars
  1563. size_t pos = s.find("../");
  1564. if(pos != std::string::npos)
  1565. {
  1566. s.replace(pos, 3, "___");
  1567. }
  1568. // replace / directory separators with a single under bar
  1569. pos = s.find("/");
  1570. while(pos != std::string::npos)
  1571. {
  1572. s.replace(pos, 1, "_");
  1573. pos = s.find("/");
  1574. }
  1575. return s;
  1576. }
  1577. void cmLocalUnixMakefileGenerator::BuildInSubDirectoryWindows(std::ostream& fout,
  1578. const char* directory,
  1579. const char* target1,
  1580. const char* target2,
  1581. bool silent)
  1582. {
  1583. if(target1)
  1584. {
  1585. std::string dir = this->ConvertToOutputForExisting(directory);
  1586. if(dir[0] == '\"')
  1587. {
  1588. dir = dir.substr(1, dir.size()-2);
  1589. }
  1590. fout << "\tif not exist \"" << dir << "\\$(NULL)\""
  1591. << " "
  1592. << "$(MAKE) $(MAKESILENT) rebuild_cache\n";
  1593. if (!silent)
  1594. {
  1595. fout << "\t@echo " << directory << ": building " << target1 << "\n";
  1596. }
  1597. fout << "\tcd " << dir << "\n"
  1598. << "\t$(MAKE) -$(MAKEFLAGS) $(MAKESILENT) " << target1 << "\n";
  1599. }
  1600. if(target2)
  1601. {
  1602. if (!silent)
  1603. {
  1604. fout << "\t@echo " << directory << ": building " << target2 << "\n";
  1605. }
  1606. fout << "\t$(MAKE) -$(MAKEFLAGS) $(MAKESILENT) " << target2 << "\n";
  1607. }
  1608. std::string currentDir = m_Makefile->GetCurrentOutputDirectory();
  1609. fout << "\tcd " << this->ConvertToOutputForExisting(currentDir.c_str()) << "\n\n";
  1610. }
  1611. void cmLocalUnixMakefileGenerator::BuildInSubDirectory(std::ostream& fout,
  1612. const char* dir,
  1613. const char* target1,
  1614. const char* target2,
  1615. bool silent)
  1616. {
  1617. if(m_WindowsShell)
  1618. {
  1619. this->BuildInSubDirectoryWindows(fout, dir, target1, target2, silent);
  1620. return;
  1621. }
  1622. std::string directory = cmSystemTools::ConvertToOutputPath(dir);
  1623. if(target1)
  1624. {
  1625. fout << "\t@if test ! -d " << directory
  1626. << "; then $(MAKE) rebuild_cache; fi\n";
  1627. if (!silent)
  1628. {
  1629. fout << "\t@echo " << directory << ": building " << target1 << "\n";
  1630. }
  1631. fout << "\t@cd " << directory
  1632. << "; $(MAKE) " << target1 << "\n";
  1633. }
  1634. if(target2)
  1635. {
  1636. if (!silent)
  1637. {
  1638. fout << "\t@echo " << directory << ": building " << target2 << "\n";
  1639. }
  1640. fout << "\t@cd " << directory
  1641. << "; $(MAKE) " << target2 << "\n";
  1642. }
  1643. fout << "\n";
  1644. }
  1645. void
  1646. cmLocalUnixMakefileGenerator::
  1647. OutputSubDirectoryVars(std::ostream& fout,
  1648. const char* var,
  1649. const char* target,
  1650. const char* target1,
  1651. const char* target2,
  1652. const char* depend,
  1653. const std::vector<std::string>& SubDirectories,
  1654. bool silent)
  1655. {
  1656. if(!depend)
  1657. {
  1658. depend = "";
  1659. }
  1660. if( SubDirectories.size() == 0)
  1661. {
  1662. return;
  1663. }
  1664. fout << "# Variable for making " << target << " in subdirectories.\n";
  1665. fout << var << " = \\\n";
  1666. unsigned int ii;
  1667. for(ii =0; ii < SubDirectories.size(); ii++)
  1668. {
  1669. std::string subdir = FixDirectoryName(SubDirectories[ii].c_str());
  1670. fout << target << "_" << subdir.c_str();
  1671. if(ii == SubDirectories.size()-1)
  1672. {
  1673. fout << " \n\n";
  1674. }
  1675. else
  1676. {
  1677. fout << " \\\n";
  1678. }
  1679. }
  1680. fout << "# Targets for making " << target << " in subdirectories.\n";
  1681. std::string last = "";
  1682. for(unsigned int cc =0; cc < SubDirectories.size(); cc++)
  1683. {
  1684. std::string subdir = FixDirectoryName(SubDirectories[cc].c_str());
  1685. fout << target << "_" << subdir.c_str() << ": " << depend;
  1686. // Make each subdirectory depend on previous one. This forces
  1687. // parallel builds (make -j 2) to build in same order as a single
  1688. // threaded build to avoid dependency problems.
  1689. if(cc > 0)
  1690. {
  1691. fout << " " << target << "_" << last.c_str();
  1692. }
  1693. fout << "\n";
  1694. last = subdir;
  1695. std::string dir = m_Makefile->GetCurrentOutputDirectory();
  1696. dir += "/";
  1697. dir += SubDirectories[cc];
  1698. this->BuildInSubDirectory(fout, dir.c_str(),
  1699. target1, target2, silent);
  1700. }
  1701. fout << "\n\n";
  1702. }
  1703. // output rules for decending into sub directories
  1704. void cmLocalUnixMakefileGenerator::OutputSubDirectoryRules(std::ostream& fout)
  1705. {
  1706. // Output Sub directory build rules
  1707. const std::vector<std::string>& SubDirectories
  1708. = m_Makefile->GetSubDirectories();
  1709. if( SubDirectories.size() == 0)
  1710. {
  1711. return;
  1712. }
  1713. this->OutputSubDirectoryVars(fout,
  1714. "SUBDIR_BUILD",
  1715. "default_target",
  1716. "default_target",
  1717. 0, "$(TARGETS)",
  1718. SubDirectories,
  1719. false);
  1720. this->OutputSubDirectoryVars(fout, "SUBDIR_CLEAN", "clean",
  1721. "clean",
  1722. 0, 0,
  1723. SubDirectories);
  1724. this->OutputSubDirectoryVars(fout, "SUBDIR_DEPEND", "depend",
  1725. "depend",
  1726. 0, 0,
  1727. SubDirectories);
  1728. this->OutputSubDirectoryVars(fout, "SUBDIR_INSTALL", "install",
  1729. "install",
  1730. 0, 0,
  1731. SubDirectories);
  1732. }
  1733. // Output the depend information for all the classes
  1734. // in the makefile. These would have been generated
  1735. // by the class cmMakeDepend GenerateMakefile
  1736. bool cmLocalUnixMakefileGenerator::OutputObjectDepends(std::ostream& fout)
  1737. {
  1738. bool ret = false;
  1739. // Iterate over every target.
  1740. std::map<cmStdString, cmTarget>& targets = m_Makefile->GetTargets();
  1741. for(std::map<cmStdString, cmTarget>::const_iterator target = targets.begin();
  1742. target != targets.end(); ++target)
  1743. {
  1744. // Iterate over every source for this target.
  1745. const std::vector<cmSourceFile*>& sources = target->second.GetSourceFiles();
  1746. for(std::vector<cmSourceFile*>::const_iterator source = sources.begin();
  1747. source != sources.end(); ++source)
  1748. {
  1749. if(!(*source)->GetPropertyAsBool("HEADER_FILE_ONLY"))
  1750. {
  1751. if(!(*source)->GetDepends().empty())
  1752. {
  1753. // Iterate through all the dependencies for this source.
  1754. for(std::vector<std::string>::const_iterator dep =
  1755. (*source)->GetDepends().begin();
  1756. dep != (*source)->GetDepends().end(); ++dep)
  1757. {
  1758. std::string s = (*source)->GetSourceName();
  1759. s += this->GetOutputExtension((*source)->GetSourceExtension().c_str());
  1760. fout << cmSystemTools::ConvertToOutputPath(s.c_str()) << " : "
  1761. << cmSystemTools::ConvertToOutputPath(dep->c_str()) << "\n";
  1762. ret = true;
  1763. }
  1764. fout << "\n\n";
  1765. }
  1766. }
  1767. }
  1768. }
  1769. return ret;
  1770. }
  1771. // Output the depend information for all the classes
  1772. // in the makefile. These would have been generated
  1773. // by the class cmMakeDepend GenerateMakefile
  1774. void cmLocalUnixMakefileGenerator::OutputCheckDepends(std::ostream& fout)
  1775. {
  1776. std::set<std::string> emittedLowerPath;
  1777. std::set<std::string> emitted;
  1778. // Iterate over every target.
  1779. std::map<cmStdString, cmTarget>& targets = m_Makefile->GetTargets();
  1780. fout << "# Suppresses display of executed commands\n";
  1781. fout << ".SILENT:\n";
  1782. fout << "# disable some common implicit rules to speed things up\n";
  1783. fout << ".SUFFIXES:\n";
  1784. fout << ".SUFFIXES:.hpuxmakemusthaverule\n";
  1785. this->OutputMakeVariables(fout);
  1786. fout << "default:\n";
  1787. fout << "\t$(MAKE) $(MAKESILENT) -f cmake.check_depends all\n"
  1788. << "\t$(MAKE) $(MAKESILENT) -f cmake.check_depends cmake.depends\n\n";
  1789. for(std::map<cmStdString, cmTarget>::const_iterator target = targets.begin();
  1790. target != targets.end(); ++target)
  1791. {
  1792. // Iterate over every source for this target.
  1793. const std::vector<cmSourceFile*>& sources = target->second.GetSourceFiles();
  1794. for(std::vector<cmSourceFile*>::const_iterator source = sources.begin();
  1795. source != sources.end(); ++source)
  1796. {
  1797. if(!(*source)->GetPropertyAsBool("HEADER_FILE_ONLY"))
  1798. {
  1799. if(!(*source)->GetDepends().empty())
  1800. {
  1801. for(std::vector<std::string>::const_iterator dep =
  1802. (*source)->GetDepends().begin();
  1803. dep != (*source)->GetDepends().end(); ++dep)
  1804. {
  1805. // do not call CollapseFullPath on dep here, because it already
  1806. // has been done because m_FullPath on cmDependInformation
  1807. // always is it called. If it is called here, network builds are
  1808. // very slow because of the number of stats
  1809. std::string dependfile = cmSystemTools::ConvertToOutputPath(dep->c_str());
  1810. // use the lower path function to create uniqe names
  1811. std::string lowerpath = this->LowerCasePath(dependfile.c_str());
  1812. if(emittedLowerPath.insert(lowerpath).second)
  1813. {
  1814. emitted.insert(dependfile);
  1815. fout << "all:: " << dependfile << "\n";
  1816. }
  1817. }
  1818. }
  1819. }
  1820. }
  1821. }
  1822. fout << "\n\n# if any of these files changes run make dependlocal\n";
  1823. std::set<std::string>::iterator i;
  1824. for(i = emitted.begin(); i != emitted.end(); ++i)
  1825. {
  1826. fout << "cmake.depends:: " << *i <<
  1827. "\n\t$(MAKE) $(MAKESILENT) dependlocal\n\n";
  1828. }
  1829. fout << "\n\n";
  1830. fout << "# if a .h file is removed then run make dependlocal\n\n";
  1831. for(std::set<std::string>::iterator it = emitted.begin();
  1832. it != emitted.end(); ++it)
  1833. {
  1834. fout << *it << ":\n"
  1835. << "\t$(MAKE) $(MAKESILENT) dependlocal\n\n";
  1836. }
  1837. }
  1838. // Output each custom rule in the following format:
  1839. // output: source depends...
  1840. // (tab) command...
  1841. void cmLocalUnixMakefileGenerator::OutputCustomRules(std::ostream& fout)
  1842. {
  1843. // we cannot provide multiple rules for a single output
  1844. // so we will keep track of outputs to make sure we don't write
  1845. // two rules. First found wins
  1846. std::set<std::string> processedOutputs;
  1847. // first output all custom rules
  1848. const std::vector<cmSourceFile*>& sources = m_Makefile->GetSourceFiles();
  1849. for(std::vector<cmSourceFile*>::const_iterator i = sources.begin();
  1850. i != sources.end(); ++i)
  1851. {
  1852. if ((*i)->GetCustomCommand())
  1853. {
  1854. cmCustomCommand *c = (*i)->GetCustomCommand();
  1855. // escape spaces and convert to native slashes path for
  1856. // the command
  1857. std::string comment = c->GetComment();
  1858. std::string command = c->GetCommand();
  1859. cmSystemTools::ReplaceString(command, "/./", "/");
  1860. command = cmSystemTools::ConvertToOutputPath(command.c_str());
  1861. command += " ";
  1862. // now add the arguments
  1863. command += c->GetArguments();
  1864. std::string depends;
  1865. // Collect out all the dependencies for this rule.
  1866. for(std::vector<std::string>::const_iterator d =
  1867. c->GetDepends().begin();
  1868. d != c->GetDepends().end(); ++d)
  1869. {
  1870. std::string dep = *d;
  1871. m_Makefile->ExpandVariablesInString(dep);
  1872. // watch for target dependencies,
  1873. std::string libPath = dep + "_CMAKE_PATH";
  1874. const char* cacheValue = m_Makefile->GetDefinition(libPath.c_str());
  1875. if (cacheValue)
  1876. {
  1877. libPath = cacheValue;
  1878. if (m_Makefile->GetDefinition("EXECUTABLE_OUTPUT_PATH") &&
  1879. m_Makefile->GetDefinition("EXECUTABLE_OUTPUT_PATH")[0] != '\0')
  1880. {
  1881. libPath = m_Makefile->GetDefinition("EXECUTABLE_OUTPUT_PATH");
  1882. }
  1883. libPath += "/";
  1884. libPath += dep;
  1885. libPath += cmSystemTools::GetExecutableExtension();
  1886. dep = libPath;
  1887. }
  1888. cmSystemTools::ReplaceString(dep, "/./", "/");
  1889. cmSystemTools::ReplaceString(dep, "/$(IntDir)/", "/");
  1890. dep = cmSystemTools::ConvertToOutputPath(dep.c_str());
  1891. depends += " ";
  1892. depends += dep;
  1893. }
  1894. // output rule
  1895. if (processedOutputs.find(c->GetOutput()) == processedOutputs.end())
  1896. {
  1897. this->OutputMakeRule(fout,
  1898. (comment.size()?comment.c_str():"Custom command"),
  1899. c->GetOutput().c_str(),
  1900. depends.c_str(),
  1901. command.c_str());
  1902. processedOutputs.insert(c->GetOutput());
  1903. }
  1904. else
  1905. {
  1906. cmSystemTools::Error("An output was found with multiple rules on how to build it for output: ",
  1907. c->GetOutput().c_str());
  1908. }
  1909. }
  1910. }
  1911. }
  1912. std::string
  1913. cmLocalUnixMakefileGenerator::ConvertToOutputForExisting(const char* p)
  1914. {
  1915. std::string ret = cmSystemTools::ConvertToOutputPath(p);
  1916. // if there are spaces in the path, then get the short path version
  1917. // if there is one
  1918. if(ret.find(' ') != std::string::npos)
  1919. {
  1920. if(cmSystemTools::FileExists(p))
  1921. {
  1922. if(!cmSystemTools::GetShortPath(ret.c_str(), ret))
  1923. {
  1924. ret = p;
  1925. }
  1926. }
  1927. }
  1928. return ret;
  1929. }
  1930. void cmLocalUnixMakefileGenerator::OutputMakeVariables(std::ostream& fout)
  1931. {
  1932. const char* variables =
  1933. "# the standard shell for make\n"
  1934. "SHELL = /bin/sh\n"
  1935. "\n";
  1936. if(!m_WindowsShell)
  1937. {
  1938. fout << variables;
  1939. }
  1940. else
  1941. {
  1942. fout <<
  1943. "!IF \"$(OS)\" == \"Windows_NT\"\n"
  1944. "NULL=\n"
  1945. "!ELSE \n"
  1946. "NULL=nul\n"
  1947. "!ENDIF \n";
  1948. }
  1949. if(m_MakeSilentFlag.size())
  1950. {
  1951. fout << "MAKESILENT = " << m_MakeSilentFlag << "\n";
  1952. }
  1953. std::string cmakecommand = this->ConvertToOutputForExisting(
  1954. m_Makefile->GetDefinition("CMAKE_COMMAND"));
  1955. fout << "CMAKE_COMMAND = "
  1956. << cmakecommand
  1957. << "\n";
  1958. fout << "RM = " << cmakecommand.c_str() << " -E remove -f\n";
  1959. if(m_Makefile->GetDefinition("CMAKE_EDIT_COMMAND"))
  1960. {
  1961. fout << "CMAKE_EDIT_COMMAND = "
  1962. << this->ConvertToOutputForExisting(m_Makefile->GetDefinition("CMAKE_EDIT_COMMAND"))
  1963. << "\n";
  1964. }
  1965. fout << "CMAKE_CURRENT_SOURCE = " <<
  1966. cmSystemTools::ConvertToOutputPath(m_Makefile->GetStartDirectory())
  1967. << "\n";
  1968. fout << "CMAKE_CURRENT_BINARY = " <<
  1969. cmSystemTools::ConvertToOutputPath(m_Makefile->GetStartOutputDirectory())
  1970. << "\n";
  1971. fout << "CMAKE_SOURCE_DIR = " <<
  1972. cmSystemTools::ConvertToOutputPath(m_Makefile->GetHomeDirectory())
  1973. << "\n";
  1974. fout << "CMAKE_BINARY_DIR = " <<
  1975. cmSystemTools::ConvertToOutputPath(m_Makefile->GetHomeOutputDirectory())
  1976. << "\n";
  1977. // Output Include paths
  1978. fout << "INCLUDE_FLAGS = ";
  1979. std::vector<std::string>& includes = m_Makefile->GetIncludeDirectories();
  1980. std::vector<std::string>::iterator i;
  1981. fout << "-I" <<
  1982. this->ConvertToOutputForExisting(m_Makefile->GetStartDirectory()) << " ";
  1983. for(i = includes.begin(); i != includes.end(); ++i)
  1984. {
  1985. std::string include = *i;
  1986. // Don't output a -I for the standard include path "/usr/include".
  1987. // This can cause problems with certain standard library
  1988. // implementations because the wrong headers may be found first.
  1989. if(include != "/usr/include")
  1990. {
  1991. fout << "-I" << this->ConvertToOutputForExisting(i->c_str()) << " ";
  1992. }
  1993. }
  1994. fout << m_Makefile->GetDefineFlags();
  1995. fout << "\n\n";
  1996. }
  1997. void cmLocalUnixMakefileGenerator::OutputInstallRules(std::ostream& fout)
  1998. {
  1999. const char* root
  2000. = m_Makefile->GetDefinition("CMAKE_ROOT");
  2001. fout << "INSTALL = \"" << root << "/Templates/install-sh\" -c\n";
  2002. fout << "INSTALL_PROGRAM = $(INSTALL)\n";
  2003. fout << "INSTALL_DATA = $(INSTALL) -m 644\n";
  2004. const cmTargets &tgts = m_Makefile->GetTargets();
  2005. fout << "install: $(SUBDIR_INSTALL)\n";
  2006. fout << "\t@echo \"Installing ...\"\n";
  2007. const char* prefix
  2008. = m_Makefile->GetDefinition("CMAKE_INSTALL_PREFIX");
  2009. if (!prefix)
  2010. {
  2011. prefix = "/usr/local";
  2012. }
  2013. for(cmTargets::const_iterator l = tgts.begin();
  2014. l != tgts.end(); l++)
  2015. {
  2016. if (l->second.GetInstallPath() != "")
  2017. {
  2018. // first make the directories for each target
  2019. fout << "\t@if [ ! -d \"$(DESTDIR)" << prefix << l->second.GetInstallPath() <<
  2020. "\" ] ; then \\\n";
  2021. fout << "\t @echo \"Making directory \\\"$(DESTDIR)" << prefix
  2022. << l->second.GetInstallPath() << "\\\" \"; \\\n";
  2023. fout << "\t mkdir -p \"$(DESTDIR)" << prefix << l->second.GetInstallPath()
  2024. << "\"; \\\n";
  2025. fout << "\t chmod 755 \"$(DESTDIR)" << prefix << l->second.GetInstallPath()
  2026. << "\"; \\\n";
  2027. fout << "\t else true; \\\n";
  2028. fout << "\t fi\n";
  2029. std::string fname;
  2030. // now install the target
  2031. switch (l->second.GetType())
  2032. {
  2033. case cmTarget::STATIC_LIBRARY:
  2034. case cmTarget::SHARED_LIBRARY:
  2035. case cmTarget::MODULE_LIBRARY:
  2036. fname = m_LibraryOutputPath;
  2037. fname += this->GetFullTargetName(l->first.c_str(), l->second);
  2038. fout << "\t$(INSTALL_DATA) " << cmSystemTools::ConvertToOutputPath(fname.c_str())
  2039. << " \"$(DESTDIR)" << prefix << l->second.GetInstallPath() << "\"\n";
  2040. break;
  2041. case cmTarget::WIN32_EXECUTABLE:
  2042. case cmTarget::EXECUTABLE:
  2043. fname = m_ExecutableOutputPath;
  2044. fname += this->GetFullTargetName(l->first.c_str(), l->second);
  2045. fout << "\t$(INSTALL_PROGRAM) " << cmSystemTools::ConvertToOutputPath(fname.c_str())
  2046. << " \"$(DESTDIR)" << prefix << l->second.GetInstallPath() << "\"\n";
  2047. break;
  2048. case cmTarget::INSTALL_FILES:
  2049. {
  2050. std::string sourcePath = m_Makefile->GetCurrentDirectory();
  2051. std::string binaryPath = m_Makefile->GetCurrentOutputDirectory();
  2052. sourcePath += "/";
  2053. binaryPath += "/";
  2054. const std::vector<std::string> &sf = l->second.GetSourceLists();
  2055. std::vector<std::string>::const_iterator i;
  2056. for (i = sf.begin(); i != sf.end(); ++i)
  2057. {
  2058. std::string f = *i;
  2059. if(f.substr(0, sourcePath.length()) == sourcePath)
  2060. {
  2061. f = f.substr(sourcePath.length());
  2062. }
  2063. else if(f.substr(0, binaryPath.length()) == binaryPath)
  2064. {
  2065. f = f.substr(binaryPath.length());
  2066. }
  2067. fout << "\t@echo \"Installing " << f.c_str() << " \"\n";
  2068. // avoid using install-sh to install install-sh
  2069. // does not work on windows....
  2070. if(*i == "install-sh")
  2071. {
  2072. fout << "\tcp ";
  2073. }
  2074. else
  2075. {
  2076. fout << "\t$(INSTALL_DATA) ";
  2077. }
  2078. fout << cmSystemTools::ConvertToOutputPath(i->c_str())
  2079. << " \"$(DESTDIR)" << prefix << l->second.GetInstallPath() << "\"\n";
  2080. }
  2081. }
  2082. break;
  2083. case cmTarget::INSTALL_PROGRAMS:
  2084. {
  2085. std::string sourcePath = m_Makefile->GetCurrentDirectory();
  2086. std::string binaryPath = m_Makefile->GetCurrentOutputDirectory();
  2087. sourcePath += "/";
  2088. binaryPath += "/";
  2089. const std::vector<std::string> &sf = l->second.GetSourceLists();
  2090. std::vector<std::string>::const_iterator i;
  2091. for (i = sf.begin(); i != sf.end(); ++i)
  2092. {
  2093. std::string f = *i;
  2094. if(f.substr(0, sourcePath.length()) == sourcePath)
  2095. {
  2096. f = f.substr(sourcePath.length());
  2097. }
  2098. else if(f.substr(0, binaryPath.length()) == binaryPath)
  2099. {
  2100. f = f.substr(binaryPath.length());
  2101. }
  2102. fout << "\t@echo \"Installing " << f.c_str() << " \"\n";
  2103. // avoid using install-sh to install install-sh
  2104. // does not work on windows....
  2105. if(*i == "install-sh")
  2106. {
  2107. fout << "\t @cp ";
  2108. }
  2109. else
  2110. {
  2111. fout << "\t @$(INSTALL_PROGRAM) ";
  2112. }
  2113. fout << cmSystemTools::ConvertToOutputPath(i->c_str())
  2114. << " \"$(DESTDIR)" << prefix << l->second.GetInstallPath() << "\"\n";
  2115. }
  2116. }
  2117. break;
  2118. case cmTarget::UTILITY:
  2119. default:
  2120. break;
  2121. }
  2122. }
  2123. }
  2124. }
  2125. void cmLocalUnixMakefileGenerator::OutputMakeRules(std::ostream& fout)
  2126. {
  2127. this->OutputMakeRule(fout,
  2128. "default build rule",
  2129. "all",
  2130. "cmake.depends $(TARGETS) $(SUBDIR_BUILD)",
  2131. 0);
  2132. this->OutputMakeRule(fout,
  2133. "clean generated files",
  2134. "clean",
  2135. "$(SUBDIR_CLEAN)",
  2136. "-@ $(RM) $(CLEAN_OBJECT_FILES) "
  2137. " $(TARGETS) $(GENERATED_QT_FILES) $(GENERATED_FLTK_FILES)");
  2138. // collect up all the sources
  2139. std::string allsources;
  2140. std::map<cmStdString, cmTarget>& targets = m_Makefile->GetTargets();
  2141. for(std::map<cmStdString,cmTarget>::const_iterator target = targets.begin();
  2142. target != targets.end(); ++target)
  2143. {
  2144. // Iterate over every source for this target.
  2145. const std::vector<cmSourceFile*>& sources = target->second.GetSourceFiles();
  2146. for(std::vector<cmSourceFile*>::const_iterator source = sources.begin();
  2147. source != sources.end(); ++source)
  2148. {
  2149. if(!(*source)->GetPropertyAsBool("HEADER_FILE_ONLY"))
  2150. {
  2151. allsources += " \\\n";
  2152. allsources += cmSystemTools::ConvertToOutputPath((*source)->GetFullPath().c_str());
  2153. }
  2154. }
  2155. }
  2156. this->OutputMakeRule(fout,
  2157. "dependencies.",
  2158. "cmake.depends",
  2159. "$(CMAKE_MAKEFILE_SOURCES)",
  2160. "$(CMAKE_COMMAND) "
  2161. "-S$(CMAKE_CURRENT_SOURCE) -O$(CMAKE_CURRENT_BINARY) "
  2162. "-H$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR)"
  2163. );
  2164. this->OutputMakeRule(fout,
  2165. "dependencies",
  2166. "cmake.check_depends",
  2167. allsources.c_str(),
  2168. "$(CMAKE_COMMAND) "
  2169. "-S$(CMAKE_CURRENT_SOURCE) -O$(CMAKE_CURRENT_BINARY) "
  2170. "-H$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR)"
  2171. );
  2172. this->OutputMakeRule(fout,
  2173. "dependencies",
  2174. "depend",
  2175. "$(SUBDIR_DEPEND)",
  2176. "$(CMAKE_COMMAND) "
  2177. "-S$(CMAKE_CURRENT_SOURCE) -O$(CMAKE_CURRENT_BINARY) "
  2178. "-H$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR)");
  2179. this->OutputMakeRule(fout,
  2180. "dependencies",
  2181. "dependlocal",
  2182. 0,
  2183. "$(CMAKE_COMMAND) "
  2184. "-S$(CMAKE_CURRENT_SOURCE) -O$(CMAKE_CURRENT_BINARY) "
  2185. "-H$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR)");
  2186. this->OutputMakeRule(fout,
  2187. "CMakeCache.txt",
  2188. "rebuild_cache",
  2189. "$(CMAKE_BINARY_DIR)/CMakeCache.txt",
  2190. "$(CMAKE_COMMAND) "
  2191. "-H$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR)");
  2192. std::string checkCache = m_Makefile->GetHomeOutputDirectory();
  2193. checkCache += "/cmake.check_cache";
  2194. checkCache = cmSystemTools::ConvertToOutputPath(checkCache.c_str());
  2195. std::string CMakeCache = m_Makefile->GetHomeOutputDirectory();
  2196. CMakeCache += "/CMakeCache.txt";
  2197. CMakeCache = cmSystemTools::ConvertToOutputPath(CMakeCache.c_str());
  2198. this->OutputMakeRule(fout,
  2199. "CMakeCache.txt because out-of-date:",
  2200. checkCache.c_str(),
  2201. CMakeCache.c_str(),
  2202. "$(CMAKE_COMMAND) "
  2203. "-H$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR)");
  2204. // if CMAKE_EDIT_COMMAND is defined then add a rule to run it
  2205. // called edit_cache
  2206. if(m_Makefile->GetDefinition("CMAKE_EDIT_COMMAND"))
  2207. {
  2208. this->OutputMakeRule(fout,
  2209. "edit CMakeCache.txt",
  2210. "edit_cache",
  2211. 0,
  2212. "$(CMAKE_EDIT_COMMAND) "
  2213. "-H$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR)");
  2214. }
  2215. this->OutputMakeRule(fout,
  2216. "CMakeCache.txt",
  2217. "$(CMAKE_BINARY_DIR)/CMakeCache.txt",
  2218. 0,
  2219. "$(CMAKE_COMMAND) "
  2220. "-H$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR)");
  2221. this->OutputMakeRule(fout,
  2222. "Rule to keep make from removing Makefiles "
  2223. "if control-C is hit during a run of cmake.",
  2224. ".PRECIOUS",
  2225. "Makefile cmake.depends",
  2226. 0);
  2227. this->OutputSourceObjectBuildRules(fout);
  2228. // find ctest
  2229. std::string ctest = m_Makefile->GetDefinition("CMAKE_COMMAND");
  2230. ctest = cmSystemTools::GetFilenamePath(ctest.c_str());
  2231. ctest += "/";
  2232. ctest += "ctest";
  2233. ctest += cmSystemTools::GetExecutableExtension();
  2234. if(!cmSystemTools::FileExists(ctest.c_str()))
  2235. {
  2236. ctest = m_Makefile->GetDefinition("CMAKE_COMMAND");
  2237. ctest = cmSystemTools::GetFilenamePath(ctest.c_str());
  2238. ctest += "/Debug/";
  2239. ctest += "ctest";
  2240. ctest += cmSystemTools::GetExecutableExtension();
  2241. }
  2242. if(!cmSystemTools::FileExists(ctest.c_str()))
  2243. {
  2244. ctest = m_Makefile->GetDefinition("CMAKE_COMMAND");
  2245. ctest = cmSystemTools::GetFilenamePath(ctest.c_str());
  2246. ctest += "/Release/";
  2247. ctest += "ctest";
  2248. ctest += cmSystemTools::GetExecutableExtension();
  2249. }
  2250. if (!cmSystemTools::FileExists(ctest.c_str()))
  2251. {
  2252. if ( !m_Makefile->GetDefinition("PROJECT_NAME") ||
  2253. strcmp(m_Makefile->GetDefinition("PROJECT_NAME"), "CMake") )
  2254. {
  2255. return;
  2256. }
  2257. ctest = m_Makefile->GetDefinition("EXECUTABLE_OUTPUT_PATH");
  2258. ctest += "/ctest";
  2259. }
  2260. fout << "ARGS=\n";
  2261. std::string cmd = this->ConvertToOutputForExisting(ctest.c_str());
  2262. cmd += " $(ARGS)";
  2263. this->OutputMakeRule(fout,
  2264. "tests",
  2265. "test",
  2266. "",
  2267. cmd.c_str());
  2268. }
  2269. void
  2270. cmLocalUnixMakefileGenerator::
  2271. OutputBuildObjectFromSource(std::ostream& fout,
  2272. const char* shortName,
  2273. const cmSourceFile& source,
  2274. const char* extraCompileFlags,
  2275. bool shared)
  2276. {
  2277. // Header files shouldn't have build rules.
  2278. if(source.GetPropertyAsBool("HEADER_FILE_ONLY"))
  2279. {
  2280. return;
  2281. }
  2282. std::string comment = "object file";
  2283. std::string objectFile = std::string(shortName) +
  2284. this->GetOutputExtension(source.GetSourceExtension().c_str());
  2285. objectFile = cmSystemTools::ConvertToOutputPath(objectFile.c_str());
  2286. cmSystemTools::FileFormat format =
  2287. cmSystemTools::GetFileFormat(source.GetSourceExtension().c_str());
  2288. std::vector<std::string> rules;
  2289. std::string flags;
  2290. if(extraCompileFlags)
  2291. {
  2292. flags += extraCompileFlags;
  2293. }
  2294. std::string sourceFile =
  2295. cmSystemTools::ConvertToOutputPath(source.GetFullPath().c_str());
  2296. std::string buildType = this->GetSafeDefinition("CMAKE_BUILD_TYPE");
  2297. buildType = cmSystemTools::UpperCase(buildType);
  2298. switch(format)
  2299. {
  2300. case cmSystemTools::C_FILE_FORMAT:
  2301. {
  2302. rules.push_back(m_Makefile->GetDefinition("CMAKE_C_COMPILE_OBJECT"));
  2303. flags += this->GetSafeDefinition("CMAKE_C_FLAGS");
  2304. flags += " ";
  2305. if(buildType.size())
  2306. {
  2307. std::string build = "CMAKE_C_FLAGS_";
  2308. build += buildType;
  2309. flags += this->GetSafeDefinition(build.c_str());
  2310. flags += " ";
  2311. }
  2312. if(shared)
  2313. {
  2314. flags += this->GetSafeDefinition("CMAKE_SHARED_LIBRARY_C_FLAGS");
  2315. flags += " ";
  2316. }
  2317. if(cmSystemTools::IsOn(m_Makefile->GetDefinition("BUILD_SHARED_LIBS")))
  2318. {
  2319. flags += this->GetSafeDefinition("CMAKE_SHARED_BUILD_C_FLAGS");
  2320. flags += " ";
  2321. }
  2322. break;
  2323. }
  2324. case cmSystemTools::CXX_FILE_FORMAT:
  2325. {
  2326. rules.push_back(m_Makefile->GetDefinition("CMAKE_CXX_COMPILE_OBJECT"));
  2327. flags += this->GetSafeDefinition("CMAKE_CXX_FLAGS");
  2328. flags += " ";
  2329. if(buildType.size())
  2330. {
  2331. std::string build = "CMAKE_CXX_FLAGS_";
  2332. build += buildType;
  2333. flags += this->GetSafeDefinition(build.c_str());
  2334. flags += " ";
  2335. }
  2336. if(shared)
  2337. {
  2338. flags += this->GetSafeDefinition("CMAKE_SHARED_LIBRARY_CXX_FLAGS");
  2339. flags += " ";
  2340. }
  2341. if(cmSystemTools::IsOn(m_Makefile->GetDefinition("BUILD_SHARED_LIBS")))
  2342. {
  2343. flags += this->GetSafeDefinition("CMAKE_SHARED_BUILD_CXX_FLAGS");
  2344. flags += " ";
  2345. }
  2346. break;
  2347. }
  2348. case cmSystemTools::HEADER_FILE_FORMAT:
  2349. return;
  2350. case cmSystemTools::DEFINITION_FILE_FORMAT:
  2351. return;
  2352. case cmSystemTools::RESOURCE_FILE_FORMAT:
  2353. {
  2354. flags = " $(INCLUDE_FLAGS) ";
  2355. // use rc rule here if it is defined
  2356. const char* rule = m_Makefile->GetDefinition("CMAKE_COMPILE_RESOURCE");
  2357. if(rule)
  2358. {
  2359. rules.push_back(rule);
  2360. }
  2361. }
  2362. break;
  2363. case cmSystemTools::NO_FILE_FORMAT:
  2364. case cmSystemTools::JAVA_FILE_FORMAT:
  2365. case cmSystemTools::STATIC_LIBRARY_FILE_FORMAT:
  2366. case cmSystemTools::SHARED_LIBRARY_FILE_FORMAT:
  2367. case cmSystemTools::MODULE_FILE_FORMAT:
  2368. case cmSystemTools::OBJECT_FILE_FORMAT:
  2369. case cmSystemTools::UNKNOWN_FILE_FORMAT:
  2370. cmSystemTools::Error("Unexpected file type ",
  2371. sourceFile.c_str());
  2372. break;
  2373. }
  2374. flags += "$(INCLUDE_FLAGS) ";
  2375. // expand multi-command semi-colon separated lists
  2376. // of commands into separate commands
  2377. std::vector<std::string> commands;
  2378. cmSystemTools::ExpandList(rules, commands);
  2379. for(std::vector<std::string>::iterator i = commands.begin();
  2380. i != commands.end(); ++i)
  2381. {
  2382. this->ExpandRuleVariables(*i,
  2383. 0, // no objects
  2384. 0, // no target
  2385. 0, // no link libs
  2386. sourceFile.c_str(),
  2387. objectFile.c_str(),
  2388. flags.c_str());
  2389. }
  2390. std::vector<std::string> sourceAndDeps;
  2391. sourceAndDeps.push_back(sourceFile);
  2392. // Check for extra object-file dependencies.
  2393. std::vector<std::string> depends;
  2394. const char* additionalDeps = source.GetProperty("OBJECT_DEPENDS");
  2395. if(additionalDeps)
  2396. {
  2397. cmSystemTools::ExpandListArgument(additionalDeps, depends);
  2398. for(std::vector<std::string>::iterator i = depends.begin();
  2399. i != depends.end(); ++i)
  2400. {
  2401. sourceAndDeps.push_back(cmSystemTools::ConvertToOutputPath(i->c_str()));
  2402. }
  2403. }
  2404. this->OutputMakeRule(fout,
  2405. comment.c_str(),
  2406. objectFile.c_str(),
  2407. sourceAndDeps,
  2408. commands);
  2409. }
  2410. void cmLocalUnixMakefileGenerator::OutputSourceObjectBuildRules(std::ostream& fout)
  2411. {
  2412. fout << "# Rules to build " << this->GetOutputExtension("")
  2413. << " files from their sources:\n";
  2414. std::set<std::string> rules;
  2415. // Iterate over every target.
  2416. std::map<cmStdString, cmTarget>& targets = m_Makefile->GetTargets();
  2417. for(std::map<cmStdString, cmTarget>::const_iterator target = targets.begin();
  2418. target != targets.end(); ++target)
  2419. {
  2420. bool shared = ((target->second.GetType() == cmTarget::SHARED_LIBRARY) ||
  2421. (target->second.GetType() == cmTarget::MODULE_LIBRARY));
  2422. std::string exportsDef = "";
  2423. if(shared)
  2424. {
  2425. std::string export_symbol;
  2426. if (const char* custom_export_name = target->second.GetProperty("DEFINE_SYMBOL"))
  2427. {
  2428. export_symbol = custom_export_name;
  2429. }
  2430. else
  2431. {
  2432. std::string in = target->first + "_EXPORTS";
  2433. export_symbol = cmSystemTools::MakeCindentifier(in.c_str());
  2434. }
  2435. exportsDef = "-D"+ export_symbol;
  2436. }
  2437. // Iterate over every source for this target.
  2438. const std::vector<cmSourceFile*>& sources =
  2439. target->second.GetSourceFiles();
  2440. for(std::vector<cmSourceFile*>::const_iterator source = sources.begin();
  2441. source != sources.end(); ++source)
  2442. {
  2443. if(!(*source)->GetPropertyAsBool("HEADER_FILE_ONLY") &&
  2444. !(*source)->GetCustomCommand())
  2445. {
  2446. std::string shortName;
  2447. std::string sourceName;
  2448. // If the full path to the source file includes this
  2449. // directory, we want to use the relative path for the
  2450. // filename of the object file. Otherwise, we will use just
  2451. // the filename portion.
  2452. if((cmSystemTools::GetFilenamePath(
  2453. (*source)->GetFullPath()).find(
  2454. m_Makefile->GetCurrentDirectory()) == 0)
  2455. || (cmSystemTools::GetFilenamePath(
  2456. (*source)->GetFullPath()).find(
  2457. m_Makefile->GetCurrentOutputDirectory()) == 0))
  2458. {
  2459. sourceName = (*source)->GetSourceName()+"."+
  2460. (*source)->GetSourceExtension();
  2461. shortName = (*source)->GetSourceName();
  2462. // The path may be relative. See if a directory needs to be
  2463. // created for the output file. This is a ugly, and perhaps
  2464. // should be moved elsewhere.
  2465. std::string relPath =
  2466. cmSystemTools::GetFilenamePath((*source)->GetSourceName());
  2467. if(relPath != "")
  2468. {
  2469. std::string outPath = m_Makefile->GetCurrentOutputDirectory();
  2470. outPath += "/"+relPath;
  2471. cmSystemTools::MakeDirectory(outPath.c_str());
  2472. }
  2473. }
  2474. else
  2475. {
  2476. sourceName = (*source)->GetFullPath();
  2477. shortName = cmSystemTools::GetFilenameName((*source)->GetSourceName());
  2478. }
  2479. std::string shortNameWithExt = shortName +
  2480. (*source)->GetSourceExtension();
  2481. // Only output a rule for each .o once.
  2482. std::string compileFlags = exportsDef;
  2483. compileFlags += " ";
  2484. if(rules.find(shortNameWithExt) == rules.end())
  2485. {
  2486. if((*source)->GetProperty("COMPILE_FLAGS"))
  2487. {
  2488. compileFlags += (*source)->GetProperty("COMPILE_FLAGS");
  2489. compileFlags += " ";
  2490. }
  2491. this->OutputBuildObjectFromSource(fout,
  2492. shortName.c_str(),
  2493. *(*source),
  2494. compileFlags.c_str(),
  2495. shared);
  2496. rules.insert(shortNameWithExt);
  2497. }
  2498. }
  2499. }
  2500. }
  2501. }
  2502. void cmLocalUnixMakefileGenerator::OutputMakeRule(std::ostream& fout,
  2503. const char* comment,
  2504. const char* target,
  2505. const char* depends,
  2506. const char* command,
  2507. const char* command2,
  2508. const char* command3,
  2509. const char* command4)
  2510. {
  2511. std::vector<std::string> commands;
  2512. if(command)
  2513. {
  2514. commands.push_back(command);
  2515. }
  2516. if(command2)
  2517. {
  2518. commands.push_back(command2);
  2519. }
  2520. if(command3)
  2521. {
  2522. commands.push_back(command3);
  2523. }
  2524. if(command4)
  2525. {
  2526. commands.push_back(command4);
  2527. }
  2528. this->OutputMakeRule(fout, comment, target, depends, commands);
  2529. }
  2530. void cmLocalUnixMakefileGenerator::OutputMakeRule(std::ostream& fout,
  2531. const char* comment,
  2532. const char* target,
  2533. const char* depends,
  2534. const std::vector<std::string>& commands)
  2535. {
  2536. std::vector<std::string> depend;
  2537. if(depends)
  2538. {
  2539. depend.push_back(depends);
  2540. }
  2541. this->OutputMakeRule(fout, comment, target, depend, commands);
  2542. }
  2543. void cmLocalUnixMakefileGenerator::OutputMakeRule(std::ostream& fout,
  2544. const char* comment,
  2545. const char* target,
  2546. const std::vector<std::string>& depends,
  2547. const std::vector<std::string>& commands)
  2548. {
  2549. if(!target)
  2550. {
  2551. cmSystemTools::Error("no target for OutputMakeRule");
  2552. return;
  2553. }
  2554. std::string replace;
  2555. if(comment)
  2556. {
  2557. replace = comment;
  2558. m_Makefile->ExpandVariablesInString(replace);
  2559. fout << "#---------------------------------------------------------\n";
  2560. fout << "# " << replace;
  2561. fout << "\n#\n";
  2562. }
  2563. fout << "\n";
  2564. replace = target;
  2565. m_Makefile->ExpandVariablesInString(replace);
  2566. fout << cmSystemTools::ConvertToOutputPath(replace.c_str()) << ":";
  2567. for(std::vector<std::string>::const_iterator dep = depends.begin();
  2568. dep != depends.end(); ++dep)
  2569. {
  2570. replace = *dep;
  2571. m_Makefile->ExpandVariablesInString(replace);
  2572. fout << " " << replace.c_str();
  2573. }
  2574. fout << "\n";
  2575. int count = 0;
  2576. for (std::vector<std::string>::const_iterator i = commands.begin();
  2577. i != commands.end(); ++i)
  2578. {
  2579. replace = *i;
  2580. m_Makefile->ExpandVariablesInString(replace);
  2581. if(count == 0 && replace.find_first_not_of(" \t\n\r") != std::string::npos &&
  2582. replace[0] != '-' && replace.find("echo") != 0
  2583. && replace.find("$(MAKE)") != 0)
  2584. {
  2585. std::string echostring = "Building ";
  2586. echostring += comment;
  2587. echostring += " ";
  2588. echostring += target;
  2589. echostring += "...";
  2590. // for unix we want to quote the output of echo
  2591. // for nmake and borland, the echo should not be quoted
  2592. if(strcmp(m_GlobalGenerator->GetName(), "Unix Makefiles") == 0)
  2593. {
  2594. cmSystemTools::ReplaceString(echostring, "\\\n", " ");
  2595. cmSystemTools::ReplaceString(echostring, " \t", " ");
  2596. cmSystemTools::ReplaceString(echostring, "\n\t", "\"\n\t@echo \"");
  2597. fout << "\t@echo \"" << echostring.c_str() << "\"\n";
  2598. }
  2599. else
  2600. {
  2601. cmSystemTools::ReplaceString(echostring, "\n\t", "\n\t@echo ");
  2602. fout << "\t@echo " << echostring.c_str() << "\n";
  2603. }
  2604. }
  2605. fout << "\t" << replace.c_str() << "\n";
  2606. count++;
  2607. }
  2608. fout << "\n";
  2609. }
  2610. const char* cmLocalUnixMakefileGenerator::GetSafeDefinition(const char* def)
  2611. {
  2612. const char* ret = m_Makefile->GetDefinition(def);
  2613. if(!ret)
  2614. {
  2615. return "";
  2616. }
  2617. return ret;
  2618. }
  2619. std::string cmLocalUnixMakefileGenerator::LowerCasePath(const char* path)
  2620. {
  2621. #ifdef _WIN32
  2622. return cmSystemTools::LowerCase(path);
  2623. #else
  2624. return std::string(path);
  2625. #endif
  2626. }
  2627. std::string
  2628. cmLocalUnixMakefileGenerator::CreateMakeVariable(const char* s, const char* s2)
  2629. {
  2630. if(!m_MakefileVariableSize)
  2631. {
  2632. return std::string(s) + std::string(s2);
  2633. }
  2634. std::string unmodified = s;
  2635. unmodified += s2;
  2636. // see if th
  2637. std::map<cmStdString, cmStdString>::iterator i = m_MakeVariableMap.find(unmodified);
  2638. if(i != m_MakeVariableMap.end())
  2639. {
  2640. return i->second;
  2641. }
  2642. std::string ret = unmodified;
  2643. // if the string is greater the 32 chars it is an invalid vairable name
  2644. // for borland make
  2645. if(static_cast<int>(ret.size()) > m_MakefileVariableSize)
  2646. {
  2647. int keep = m_MakefileVariableSize - 8;
  2648. int size = keep + 3;
  2649. std::string str1 = s;
  2650. std::string str2 = s2;
  2651. // we must shorten the combined string by 4 charactors
  2652. // keep no more than 24 charactors from the second string
  2653. if(static_cast<int>(str2.size()) > keep)
  2654. {
  2655. str2 = str2.substr(0, keep);
  2656. }
  2657. if(static_cast<int>(str1.size()) + static_cast<int>(str2.size()) > size)
  2658. {
  2659. str1 = str1.substr(0, size - str2.size());
  2660. }
  2661. char buffer[5];
  2662. int ni = 0;
  2663. sprintf(buffer, "%04d", ni);
  2664. ret = str1 + str2 + buffer;
  2665. while(m_ShortMakeVariableMap.count(ret) && ni < 1000)
  2666. {
  2667. ++ni;
  2668. sprintf(buffer, "%04d", ni);
  2669. ret = str1 + str2 + buffer;
  2670. }
  2671. if(ni == 1000)
  2672. {
  2673. cmSystemTools::Error("Borland makefile variable length too long");
  2674. return unmodified;
  2675. }
  2676. // once an unused variable is found
  2677. m_ShortMakeVariableMap[ret] = "1";
  2678. }
  2679. // always make an entry into the unmodified to variable map
  2680. m_MakeVariableMap[unmodified] = ret;
  2681. return ret;
  2682. }