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