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.

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