Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wrap OBJDIR creation in prevent gmake warning #2038

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

thomashope
Copy link
Contributor

Wrap OBJDIR creation in conditional to prevent defining two rules with the same name

What does this PR do?

Make doesn't want you to create two rules with the same name and will emit a warning if you do (unless they are double colon rules which have some caveats?).

If you set the targetdir and objdir to the same location in Premake two rules are produced with the same name, as described in #726, causing make to complain.

How does this PR change Premake's behavior?

Wraps the OBJDIR rule in a conditional so it is not run if OBJDIR and TARGETDIR are the same.

closes #726

Anything else we should know?

I'm not an expert on makefiles but in my research I saw two possible solutions to this issue.

  1. Change the rules to double colon rules which did work but possibly has some caveats.

  2. Wrap a conditional around one of the rules. Apparently make has the concept of immediate and deferred contexts which I looked into a bit but seems to not be an issue for this case. I was reading about the concepts here.

I selected option 2 because as far as I could tell I didn't have any relevant caveats and seemed the least surprising for someone reading the makefile / Lua code.

Tests were not included because the warning was only visible when you run the makefile and I wasn't sure how / if it was worthing testing that.

Did you check all the boxes?

  • Focus on a single fix or feature; remove any unrelated formatting or code changes
  • Add unit tests showing fix or feature works; all tests pass
  • Mention any related issues (put closes #XXXX in comment to auto-close issue when PR is merged)
  • Follow our coding conventions
  • Minimize the number of commits
  • Align documentation to your changes

You can now support Premake on our OpenCollective. Your contributions help us spend more time responding to requests like these!

@nickclark2016
Copy link
Member

I believe Visual Studio may actually have an issue with the intermediate and target directories being the same. We may want to do this at a core level, rather than a per-exporter level.

@thomashope
Copy link
Contributor Author

Hmm I thought I'd had a VS project setup in the past that put them in the same place and it didn't mind, although I didn't test when investigating this issue.

Just tried on Xcode and it seemed happy to use the same dir for both

@nickclark2016
Copy link
Member

It's very possible I'm thinking of another quirk with intermediate and target paths.

@thomashope
Copy link
Contributor Author

If I get a chance to later I will dust off my PC and give it a try. If you want to try in the meantime though this is the test script I've been using. Just supply your own main.cpp.

local project_name = "test"

workspace (project_name)
	configurations ("Debug", "Release")
    location ("build/" .. _ACTION)

project (project_name)
	kind "ConsoleApp"
    location ("build/" .. _ACTION)
    language "C++"
    cppdialect "C++11"
    architecture "x86_64"

    files {
    	"main.cpp",
    }

    -- Reproducing a bug where setting targetdir and objdir to be the same directory
    -- causes makefiles to emit a warning due to two rules having the same name
    --
    -- github issue #726 https://github.com/premake/premake-core/issues/726
    targetdir ("bin/" .. _ACTION .. "/%{cfg.buildcfg}")

    objdir ("bin/" .. _ACTION .. "/%{cfg.buildcfg}")
    -- objdir ("obj/" .. _ACTION .. "/%{cfg.buildcfg}")

@Jarod42
Copy link
Contributor

Jarod42 commented Mar 4, 2023

(deprecated) gmake can have similar fix.

Question, why not have something like following instead

function gmake2.objDirRules(cfg, toolset)
    if cfg.objdir ~= cfg.targetdir then
        gmake2.mkdirRules("$(OBJDIR)")
    end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Make warnings if objdir and targetdir point to the same directory
3 participants