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.

1278 lines
53KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2022 - Raw Material Software Limited
  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 7 End-User License
  8. Agreement and JUCE Privacy Policy.
  9. End User License Agreement: www.juce.com/juce-7-licence
  10. Privacy Policy: www.juce.com/juce-privacy-policy
  11. Or: You may also use this code under the terms of the GPL v3 (see
  12. www.gnu.org/licenses).
  13. JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
  14. EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
  15. DISCLAIMED.
  16. ==============================================================================
  17. */
  18. #pragma once
  19. //==============================================================================
  20. class MakefileProjectExporter : public ProjectExporter
  21. {
  22. protected:
  23. //==============================================================================
  24. class MakeBuildConfiguration : public BuildConfiguration
  25. {
  26. public:
  27. MakeBuildConfiguration (Project& p, const ValueTree& settings, const ProjectExporter& e)
  28. : BuildConfiguration (p, settings, e),
  29. architectureTypeValue (config, Ids::linuxArchitecture, getUndoManager(), String()),
  30. pluginBinaryCopyStepValue (config, Ids::enablePluginBinaryCopyStep, getUndoManager(), true),
  31. vstBinaryLocation (config, Ids::vstBinaryLocation, getUndoManager(), "$(HOME)/.vst"),
  32. vst3BinaryLocation (config, Ids::vst3BinaryLocation, getUndoManager(), "$(HOME)/.vst3"),
  33. lv2BinaryLocation (config, Ids::lv2BinaryLocation, getUndoManager(), "$(HOME)/.lv2"),
  34. unityPluginBinaryLocation (config, Ids::unityPluginBinaryLocation, getUndoManager(), "$(HOME)/UnityPlugins")
  35. {
  36. linkTimeOptimisationValue.setDefault (false);
  37. optimisationLevelValue.setDefault (isDebug() ? gccO0 : gccO3);
  38. }
  39. void createConfigProperties (PropertyListBuilder& props) override
  40. {
  41. addRecommendedLinuxCompilerWarningsProperty (props);
  42. addGCCOptimisationProperty (props);
  43. props.add (new ChoicePropertyComponent (architectureTypeValue, "Architecture",
  44. { "<None>", "Native", "32-bit (-m32)", "64-bit (-m64)", "ARM v6", "ARM v7", "ARM v8-a" },
  45. { { String() }, "-march=native", "-m32", "-m64", "-march=armv6", "-march=armv7", "-march=armv8-a" }),
  46. "Specifies the 32/64-bit architecture to use. If you don't see the required architecture in this list, you can also specify the desired "
  47. "flag on the command-line when invoking make by passing \"TARGET_ARCH=-march=<arch to use>\"");
  48. auto isBuildingAnyPlugins = (project.shouldBuildVST() || project.shouldBuildVST3() || project.shouldBuildUnityPlugin() || project.shouldBuildLV2());
  49. if (isBuildingAnyPlugins)
  50. {
  51. props.add (new ChoicePropertyComponent (pluginBinaryCopyStepValue, "Enable Plugin Copy Step"),
  52. "Enable this to copy plugin binaries to a specified folder after building.");
  53. if (project.shouldBuildVST3())
  54. props.add (new TextPropertyComponentWithEnablement (vst3BinaryLocation, pluginBinaryCopyStepValue, "VST3 Binary Location",
  55. 1024, false),
  56. "The folder in which the compiled VST3 binary should be placed.");
  57. if (project.shouldBuildLV2())
  58. props.add (new TextPropertyComponentWithEnablement (lv2BinaryLocation, pluginBinaryCopyStepValue, "LV2 Binary Location",
  59. 1024, false),
  60. "The folder in which the compiled LV2 binary should be placed.");
  61. if (project.shouldBuildUnityPlugin())
  62. props.add (new TextPropertyComponentWithEnablement (unityPluginBinaryLocation, pluginBinaryCopyStepValue, "Unity Binary Location",
  63. 1024, false),
  64. "The folder in which the compiled Unity plugin binary and associated C# GUI script should be placed.");
  65. if (project.shouldBuildVST())
  66. props.add (new TextPropertyComponentWithEnablement (vstBinaryLocation, pluginBinaryCopyStepValue, "VST (Legacy) Binary Location",
  67. 1024, false),
  68. "The folder in which the compiled legacy VST binary should be placed.");
  69. }
  70. }
  71. String getModuleLibraryArchName() const override
  72. {
  73. auto archFlag = getArchitectureTypeString();
  74. String prefix ("-march=");
  75. if (archFlag.startsWith (prefix))
  76. return archFlag.substring (prefix.length());
  77. if (archFlag == "-m64")
  78. return "x86_64";
  79. if (archFlag == "-m32")
  80. return "i386";
  81. return "${JUCE_ARCH_LABEL}";
  82. }
  83. String getArchitectureTypeString() const { return architectureTypeValue.get(); }
  84. bool isPluginBinaryCopyStepEnabled() const { return pluginBinaryCopyStepValue.get(); }
  85. String getVSTBinaryLocationString() const { return vstBinaryLocation.get(); }
  86. String getVST3BinaryLocationString() const { return vst3BinaryLocation.get(); }
  87. String getLV2BinaryLocationString() const { return lv2BinaryLocation.get(); }
  88. String getUnityPluginBinaryLocationString() const { return unityPluginBinaryLocation.get(); }
  89. private:
  90. //==============================================================================
  91. ValueTreePropertyWithDefault architectureTypeValue, pluginBinaryCopyStepValue,
  92. vstBinaryLocation, vst3BinaryLocation, lv2BinaryLocation, unityPluginBinaryLocation;
  93. };
  94. BuildConfiguration::Ptr createBuildConfig (const ValueTree& tree) const override
  95. {
  96. return *new MakeBuildConfiguration (project, tree, *this);
  97. }
  98. public:
  99. //==============================================================================
  100. class MakefileTarget : public build_tools::ProjectType::Target
  101. {
  102. public:
  103. MakefileTarget (build_tools::ProjectType::Target::Type targetType, const MakefileProjectExporter& exporter)
  104. : build_tools::ProjectType::Target (targetType), owner (exporter)
  105. {}
  106. StringArray getCompilerFlags() const
  107. {
  108. StringArray result;
  109. if (getTargetFileType() == sharedLibraryOrDLL || getTargetFileType() == pluginBundle)
  110. {
  111. result.add ("-fPIC");
  112. result.add ("-fvisibility=hidden");
  113. }
  114. return result;
  115. }
  116. StringArray getLinkerFlags() const
  117. {
  118. StringArray result;
  119. if (getTargetFileType() == sharedLibraryOrDLL || getTargetFileType() == pluginBundle)
  120. {
  121. result.add ("-shared");
  122. if (getTargetFileType() == pluginBundle)
  123. result.add ("-Wl,--no-undefined");
  124. }
  125. return result;
  126. }
  127. StringPairArray getDefines (const BuildConfiguration& config) const
  128. {
  129. StringPairArray result;
  130. auto commonOptionKeys = owner.getAllPreprocessorDefs (config, build_tools::ProjectType::Target::unspecified).getAllKeys();
  131. auto targetSpecific = owner.getAllPreprocessorDefs (config, type);
  132. for (auto& key : targetSpecific.getAllKeys())
  133. if (! commonOptionKeys.contains (key))
  134. result.set (key, targetSpecific[key]);
  135. return result;
  136. }
  137. StringArray getTargetSettings (const MakeBuildConfiguration& config) const
  138. {
  139. if (type == AggregateTarget) // the aggregate target should not specify any settings at all!
  140. return {}; // it just defines dependencies on the other targets.
  141. StringArray s;
  142. auto cppflagsVarName = "JUCE_CPPFLAGS_" + getTargetVarName();
  143. s.add (cppflagsVarName + " := " + createGCCPreprocessorFlags (getDefines (config)));
  144. auto cflags = getCompilerFlags();
  145. if (! cflags.isEmpty())
  146. s.add ("JUCE_CFLAGS_" + getTargetVarName() + " := " + cflags.joinIntoString (" "));
  147. auto ldflags = getLinkerFlags();
  148. if (! ldflags.isEmpty())
  149. s.add ("JUCE_LDFLAGS_" + getTargetVarName() + " := " + ldflags.joinIntoString (" "));
  150. auto targetName = owner.replacePreprocessorTokens (config, config.getTargetBinaryNameString (type == UnityPlugIn));
  151. if (owner.projectType.isStaticLibrary())
  152. targetName = getStaticLibbedFilename (targetName);
  153. else if (owner.projectType.isDynamicLibrary())
  154. targetName = getDynamicLibbedFilename (targetName);
  155. else
  156. targetName = targetName.upToLastOccurrenceOf (".", false, false) + getTargetFileSuffix();
  157. if (type == VST3PlugIn)
  158. {
  159. s.add ("JUCE_VST3DIR := " + escapeQuotesAndSpaces (targetName).upToLastOccurrenceOf (".", false, false) + ".vst3");
  160. s.add ("VST3_PLATFORM_ARCH := $(shell $(CXX) make_helpers/arch_detection.cpp 2>&1 | tr '\\n' ' ' | sed \"s/.*JUCE_ARCH \\([a-zA-Z0-9_-]*\\).*/\\1/\")");
  161. s.add ("JUCE_VST3SUBDIR := Contents/$(VST3_PLATFORM_ARCH)-linux");
  162. targetName = "$(JUCE_VST3DIR)/$(JUCE_VST3SUBDIR)/" + targetName;
  163. }
  164. else if (type == UnityPlugIn)
  165. {
  166. s.add ("JUCE_UNITYDIR := Unity");
  167. targetName = "$(JUCE_UNITYDIR)/" + targetName;
  168. }
  169. else if (type == LV2PlugIn)
  170. {
  171. s.add ("JUCE_LV2DIR := " + escapeQuotesAndSpaces (targetName) + ".lv2");
  172. targetName = "$(JUCE_LV2DIR)/" + targetName + ".so";
  173. }
  174. else if (type == LV2Helper)
  175. {
  176. targetName = Project::getLV2FileWriterName();
  177. }
  178. else if (type == VST3Helper)
  179. {
  180. targetName = Project::getVST3FileWriterName();
  181. }
  182. s.add ("JUCE_TARGET_" + getTargetVarName() + String (" := ") + escapeQuotesAndSpaces (targetName));
  183. if (type == LV2PlugIn)
  184. s.add ("JUCE_LV2_FULL_PATH := $(JUCE_OUTDIR)/$(JUCE_TARGET_LV2_PLUGIN)");
  185. if (config.isPluginBinaryCopyStepEnabled()
  186. && (type == VST3PlugIn || type == VSTPlugIn || type == UnityPlugIn || type == LV2PlugIn))
  187. {
  188. String copyCmd ("JUCE_COPYCMD_" + getTargetVarName() + String (" := $(JUCE_OUTDIR)/"));
  189. if (type == VST3PlugIn)
  190. {
  191. s.add ("JUCE_VST3DESTDIR := " + config.getVST3BinaryLocationString());
  192. s.add (copyCmd + "$(JUCE_VST3DIR) $(JUCE_VST3DESTDIR)");
  193. }
  194. else if (type == VSTPlugIn)
  195. {
  196. s.add ("JUCE_VSTDESTDIR := " + config.getVSTBinaryLocationString());
  197. s.add (copyCmd + escapeQuotesAndSpaces (targetName) + " $(JUCE_VSTDESTDIR)");
  198. }
  199. else if (type == UnityPlugIn)
  200. {
  201. s.add ("JUCE_UNITYDESTDIR := " + config.getUnityPluginBinaryLocationString());
  202. s.add (copyCmd + "$(JUCE_UNITYDIR)/. $(JUCE_UNITYDESTDIR)");
  203. }
  204. else if (type == LV2PlugIn)
  205. {
  206. s.add ("JUCE_LV2DESTDIR := " + config.getLV2BinaryLocationString());
  207. s.add (copyCmd + "$(JUCE_LV2DIR) $(JUCE_LV2DESTDIR)");
  208. }
  209. }
  210. return s;
  211. }
  212. String getTargetFileSuffix() const
  213. {
  214. if (type == VSTPlugIn || type == VST3PlugIn || type == UnityPlugIn || type == DynamicLibrary)
  215. return ".so";
  216. if (type == SharedCodeTarget || type == StaticLibrary)
  217. return ".a";
  218. return {};
  219. }
  220. String getTargetVarName() const
  221. {
  222. return String (getName()).toUpperCase().replaceCharacter (L' ', L'_');
  223. }
  224. void writeObjects (OutputStream& out, const std::vector<std::pair<build_tools::RelativePath, String>>& filesToCompile) const
  225. {
  226. out << "OBJECTS_" + getTargetVarName() + String (" := \\") << newLine;
  227. for (auto& f : filesToCompile)
  228. out << " $(JUCE_OBJDIR)/" << escapeQuotesAndSpaces (owner.getObjectFileFor (f.first))
  229. << " \\" << newLine;
  230. out << newLine;
  231. }
  232. void addFiles (OutputStream& out, const std::vector<std::pair<build_tools::RelativePath, String>>& filesToCompile)
  233. {
  234. auto cppflagsVarName = "JUCE_CPPFLAGS_" + getTargetVarName();
  235. auto cflagsVarName = "JUCE_CFLAGS_" + getTargetVarName();
  236. for (auto& [path, flags] : filesToCompile)
  237. {
  238. const auto additionalTargetDependencies = [&path = path, this]
  239. {
  240. if ( owner.linuxSubprocessHelperProperties.shouldUseLinuxSubprocessHelper()
  241. && path.getFileName().contains ("include_juce_gui_extra.cpp"))
  242. {
  243. return owner.linuxSubprocessHelperProperties
  244. .getLinuxSubprocessHelperBinaryDataSource()
  245. .toUnixStyle();
  246. }
  247. return String{};
  248. }();
  249. const auto prependedWithSpaceIfNotEmpty = [] (auto s)
  250. {
  251. return s.isEmpty() ? s : " " + s;
  252. };
  253. out << "$(JUCE_OBJDIR)/" << escapeQuotesAndSpaces (owner.getObjectFileFor (path)) << ": " << escapeQuotesAndSpaces (path.toUnixStyle())
  254. << prependedWithSpaceIfNotEmpty (additionalTargetDependencies) << newLine
  255. << "\t-$(V_AT)mkdir -p $(@D)" << newLine
  256. << "\t@echo \"Compiling " << path.getFileName() << "\"" << newLine
  257. << (path.hasFileExtension ("c;s;S") ? "\t$(V_AT)$(CC) $(JUCE_CFLAGS) " : "\t$(V_AT)$(CXX) $(JUCE_CXXFLAGS) ")
  258. << "$(" << cppflagsVarName << ") $(" << cflagsVarName << ")"
  259. << (flags.isNotEmpty() ? " $(" + owner.getCompilerFlagSchemeVariableName (flags) + ")" : "") << " -o \"$@\" -c \"$<\"" << newLine
  260. << newLine;
  261. }
  262. }
  263. String getBuildProduct() const
  264. {
  265. return "$(JUCE_OUTDIR)/$(JUCE_TARGET_" + getTargetVarName() + ")";
  266. }
  267. String getPhonyName() const
  268. {
  269. if (type == LV2Helper)
  270. return "LV2_MANIFEST_HELPER";
  271. if (type == VST3Helper)
  272. return "VST3_MANIFEST_HELPER";
  273. return String (getName()).upToFirstOccurrenceOf (" ", false, false);
  274. }
  275. void writeTargetLine (OutputStream& out, const StringArray& packages)
  276. {
  277. jassert (type != AggregateTarget);
  278. out << getBuildProduct() << " : "
  279. << "$(OBJECTS_" << getTargetVarName() << ") $(JUCE_OBJDIR)/execinfo.cmd $(RESOURCES)";
  280. if (type != SharedCodeTarget && owner.shouldBuildTargetType (SharedCodeTarget))
  281. out << " $(JUCE_OUTDIR)/$(JUCE_TARGET_SHARED_CODE)";
  282. if (type == LV2PlugIn)
  283. out << " $(JUCE_OUTDIR)/$(JUCE_TARGET_LV2_MANIFEST_HELPER)";
  284. else if (type == VST3PlugIn)
  285. out << " $(JUCE_OUTDIR)/$(JUCE_TARGET_VST3_MANIFEST_HELPER)";
  286. out << newLine;
  287. if (! packages.isEmpty())
  288. {
  289. out << "\t@command -v $(PKG_CONFIG) >/dev/null 2>&1 || { echo >&2 \"pkg-config not installed. Please, install it.\"; exit 1; }" << newLine
  290. << "\t@$(PKG_CONFIG) --print-errors";
  291. for (auto& pkg : packages)
  292. out << " " << pkg;
  293. out << newLine;
  294. }
  295. out << "\t@echo Linking \"" << owner.projectName << " - " << getName() << "\"" << newLine
  296. << "\t-$(V_AT)mkdir -p $(JUCE_BINDIR)" << newLine
  297. << "\t-$(V_AT)mkdir -p $(JUCE_LIBDIR)" << newLine
  298. << "\t-$(V_AT)mkdir -p $(JUCE_OUTDIR)" << newLine;
  299. if (type == VST3PlugIn)
  300. out << "\t-$(V_AT)mkdir -p $(JUCE_OUTDIR)/$(JUCE_VST3DIR)/$(JUCE_VST3SUBDIR)" << newLine;
  301. else if (type == UnityPlugIn)
  302. out << "\t-$(V_AT)mkdir -p $(JUCE_OUTDIR)/$(JUCE_UNITYDIR)" << newLine;
  303. else if (type == LV2PlugIn)
  304. out << "\t-$(V_AT)mkdir -p $(JUCE_OUTDIR)/$(JUCE_LV2DIR)" << newLine;
  305. if (owner.projectType.isStaticLibrary() || type == SharedCodeTarget)
  306. {
  307. out << "\t$(V_AT)$(AR) -rcs " << getBuildProduct()
  308. << " $(OBJECTS_" << getTargetVarName() << ")" << newLine;
  309. }
  310. else
  311. {
  312. out << "\t$(V_AT)$(CXX) -o " << getBuildProduct()
  313. << " $(OBJECTS_" << getTargetVarName() << ") ";
  314. if (owner.shouldBuildTargetType (SharedCodeTarget))
  315. out << "$(JUCE_OUTDIR)/$(JUCE_TARGET_SHARED_CODE) ";
  316. out << "$(JUCE_LDFLAGS) $(shell cat $(JUCE_OBJDIR)/execinfo.cmd) ";
  317. if (getTargetFileType() == sharedLibraryOrDLL || getTargetFileType() == pluginBundle
  318. || type == GUIApp || type == StandalonePlugIn)
  319. out << "$(JUCE_LDFLAGS_" << getTargetVarName() << ") ";
  320. out << "$(RESOURCES) $(TARGET_ARCH)" << newLine;
  321. }
  322. if (type == VST3PlugIn)
  323. {
  324. out << "\t-$(V_AT)mkdir -p $(JUCE_OUTDIR)/$(JUCE_VST3DIR)/Contents/Resources" << newLine
  325. << "\t-$(V_AT)rm -f $(JUCE_OUTDIR)/$(JUCE_VST3DIR)/Contents/moduleinfo.json" << newLine
  326. << "\t$(V_AT) $(JUCE_OUTDIR)/$(JUCE_TARGET_VST3_MANIFEST_HELPER) "
  327. "-create "
  328. "-version " << owner.project.getVersionString().quoted() << " "
  329. "-path \"$(JUCE_OUTDIR)/$(JUCE_VST3DIR)\" "
  330. "-output \"$(JUCE_OUTDIR)/$(JUCE_VST3DIR)/Contents/Resources/moduleinfo.json\"" << newLine
  331. << "\t-$(V_AT)[ ! \"$(JUCE_VST3DESTDIR)\" ] || (mkdir -p $(JUCE_VST3DESTDIR) && cp -R $(JUCE_COPYCMD_VST3))" << newLine;
  332. }
  333. else if (type == VSTPlugIn)
  334. {
  335. out << "\t-$(V_AT)[ ! \"$(JUCE_VSTDESTDIR)\" ] || (mkdir -p $(JUCE_VSTDESTDIR) && cp -R $(JUCE_COPYCMD_VST))" << newLine;
  336. }
  337. else if (type == UnityPlugIn)
  338. {
  339. auto scriptName = owner.getProject().getUnityScriptName();
  340. build_tools::RelativePath scriptPath (owner.getProject().getGeneratedCodeFolder().getChildFile (scriptName),
  341. owner.getTargetFolder(),
  342. build_tools::RelativePath::projectFolder);
  343. out << "\t-$(V_AT)cp " + scriptPath.toUnixStyle() + " $(JUCE_OUTDIR)/$(JUCE_UNITYDIR)" << newLine
  344. << "\t-$(V_AT)[ ! \"$(JUCE_UNITYDESTDIR)\" ] || (mkdir -p $(JUCE_UNITYDESTDIR) && cp -R $(JUCE_COPYCMD_UNITY_PLUGIN))" << newLine;
  345. }
  346. else if (type == LV2PlugIn)
  347. {
  348. out << "\t$(V_AT) $(JUCE_OUTDIR)/$(JUCE_TARGET_LV2_MANIFEST_HELPER) $(JUCE_LV2_FULL_PATH)" << newLine
  349. << "\t-$(V_AT)[ ! \"$(JUCE_LV2DESTDIR)\" ] || (mkdir -p $(JUCE_LV2DESTDIR) && cp -R $(JUCE_COPYCMD_LV2_PLUGIN))" << newLine;
  350. }
  351. out << newLine;
  352. }
  353. const MakefileProjectExporter& owner;
  354. };
  355. //==============================================================================
  356. static String getDisplayName() { return "Linux Makefile"; }
  357. static String getValueTreeTypeName() { return "LINUX_MAKE"; }
  358. static String getTargetFolderName() { return "LinuxMakefile"; }
  359. Identifier getExporterIdentifier() const override { return getValueTreeTypeName(); }
  360. static MakefileProjectExporter* createForSettings (Project& projectToUse, const ValueTree& settingsToUse)
  361. {
  362. if (settingsToUse.hasType (getValueTreeTypeName()))
  363. return new MakefileProjectExporter (projectToUse, settingsToUse);
  364. return nullptr;
  365. }
  366. //==============================================================================
  367. MakefileProjectExporter (Project& p, const ValueTree& t)
  368. : ProjectExporter (p, t),
  369. extraPkgConfigValue (settings, Ids::linuxExtraPkgConfig, getUndoManager())
  370. {
  371. name = getDisplayName();
  372. targetLocationValue.setDefault (getDefaultBuildsRootFolder() + getTargetFolderName());
  373. }
  374. //==============================================================================
  375. bool canLaunchProject() override { return false; }
  376. bool launchProject() override { return false; }
  377. bool usesMMFiles() const override { return false; }
  378. bool canCopeWithDuplicateFiles() override { return false; }
  379. bool supportsUserDefinedConfigurations() const override { return true; }
  380. bool isXcode() const override { return false; }
  381. bool isVisualStudio() const override { return false; }
  382. bool isCodeBlocks() const override { return false; }
  383. bool isMakefile() const override { return true; }
  384. bool isAndroidStudio() const override { return false; }
  385. bool isAndroid() const override { return false; }
  386. bool isWindows() const override { return false; }
  387. bool isLinux() const override { return true; }
  388. bool isOSX() const override { return false; }
  389. bool isiOS() const override { return false; }
  390. String getNewLineString() const override { return "\n"; }
  391. bool supportsTargetType (build_tools::ProjectType::Target::Type type) const override
  392. {
  393. using Target = build_tools::ProjectType::Target;
  394. switch (type)
  395. {
  396. case Target::GUIApp:
  397. case Target::ConsoleApp:
  398. case Target::StaticLibrary:
  399. case Target::SharedCodeTarget:
  400. case Target::AggregateTarget:
  401. case Target::VSTPlugIn:
  402. case Target::VST3PlugIn:
  403. case Target::VST3Helper:
  404. case Target::StandalonePlugIn:
  405. case Target::DynamicLibrary:
  406. case Target::UnityPlugIn:
  407. case Target::LV2PlugIn:
  408. case Target::LV2Helper:
  409. return true;
  410. case Target::AAXPlugIn:
  411. case Target::AudioUnitPlugIn:
  412. case Target::AudioUnitv3PlugIn:
  413. case Target::unspecified:
  414. default:
  415. break;
  416. }
  417. return false;
  418. }
  419. void createExporterProperties (PropertyListBuilder& properties) override
  420. {
  421. properties.add (new TextPropertyComponent (extraPkgConfigValue, "pkg-config libraries", 8192, false),
  422. "Extra pkg-config libraries for you application. Each package should be space separated.");
  423. }
  424. void initialiseDependencyPathValues() override
  425. {
  426. vstLegacyPathValueWrapper.init ({ settings, Ids::vstLegacyFolder, nullptr },
  427. getAppSettings().getStoredPath (Ids::vstLegacyPath, TargetOS::linux), TargetOS::linux);
  428. araPathValueWrapper.init ({ settings, Ids::araFolder, nullptr },
  429. getAppSettings().getStoredPath (Ids::araPath, TargetOS::linux), TargetOS::linux);
  430. }
  431. //==============================================================================
  432. bool anyTargetIsSharedLibrary() const
  433. {
  434. for (auto* target : targets)
  435. {
  436. auto fileType = target->getTargetFileType();
  437. if (fileType == build_tools::ProjectType::Target::sharedLibraryOrDLL
  438. || fileType == build_tools::ProjectType::Target::pluginBundle)
  439. return true;
  440. }
  441. return false;
  442. }
  443. //==============================================================================
  444. void create (const OwnedArray<LibraryModule>&) const override
  445. {
  446. build_tools::writeStreamToFile (getTargetFolder().getChildFile ("Makefile"), [&] (MemoryOutputStream& mo)
  447. {
  448. mo.setNewLineString (getNewLineString());
  449. writeMakefile (mo);
  450. });
  451. if (project.shouldBuildVST3())
  452. {
  453. auto helperDir = getTargetFolder().getChildFile ("make_helpers");
  454. helperDir.createDirectory();
  455. build_tools::overwriteFileIfDifferentOrThrow (helperDir.getChildFile ("arch_detection.cpp"),
  456. BinaryData::juce_runtime_arch_detection_cpp);
  457. }
  458. linuxSubprocessHelperProperties.deployLinuxSubprocessHelperSourceFilesIfNecessary();
  459. }
  460. //==============================================================================
  461. void addPlatformSpecificSettingsForProjectType (const build_tools::ProjectType&) override
  462. {
  463. linuxSubprocessHelperProperties.addToExtraSearchPathsIfNecessary();
  464. callForAllSupportedTargets ([this] (build_tools::ProjectType::Target::Type targetType)
  465. {
  466. targets.insert (targetType == build_tools::ProjectType::Target::AggregateTarget ? 0 : -1,
  467. new MakefileTarget (targetType, *this));
  468. });
  469. // If you hit this assert, you tried to generate a project for an exporter
  470. // that does not support any of your targets!
  471. jassert (targets.size() > 0);
  472. }
  473. private:
  474. ValueTreePropertyWithDefault extraPkgConfigValue;
  475. //==============================================================================
  476. StringPairArray getDefines (const BuildConfiguration& config) const
  477. {
  478. StringPairArray result;
  479. result.set ("LINUX", "1");
  480. if (config.isDebug())
  481. {
  482. result.set ("DEBUG", "1");
  483. result.set ("_DEBUG", "1");
  484. }
  485. else
  486. {
  487. result.set ("NDEBUG", "1");
  488. }
  489. result = mergePreprocessorDefs (result, getAllPreprocessorDefs (config, build_tools::ProjectType::Target::unspecified));
  490. return result;
  491. }
  492. StringArray getExtraPkgConfigPackages() const
  493. {
  494. auto packages = StringArray::fromTokens (extraPkgConfigValue.get().toString(), " ", "\"'");
  495. packages.removeEmptyStrings();
  496. return packages;
  497. }
  498. StringArray getCompilePackages() const
  499. {
  500. auto packages = getLinuxPackages (PackageDependencyType::compile);
  501. packages.addArray (getExtraPkgConfigPackages());
  502. return packages;
  503. }
  504. StringArray getLinkPackages() const
  505. {
  506. auto packages = getLinuxPackages (PackageDependencyType::link);
  507. packages.addArray (getExtraPkgConfigPackages());
  508. return packages;
  509. }
  510. String getPreprocessorPkgConfigFlags() const
  511. {
  512. auto compilePackages = getCompilePackages();
  513. if (compilePackages.size() > 0)
  514. return "$(shell $(PKG_CONFIG) --cflags " + compilePackages.joinIntoString (" ") + ")";
  515. return {};
  516. }
  517. String getLinkerPkgConfigFlags() const
  518. {
  519. auto linkPackages = getLinkPackages();
  520. if (linkPackages.size() > 0)
  521. return "$(shell $(PKG_CONFIG) --libs " + linkPackages.joinIntoString (" ") + ")";
  522. return {};
  523. }
  524. StringArray getCPreprocessorFlags (const BuildConfiguration&) const
  525. {
  526. StringArray result;
  527. if (linuxLibs.contains ("pthread"))
  528. result.add ("-pthread");
  529. return result;
  530. }
  531. StringArray getCFlags (const BuildConfiguration& config) const
  532. {
  533. StringArray result;
  534. if (anyTargetIsSharedLibrary())
  535. result.add ("-fPIC");
  536. if (config.isDebug())
  537. {
  538. result.add ("-g");
  539. result.add ("-ggdb");
  540. }
  541. result.add ("-O" + config.getGCCOptimisationFlag());
  542. if (config.isLinkTimeOptimisationEnabled())
  543. result.add ("-flto");
  544. for (auto& recommended : config.getRecommendedCompilerWarningFlags().common)
  545. result.add (recommended);
  546. auto extra = replacePreprocessorTokens (config, config.getAllCompilerFlagsString()).trim();
  547. if (extra.isNotEmpty())
  548. result.add (extra);
  549. return result;
  550. }
  551. StringArray getCXXFlags (const BuildConfiguration& config) const
  552. {
  553. StringArray result;
  554. for (auto& recommended : config.getRecommendedCompilerWarningFlags().cpp)
  555. result.add (recommended);
  556. auto cppStandard = project.getCppStandardString();
  557. if (cppStandard == "latest")
  558. cppStandard = project.getLatestNumberedCppStandardString();
  559. result.add ("-std=" + String (shouldUseGNUExtensions() ? "gnu++" : "c++") + cppStandard);
  560. return result;
  561. }
  562. StringArray getHeaderSearchPaths (const BuildConfiguration& config) const
  563. {
  564. StringArray searchPaths (extraSearchPaths);
  565. searchPaths.addArray (config.getHeaderSearchPaths());
  566. searchPaths = getCleanedStringArray (searchPaths);
  567. StringArray result;
  568. for (auto& path : searchPaths)
  569. result.add (build_tools::unixStylePath (replacePreprocessorTokens (config, path)));
  570. return result;
  571. }
  572. StringArray getLibraryNames (const BuildConfiguration& config) const
  573. {
  574. StringArray result (linuxLibs);
  575. auto libraries = StringArray::fromTokens (getExternalLibrariesString(), ";", "\"'");
  576. libraries.removeEmptyStrings();
  577. for (auto& lib : libraries)
  578. result.add (replacePreprocessorTokens (config, lib).trim());
  579. return result;
  580. }
  581. StringArray getLibrarySearchPaths (const BuildConfiguration& config) const
  582. {
  583. auto result = getSearchPathsFromString (config.getLibrarySearchPathString());
  584. for (auto path : moduleLibSearchPaths)
  585. result.add (path + "/" + config.getModuleLibraryArchName());
  586. return result;
  587. }
  588. StringArray getLinkerFlags (const BuildConfiguration& config) const
  589. {
  590. auto result = makefileExtraLinkerFlags;
  591. result.add ("-fvisibility=hidden");
  592. if (config.isLinkTimeOptimisationEnabled())
  593. result.add ("-flto");
  594. const auto extraFlags = config.getAllLinkerFlagsString().trim();
  595. if (extraFlags.isNotEmpty())
  596. result.add (replacePreprocessorTokens (config, extraFlags));
  597. return result;
  598. }
  599. //==============================================================================
  600. void writeDefineFlags (OutputStream& out, const MakeBuildConfiguration& config) const
  601. {
  602. out << createGCCPreprocessorFlags (mergePreprocessorDefs (getDefines (config), getAllPreprocessorDefs (config, build_tools::ProjectType::Target::unspecified)));
  603. }
  604. void writePkgConfigFlags (OutputStream& out) const
  605. {
  606. auto flags = getPreprocessorPkgConfigFlags();
  607. if (flags.isNotEmpty())
  608. out << " " << flags;
  609. }
  610. void writeCPreprocessorFlags (OutputStream& out, const BuildConfiguration& config) const
  611. {
  612. auto flags = getCPreprocessorFlags (config);
  613. if (! flags.isEmpty())
  614. out << " " << flags.joinIntoString (" ");
  615. }
  616. void writeHeaderPathFlags (OutputStream& out, const BuildConfiguration& config) const
  617. {
  618. for (auto& path : getHeaderSearchPaths (config))
  619. out << " -I" << escapeQuotesAndSpaces (path).replace ("~", "$(HOME)");
  620. }
  621. void writeCppFlags (OutputStream& out, const MakeBuildConfiguration& config) const
  622. {
  623. out << " JUCE_CPPFLAGS := $(DEPFLAGS)";
  624. writeDefineFlags (out, config);
  625. writePkgConfigFlags (out);
  626. writeCPreprocessorFlags (out, config);
  627. writeHeaderPathFlags (out, config);
  628. out << " $(CPPFLAGS)" << newLine;
  629. }
  630. void writeLinkerFlags (OutputStream& out, const BuildConfiguration& config) const
  631. {
  632. out << " JUCE_LDFLAGS += $(TARGET_ARCH) -L$(JUCE_BINDIR) -L$(JUCE_LIBDIR)";
  633. for (auto path : getLibrarySearchPaths (config))
  634. out << " -L" << escapeQuotesAndSpaces (path).replace ("~", "$(HOME)");
  635. auto pkgConfigFlags = getLinkerPkgConfigFlags();
  636. if (pkgConfigFlags.isNotEmpty())
  637. out << " " << getLinkerPkgConfigFlags();
  638. auto linkerFlags = getLinkerFlags (config).joinIntoString (" ");
  639. if (linkerFlags.isNotEmpty())
  640. out << " " << linkerFlags;
  641. for (auto& libName : getLibraryNames (config))
  642. out << " -l" << libName;
  643. out << " $(LDFLAGS)" << newLine;
  644. }
  645. void writeTargetLines (OutputStream& out, const StringArray& packages) const
  646. {
  647. auto n = targets.size();
  648. for (int i = 0; i < n; ++i)
  649. {
  650. if (auto* target = targets.getUnchecked (i))
  651. {
  652. if (target->type == build_tools::ProjectType::Target::AggregateTarget)
  653. {
  654. StringArray dependencies;
  655. MemoryOutputStream subTargetLines;
  656. for (int j = 0; j < n; ++j)
  657. {
  658. if (i == j) continue;
  659. if (auto* dependency = targets.getUnchecked (j))
  660. {
  661. if (dependency->type != build_tools::ProjectType::Target::SharedCodeTarget)
  662. {
  663. auto phonyName = dependency->getPhonyName();
  664. subTargetLines << phonyName << " : " << dependency->getBuildProduct() << newLine;
  665. dependencies.add (phonyName);
  666. }
  667. }
  668. }
  669. out << "all : " << dependencies.joinIntoString (" ") << newLine << newLine;
  670. out << subTargetLines.toString() << newLine << newLine;
  671. }
  672. else
  673. {
  674. if (! getProject().isAudioPluginProject())
  675. out << "all : " << target->getBuildProduct() << newLine << newLine;
  676. target->writeTargetLine (out, packages);
  677. }
  678. }
  679. }
  680. }
  681. void writeConfig (OutputStream& out, const MakeBuildConfiguration& config) const
  682. {
  683. String buildDirName ("build");
  684. auto intermediatesDirName = buildDirName + "/intermediate/" + config.getName();
  685. auto outputDir = buildDirName;
  686. if (config.getTargetBinaryRelativePathString().isNotEmpty())
  687. {
  688. build_tools::RelativePath binaryPath (config.getTargetBinaryRelativePathString(), build_tools::RelativePath::projectFolder);
  689. outputDir = binaryPath.rebased (projectFolder, getTargetFolder(), build_tools::RelativePath::buildTargetFolder).toUnixStyle();
  690. }
  691. out << "ifeq ($(CONFIG)," << escapeQuotesAndSpaces (config.getName()) << ")" << newLine
  692. << " JUCE_BINDIR := " << escapeQuotesAndSpaces (buildDirName) << newLine
  693. << " JUCE_LIBDIR := " << escapeQuotesAndSpaces (buildDirName) << newLine
  694. << " JUCE_OBJDIR := " << escapeQuotesAndSpaces (intermediatesDirName) << newLine
  695. << " JUCE_OUTDIR := " << escapeQuotesAndSpaces (outputDir) << newLine
  696. << newLine
  697. << " ifeq ($(TARGET_ARCH),)" << newLine
  698. << " TARGET_ARCH := " << getArchFlags (config) << newLine
  699. << " endif" << newLine
  700. << newLine;
  701. writeCppFlags (out, config);
  702. for (auto target : targets)
  703. {
  704. auto lines = target->getTargetSettings (config);
  705. if (lines.size() > 0)
  706. out << " " << lines.joinIntoString ("\n ") << newLine;
  707. out << newLine;
  708. }
  709. out << " JUCE_CFLAGS += $(JUCE_CPPFLAGS) $(TARGET_ARCH)";
  710. auto cflags = getCFlags (config).joinIntoString (" ");
  711. if (cflags.isNotEmpty())
  712. out << " " << cflags;
  713. out << " $(CFLAGS)" << newLine;
  714. out << " JUCE_CXXFLAGS += $(JUCE_CFLAGS)";
  715. auto cxxflags = getCXXFlags (config).joinIntoString (" ");
  716. if (cxxflags.isNotEmpty())
  717. out << " " << cxxflags;
  718. out << " $(CXXFLAGS)" << newLine;
  719. writeLinkerFlags (out, config);
  720. out << newLine;
  721. const auto preBuildDirectory = [&]() -> String
  722. {
  723. if (linuxSubprocessHelperProperties.shouldUseLinuxSubprocessHelper())
  724. {
  725. using LSHP = LinuxSubprocessHelperProperties;
  726. const auto dataSource = linuxSubprocessHelperProperties.getLinuxSubprocessHelperBinaryDataSource();
  727. if (auto preBuildDir = LSHP::getParentDirectoryRelativeToBuildTargetFolder (dataSource))
  728. return " " + *preBuildDir;
  729. }
  730. return "";
  731. }();
  732. out << " CLEANCMD = rm -rf $(JUCE_OUTDIR)/$(TARGET) $(JUCE_OBJDIR)" << preBuildDirectory << newLine
  733. << "endif" << newLine
  734. << newLine;
  735. }
  736. void writeIncludeLines (OutputStream& out) const
  737. {
  738. auto n = targets.size();
  739. for (int i = 0; i < n; ++i)
  740. {
  741. if (auto* target = targets.getUnchecked (i))
  742. {
  743. if (target->type == build_tools::ProjectType::Target::AggregateTarget)
  744. continue;
  745. out << "-include $(OBJECTS_" << target->getTargetVarName()
  746. << ":%.o=%.d)" << newLine;
  747. }
  748. }
  749. }
  750. static String getCompilerFlagSchemeVariableName (const String& schemeName) { return "JUCE_COMPILERFLAGSCHEME_" + schemeName; }
  751. std::vector<std::pair<File, String>> findAllFilesToCompile (const Project::Item& projectItem) const
  752. {
  753. std::vector<std::pair<File, String>> results;
  754. if (projectItem.isGroup())
  755. {
  756. for (int i = 0; i < projectItem.getNumChildren(); ++i)
  757. {
  758. auto inner = findAllFilesToCompile (projectItem.getChild (i));
  759. results.insert (results.end(),
  760. std::make_move_iterator (inner.cbegin()),
  761. std::make_move_iterator (inner.cend()));
  762. }
  763. }
  764. else
  765. {
  766. if (projectItem.shouldBeCompiled())
  767. {
  768. auto f = projectItem.getFile();
  769. if (shouldFileBeCompiledByDefault (f))
  770. {
  771. auto scheme = projectItem.getCompilerFlagSchemeString();
  772. auto flags = getCompilerFlagsForProjectItem (projectItem);
  773. if (scheme.isNotEmpty() && flags.isNotEmpty())
  774. results.emplace_back (f, scheme);
  775. else
  776. results.emplace_back (f, String{});
  777. }
  778. }
  779. }
  780. return results;
  781. }
  782. void writeCompilerFlagSchemes (OutputStream& out, const std::vector<std::pair<File, String>>& filesToCompile) const
  783. {
  784. std::set<String> schemesToWrite;
  785. for (const auto& pair : filesToCompile)
  786. if (pair.second.isNotEmpty())
  787. schemesToWrite.insert (pair.second);
  788. if (schemesToWrite.empty())
  789. return;
  790. for (const auto& s : schemesToWrite)
  791. if (const auto flags = getCompilerFlagsForFileCompilerFlagScheme (s); flags.isNotEmpty())
  792. out << getCompilerFlagSchemeVariableName (s) << " := " << flags << newLine;
  793. out << newLine;
  794. }
  795. /* These targets are responsible for building the juce_linux_subprocess_helper, the
  796. juce_simple_binary_builder, and then using the binary builder to create embeddable .h and .cpp
  797. files from the linux subprocess helper.
  798. */
  799. void writeSubprocessHelperTargets (OutputStream& out) const
  800. {
  801. using LSHP = LinuxSubprocessHelperProperties;
  802. const auto ensureDirs = [] (auto& outStream, std::vector<String> dirs)
  803. {
  804. for (const auto& dir : dirs)
  805. outStream << "\t-$(V_AT)mkdir -p " << dir << newLine;
  806. };
  807. const auto makeTarget = [&ensureDirs] (auto& outStream, String input, String output)
  808. {
  809. const auto isObjectTarget = output.endsWith (".o");
  810. const auto isSourceInput = input.endsWith (".cpp");
  811. const auto targetOutput = isObjectTarget ? "$(JUCE_OBJDIR)/" + output : output;
  812. outStream << (isObjectTarget ? "$(JUCE_OBJDIR)/" : "") << output << ": " << input << newLine;
  813. const auto createBuildTargetRelative = [] (auto path)
  814. {
  815. return build_tools::RelativePath { path, build_tools::RelativePath::buildTargetFolder };
  816. };
  817. if (isObjectTarget)
  818. ensureDirs (outStream, { "$(JUCE_OBJDIR)" });
  819. else if (auto outputParentFolder = LSHP::getParentDirectoryRelativeToBuildTargetFolder (createBuildTargetRelative (output)))
  820. ensureDirs (outStream, { *outputParentFolder });
  821. outStream << (isObjectTarget ? "\t@echo \"Compiling " : "\t@echo \"Linking ")
  822. << (isObjectTarget ? input : output) << "\"" << newLine
  823. << "\t$(V_AT)$(CXX) $(JUCE_CXXFLAGS) -o " << targetOutput.quoted()
  824. << " " << (isSourceInput ? "-c \"$<\"" : input.quoted());
  825. if (! isObjectTarget)
  826. outStream << " $(JUCE_LDFLAGS)";
  827. outStream << " $(TARGET_ARCH)" << newLine << newLine;
  828. return targetOutput;
  829. };
  830. const auto subprocessHelperSource = linuxSubprocessHelperProperties.getLinuxSubprocessHelperSource();
  831. const auto subprocessHelperObj = makeTarget (out,
  832. subprocessHelperSource.toUnixStyle(),
  833. getObjectFileFor (subprocessHelperSource));
  834. const auto subprocessHelperPath = makeTarget (out,
  835. subprocessHelperObj,
  836. "$(JUCE_BINDIR)/" + LSHP::getBinaryNameFromSource (subprocessHelperSource));
  837. const auto binaryBuilderSource = linuxSubprocessHelperProperties.getSimpleBinaryBuilderSource();
  838. const auto binaryBuilderObj = makeTarget (out,
  839. binaryBuilderSource.toUnixStyle(),
  840. getObjectFileFor (binaryBuilderSource));
  841. const auto binaryBuilderPath = makeTarget (out,
  842. binaryBuilderObj,
  843. "$(JUCE_BINDIR)/" + LSHP::getBinaryNameFromSource (binaryBuilderSource));
  844. const auto binaryDataSource = linuxSubprocessHelperProperties.getLinuxSubprocessHelperBinaryDataSource();
  845. jassert (binaryDataSource.getRoot() == build_tools::RelativePath::buildTargetFolder);
  846. out << binaryDataSource.toUnixStyle() << ": " << subprocessHelperPath
  847. << " " << binaryBuilderPath
  848. << newLine;
  849. const auto binarySourceDir = [&]() -> String
  850. {
  851. if (const auto p = LSHP::getParentDirectoryRelativeToBuildTargetFolder (binaryDataSource))
  852. return *p;
  853. return ".";
  854. }();
  855. out << "\t$(V_AT)" << binaryBuilderPath.quoted() << " " << subprocessHelperPath.quoted()
  856. << " " << binarySourceDir.quoted() << " " << binaryDataSource.getFileNameWithoutExtension().quoted()
  857. << " LinuxSubprocessHelperBinaryData" << newLine;
  858. out << newLine;
  859. }
  860. void writeMakefile (OutputStream& out) const
  861. {
  862. out << "# Automatically generated makefile, created by the Projucer" << newLine
  863. << "# Don't edit this file! Your changes will be overwritten when you re-save the Projucer project!" << newLine
  864. << newLine;
  865. out << "# build with \"V=1\" for verbose builds" << newLine
  866. << "ifeq ($(V), 1)" << newLine
  867. << "V_AT =" << newLine
  868. << "else" << newLine
  869. << "V_AT = @" << newLine
  870. << "endif" << newLine
  871. << newLine;
  872. out << "# (this disables dependency generation if multiple architectures are set)" << newLine
  873. << "DEPFLAGS := $(if $(word 2, $(TARGET_ARCH)), , -MMD)" << newLine
  874. << newLine;
  875. out << "ifndef PKG_CONFIG" << newLine
  876. << " PKG_CONFIG=pkg-config" << newLine
  877. << "endif" << newLine
  878. << newLine;
  879. out << "ifndef STRIP" << newLine
  880. << " STRIP=strip" << newLine
  881. << "endif" << newLine
  882. << newLine;
  883. out << "ifndef AR" << newLine
  884. << " AR=ar" << newLine
  885. << "endif" << newLine
  886. << newLine;
  887. out << "ifndef CONFIG" << newLine
  888. << " CONFIG=" << escapeQuotesAndSpaces (getConfiguration(0)->getName()) << newLine
  889. << "endif" << newLine
  890. << newLine;
  891. out << "JUCE_ARCH_LABEL := $(shell uname -m)" << newLine
  892. << newLine;
  893. for (ConstConfigIterator config (*this); config.next();)
  894. writeConfig (out, dynamic_cast<const MakeBuildConfiguration&> (*config));
  895. std::vector<std::pair<File, String>> filesToCompile;
  896. for (int i = 0; i < getAllGroups().size(); ++i)
  897. {
  898. auto group = findAllFilesToCompile (getAllGroups().getReference (i));
  899. filesToCompile.insert (filesToCompile.end(),
  900. std::make_move_iterator (group.cbegin()),
  901. std::make_move_iterator (group.cend()));
  902. }
  903. writeCompilerFlagSchemes (out, filesToCompile);
  904. const auto getFilesForTarget = [this] (const std::vector<std::pair<File, String>>& files,
  905. MakefileTarget* target,
  906. const Project& p)
  907. {
  908. std::vector<std::pair<build_tools::RelativePath, String>> targetFiles;
  909. auto targetType = (p.isAudioPluginProject() ? target->type : MakefileTarget::SharedCodeTarget);
  910. for (auto& [path, flags] : files)
  911. {
  912. if (p.getTargetTypeFromFilePath (path, true) == targetType)
  913. {
  914. targetFiles.emplace_back (build_tools::RelativePath { path,
  915. getTargetFolder(),
  916. build_tools::RelativePath::buildTargetFolder },
  917. flags);
  918. }
  919. }
  920. if (( targetType == MakefileTarget::SharedCodeTarget
  921. || targetType == MakefileTarget::StaticLibrary
  922. || targetType == MakefileTarget::DynamicLibrary)
  923. && linuxSubprocessHelperProperties.shouldUseLinuxSubprocessHelper())
  924. {
  925. targetFiles.emplace_back (linuxSubprocessHelperProperties.getLinuxSubprocessHelperBinaryDataSource(), "");
  926. }
  927. if (targetType == MakefileTarget::LV2Helper)
  928. {
  929. targetFiles.emplace_back (getLV2HelperProgramSource().rebased (projectFolder,
  930. getTargetFolder(),
  931. build_tools::RelativePath::buildTargetFolder),
  932. String{});
  933. }
  934. else if (targetType == MakefileTarget::VST3Helper)
  935. {
  936. targetFiles.emplace_back (getVST3HelperProgramSource().rebased (projectFolder,
  937. getTargetFolder(),
  938. build_tools::RelativePath::buildTargetFolder),
  939. String{});
  940. }
  941. return targetFiles;
  942. };
  943. for (auto target : targets)
  944. target->writeObjects (out, getFilesForTarget (filesToCompile, target, project));
  945. out << getPhonyTargetLine() << newLine << newLine;
  946. writeTargetLines (out, getLinkPackages());
  947. for (auto target : targets)
  948. target->addFiles (out, getFilesForTarget (filesToCompile, target, project));
  949. // libexecinfo is a separate library on BSD
  950. out << "$(JUCE_OBJDIR)/execinfo.cmd:" << newLine
  951. << "\t-$(V_AT)mkdir -p $(@D)" << newLine
  952. << "\t-@if [ -z \"$(V_AT)\" ]; then echo \"Checking if we need to link libexecinfo\"; fi" << newLine
  953. << "\t$(V_AT)printf \"int main() { return 0; }\" | $(CXX) -x c++ -o $(@D)/execinfo.x -lexecinfo - >/dev/null 2>&1 && printf -- \"-lexecinfo\" > \"$@\" || touch \"$@\"" << newLine
  954. << newLine;
  955. if (linuxSubprocessHelperProperties.shouldUseLinuxSubprocessHelper())
  956. writeSubprocessHelperTargets (out);
  957. out << "clean:" << newLine
  958. << "\t@echo Cleaning " << projectName << newLine
  959. << "\t$(V_AT)$(CLEANCMD)" << newLine
  960. << newLine;
  961. out << "strip:" << newLine
  962. << "\t@echo Stripping " << projectName << newLine
  963. << "\t-$(V_AT)$(STRIP) --strip-unneeded $(JUCE_OUTDIR)/$(TARGET)" << newLine
  964. << newLine;
  965. writeIncludeLines (out);
  966. }
  967. String getArchFlags (const BuildConfiguration& config) const
  968. {
  969. if (auto* makeConfig = dynamic_cast<const MakeBuildConfiguration*> (&config))
  970. return makeConfig->getArchitectureTypeString();
  971. return "-march=native";
  972. }
  973. String getObjectFileFor (const build_tools::RelativePath& file) const
  974. {
  975. return file.getFileNameWithoutExtension()
  976. + "_" + String::toHexString (file.toUnixStyle().hashCode()) + ".o";
  977. }
  978. String getPhonyTargetLine() const
  979. {
  980. MemoryOutputStream phonyTargetLine;
  981. phonyTargetLine << ".PHONY: clean all strip";
  982. if (! getProject().isAudioPluginProject())
  983. return phonyTargetLine.toString();
  984. for (auto target : targets)
  985. if (target->type != build_tools::ProjectType::Target::SharedCodeTarget
  986. && target->type != build_tools::ProjectType::Target::AggregateTarget)
  987. phonyTargetLine << " " << target->getPhonyName();
  988. return phonyTargetLine.toString();
  989. }
  990. OwnedArray<MakefileTarget> targets;
  991. JUCE_DECLARE_NON_COPYABLE (MakefileProjectExporter)
  992. };