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.

1282 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 && owner.project.isVst3ManifestEnabled())
  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. if (owner.project.isVst3ManifestEnabled())
  325. {
  326. out << "\t-$(V_AT)mkdir -p $(JUCE_OUTDIR)/$(JUCE_VST3DIR)/Contents/Resources" << newLine
  327. << "\t-$(V_AT)rm -f $(JUCE_OUTDIR)/$(JUCE_VST3DIR)/Contents/moduleinfo.json" << newLine
  328. << "\t$(V_AT) $(JUCE_OUTDIR)/$(JUCE_TARGET_VST3_MANIFEST_HELPER) "
  329. "-create "
  330. "-version " << owner.project.getVersionString().quoted() << " "
  331. "-path \"$(JUCE_OUTDIR)/$(JUCE_VST3DIR)\" "
  332. "-output \"$(JUCE_OUTDIR)/$(JUCE_VST3DIR)/Contents/Resources/moduleinfo.json\"" << newLine;
  333. }
  334. out << "\t-$(V_AT)[ ! \"$(JUCE_VST3DESTDIR)\" ] || (mkdir -p $(JUCE_VST3DESTDIR) && cp -R $(JUCE_COPYCMD_VST3))" << newLine;
  335. }
  336. else if (type == VSTPlugIn)
  337. {
  338. out << "\t-$(V_AT)[ ! \"$(JUCE_VSTDESTDIR)\" ] || (mkdir -p $(JUCE_VSTDESTDIR) && cp -R $(JUCE_COPYCMD_VST))" << newLine;
  339. }
  340. else if (type == UnityPlugIn)
  341. {
  342. auto scriptName = owner.getProject().getUnityScriptName();
  343. build_tools::RelativePath scriptPath (owner.getProject().getGeneratedCodeFolder().getChildFile (scriptName),
  344. owner.getTargetFolder(),
  345. build_tools::RelativePath::projectFolder);
  346. out << "\t-$(V_AT)cp " + scriptPath.toUnixStyle() + " $(JUCE_OUTDIR)/$(JUCE_UNITYDIR)" << newLine
  347. << "\t-$(V_AT)[ ! \"$(JUCE_UNITYDESTDIR)\" ] || (mkdir -p $(JUCE_UNITYDESTDIR) && cp -R $(JUCE_COPYCMD_UNITY_PLUGIN))" << newLine;
  348. }
  349. else if (type == LV2PlugIn)
  350. {
  351. out << "\t$(V_AT) $(JUCE_OUTDIR)/$(JUCE_TARGET_LV2_MANIFEST_HELPER) $(JUCE_LV2_FULL_PATH)" << newLine
  352. << "\t-$(V_AT)[ ! \"$(JUCE_LV2DESTDIR)\" ] || (mkdir -p $(JUCE_LV2DESTDIR) && cp -R $(JUCE_COPYCMD_LV2_PLUGIN))" << newLine;
  353. }
  354. out << newLine;
  355. }
  356. const MakefileProjectExporter& owner;
  357. };
  358. //==============================================================================
  359. static String getDisplayName() { return "Linux Makefile"; }
  360. static String getValueTreeTypeName() { return "LINUX_MAKE"; }
  361. static String getTargetFolderName() { return "LinuxMakefile"; }
  362. Identifier getExporterIdentifier() const override { return getValueTreeTypeName(); }
  363. static MakefileProjectExporter* createForSettings (Project& projectToUse, const ValueTree& settingsToUse)
  364. {
  365. if (settingsToUse.hasType (getValueTreeTypeName()))
  366. return new MakefileProjectExporter (projectToUse, settingsToUse);
  367. return nullptr;
  368. }
  369. //==============================================================================
  370. MakefileProjectExporter (Project& p, const ValueTree& t)
  371. : ProjectExporter (p, t),
  372. extraPkgConfigValue (settings, Ids::linuxExtraPkgConfig, getUndoManager())
  373. {
  374. name = getDisplayName();
  375. targetLocationValue.setDefault (getDefaultBuildsRootFolder() + getTargetFolderName());
  376. }
  377. //==============================================================================
  378. bool canLaunchProject() override { return false; }
  379. bool launchProject() override { return false; }
  380. bool usesMMFiles() const override { return false; }
  381. bool canCopeWithDuplicateFiles() override { return false; }
  382. bool supportsUserDefinedConfigurations() const override { return true; }
  383. bool isXcode() const override { return false; }
  384. bool isVisualStudio() const override { return false; }
  385. bool isCodeBlocks() const override { return false; }
  386. bool isMakefile() const override { return true; }
  387. bool isAndroidStudio() const override { return false; }
  388. bool isAndroid() const override { return false; }
  389. bool isWindows() const override { return false; }
  390. bool isLinux() const override { return true; }
  391. bool isOSX() const override { return false; }
  392. bool isiOS() const override { return false; }
  393. String getNewLineString() const override { return "\n"; }
  394. bool supportsTargetType (build_tools::ProjectType::Target::Type type) const override
  395. {
  396. using Target = build_tools::ProjectType::Target;
  397. switch (type)
  398. {
  399. case Target::GUIApp:
  400. case Target::ConsoleApp:
  401. case Target::StaticLibrary:
  402. case Target::SharedCodeTarget:
  403. case Target::AggregateTarget:
  404. case Target::VSTPlugIn:
  405. case Target::VST3PlugIn:
  406. case Target::VST3Helper:
  407. case Target::StandalonePlugIn:
  408. case Target::DynamicLibrary:
  409. case Target::UnityPlugIn:
  410. case Target::LV2PlugIn:
  411. case Target::LV2Helper:
  412. return true;
  413. case Target::AAXPlugIn:
  414. case Target::AudioUnitPlugIn:
  415. case Target::AudioUnitv3PlugIn:
  416. case Target::unspecified:
  417. default:
  418. break;
  419. }
  420. return false;
  421. }
  422. void createExporterProperties (PropertyListBuilder& properties) override
  423. {
  424. properties.add (new TextPropertyComponent (extraPkgConfigValue, "pkg-config libraries", 8192, false),
  425. "Extra pkg-config libraries for you application. Each package should be space separated.");
  426. }
  427. void initialiseDependencyPathValues() override
  428. {
  429. vstLegacyPathValueWrapper.init ({ settings, Ids::vstLegacyFolder, nullptr },
  430. getAppSettings().getStoredPath (Ids::vstLegacyPath, TargetOS::linux), TargetOS::linux);
  431. araPathValueWrapper.init ({ settings, Ids::araFolder, nullptr },
  432. getAppSettings().getStoredPath (Ids::araPath, TargetOS::linux), TargetOS::linux);
  433. }
  434. //==============================================================================
  435. bool anyTargetIsSharedLibrary() const
  436. {
  437. for (auto* target : targets)
  438. {
  439. auto fileType = target->getTargetFileType();
  440. if (fileType == build_tools::ProjectType::Target::sharedLibraryOrDLL
  441. || fileType == build_tools::ProjectType::Target::pluginBundle)
  442. return true;
  443. }
  444. return false;
  445. }
  446. //==============================================================================
  447. void create (const OwnedArray<LibraryModule>&) const override
  448. {
  449. build_tools::writeStreamToFile (getTargetFolder().getChildFile ("Makefile"), [&] (MemoryOutputStream& mo)
  450. {
  451. mo.setNewLineString (getNewLineString());
  452. writeMakefile (mo);
  453. });
  454. if (project.shouldBuildVST3())
  455. {
  456. auto helperDir = getTargetFolder().getChildFile ("make_helpers");
  457. helperDir.createDirectory();
  458. build_tools::overwriteFileIfDifferentOrThrow (helperDir.getChildFile ("arch_detection.cpp"),
  459. BinaryData::juce_runtime_arch_detection_cpp);
  460. }
  461. linuxSubprocessHelperProperties.deployLinuxSubprocessHelperSourceFilesIfNecessary();
  462. }
  463. //==============================================================================
  464. void addPlatformSpecificSettingsForProjectType (const build_tools::ProjectType&) override
  465. {
  466. linuxSubprocessHelperProperties.addToExtraSearchPathsIfNecessary();
  467. callForAllSupportedTargets ([this] (build_tools::ProjectType::Target::Type targetType)
  468. {
  469. targets.insert (targetType == build_tools::ProjectType::Target::AggregateTarget ? 0 : -1,
  470. new MakefileTarget (targetType, *this));
  471. });
  472. // If you hit this assert, you tried to generate a project for an exporter
  473. // that does not support any of your targets!
  474. jassert (targets.size() > 0);
  475. }
  476. private:
  477. ValueTreePropertyWithDefault extraPkgConfigValue;
  478. //==============================================================================
  479. StringPairArray getDefines (const BuildConfiguration& config) const
  480. {
  481. StringPairArray result;
  482. result.set ("LINUX", "1");
  483. if (config.isDebug())
  484. {
  485. result.set ("DEBUG", "1");
  486. result.set ("_DEBUG", "1");
  487. }
  488. else
  489. {
  490. result.set ("NDEBUG", "1");
  491. }
  492. result = mergePreprocessorDefs (result, getAllPreprocessorDefs (config, build_tools::ProjectType::Target::unspecified));
  493. return result;
  494. }
  495. StringArray getExtraPkgConfigPackages() const
  496. {
  497. auto packages = StringArray::fromTokens (extraPkgConfigValue.get().toString(), " ", "\"'");
  498. packages.removeEmptyStrings();
  499. return packages;
  500. }
  501. StringArray getCompilePackages() const
  502. {
  503. auto packages = getLinuxPackages (PackageDependencyType::compile);
  504. packages.addArray (getExtraPkgConfigPackages());
  505. return packages;
  506. }
  507. StringArray getLinkPackages() const
  508. {
  509. auto packages = getLinuxPackages (PackageDependencyType::link);
  510. packages.addArray (getExtraPkgConfigPackages());
  511. return packages;
  512. }
  513. String getPreprocessorPkgConfigFlags() const
  514. {
  515. auto compilePackages = getCompilePackages();
  516. if (compilePackages.size() > 0)
  517. return "$(shell $(PKG_CONFIG) --cflags " + compilePackages.joinIntoString (" ") + ")";
  518. return {};
  519. }
  520. String getLinkerPkgConfigFlags() const
  521. {
  522. auto linkPackages = getLinkPackages();
  523. if (linkPackages.size() > 0)
  524. return "$(shell $(PKG_CONFIG) --libs " + linkPackages.joinIntoString (" ") + ")";
  525. return {};
  526. }
  527. StringArray getCPreprocessorFlags (const BuildConfiguration&) const
  528. {
  529. StringArray result;
  530. if (linuxLibs.contains ("pthread"))
  531. result.add ("-pthread");
  532. return result;
  533. }
  534. StringArray getCFlags (const BuildConfiguration& config) const
  535. {
  536. StringArray result;
  537. if (anyTargetIsSharedLibrary())
  538. result.add ("-fPIC");
  539. if (config.isDebug())
  540. {
  541. result.add ("-g");
  542. result.add ("-ggdb");
  543. }
  544. result.add ("-O" + config.getGCCOptimisationFlag());
  545. if (config.isLinkTimeOptimisationEnabled())
  546. result.add ("-flto");
  547. for (auto& recommended : config.getRecommendedCompilerWarningFlags().common)
  548. result.add (recommended);
  549. auto extra = replacePreprocessorTokens (config, config.getAllCompilerFlagsString()).trim();
  550. if (extra.isNotEmpty())
  551. result.add (extra);
  552. return result;
  553. }
  554. StringArray getCXXFlags (const BuildConfiguration& config) const
  555. {
  556. StringArray result;
  557. for (auto& recommended : config.getRecommendedCompilerWarningFlags().cpp)
  558. result.add (recommended);
  559. auto cppStandard = project.getCppStandardString();
  560. if (cppStandard == "latest")
  561. cppStandard = project.getLatestNumberedCppStandardString();
  562. result.add ("-std=" + String (shouldUseGNUExtensions() ? "gnu++" : "c++") + cppStandard);
  563. return result;
  564. }
  565. StringArray getHeaderSearchPaths (const BuildConfiguration& config) const
  566. {
  567. StringArray searchPaths (extraSearchPaths);
  568. searchPaths.addArray (config.getHeaderSearchPaths());
  569. searchPaths = getCleanedStringArray (searchPaths);
  570. StringArray result;
  571. for (auto& path : searchPaths)
  572. result.add (build_tools::unixStylePath (replacePreprocessorTokens (config, path)));
  573. return result;
  574. }
  575. StringArray getLibraryNames (const BuildConfiguration& config) const
  576. {
  577. StringArray result (linuxLibs);
  578. auto libraries = StringArray::fromTokens (getExternalLibrariesString(), ";", "\"'");
  579. libraries.removeEmptyStrings();
  580. for (auto& lib : libraries)
  581. result.add (replacePreprocessorTokens (config, lib).trim());
  582. return result;
  583. }
  584. StringArray getLibrarySearchPaths (const BuildConfiguration& config) const
  585. {
  586. auto result = getSearchPathsFromString (config.getLibrarySearchPathString());
  587. for (auto path : moduleLibSearchPaths)
  588. result.add (path + "/" + config.getModuleLibraryArchName());
  589. return result;
  590. }
  591. StringArray getLinkerFlags (const BuildConfiguration& config) const
  592. {
  593. auto result = makefileExtraLinkerFlags;
  594. result.add ("-fvisibility=hidden");
  595. if (config.isLinkTimeOptimisationEnabled())
  596. result.add ("-flto");
  597. const auto extraFlags = config.getAllLinkerFlagsString().trim();
  598. if (extraFlags.isNotEmpty())
  599. result.add (replacePreprocessorTokens (config, extraFlags));
  600. return result;
  601. }
  602. //==============================================================================
  603. void writeDefineFlags (OutputStream& out, const MakeBuildConfiguration& config) const
  604. {
  605. out << createGCCPreprocessorFlags (mergePreprocessorDefs (getDefines (config), getAllPreprocessorDefs (config, build_tools::ProjectType::Target::unspecified)));
  606. }
  607. void writePkgConfigFlags (OutputStream& out) const
  608. {
  609. auto flags = getPreprocessorPkgConfigFlags();
  610. if (flags.isNotEmpty())
  611. out << " " << flags;
  612. }
  613. void writeCPreprocessorFlags (OutputStream& out, const BuildConfiguration& config) const
  614. {
  615. auto flags = getCPreprocessorFlags (config);
  616. if (! flags.isEmpty())
  617. out << " " << flags.joinIntoString (" ");
  618. }
  619. void writeHeaderPathFlags (OutputStream& out, const BuildConfiguration& config) const
  620. {
  621. for (auto& path : getHeaderSearchPaths (config))
  622. out << " -I" << escapeQuotesAndSpaces (path).replace ("~", "$(HOME)");
  623. }
  624. void writeCppFlags (OutputStream& out, const MakeBuildConfiguration& config) const
  625. {
  626. out << " JUCE_CPPFLAGS := $(DEPFLAGS)";
  627. writeDefineFlags (out, config);
  628. writePkgConfigFlags (out);
  629. writeCPreprocessorFlags (out, config);
  630. writeHeaderPathFlags (out, config);
  631. out << " $(CPPFLAGS)" << newLine;
  632. }
  633. void writeLinkerFlags (OutputStream& out, const BuildConfiguration& config) const
  634. {
  635. out << " JUCE_LDFLAGS += $(TARGET_ARCH) -L$(JUCE_BINDIR) -L$(JUCE_LIBDIR)";
  636. for (auto path : getLibrarySearchPaths (config))
  637. out << " -L" << escapeQuotesAndSpaces (path).replace ("~", "$(HOME)");
  638. auto pkgConfigFlags = getLinkerPkgConfigFlags();
  639. if (pkgConfigFlags.isNotEmpty())
  640. out << " " << getLinkerPkgConfigFlags();
  641. auto linkerFlags = getLinkerFlags (config).joinIntoString (" ");
  642. if (linkerFlags.isNotEmpty())
  643. out << " " << linkerFlags;
  644. for (auto& libName : getLibraryNames (config))
  645. out << " -l" << libName;
  646. out << " $(LDFLAGS)" << newLine;
  647. }
  648. void writeTargetLines (OutputStream& out, const StringArray& packages) const
  649. {
  650. auto n = targets.size();
  651. for (int i = 0; i < n; ++i)
  652. {
  653. if (auto* target = targets.getUnchecked (i))
  654. {
  655. if (target->type == build_tools::ProjectType::Target::AggregateTarget)
  656. {
  657. StringArray dependencies;
  658. MemoryOutputStream subTargetLines;
  659. for (int j = 0; j < n; ++j)
  660. {
  661. if (i == j) continue;
  662. if (auto* dependency = targets.getUnchecked (j))
  663. {
  664. if (dependency->type != build_tools::ProjectType::Target::SharedCodeTarget)
  665. {
  666. auto phonyName = dependency->getPhonyName();
  667. subTargetLines << phonyName << " : " << dependency->getBuildProduct() << newLine;
  668. dependencies.add (phonyName);
  669. }
  670. }
  671. }
  672. out << "all : " << dependencies.joinIntoString (" ") << newLine << newLine;
  673. out << subTargetLines.toString() << newLine << newLine;
  674. }
  675. else
  676. {
  677. if (! getProject().isAudioPluginProject())
  678. out << "all : " << target->getBuildProduct() << newLine << newLine;
  679. target->writeTargetLine (out, packages);
  680. }
  681. }
  682. }
  683. }
  684. void writeConfig (OutputStream& out, const MakeBuildConfiguration& config) const
  685. {
  686. String buildDirName ("build");
  687. auto intermediatesDirName = buildDirName + "/intermediate/" + config.getName();
  688. auto outputDir = buildDirName;
  689. if (config.getTargetBinaryRelativePathString().isNotEmpty())
  690. {
  691. build_tools::RelativePath binaryPath (config.getTargetBinaryRelativePathString(), build_tools::RelativePath::projectFolder);
  692. outputDir = binaryPath.rebased (projectFolder, getTargetFolder(), build_tools::RelativePath::buildTargetFolder).toUnixStyle();
  693. }
  694. out << "ifeq ($(CONFIG)," << escapeQuotesAndSpaces (config.getName()) << ")" << newLine
  695. << " JUCE_BINDIR := " << escapeQuotesAndSpaces (buildDirName) << newLine
  696. << " JUCE_LIBDIR := " << escapeQuotesAndSpaces (buildDirName) << newLine
  697. << " JUCE_OBJDIR := " << escapeQuotesAndSpaces (intermediatesDirName) << newLine
  698. << " JUCE_OUTDIR := " << escapeQuotesAndSpaces (outputDir) << newLine
  699. << newLine
  700. << " ifeq ($(TARGET_ARCH),)" << newLine
  701. << " TARGET_ARCH := " << getArchFlags (config) << newLine
  702. << " endif" << newLine
  703. << newLine;
  704. writeCppFlags (out, config);
  705. for (auto target : targets)
  706. {
  707. auto lines = target->getTargetSettings (config);
  708. if (lines.size() > 0)
  709. out << " " << lines.joinIntoString ("\n ") << newLine;
  710. out << newLine;
  711. }
  712. out << " JUCE_CFLAGS += $(JUCE_CPPFLAGS) $(TARGET_ARCH)";
  713. auto cflags = getCFlags (config).joinIntoString (" ");
  714. if (cflags.isNotEmpty())
  715. out << " " << cflags;
  716. out << " $(CFLAGS)" << newLine;
  717. out << " JUCE_CXXFLAGS += $(JUCE_CFLAGS)";
  718. auto cxxflags = getCXXFlags (config).joinIntoString (" ");
  719. if (cxxflags.isNotEmpty())
  720. out << " " << cxxflags;
  721. out << " $(CXXFLAGS)" << newLine;
  722. writeLinkerFlags (out, config);
  723. out << newLine;
  724. const auto preBuildDirectory = [&]() -> String
  725. {
  726. if (linuxSubprocessHelperProperties.shouldUseLinuxSubprocessHelper())
  727. {
  728. using LSHP = LinuxSubprocessHelperProperties;
  729. const auto dataSource = linuxSubprocessHelperProperties.getLinuxSubprocessHelperBinaryDataSource();
  730. if (auto preBuildDir = LSHP::getParentDirectoryRelativeToBuildTargetFolder (dataSource))
  731. return " " + *preBuildDir;
  732. }
  733. return "";
  734. }();
  735. out << " CLEANCMD = rm -rf $(JUCE_OUTDIR)/$(TARGET) $(JUCE_OBJDIR)" << preBuildDirectory << newLine
  736. << "endif" << newLine
  737. << newLine;
  738. }
  739. void writeIncludeLines (OutputStream& out) const
  740. {
  741. auto n = targets.size();
  742. for (int i = 0; i < n; ++i)
  743. {
  744. if (auto* target = targets.getUnchecked (i))
  745. {
  746. if (target->type == build_tools::ProjectType::Target::AggregateTarget)
  747. continue;
  748. out << "-include $(OBJECTS_" << target->getTargetVarName()
  749. << ":%.o=%.d)" << newLine;
  750. }
  751. }
  752. }
  753. static String getCompilerFlagSchemeVariableName (const String& schemeName) { return "JUCE_COMPILERFLAGSCHEME_" + schemeName; }
  754. std::vector<std::pair<File, String>> findAllFilesToCompile (const Project::Item& projectItem) const
  755. {
  756. std::vector<std::pair<File, String>> results;
  757. if (projectItem.isGroup())
  758. {
  759. for (int i = 0; i < projectItem.getNumChildren(); ++i)
  760. {
  761. auto inner = findAllFilesToCompile (projectItem.getChild (i));
  762. results.insert (results.end(),
  763. std::make_move_iterator (inner.cbegin()),
  764. std::make_move_iterator (inner.cend()));
  765. }
  766. }
  767. else
  768. {
  769. if (projectItem.shouldBeCompiled())
  770. {
  771. auto f = projectItem.getFile();
  772. if (shouldFileBeCompiledByDefault (f))
  773. {
  774. auto scheme = projectItem.getCompilerFlagSchemeString();
  775. auto flags = getCompilerFlagsForProjectItem (projectItem);
  776. if (scheme.isNotEmpty() && flags.isNotEmpty())
  777. results.emplace_back (f, scheme);
  778. else
  779. results.emplace_back (f, String{});
  780. }
  781. }
  782. }
  783. return results;
  784. }
  785. void writeCompilerFlagSchemes (OutputStream& out, const std::vector<std::pair<File, String>>& filesToCompile) const
  786. {
  787. std::set<String> schemesToWrite;
  788. for (const auto& pair : filesToCompile)
  789. if (pair.second.isNotEmpty())
  790. schemesToWrite.insert (pair.second);
  791. if (schemesToWrite.empty())
  792. return;
  793. for (const auto& s : schemesToWrite)
  794. if (const auto flags = getCompilerFlagsForFileCompilerFlagScheme (s); flags.isNotEmpty())
  795. out << getCompilerFlagSchemeVariableName (s) << " := " << flags << newLine;
  796. out << newLine;
  797. }
  798. /* These targets are responsible for building the juce_linux_subprocess_helper, the
  799. juce_simple_binary_builder, and then using the binary builder to create embeddable .h and .cpp
  800. files from the linux subprocess helper.
  801. */
  802. void writeSubprocessHelperTargets (OutputStream& out) const
  803. {
  804. using LSHP = LinuxSubprocessHelperProperties;
  805. const auto ensureDirs = [] (auto& outStream, std::vector<String> dirs)
  806. {
  807. for (const auto& dir : dirs)
  808. outStream << "\t-$(V_AT)mkdir -p " << dir << newLine;
  809. };
  810. const auto makeTarget = [&ensureDirs] (auto& outStream, String input, String output)
  811. {
  812. const auto isObjectTarget = output.endsWith (".o");
  813. const auto isSourceInput = input.endsWith (".cpp");
  814. const auto targetOutput = isObjectTarget ? "$(JUCE_OBJDIR)/" + output : output;
  815. outStream << (isObjectTarget ? "$(JUCE_OBJDIR)/" : "") << output << ": " << input << newLine;
  816. const auto createBuildTargetRelative = [] (auto path)
  817. {
  818. return build_tools::RelativePath { path, build_tools::RelativePath::buildTargetFolder };
  819. };
  820. if (isObjectTarget)
  821. ensureDirs (outStream, { "$(JUCE_OBJDIR)" });
  822. else if (auto outputParentFolder = LSHP::getParentDirectoryRelativeToBuildTargetFolder (createBuildTargetRelative (output)))
  823. ensureDirs (outStream, { *outputParentFolder });
  824. outStream << (isObjectTarget ? "\t@echo \"Compiling " : "\t@echo \"Linking ")
  825. << (isObjectTarget ? input : output) << "\"" << newLine
  826. << "\t$(V_AT)$(CXX) $(JUCE_CXXFLAGS) -o " << targetOutput.quoted()
  827. << " " << (isSourceInput ? "-c \"$<\"" : input.quoted());
  828. if (! isObjectTarget)
  829. outStream << " $(JUCE_LDFLAGS)";
  830. outStream << " $(TARGET_ARCH)" << newLine << newLine;
  831. return targetOutput;
  832. };
  833. const auto subprocessHelperSource = linuxSubprocessHelperProperties.getLinuxSubprocessHelperSource();
  834. const auto subprocessHelperObj = makeTarget (out,
  835. subprocessHelperSource.toUnixStyle(),
  836. getObjectFileFor (subprocessHelperSource));
  837. const auto subprocessHelperPath = makeTarget (out,
  838. subprocessHelperObj,
  839. "$(JUCE_BINDIR)/" + LSHP::getBinaryNameFromSource (subprocessHelperSource));
  840. const auto binaryBuilderSource = linuxSubprocessHelperProperties.getSimpleBinaryBuilderSource();
  841. const auto binaryBuilderObj = makeTarget (out,
  842. binaryBuilderSource.toUnixStyle(),
  843. getObjectFileFor (binaryBuilderSource));
  844. const auto binaryBuilderPath = makeTarget (out,
  845. binaryBuilderObj,
  846. "$(JUCE_BINDIR)/" + LSHP::getBinaryNameFromSource (binaryBuilderSource));
  847. const auto binaryDataSource = linuxSubprocessHelperProperties.getLinuxSubprocessHelperBinaryDataSource();
  848. jassert (binaryDataSource.getRoot() == build_tools::RelativePath::buildTargetFolder);
  849. out << binaryDataSource.toUnixStyle() << ": " << subprocessHelperPath
  850. << " " << binaryBuilderPath
  851. << newLine;
  852. const auto binarySourceDir = [&]() -> String
  853. {
  854. if (const auto p = LSHP::getParentDirectoryRelativeToBuildTargetFolder (binaryDataSource))
  855. return *p;
  856. return ".";
  857. }();
  858. out << "\t$(V_AT)" << binaryBuilderPath.quoted() << " " << subprocessHelperPath.quoted()
  859. << " " << binarySourceDir.quoted() << " " << binaryDataSource.getFileNameWithoutExtension().quoted()
  860. << " LinuxSubprocessHelperBinaryData" << newLine;
  861. out << newLine;
  862. }
  863. void writeMakefile (OutputStream& out) const
  864. {
  865. out << "# Automatically generated makefile, created by the Projucer" << newLine
  866. << "# Don't edit this file! Your changes will be overwritten when you re-save the Projucer project!" << newLine
  867. << newLine;
  868. out << "# build with \"V=1\" for verbose builds" << newLine
  869. << "ifeq ($(V), 1)" << newLine
  870. << "V_AT =" << newLine
  871. << "else" << newLine
  872. << "V_AT = @" << newLine
  873. << "endif" << newLine
  874. << newLine;
  875. out << "# (this disables dependency generation if multiple architectures are set)" << newLine
  876. << "DEPFLAGS := $(if $(word 2, $(TARGET_ARCH)), , -MMD)" << newLine
  877. << newLine;
  878. out << "ifndef PKG_CONFIG" << newLine
  879. << " PKG_CONFIG=pkg-config" << newLine
  880. << "endif" << newLine
  881. << newLine;
  882. out << "ifndef STRIP" << newLine
  883. << " STRIP=strip" << newLine
  884. << "endif" << newLine
  885. << newLine;
  886. out << "ifndef AR" << newLine
  887. << " AR=ar" << newLine
  888. << "endif" << newLine
  889. << newLine;
  890. out << "ifndef CONFIG" << newLine
  891. << " CONFIG=" << escapeQuotesAndSpaces (getConfiguration(0)->getName()) << newLine
  892. << "endif" << newLine
  893. << newLine;
  894. out << "JUCE_ARCH_LABEL := $(shell uname -m)" << newLine
  895. << newLine;
  896. for (ConstConfigIterator config (*this); config.next();)
  897. writeConfig (out, dynamic_cast<const MakeBuildConfiguration&> (*config));
  898. std::vector<std::pair<File, String>> filesToCompile;
  899. for (int i = 0; i < getAllGroups().size(); ++i)
  900. {
  901. auto group = findAllFilesToCompile (getAllGroups().getReference (i));
  902. filesToCompile.insert (filesToCompile.end(),
  903. std::make_move_iterator (group.cbegin()),
  904. std::make_move_iterator (group.cend()));
  905. }
  906. writeCompilerFlagSchemes (out, filesToCompile);
  907. const auto getFilesForTarget = [this] (const std::vector<std::pair<File, String>>& files,
  908. MakefileTarget* target,
  909. const Project& p)
  910. {
  911. std::vector<std::pair<build_tools::RelativePath, String>> targetFiles;
  912. auto targetType = (p.isAudioPluginProject() ? target->type : MakefileTarget::SharedCodeTarget);
  913. for (auto& [path, flags] : files)
  914. {
  915. if (p.getTargetTypeFromFilePath (path, true) == targetType)
  916. {
  917. targetFiles.emplace_back (build_tools::RelativePath { path,
  918. getTargetFolder(),
  919. build_tools::RelativePath::buildTargetFolder },
  920. flags);
  921. }
  922. }
  923. if (( targetType == MakefileTarget::SharedCodeTarget
  924. || targetType == MakefileTarget::StaticLibrary
  925. || targetType == MakefileTarget::DynamicLibrary)
  926. && linuxSubprocessHelperProperties.shouldUseLinuxSubprocessHelper())
  927. {
  928. targetFiles.emplace_back (linuxSubprocessHelperProperties.getLinuxSubprocessHelperBinaryDataSource(), "");
  929. }
  930. if (targetType == MakefileTarget::LV2Helper)
  931. {
  932. targetFiles.emplace_back (getLV2HelperProgramSource().rebased (projectFolder,
  933. getTargetFolder(),
  934. build_tools::RelativePath::buildTargetFolder),
  935. String{});
  936. }
  937. else if (targetType == MakefileTarget::VST3Helper)
  938. {
  939. targetFiles.emplace_back (getVST3HelperProgramSource().rebased (projectFolder,
  940. getTargetFolder(),
  941. build_tools::RelativePath::buildTargetFolder),
  942. String{});
  943. }
  944. return targetFiles;
  945. };
  946. for (auto target : targets)
  947. target->writeObjects (out, getFilesForTarget (filesToCompile, target, project));
  948. out << getPhonyTargetLine() << newLine << newLine;
  949. writeTargetLines (out, getLinkPackages());
  950. for (auto target : targets)
  951. target->addFiles (out, getFilesForTarget (filesToCompile, target, project));
  952. // libexecinfo is a separate library on BSD
  953. out << "$(JUCE_OBJDIR)/execinfo.cmd:" << newLine
  954. << "\t-$(V_AT)mkdir -p $(@D)" << newLine
  955. << "\t-@if [ -z \"$(V_AT)\" ]; then echo \"Checking if we need to link libexecinfo\"; fi" << newLine
  956. << "\t$(V_AT)printf \"int main() { return 0; }\" | $(CXX) -x c++ -o $(@D)/execinfo.x -lexecinfo - >/dev/null 2>&1 && printf -- \"-lexecinfo\" > \"$@\" || touch \"$@\"" << newLine
  957. << newLine;
  958. if (linuxSubprocessHelperProperties.shouldUseLinuxSubprocessHelper())
  959. writeSubprocessHelperTargets (out);
  960. out << "clean:" << newLine
  961. << "\t@echo Cleaning " << projectName << newLine
  962. << "\t$(V_AT)$(CLEANCMD)" << newLine
  963. << newLine;
  964. out << "strip:" << newLine
  965. << "\t@echo Stripping " << projectName << newLine
  966. << "\t-$(V_AT)$(STRIP) --strip-unneeded $(JUCE_OUTDIR)/$(TARGET)" << newLine
  967. << newLine;
  968. writeIncludeLines (out);
  969. }
  970. String getArchFlags (const BuildConfiguration& config) const
  971. {
  972. if (auto* makeConfig = dynamic_cast<const MakeBuildConfiguration*> (&config))
  973. return makeConfig->getArchitectureTypeString();
  974. return "-march=native";
  975. }
  976. String getObjectFileFor (const build_tools::RelativePath& file) const
  977. {
  978. return file.getFileNameWithoutExtension()
  979. + "_" + String::toHexString (file.toUnixStyle().hashCode()) + ".o";
  980. }
  981. String getPhonyTargetLine() const
  982. {
  983. MemoryOutputStream phonyTargetLine;
  984. phonyTargetLine << ".PHONY: clean all strip";
  985. if (! getProject().isAudioPluginProject())
  986. return phonyTargetLine.toString();
  987. for (auto target : targets)
  988. if (target->type != build_tools::ProjectType::Target::SharedCodeTarget
  989. && target->type != build_tools::ProjectType::Target::AggregateTarget)
  990. phonyTargetLine << " " << target->getPhonyName();
  991. return phonyTargetLine.toString();
  992. }
  993. OwnedArray<MakefileTarget> targets;
  994. JUCE_DECLARE_NON_COPYABLE (MakefileProjectExporter)
  995. };