The JUCE cross-platform C++ framework, with DISTRHO/KXStudio specific changes
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

759 lines
29KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2017 - ROLI Ltd.
  5. JUCE is an open source library subject to commercial or open-source
  6. licensing.
  7. By using JUCE, you agree to the terms of both the JUCE 5 End-User License
  8. Agreement and JUCE 5 Privacy Policy (both updated and effective as of the
  9. 27th April 2017).
  10. End User License Agreement: www.juce.com/juce-5-licence
  11. Privacy Policy: www.juce.com/juce-5-privacy-policy
  12. Or: You may also use this code under the terms of the GPL v3 (see
  13. www.gnu.org/licenses).
  14. JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
  15. EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
  16. DISCLAIMED.
  17. ==============================================================================
  18. */
  19. class MakefileProjectExporter : public ProjectExporter
  20. {
  21. protected:
  22. //==============================================================================
  23. class MakeBuildConfiguration : public BuildConfiguration
  24. {
  25. public:
  26. MakeBuildConfiguration (Project& p, const ValueTree& settings, const ProjectExporter& e)
  27. : BuildConfiguration (p, settings, e)
  28. {
  29. }
  30. Value getArchitectureType() { return getValue (Ids::linuxArchitecture); }
  31. var getArchitectureTypeVar() const { return config [Ids::linuxArchitecture]; }
  32. var getDefaultOptimisationLevel() const override { return var ((int) (isDebug() ? gccO0 : gccO3)); }
  33. void createConfigProperties (PropertyListBuilder& props) override
  34. {
  35. addGCCOptimisationProperty (props);
  36. static const char* const archNames[] = { "(Default)", "<None>", "32-bit (-m32)", "64-bit (-m64)", "ARM v6", "ARM v7" };
  37. const var archFlags[] = { var(), var (String()), "-m32", "-m64", "-march=armv6", "-march=armv7" };
  38. props.add (new ChoicePropertyComponent (getArchitectureType(), "Architecture",
  39. StringArray (archNames, numElementsInArray (archNames)),
  40. Array<var> (archFlags, numElementsInArray (archFlags))));
  41. }
  42. String getModuleLibraryArchName() const override
  43. {
  44. String archFlag = getArchitectureTypeVar();
  45. String prefix ("-march=");
  46. if (archFlag.startsWith (prefix))
  47. return archFlag.substring (prefix.length());
  48. if (archFlag == "-m64")
  49. return "x86_64";
  50. if (archFlag == "-m32")
  51. return "i386";
  52. return "$(shell uname -m)";
  53. }
  54. };
  55. BuildConfiguration::Ptr createBuildConfig (const ValueTree& tree) const override
  56. {
  57. return new MakeBuildConfiguration (project, tree, *this);
  58. }
  59. public:
  60. //==============================================================================
  61. class MakefileTarget : public ProjectType::Target
  62. {
  63. public:
  64. MakefileTarget (ProjectType::Target::Type targetType, const MakefileProjectExporter& exporter)
  65. : ProjectType::Target (targetType), owner (exporter)
  66. {}
  67. StringArray getTargetSettings (const BuildConfiguration& config) const
  68. {
  69. if (type == AggregateTarget)
  70. // the aggregate target should not specify any settings at all!
  71. // it just defines dependencies on the other targets.
  72. return {};
  73. StringPairArray commonOptions = owner.getAllPreprocessorDefs (config, ProjectType::Target::unspecified);
  74. StringPairArray targetSpecific = owner.getAllPreprocessorDefs (config, type);
  75. StringArray defs;
  76. // remove any defines that have already been added by the configuration
  77. const int n = targetSpecific.size();
  78. for (int i = 0 ; i < n; ++i)
  79. {
  80. const String& key = targetSpecific.getAllKeys()[i];
  81. if (! commonOptions.getAllKeys().contains (key))
  82. defs.add (String ("-D") + key + String ("=") + targetSpecific.getAllValues()[i]);
  83. }
  84. StringArray s;
  85. const String cppflagsVarName = String ("JUCE_CPPFLAGS_") + getTargetVarName();
  86. s.add (cppflagsVarName + String (" := ") + defs.joinIntoString (" "));
  87. if (getTargetFileType() == sharedLibraryOrDLL || getTargetFileType() == pluginBundle)
  88. {
  89. s.add (String ("JUCE_CFLAGS_") + getTargetVarName() + String (" := -fPIC -fvisibility=hidden"));
  90. const String ldflagsVarName = String ("JUCE_LDFLAGS_") + getTargetVarName();
  91. String targetLinkOptions = ldflagsVarName + String (" := -shared");
  92. if (getTargetFileType() == pluginBundle)
  93. targetLinkOptions += " -Wl,--no-undefined";
  94. s.add (targetLinkOptions);
  95. }
  96. String targetName (owner.replacePreprocessorTokens (config, config.getTargetBinaryNameString()));
  97. if (owner.projectType.isStaticLibrary())
  98. targetName = getStaticLibbedFilename (targetName);
  99. else if (owner.projectType.isDynamicLibrary())
  100. targetName = getDynamicLibbedFilename (targetName);
  101. else
  102. targetName = targetName.upToLastOccurrenceOf (".", false, false) + getTargetFileSuffix();
  103. s.add (String ("JUCE_TARGET_") + getTargetVarName() + String (" := ") + escapeSpaces (targetName));
  104. return s;
  105. }
  106. String getTargetFileSuffix() const
  107. {
  108. switch (type)
  109. {
  110. case VSTPlugIn: return ".so";
  111. case VST3PlugIn: return ".vst3";
  112. case SharedCodeTarget: return ".a";
  113. default: break;
  114. }
  115. return {};
  116. }
  117. String getTargetVarName() const
  118. {
  119. return String (getName()).toUpperCase().replaceCharacter (L' ', L'_');
  120. }
  121. void writeObjects (OutputStream& out) const
  122. {
  123. Array<RelativePath> targetFiles;
  124. for (int i = 0; i < owner.getAllGroups().size(); ++i)
  125. findAllFilesToCompile (owner.getAllGroups().getReference(i), targetFiles);
  126. out << "OBJECTS_" + getTargetVarName() + String (" := \\") << newLine;
  127. for (int i = 0; i < targetFiles.size(); ++i)
  128. out << " $(JUCE_OBJDIR)/" << escapeSpaces (owner.getObjectFileFor (targetFiles.getReference(i))) << " \\" << newLine;
  129. out << newLine;
  130. }
  131. void findAllFilesToCompile (const Project::Item& projectItem, Array<RelativePath>& results) const
  132. {
  133. if (projectItem.isGroup())
  134. {
  135. for (int i = 0; i < projectItem.getNumChildren(); ++i)
  136. findAllFilesToCompile (projectItem.getChild(i), results);
  137. }
  138. else
  139. {
  140. if (projectItem.shouldBeCompiled())
  141. {
  142. const Type targetType = (owner.getProject().getProjectType().isAudioPlugin() ? type : SharedCodeTarget);
  143. const File f = projectItem.getFile();
  144. RelativePath relativePath (f, owner.getTargetFolder(), RelativePath::buildTargetFolder);
  145. if (owner.shouldFileBeCompiledByDefault (relativePath)
  146. && owner.getProject().getTargetTypeFromFilePath (f, true) == targetType)
  147. results.add (relativePath);
  148. }
  149. }
  150. }
  151. void addFiles (OutputStream& out)
  152. {
  153. Array<RelativePath> targetFiles;
  154. for (int i = 0; i < owner.getAllGroups().size(); ++i)
  155. findAllFilesToCompile (owner.getAllGroups().getReference(i), targetFiles);
  156. const String cppflagsVarName = String ("JUCE_CPPFLAGS_") + getTargetVarName();
  157. const String cflagsVarName = String ("JUCE_CFLAGS_") + getTargetVarName();
  158. for (int i = 0; i < targetFiles.size(); ++i)
  159. {
  160. jassert (targetFiles.getReference(i).getRoot() == RelativePath::buildTargetFolder);
  161. out << "$(JUCE_OBJDIR)/" << escapeSpaces (owner.getObjectFileFor (targetFiles.getReference(i)))
  162. << ": " << escapeSpaces (targetFiles.getReference(i).toUnixStyle()) << newLine
  163. << "\t-$(V_AT)mkdir -p $(JUCE_OBJDIR)" << newLine
  164. << "\t@echo \"Compiling " << targetFiles.getReference(i).getFileName() << "\"" << newLine
  165. << (targetFiles.getReference(i).hasFileExtension ("c;s;S") ? "\t$(V_AT)$(CC) $(JUCE_CFLAGS) " : "\t$(V_AT)$(CXX) $(JUCE_CXXFLAGS) ")
  166. << "$(" << cppflagsVarName << ") $(" << cflagsVarName << ") -o \"$@\" -c \"$<\""
  167. << newLine << newLine;
  168. }
  169. }
  170. String getBuildProduct() const
  171. {
  172. return String ("$(JUCE_OUTDIR)/$(JUCE_TARGET_") + getTargetVarName() + String (")");
  173. }
  174. String getPhonyName() const
  175. {
  176. return String (getName()).upToFirstOccurrenceOf (" ", false, false);
  177. }
  178. void writeTargetLine (OutputStream& out, const bool useLinuxPackages)
  179. {
  180. jassert (type != AggregateTarget);
  181. out << getBuildProduct() << " : "
  182. << ((useLinuxPackages) ? "check-pkg-config " : "")
  183. << "$(OBJECTS_" << getTargetVarName() << ") $(RESOURCES)";
  184. if (type != SharedCodeTarget && owner.shouldBuildTargetType (SharedCodeTarget))
  185. out << " $(JUCE_OUTDIR)/$(JUCE_TARGET_SHARED_CODE)";
  186. out << newLine << "\t@echo Linking \"" << owner.projectName << " - " << getName() << "\"" << newLine
  187. << "\t-$(V_AT)mkdir -p $(JUCE_BINDIR)" << newLine
  188. << "\t-$(V_AT)mkdir -p $(JUCE_LIBDIR)" << newLine
  189. << "\t-$(V_AT)mkdir -p $(JUCE_OUTDIR)" << newLine;
  190. if (owner.projectType.isStaticLibrary() || type == SharedCodeTarget)
  191. out << "\t$(V_AT)$(AR) -rcs " << getBuildProduct()
  192. << " $(OBJECTS_" << getTargetVarName() << ")" << newLine;
  193. else
  194. {
  195. out << "\t$(V_AT)$(CXX) -o " << getBuildProduct()
  196. << " $(OBJECTS_" << getTargetVarName() << ") ";
  197. if (owner.shouldBuildTargetType (SharedCodeTarget))
  198. out << "$(JUCE_OUTDIR)/$(JUCE_TARGET_SHARED_CODE) ";
  199. out << "$(JUCE_LDFLAGS) ";
  200. if (getTargetFileType() == sharedLibraryOrDLL || getTargetFileType() == pluginBundle)
  201. out << "$(JUCE_LDFLAGS_" << getTargetVarName() << ") ";
  202. out << "$(RESOURCES) $(TARGET_ARCH)" << newLine;
  203. }
  204. out << newLine;
  205. }
  206. const MakefileProjectExporter& owner;
  207. };
  208. //==============================================================================
  209. static const char* getNameLinux() { return "Linux Makefile"; }
  210. static const char* getValueTreeTypeName() { return "LINUX_MAKE"; }
  211. Value getExtraPkgConfig() { return getSetting (Ids::linuxExtraPkgConfig); }
  212. String getExtraPkgConfigString() const { return getSettingString (Ids::linuxExtraPkgConfig); }
  213. static MakefileProjectExporter* createForSettings (Project& project, const ValueTree& settings)
  214. {
  215. if (settings.hasType (getValueTreeTypeName()))
  216. return new MakefileProjectExporter (project, settings);
  217. return nullptr;
  218. }
  219. StringArray getPackages() const
  220. {
  221. StringArray packages;
  222. packages.addTokens (getExtraPkgConfigString(), " ", "\"'");
  223. packages.removeEmptyStrings();
  224. packages.addArray (linuxPackages);
  225. if (isWebBrowserComponentEnabled())
  226. {
  227. packages.add ("webkit2gtk-4.0");
  228. packages.add ("gtk+-x11-3.0");
  229. }
  230. packages.removeDuplicates (false);
  231. return packages;
  232. }
  233. //==============================================================================
  234. MakefileProjectExporter (Project& p, const ValueTree& t) : ProjectExporter (p, t)
  235. {
  236. name = getNameLinux();
  237. if (getTargetLocationString().isEmpty())
  238. getTargetLocationValue() = getDefaultBuildsRootFolder() + "LinuxMakefile";
  239. }
  240. //==============================================================================
  241. bool canLaunchProject() override { return false; }
  242. bool launchProject() override { return false; }
  243. bool usesMMFiles() const override { return false; }
  244. bool canCopeWithDuplicateFiles() override { return false; }
  245. bool supportsUserDefinedConfigurations() const override { return true; }
  246. bool isXcode() const override { return false; }
  247. bool isVisualStudio() const override { return false; }
  248. bool isCodeBlocks() const override { return false; }
  249. bool isMakefile() const override { return true; }
  250. bool isAndroidStudio() const override { return false; }
  251. bool isAndroid() const override { return false; }
  252. bool isWindows() const override { return false; }
  253. bool isLinux() const override { return true; }
  254. bool isOSX() const override { return false; }
  255. bool isiOS() const override { return false; }
  256. bool supportsTargetType (ProjectType::Target::Type type) const override
  257. {
  258. switch (type)
  259. {
  260. case ProjectType::Target::GUIApp:
  261. case ProjectType::Target::ConsoleApp:
  262. case ProjectType::Target::StaticLibrary:
  263. case ProjectType::Target::SharedCodeTarget:
  264. case ProjectType::Target::AggregateTarget:
  265. case ProjectType::Target::VSTPlugIn:
  266. case ProjectType::Target::StandalonePlugIn:
  267. case ProjectType::Target::DynamicLibrary:
  268. return true;
  269. default:
  270. break;
  271. }
  272. return false;
  273. }
  274. void createExporterProperties (PropertyListBuilder& properties) override
  275. {
  276. properties.add (new TextPropertyComponent (getExtraPkgConfig(), "pkg-config libraries", 8192, false),
  277. "Extra pkg-config libraries for you application. Each package should be space separated.");
  278. }
  279. //==============================================================================
  280. bool anyTargetIsSharedLibrary() const
  281. {
  282. const int n = targets.size();
  283. for (int i = 0; i < n; ++i)
  284. {
  285. const ProjectType::Target::TargetFileType fileType = targets.getUnchecked (i)->getTargetFileType();
  286. if (fileType == ProjectType::Target::sharedLibraryOrDLL || fileType == ProjectType::Target::pluginBundle)
  287. return true;
  288. }
  289. return false;
  290. }
  291. //==============================================================================
  292. void create (const OwnedArray<LibraryModule>&) const override
  293. {
  294. MemoryOutputStream mo;
  295. writeMakefile (mo);
  296. overwriteFileIfDifferentOrThrow (getTargetFolder().getChildFile ("Makefile"), mo);
  297. }
  298. //==============================================================================
  299. void addPlatformSpecificSettingsForProjectType (const ProjectType&) override
  300. {
  301. callForAllSupportedTargets ([this] (ProjectType::Target::Type targetType)
  302. {
  303. if (MakefileTarget* target = new MakefileTarget (targetType, *this))
  304. {
  305. if (targetType == ProjectType::Target::AggregateTarget)
  306. targets.insert (0, target);
  307. else
  308. targets.add (target);
  309. }
  310. });
  311. // If you hit this assert, you tried to generate a project for an exporter
  312. // that does not support any of your targets!
  313. jassert (targets.size() > 0);
  314. }
  315. //==============================================================================
  316. void initialiseDependencyPathValues() override
  317. {
  318. vst3Path.referTo (Value (new DependencyPathValueSource (getSetting (Ids::vst3Folder),
  319. Ids::vst3Path,
  320. TargetOS::linux)));
  321. }
  322. private:
  323. bool isWebBrowserComponentEnabled() const
  324. {
  325. static String guiExtrasModule ("juce_gui_extra");
  326. return (project.getModules().isModuleEnabled (guiExtrasModule)
  327. && project.isConfigFlagEnabled ("JUCE_WEB_BROWSER", true));
  328. }
  329. //==============================================================================
  330. void writeDefineFlags (OutputStream& out, const BuildConfiguration& config) const
  331. {
  332. StringPairArray defines;
  333. defines.set ("LINUX", "1");
  334. if (config.isDebug())
  335. {
  336. defines.set ("DEBUG", "1");
  337. defines.set ("_DEBUG", "1");
  338. }
  339. else
  340. {
  341. defines.set ("NDEBUG", "1");
  342. }
  343. out << createGCCPreprocessorFlags (mergePreprocessorDefs (defines, getAllPreprocessorDefs (config, ProjectType::Target::unspecified)));
  344. }
  345. void writeHeaderPathFlags (OutputStream& out, const BuildConfiguration& config) const
  346. {
  347. StringArray searchPaths (extraSearchPaths);
  348. searchPaths.addArray (config.getHeaderSearchPaths());
  349. auto packages = getPackages();
  350. if (packages.size() > 0)
  351. {
  352. out << " $(shell pkg-config --cflags";
  353. for (int i = 0; i < packages.size(); ++i)
  354. out << " " << packages[i];
  355. out << ")";
  356. }
  357. if (linuxLibs.contains("pthread"))
  358. out << " -pthread";
  359. searchPaths = getCleanedStringArray (searchPaths);
  360. // Replace ~ character with $(HOME) environment variable
  361. for (int i = 0; i < searchPaths.size(); ++i)
  362. out << " -I" << escapeSpaces (FileHelpers::unixStylePath (replacePreprocessorTokens (config, searchPaths[i]))).replace ("~", "$(HOME)");
  363. }
  364. void writeCppFlags (OutputStream& out, const BuildConfiguration& config) const
  365. {
  366. out << " JUCE_CPPFLAGS := $(DEPFLAGS)";
  367. writeDefineFlags (out, config);
  368. writeHeaderPathFlags (out, config);
  369. out << " $(CPPFLAGS)" << newLine;
  370. }
  371. void writeLinkerFlags (OutputStream& out, const BuildConfiguration& config) const
  372. {
  373. out << " JUCE_LDFLAGS += $(TARGET_ARCH) -L$(JUCE_BINDIR) -L$(JUCE_LIBDIR)";
  374. {
  375. StringArray flags (makefileExtraLinkerFlags);
  376. if (! config.isDebug())
  377. flags.add ("-fvisibility=hidden");
  378. if (flags.size() > 0)
  379. out << " " << getCleanedStringArray (flags).joinIntoString (" ");
  380. }
  381. out << config.getGCCLibraryPathFlags();
  382. auto packages = getPackages();
  383. if (packages.size() > 0 )
  384. {
  385. out << " $(shell pkg-config --libs";
  386. for (int i = 0; i < packages.size(); ++i)
  387. out << " " << packages[i];
  388. out << ")";
  389. }
  390. for (int i = 0; i < linuxLibs.size(); ++i)
  391. out << " -l" << linuxLibs[i];
  392. StringArray libraries;
  393. libraries.addTokens (getExternalLibrariesString(), ";", "\"'");
  394. libraries.removeEmptyStrings();
  395. if (libraries.size() != 0)
  396. out << " -l" << replacePreprocessorTokens (config, libraries.joinIntoString (" -l")).trim();
  397. out << " " << replacePreprocessorTokens (config, getExtraLinkerFlagsString()).trim()
  398. << " $(LDFLAGS)" << newLine;
  399. }
  400. void writeTargetLines (OutputStream& out, const bool useLinuxPackages) const
  401. {
  402. const int n = targets.size();
  403. for (int i = 0; i < n; ++i)
  404. {
  405. if (MakefileTarget* target = targets.getUnchecked (i))
  406. {
  407. if (target->type == ProjectType::Target::AggregateTarget)
  408. {
  409. StringArray dependencies;
  410. MemoryOutputStream subTargetLines;
  411. for (int j = 0; j < n; ++j)
  412. {
  413. if (i == j) continue;
  414. if (MakefileTarget* dependency = targets.getUnchecked (j))
  415. {
  416. if (dependency->type != ProjectType::Target::SharedCodeTarget)
  417. {
  418. auto phonyName = dependency->getPhonyName();
  419. subTargetLines << phonyName << " : " << dependency->getBuildProduct() << newLine;
  420. dependencies.add (phonyName);
  421. }
  422. }
  423. }
  424. out << "all : " << dependencies.joinIntoString (" ") << newLine << newLine;
  425. out << subTargetLines.toString() << newLine << newLine;
  426. }
  427. else
  428. {
  429. if (! getProject().getProjectType().isAudioPlugin())
  430. out << "all : " << target->getBuildProduct() << newLine << newLine;
  431. target->writeTargetLine (out, useLinuxPackages);
  432. }
  433. }
  434. }
  435. }
  436. void writeConfig (OutputStream& out, const BuildConfiguration& config) const
  437. {
  438. const String buildDirName ("build");
  439. const String intermediatesDirName (buildDirName + "/intermediate/" + config.getName());
  440. String outputDir (buildDirName);
  441. if (config.getTargetBinaryRelativePathString().isNotEmpty())
  442. {
  443. RelativePath binaryPath (config.getTargetBinaryRelativePathString(), RelativePath::projectFolder);
  444. outputDir = binaryPath.rebased (projectFolder, getTargetFolder(), RelativePath::buildTargetFolder).toUnixStyle();
  445. }
  446. out << "ifeq ($(CONFIG)," << escapeSpaces (config.getName()) << ")" << newLine;
  447. out << " JUCE_BINDIR := " << escapeSpaces (buildDirName) << newLine
  448. << " JUCE_LIBDIR := " << escapeSpaces (buildDirName) << newLine
  449. << " JUCE_OBJDIR := " << escapeSpaces (intermediatesDirName) << newLine
  450. << " JUCE_OUTDIR := " << escapeSpaces (outputDir) << newLine
  451. << newLine
  452. << " ifeq ($(TARGET_ARCH),)" << newLine
  453. << " TARGET_ARCH := " << getArchFlags (config) << newLine
  454. << " endif" << newLine
  455. << newLine;
  456. writeCppFlags (out, config);
  457. for (auto target : targets)
  458. {
  459. StringArray lines = target->getTargetSettings (config);
  460. if (lines.size() > 0)
  461. out << " " << lines.joinIntoString ("\n ") << newLine;
  462. out << newLine;
  463. }
  464. out << " JUCE_CFLAGS += $(JUCE_CPPFLAGS) $(TARGET_ARCH)";
  465. if (anyTargetIsSharedLibrary())
  466. out << " -fPIC";
  467. if (config.isDebug())
  468. out << " -g -ggdb";
  469. out << " -O" << config.getGCCOptimisationFlag()
  470. << (" " + replacePreprocessorTokens (config, getExtraCompilerFlagsString())).trimEnd()
  471. << " $(CFLAGS)" << newLine;
  472. {
  473. auto cppStandard = config.project.getCppStandardValue().toString();
  474. if (cppStandard == "latest")
  475. cppStandard = "1z";
  476. cppStandard = "-std=" + String (shouldUseGNUExtensions() ? "gnu++" : "c++") + cppStandard;
  477. out << " JUCE_CXXFLAGS += $(CXXFLAGS) $(JUCE_CFLAGS) "
  478. << cppStandard << " $(CXXFLAGS)" << newLine;
  479. }
  480. writeLinkerFlags (out, config);
  481. out << newLine;
  482. out << " CLEANCMD = rm -rf $(JUCE_OUTDIR)/$(TARGET) $(JUCE_OBJDIR)" << newLine
  483. << "endif" << newLine
  484. << newLine;
  485. }
  486. void writeIncludeLines (OutputStream& out) const
  487. {
  488. const int n = targets.size();
  489. for (int i = 0; i < n; ++i)
  490. {
  491. if (MakefileTarget* target = targets.getUnchecked (i))
  492. {
  493. if (target->type == ProjectType::Target::AggregateTarget)
  494. continue;
  495. out << "-include $(OBJECTS_" << target->getTargetVarName()
  496. << ":%.o=%.d)" << newLine;
  497. }
  498. }
  499. }
  500. void writeMakefile (OutputStream& out) const
  501. {
  502. out << "# Automatically generated makefile, created by the Projucer" << newLine
  503. << "# Don't edit this file! Your changes will be overwritten when you re-save the Projucer project!" << newLine
  504. << newLine;
  505. out << "# build with \"V=1\" for verbose builds" << newLine
  506. << "ifeq ($(V), 1)" << newLine
  507. << "V_AT =" << newLine
  508. << "else" << newLine
  509. << "V_AT = @" << newLine
  510. << "endif" << newLine
  511. << newLine;
  512. out << "# (this disables dependency generation if multiple architectures are set)" << newLine
  513. << "DEPFLAGS := $(if $(word 2, $(TARGET_ARCH)), , -MMD)" << newLine
  514. << newLine;
  515. out << "ifndef STRIP" << newLine
  516. << " STRIP=strip" << newLine
  517. << "endif" << newLine
  518. << newLine;
  519. out << "ifndef AR" << newLine
  520. << " AR=ar" << newLine
  521. << "endif" << newLine
  522. << newLine;
  523. out << "ifndef CONFIG" << newLine
  524. << " CONFIG=" << escapeSpaces (getConfiguration(0)->getName()) << newLine
  525. << "endif" << newLine
  526. << newLine;
  527. for (ConstConfigIterator config (*this); config.next();)
  528. writeConfig (out, *config);
  529. for (auto target : targets)
  530. target->writeObjects (out);
  531. out << getPhonyTargetLine() << newLine << newLine;
  532. StringArray packages;
  533. packages.addTokens (getExtraPkgConfigString(), " ", "\"'");
  534. packages.removeEmptyStrings();
  535. const bool useLinuxPackages = (linuxPackages.size() > 0 || packages.size() > 0);
  536. writeTargetLines (out, useLinuxPackages);
  537. for (auto target : targets)
  538. target->addFiles (out);
  539. if (useLinuxPackages)
  540. {
  541. out << "check-pkg-config:" << newLine
  542. << "\t@command -v pkg-config >/dev/null 2>&1 || "
  543. "{ echo >&2 \"pkg-config not installed. Please, install it.\"; "
  544. "exit 1; }" << newLine
  545. << "\t@pkg-config --print-errors";
  546. for (int i = 0; i < linuxPackages.size(); ++i)
  547. out << " " << linuxPackages[i];
  548. for (int i = 0; i < packages.size(); ++i)
  549. out << " " << packages[i];
  550. out << newLine << newLine;
  551. }
  552. out << "clean:" << newLine
  553. << "\t@echo Cleaning " << projectName << newLine
  554. << "\t$(V_AT)$(CLEANCMD)" << newLine
  555. << newLine;
  556. out << "strip:" << newLine
  557. << "\t@echo Stripping " << projectName << newLine
  558. << "\t-$(V_AT)$(STRIP) --strip-unneeded $(JUCE_OUTDIR)/$(TARGET)" << newLine
  559. << newLine;
  560. writeIncludeLines (out);
  561. }
  562. String getArchFlags (const BuildConfiguration& config) const
  563. {
  564. if (const MakeBuildConfiguration* makeConfig = dynamic_cast<const MakeBuildConfiguration*> (&config))
  565. if (! makeConfig->getArchitectureTypeVar().isVoid())
  566. return makeConfig->getArchitectureTypeVar();
  567. return "-march=native";
  568. }
  569. String getObjectFileFor (const RelativePath& file) const
  570. {
  571. return file.getFileNameWithoutExtension()
  572. + "_" + String::toHexString (file.toUnixStyle().hashCode()) + ".o";
  573. }
  574. String getPhonyTargetLine() const
  575. {
  576. MemoryOutputStream phonyTargetLine;
  577. phonyTargetLine << ".PHONY: clean all";
  578. if (! getProject().getProjectType().isAudioPlugin())
  579. return phonyTargetLine.toString();
  580. for (auto target : targets)
  581. if (target->type != ProjectType::Target::SharedCodeTarget
  582. && target->type != ProjectType::Target::AggregateTarget)
  583. phonyTargetLine << " " << target->getPhonyName();
  584. return phonyTargetLine.toString();
  585. }
  586. OwnedArray<MakefileTarget> targets;
  587. JUCE_DECLARE_NON_COPYABLE (MakefileProjectExporter)
  588. };