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.

719 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. //==============================================================================
  216. MakefileProjectExporter (Project& p, const ValueTree& t) : ProjectExporter (p, t)
  217. {
  218. name = getNameLinux();
  219. if (getTargetLocationString().isEmpty())
  220. getTargetLocationValue() = getDefaultBuildsRootFolder() + "LinuxMakefile";
  221. initialiseDependencyPathValues();
  222. }
  223. //==============================================================================
  224. bool canLaunchProject() override { return false; }
  225. bool launchProject() override { return false; }
  226. bool usesMMFiles() const override { return false; }
  227. bool canCopeWithDuplicateFiles() override { return false; }
  228. bool supportsUserDefinedConfigurations() const override { return true; }
  229. bool isXcode() const override { return false; }
  230. bool isVisualStudio() const override { return false; }
  231. bool isCodeBlocks() const override { return false; }
  232. bool isMakefile() const override { return true; }
  233. bool isAndroidStudio() const override { return false; }
  234. bool isAndroid() const override { return false; }
  235. bool isWindows() const override { return false; }
  236. bool isLinux() const override { return true; }
  237. bool isOSX() const override { return false; }
  238. bool isiOS() const override { return false; }
  239. bool supportsTargetType (ProjectType::Target::Type type) const override
  240. {
  241. switch (type)
  242. {
  243. case ProjectType::Target::GUIApp:
  244. case ProjectType::Target::ConsoleApp:
  245. case ProjectType::Target::StaticLibrary:
  246. case ProjectType::Target::SharedCodeTarget:
  247. case ProjectType::Target::AggregateTarget:
  248. case ProjectType::Target::VSTPlugIn:
  249. case ProjectType::Target::StandalonePlugIn:
  250. case ProjectType::Target::DynamicLibrary:
  251. return true;
  252. default:
  253. break;
  254. }
  255. return false;
  256. }
  257. Value getCppStandardValue() { return getSetting (Ids::cppLanguageStandard); }
  258. String getCppStandardString() const { return settings[Ids::cppLanguageStandard]; }
  259. void createExporterProperties (PropertyListBuilder& properties) override
  260. {
  261. static const char* cppStandardNames[] = { "C++03", "C++11", "C++14", nullptr };
  262. static const char* cppStandardValues[] = { "-std=c++03", "-std=c++11", "-std=c++14", nullptr };
  263. properties.add (new ChoicePropertyComponent (getCppStandardValue(),
  264. "C++ standard to use",
  265. StringArray (cppStandardNames),
  266. Array<var> (cppStandardValues)),
  267. "The C++ standard to specify in the makefile");
  268. properties.add (new TextPropertyComponent (getExtraPkgConfig(), "pkg-config libraries", 8192, false),
  269. "Extra pkg-config libraries for you application. Each package should be space separated.");
  270. }
  271. //==============================================================================
  272. bool anyTargetIsSharedLibrary() const
  273. {
  274. const int n = targets.size();
  275. for (int i = 0; i < n; ++i)
  276. {
  277. const ProjectType::Target::TargetFileType fileType = targets.getUnchecked (i)->getTargetFileType();
  278. if (fileType == ProjectType::Target::sharedLibraryOrDLL || fileType == ProjectType::Target::pluginBundle)
  279. return true;
  280. }
  281. return false;
  282. }
  283. //==============================================================================
  284. void create (const OwnedArray<LibraryModule>&) const override
  285. {
  286. MemoryOutputStream mo;
  287. writeMakefile (mo);
  288. overwriteFileIfDifferentOrThrow (getTargetFolder().getChildFile ("Makefile"), mo);
  289. }
  290. //==============================================================================
  291. void addPlatformSpecificSettingsForProjectType (const ProjectType&) override
  292. {
  293. callForAllSupportedTargets ([this] (ProjectType::Target::Type targetType)
  294. {
  295. if (MakefileTarget* target = new MakefileTarget (targetType, *this))
  296. {
  297. if (targetType == ProjectType::Target::AggregateTarget)
  298. targets.insert (0, target);
  299. else
  300. targets.add (target);
  301. }
  302. });
  303. // If you hit this assert, you tried to generate a project for an exporter
  304. // that does not support any of your targets!
  305. jassert (targets.size() > 0);
  306. }
  307. private:
  308. //==============================================================================
  309. void writeDefineFlags (OutputStream& out, const BuildConfiguration& config) const
  310. {
  311. StringPairArray defines;
  312. defines.set ("LINUX", "1");
  313. if (config.isDebug())
  314. {
  315. defines.set ("DEBUG", "1");
  316. defines.set ("_DEBUG", "1");
  317. }
  318. else
  319. {
  320. defines.set ("NDEBUG", "1");
  321. }
  322. out << createGCCPreprocessorFlags (mergePreprocessorDefs (defines, getAllPreprocessorDefs (config, ProjectType::Target::unspecified)));
  323. }
  324. void writeHeaderPathFlags (OutputStream& out, const BuildConfiguration& config) const
  325. {
  326. StringArray searchPaths (extraSearchPaths);
  327. searchPaths.addArray (config.getHeaderSearchPaths());
  328. StringArray packages;
  329. packages.addTokens (getExtraPkgConfigString(), " ", "\"'");
  330. packages.removeEmptyStrings();
  331. if (linuxPackages.size() > 0 || packages.size() > 0)
  332. {
  333. out << " $(shell pkg-config --cflags";
  334. for (int i = 0; i < linuxPackages.size(); ++i)
  335. out << " " << linuxPackages[i];
  336. for (int i = 0; i < packages.size(); ++i)
  337. out << " " << packages[i];
  338. out << ")";
  339. }
  340. if (linuxLibs.contains("pthread"))
  341. out << " -pthread";
  342. searchPaths = getCleanedStringArray (searchPaths);
  343. // Replace ~ character with $(HOME) environment variable
  344. for (int i = 0; i < searchPaths.size(); ++i)
  345. out << " -I" << escapeSpaces (FileHelpers::unixStylePath (replacePreprocessorTokens (config, searchPaths[i]))).replace ("~", "$(HOME)");
  346. }
  347. void writeCppFlags (OutputStream& out, const BuildConfiguration& config) const
  348. {
  349. out << " JUCE_CPPFLAGS := $(DEPFLAGS)";
  350. writeDefineFlags (out, config);
  351. writeHeaderPathFlags (out, config);
  352. out << " $(CPPFLAGS)" << newLine;
  353. }
  354. void writeLinkerFlags (OutputStream& out, const BuildConfiguration& config) const
  355. {
  356. out << " JUCE_LDFLAGS += $(TARGET_ARCH) -L$(JUCE_BINDIR) -L$(JUCE_LIBDIR)";
  357. {
  358. StringArray flags (makefileExtraLinkerFlags);
  359. if (! config.isDebug())
  360. flags.add ("-fvisibility=hidden");
  361. if (flags.size() > 0)
  362. out << " " << getCleanedStringArray (flags).joinIntoString (" ");
  363. }
  364. out << config.getGCCLibraryPathFlags();
  365. StringArray packages;
  366. packages.addTokens (getExtraPkgConfigString(), " ", "\"'");
  367. packages.removeEmptyStrings();
  368. if (linuxPackages.size() > 0 || packages.size() > 0)
  369. {
  370. out << " $(shell pkg-config --libs";
  371. for (int i = 0; i < linuxPackages.size(); ++i)
  372. out << " " << linuxPackages[i];
  373. for (int i = 0; i < packages.size(); ++i)
  374. out << " " << packages[i];
  375. out << ")";
  376. }
  377. for (int i = 0; i < linuxLibs.size(); ++i)
  378. out << " -l" << linuxLibs[i];
  379. StringArray libraries;
  380. libraries.addTokens (getExternalLibrariesString(), ";", "\"'");
  381. libraries.removeEmptyStrings();
  382. if (libraries.size() != 0)
  383. out << " -l" << replacePreprocessorTokens (config, libraries.joinIntoString (" -l")).trim();
  384. out << " " << replacePreprocessorTokens (config, getExtraLinkerFlagsString()).trim()
  385. << " $(LDFLAGS)" << newLine;
  386. }
  387. void writeTargetLines (OutputStream& out, const bool useLinuxPackages) const
  388. {
  389. const int n = targets.size();
  390. for (int i = 0; i < n; ++i)
  391. {
  392. if (MakefileTarget* target = targets.getUnchecked (i))
  393. {
  394. if (target->type == ProjectType::Target::AggregateTarget)
  395. {
  396. StringArray dependencies;
  397. for (int j = 0; j < n; ++j)
  398. {
  399. if (i == j) continue;
  400. if (MakefileTarget* dependency = targets.getUnchecked (j))
  401. {
  402. if (dependency->type != ProjectType::Target::SharedCodeTarget)
  403. dependencies.add (dependency->getBuildProduct());
  404. }
  405. }
  406. out << "all : " << dependencies.joinIntoString (" ") << newLine << newLine;
  407. }
  408. else
  409. target->writeTargetLine (out, useLinuxPackages);
  410. }
  411. }
  412. }
  413. void writeConfig (OutputStream& out, const BuildConfiguration& config) const
  414. {
  415. const String buildDirName ("build");
  416. const String intermediatesDirName (buildDirName + "/intermediate/" + config.getName());
  417. String outputDir (buildDirName);
  418. if (config.getTargetBinaryRelativePathString().isNotEmpty())
  419. {
  420. RelativePath binaryPath (config.getTargetBinaryRelativePathString(), RelativePath::projectFolder);
  421. outputDir = binaryPath.rebased (projectFolder, getTargetFolder(), RelativePath::buildTargetFolder).toUnixStyle();
  422. }
  423. out << "ifeq ($(CONFIG)," << escapeSpaces (config.getName()) << ")" << newLine;
  424. out << " JUCE_BINDIR := " << escapeSpaces (buildDirName) << newLine
  425. << " JUCE_LIBDIR := " << escapeSpaces (buildDirName) << newLine
  426. << " JUCE_OBJDIR := " << escapeSpaces (intermediatesDirName) << newLine
  427. << " JUCE_OUTDIR := " << escapeSpaces (outputDir) << newLine
  428. << newLine
  429. << " ifeq ($(TARGET_ARCH),)" << newLine
  430. << " TARGET_ARCH := " << getArchFlags (config) << newLine
  431. << " endif" << newLine
  432. << newLine;
  433. writeCppFlags (out, config);
  434. for (auto target : targets)
  435. {
  436. StringArray lines = target->getTargetSettings (config);
  437. if (lines.size() > 0)
  438. out << " " << lines.joinIntoString ("\n ") << newLine;
  439. out << newLine;
  440. }
  441. out << " JUCE_CFLAGS += $(JUCE_CPPFLAGS) $(TARGET_ARCH)";
  442. if (anyTargetIsSharedLibrary())
  443. out << " -fPIC";
  444. if (config.isDebug())
  445. out << " -g -ggdb";
  446. out << " -O" << config.getGCCOptimisationFlag()
  447. << (" " + replacePreprocessorTokens (config, getExtraCompilerFlagsString())).trimEnd()
  448. << " $(CFLAGS)" << newLine;
  449. String cppStandardToUse (getCppStandardString());
  450. if (cppStandardToUse.isEmpty())
  451. cppStandardToUse = "-std=c++11";
  452. out << " JUCE_CXXFLAGS += $(CXXFLAGS) $(JUCE_CFLAGS) "
  453. << cppStandardToUse << " $(CXXFLAGS)" << newLine;
  454. writeLinkerFlags (out, config);
  455. out << newLine;
  456. out << " CLEANCMD = rm -rf $(JUCE_OUTDIR)/$(TARGET) $(JUCE_OBJDIR)" << newLine
  457. << "endif" << newLine
  458. << newLine;
  459. }
  460. void writeIncludeLines (OutputStream& out) const
  461. {
  462. const int n = targets.size();
  463. for (int i = 0; i < n; ++i)
  464. {
  465. if (MakefileTarget* target = targets.getUnchecked (i))
  466. {
  467. if (target->type == ProjectType::Target::AggregateTarget)
  468. continue;
  469. out << "-include $(OBJECTS_" << target->getTargetVarName()
  470. << ":%.o=%.d)" << newLine;
  471. }
  472. }
  473. }
  474. void writeMakefile (OutputStream& out) const
  475. {
  476. out << "# Automatically generated makefile, created by the Projucer" << newLine
  477. << "# Don't edit this file! Your changes will be overwritten when you re-save the Projucer project!" << newLine
  478. << newLine;
  479. out << "# build with \"V=1\" for verbose builds" << newLine
  480. << "ifeq ($(V), 1)" << newLine
  481. << "V_AT =" << newLine
  482. << "else" << newLine
  483. << "V_AT = @" << newLine
  484. << "endif" << newLine
  485. << newLine;
  486. out << "# (this disables dependency generation if multiple architectures are set)" << newLine
  487. << "DEPFLAGS := $(if $(word 2, $(TARGET_ARCH)), , -MMD)" << newLine
  488. << newLine;
  489. out << "ifndef STRIP" << newLine
  490. << " STRIP=strip" << newLine
  491. << "endif" << newLine
  492. << newLine;
  493. out << "ifndef AR" << newLine
  494. << " AR=ar" << newLine
  495. << "endif" << newLine
  496. << newLine;
  497. out << "ifndef CONFIG" << newLine
  498. << " CONFIG=" << escapeSpaces (getConfiguration(0)->getName()) << newLine
  499. << "endif" << newLine
  500. << newLine;
  501. for (ConstConfigIterator config (*this); config.next();)
  502. writeConfig (out, *config);
  503. for (auto target : targets)
  504. target->writeObjects (out);
  505. out << ".PHONY: clean all" << newLine
  506. << newLine;
  507. StringArray packages;
  508. packages.addTokens (getExtraPkgConfigString(), " ", "\"'");
  509. packages.removeEmptyStrings();
  510. const bool useLinuxPackages = (linuxPackages.size() > 0 || packages.size() > 0);
  511. writeTargetLines (out, useLinuxPackages);
  512. for (auto target : targets)
  513. target->addFiles (out);
  514. if (useLinuxPackages)
  515. {
  516. out << "check-pkg-config:" << newLine
  517. << "\t@command -v pkg-config >/dev/null 2>&1 || "
  518. "{ echo >&2 \"pkg-config not installed. Please, install it.\"; "
  519. "exit 1; }" << newLine
  520. << "\t@pkg-config --print-errors";
  521. for (int i = 0; i < linuxPackages.size(); ++i)
  522. out << " " << linuxPackages[i];
  523. for (int i = 0; i < packages.size(); ++i)
  524. out << " " << packages[i];
  525. out << newLine << newLine;
  526. }
  527. out << "clean:" << newLine
  528. << "\t@echo Cleaning " << projectName << newLine
  529. << "\t$(V_AT)$(CLEANCMD)" << newLine
  530. << newLine;
  531. out << "strip:" << newLine
  532. << "\t@echo Stripping " << projectName << newLine
  533. << "\t-$(V_AT)$(STRIP) --strip-unneeded $(JUCE_OUTDIR)/$(TARGET)" << newLine
  534. << newLine;
  535. writeIncludeLines (out);
  536. }
  537. String getArchFlags (const BuildConfiguration& config) const
  538. {
  539. if (const MakeBuildConfiguration* makeConfig = dynamic_cast<const MakeBuildConfiguration*> (&config))
  540. if (! makeConfig->getArchitectureTypeVar().isVoid())
  541. return makeConfig->getArchitectureTypeVar();
  542. return "-march=native";
  543. }
  544. String getObjectFileFor (const RelativePath& file) const
  545. {
  546. return file.getFileNameWithoutExtension()
  547. + "_" + String::toHexString (file.toUnixStyle().hashCode()) + ".o";
  548. }
  549. void initialiseDependencyPathValues()
  550. {
  551. vst3Path.referTo (Value (new DependencyPathValueSource (getSetting (Ids::vst3Folder),
  552. Ids::vst3Path,
  553. TargetOS::linux)));
  554. }
  555. OwnedArray<MakefileTarget> targets;
  556. JUCE_DECLARE_NON_COPYABLE (MakefileProjectExporter)
  557. };