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

Automatically include build.mk after rules.mk. #2046

Closed
wants to merge 2 commits into from

Conversation

seebs
Copy link
Contributor

@seebs seebs commented Nov 23, 2017

In some cases, you might want to have rules which are conditional
on settings, but to allow later files to override the settings.

For instance:

FOO_ENABLE = no
ifeq $($(strip $(FOO_ENABLE)),yes)
    SRC += foo.c
endif

if you override FOO_ENABLE elsewhere, nothing happens.

So we split this into a rules.mk containing the setting, and
a build.mk containing the build rules, then include every
build.mk file after all the rules.mk files have been
included.

A call to include with no filename in an eval works
harmlessly, so we don't have to do existence checks.

Signed-off-by: seebs [email protected]

@drashna
Copy link
Member

drashna commented Jan 25, 2019

Looks like there are some merge conflicts here.

Would you mind updating this?

Especially, as I think we talked about this internally recently, and it is something that we may want to actually implement.

@seebs
Copy link
Contributor Author

seebs commented Jan 25, 2019

So I had completely forgotten about this, and when I went to master and the patch wasn't there, I thought someone had removed the rules/build thing... But now I realize I just never got it merged.

I can try to regenerate it. I do still want it, for exactly the same reason; it makes conditional inclusion of modules easier, and makes it possible for individual layouts to control presence of features.

In some cases, you might want to have rules which are conditional
on settings, but to allow later files to override the settings.

For instance:

    FOO_ENABLE = no
    ifeq $($(strip $(FOO_ENABLE)),yes)
	SRC += foo.c
    endif

if you override FOO_ENABLE elsewhere, nothing happens.

So we split this into a rules.mk containing the setting, and
a build.mk containing the build rules, then include every
build.mk file *after* all the rules.mk files have been
included. I made this change to ergodox_ez as an example.

A call to include with no filename in an eval works
harmlessly, so we don't have to do existence checks.

Signed-off-by: seebs <[email protected]>
@seebs
Copy link
Contributor Author

seebs commented Jan 26, 2019

Updated. I haven't checked this out as carefully as I'd like, and actually it looks like something called i2c_master is getting compiled in anyway, but I don't actually understand the RGB_MATRIX_ENABLE setting. Checking with $(info ...) did suggest that the SRC list was being changed, though.

@drashna
Copy link
Member

drashna commented Mar 27, 2019

i2c_master.c is used by the RGB Matrix, and the Ergodox EZ has been updated to using /drivers/avr/i2c_master.c, rather than a custom i2c implementation. (if that helps)

@seebs
Copy link
Contributor Author

seebs commented Mar 27, 2019

That helps for the i2c case, but it doesn't address the other issue I had, in my LCD branch, where I have source files that are only useful to add if a given feature is enabled, but I'd want to be able to control it in the keyboard config. So the updated patch is probably actually sane now, despite the i2c_master case being irrelevant.

Copy link
Member

@drashna drashna left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that @fredizzimo was trying to implement something along these lines, at one point.

I think this is probably a good change, but documentation for it would be ... useful.

@skullydazed
Copy link
Member

I think there's a couple open questions to be answered before this is merged:

  • Is build.mk the name we want to use here?
  • How do we document this in a way that avoids user confusion?
    • My main concern here is that inexperienced users won't know which file to use when, and will just try them at random until something works.

I'd also like to understand better why USE_RULES is defined twice, but that's a nit more than anything.

@seebs
Copy link
Contributor Author

seebs commented May 17, 2019

The Makefile definition has a comment semi-explaining this; it's magic because it's being used by PARSE_KEYBOARD which is itself magic in a way that requires an extra $ to ensure expansions happen after PARSE_KEYBOARD is expanded, rather than before it's expanded (because it changes how USE_RULES would/should expand.)

@drashna drashna requested review from a team and removed request for ezuk and fredizzimo July 30, 2019 06:17
@@ -0,0 +1,3 @@
ifeq ($(strip $(RGB_MATRIX_ENABLE)), no)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change isn't actually necessary anymore.

i2c is added via QUANTUM_LIB_SRC which has some special handling that prevents conflicts with it being added multiple times (also, prevents LTO from being applied to it, as it can cause weird timing related issues)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh, neat. that would indeed resolve this part. i'm not sure it also resolves the corresponding issue with the other optional modules, added in the later patch, though?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah. There are still a number of use cases that would make this very useful still. Such as per-keyboard features/options, that can be adjusted by the keymaps. As well as by userspace, in general.

@mtei
Copy link
Contributor

mtei commented Sep 24, 2019

I suggest using a different name instead of build.mk. For example, prepare_build.mk, post_rules.mk, etc.

@drashna
Copy link
Member

drashna commented Sep 25, 2019

A clearer name, or at least documentation of this would go a long way, I think.

@drashna
Copy link
Member

drashna commented Nov 16, 2019

  • Is build.mk the name we want to use here?

I think post_rules.mk would work, since we already have post_config.h. Would keep it consistent.

  • How do we document this in a way that avoids user confusion?

    • My main concern here is that inexperienced users won't know which file to use when, and will just try them at random until something works.

From what I can tell, the rules.mk would be for enabling and disabling features. The build.mk/post_rules/whatever, would be for setting defineds, including files, etc.

Basically, all of this stuff would got into the "post" file:

