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.

734 lines
28KB

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