Skip to content

Commit

Permalink
Fix compile issues related to NO_ACTION_MACRO/FUNCTION and LTO_ENABLE (
Browse files Browse the repository at this point in the history
…qmk#8663)

* Define NO_ACTION_MACRO/FUNCTION in header instead of makefile when LTO is enabled

Currently, boards and keymaps that define NO_ACTION_MACRO/FUNCTION unconditionally
will not compile with LTO_ENABLE (qmk#8604). This fixes the issue by moving the
definitions from common.mk to action.h, which enables us to check for previous
definitions of those macros (this cannot be done in a makefile).

* Remove LTO checks in templates

Since now NO_ACTION_MACRO/FUNCTION are defined as needed in action.h (which is
included by quantum.h), checking for LTO in keyboard and user code is no
longer required.

* Update LTO_ENABLE docs
  • Loading branch information
vomindoraan committed Apr 8, 2020
1 parent ff213d5 commit be2f581
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 15 deletions.
10 changes: 5 additions & 5 deletions docs/config_options.md
Expand Up @@ -115,9 +115,9 @@ If you define these options you will disable the associated feature, which can s
* `#define NO_ACTION_ONESHOT`
* disable one-shot modifiers
* `#define NO_ACTION_MACRO`
* disable old style macro handling: MACRO() & action_get_macro
* disable old-style macro handling using `MACRO()`, `action_get_macro()` _(deprecated)_
* `#define NO_ACTION_FUNCTION`
* disable calling of action_function() from the fn_actions array (deprecated)
* disable old-style function handling using `fn_actions`, `action_function()` _(deprecated)_

## Features That Can Be Enabled

Expand Down Expand Up @@ -317,10 +317,10 @@ This is a [make](https://www.gnu.org/software/make/manual/make.html) file that i
* `LAYOUTS`
* A list of [layouts](feature_layouts.md) this keyboard supports.
* `LINK_TIME_OPTIMIZATION_ENABLE`
* Enables Link Time Optimization (`LTO`) when compiling the keyboard. This makes the process take longer, but can significantly reduce the compiled size (and since the firmware is small, the added time is not noticeable). However, this will automatically disable the old Macros and Functions features automatically, as these break when `LTO` is enabled.
It does this by automatically defining `NO_ACTION_MACRO` and `NO_ACTION_FUNCTION`
* Enables Link Time Optimization (LTO) when compiling the keyboard. This makes the process take longer, but it can significantly reduce the compiled size (and since the firmware is small, the added time is not noticeable).
However, this will automatically disable the legacy TMK Macros and Functions features, as these break when LTO is enabled. It does this by automatically defining `NO_ACTION_MACRO` and `NO_ACTION_FUNCTION`. (Note: This does not affect QMK [Macros](feature_macros.md) and [Layers](feature_layers.md).)
* `LTO_ENABLE`
* It has the same meaning as LINK_TIME_OPTIMIZATION_ENABLE. You can use `LTO_ENABLE` instead of `LINK_TIME_OPTIMIZATION_ENABLE`.
* Has the same meaning as `LINK_TIME_OPTIMIZATION_ENABLE`. You can use `LTO_ENABLE` instead of `LINK_TIME_OPTIMIZATION_ENABLE`.

## AVR MCU Options
* `MCU = atmega32u4`
Expand Down
7 changes: 3 additions & 4 deletions quantum/template/avr/config.h
Expand Up @@ -192,10 +192,9 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
//#define NO_ACTION_ONESHOT

/* disable these deprecated features by default */
#ifndef LINK_TIME_OPTIMIZATION_ENABLE
#define NO_ACTION_MACRO
#define NO_ACTION_FUNCTION
#endif
#define NO_ACTION_MACRO
#define NO_ACTION_FUNCTION

/*
* MIDI options
*/
Expand Down
6 changes: 2 additions & 4 deletions quantum/template/ps2avrgb/config.h
Expand Up @@ -43,10 +43,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#define RGBLIGHT_ANIMATIONS

/* disable these deprecated features by default */
#ifndef LINK_TIME_OPTIMIZATION_ENABLE
#define NO_ACTION_MACRO
#define NO_ACTION_FUNCTION
#endif
#define NO_ACTION_MACRO
#define NO_ACTION_FUNCTION

/* key combination for magic key command */
/* defined by default; to change, uncomment and set to the combination you want */
Expand Down
2 changes: 0 additions & 2 deletions tmk_core/common.mk
Expand Up @@ -162,8 +162,6 @@ ifeq ($(strip $(LINK_TIME_OPTIMIZATION_ENABLE)), yes)
endif
EXTRAFLAGS += -flto
TMK_COMMON_DEFS += -DLINK_TIME_OPTIMIZATION_ENABLE
TMK_COMMON_DEFS += -DNO_ACTION_MACRO
TMK_COMMON_DEFS += -DNO_ACTION_FUNCTION
endif

# Search Path
Expand Down
10 changes: 10 additions & 0 deletions tmk_core/common/action.h
Expand Up @@ -28,6 +28,16 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
extern "C" {
#endif

/* Disable macro and function features when LTO is enabled, since they break */
#ifdef LINK_TIME_OPTIMIZATION_ENABLE
# ifndef NO_ACTION_MACRO
# define NO_ACTION_MACRO
# endif
# ifndef NO_ACTION_FUNCTION
# define NO_ACTION_FUNCTION
# endif
#endif

/* tapping count and state */
typedef struct {
bool interrupted : 1;
Expand Down

0 comments on commit be2f581

Please sign in to comment.