ifneq ($(strip $(NO_SECRETS)), yes)
ifneq ("$(wildcard $(USER_PATH)/secrets.c)","")
SRC += secrets.c
endif
ifeq ($(strip $(NO_SECRETS)), lite)
OPT_DEFS += -DNO_SECRETS
endif
endif
ifeq ($(strip $(TAP_DANCE_ENABLE)), yes)
SRC += tap_dances.c
endif
ifeq ($(strip $(RGBLIGHT_ENABLE)), yes)
SRC += rgb_stuff.c
ifeq ($(strip $(INDICATOR_LIGHTS)), yes)
OPT_DEFS += -DINDICATOR_LIGHTS
endif
ifeq ($(strip $(RGBLIGHT_TWINKLE)), yes)
OPT_DEFS += -DRGBLIGHT_TWINKLE
endif
ifeq ($(strip $(RGBLIGHT_NOEEPROM)), yes)
OPT_DEFS += -DRGBLIGHT_NOEEPROM
endif
ifeq ($(strip $(RGBLIGHT_STARTUP_ANIMATION)), yes)
OPT_DEFS += -DRGBLIGHT_STARTUP_ANIMATION
endif
endif
RGB_MATRIX_ENABLE ?= no
ifneq ($(strip $(RGB_MATRIX_ENABLE)), no)
SRC += rgb_stuff.c
endif
ifdef CONSOLE_ENABLE
ifeq ($(strip $(KEYLOGGER_ENABLE)), yes)
OPT_DEFS += -DKEYLOGGER_ENABLE
endif
endif
ifeq ($(strip $(MAKE_BOOTLOADER)), yes)
OPT_DEFS += -DMAKE_BOOTLOADER
endif

Also, it would allow for stuff like the helix's custom options to be properly processed, rather than what it's doing now:
https://github.com/qmk/qmk_firmware/blob/master/keyboards/helix/rev2/local_features.mk

And it would allow for the userspace's rules.mk to be processed correctly, as opposed to what we have now, due to how the userspaces (such as mine) are set up.

But yes, ideally, there should be some documentation on how to use this properly.

Edit:

Also, due to the mcu_selection.mk setup, and moving everything to that, it has invalidated checks like:

ifeq ($(strip $(PROTOCOL)), VUSB)
NKRO_ENABLE = no
else
NKRO_ENABLE = yes
endif

Specifically, because PROTOCOL is populated AFTER the rules.mk files have all been read. Moving the mcu_selection.mk doesn't work, and re-including the rules.mk sounds like a very good way to break things.

So, more and more, this is something that we may really need.

@tzarc
Copy link
Member

tzarc commented Feb 21, 2020

@drashna @seebs
Apart from changing things to post_rules.mk and removing the ergodox change, what else is outstanding for this PR?

@skullydazed
Copy link
Member

We also need documentation.

On the name I think post_rules.mk is not a very good name. I have to stop and think about what it means, and that will lead to confusion by people who don't know what it means.

@drashna
Copy link
Member

drashna commented Mar 3, 2020

On the name I think post_rules.mk is not a very good name. I have to stop and think about what it means, and that will lead to confusion by people who don't know what it means.

Naming is hard. I'm more than open to whatever name. I'm just not sure which is best.

@seebs
Copy link
Contributor Author

seebs commented Mar 3, 2020

So the fundamental distinction, I think, is between "things a layout should be able to override" and "things that need to be set in response to those overrides", although all the examples I can think of are file inclusions.

Maybe rules.mk and files.mk, and files.mk is "the one that decides to include files based on per-board settings"? Except that I guess the VUSB/NKRO_ENABLE setting seems problematic.

Alternative notion: Can we do this with defines? Something like defining a thing that will expand to that ifeq/endif chain, but will expand to it and be processed after all the rules.mk get done? I think gnu make is insane enough to allow that, so you could do something like

$POST_RULES += ...

@drashna
Copy link
Member

drashna commented Mar 4, 2020

Well, I know we already have post_config.h supported. I'd have to double check where that is, in the chain...

@skullydazed
Copy link
Member

We held a collaborator's meeting on this subject yesterday. We have new people on the team who have brought some fresh perspective here. I wish I could say we had a definitive answer on what the path forward is, but we don't yet. We have clarified a few issues, however.

Our primary concern right now revolves around complexity and maintainability. We're worried that this will create a situation where one needs keyboard specific context to do any maintenance at all, and since the majority of keyboards in the tree do not have an active maintainer this will put a load on anyone doing maintenance programming.

We think most of the use cases for this feature are addressed by #9058. The big open question right now is what use cases are not addressed by that PR.

@vomindoraan vomindoraan mentioned this pull request May 12, 2020
8 tasks
@vomindoraan
Copy link
Contributor

vomindoraan commented May 12, 2020

Most of my thoughts on what this feature could bring to the table moving forward are laid out in #9058 (comment).

Here I'd just like to address the naming of the new file. While post_rules.mk might not be an obvious name when considered in isolation, in the context of the current build pipeline it makes a lot of sense. Out of all of the names proposed so far, it's the only one that instantly “clicks” for me. It intuitively suggests that whatever these files do, happens after the chain of rules.mk has been processed. The presence of an existing post_config.h class of files is another plus for the name, in my opinion.

@skullydazed Could you elaborate a bit on what you mean by “create a situation where one needs keyboard specific context to do any maintenance at all”?

@drashna
Copy link
Member

drashna commented Oct 27, 2021

This has been added in a different PR, in a different matter/naming.

@drashna drashna closed this Oct 27, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants