From 9724b7f7cd74083ffc8394db8ab4fc899030af96 Mon Sep 17 00:00:00 2001 From: Aryeh Date: Sun, 27 Jun 2021 14:39:00 +1000 Subject: [PATCH 1/4] Added ability to add custom macro definitions --- Makefile | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 87616f0..3bd3964 100644 --- a/Makefile +++ b/Makefile @@ -11,6 +11,9 @@ objects := $(patsubst src/%, $(buildDir)/%, $(patsubst %.cpp, %.o, $(sources))) depends := $(patsubst %.o, %.d, $(objects)) compileFlags := -std=c++17 -I include linkFlags = -L lib/$(platform) -l raylib +ifdef MACRO_DEFS + macroDefines := -D $(MACRO_DEFS) +endif # Check for Windows ifeq ($(OS), Windows_NT) @@ -85,7 +88,7 @@ $(target): $(objects) # Compile objects to the build directory $(buildDir)/%.o: src/%.cpp Makefile $(MKDIR) $(call platformpth, $(@D)) - $(CXX) -MMD -MP -c $(compileFlags) $< -o $@ + $(CXX) -MMD -MP -c $(compileFlags) $< -o $@ $(macroDefines) # Run the executable execute: From e95b95118f6e64d26319779e3303642550eb6f45 Mon Sep 17 00:00:00 2001 From: Aryeh Date: Sun, 27 Jun 2021 16:33:58 +1000 Subject: [PATCH 2/4] Updated README for custom macro definitions --- README.md | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/README.md b/README.md index fb69f4b..8b8867e 100644 --- a/README.md +++ b/README.md @@ -91,6 +91,21 @@ $ make ARGS="--somearg" > mingw32-make ARGS="--somearg" ``` +### Specifying Custom Macro Definitions +You may also want to pass in your own macro definitions for certain configurations (such as setting log levels). You can pass in your definitions using the `MACRO_DEFS` flag: + +#### macOS & Linux + +```console +$ make MACRO_DEFS=MY_MACRO +``` + +#### Windows + +```console +> mingw32-make MACRO_DEFS=MY_MACRO +``` + ### Specifying a Non-Default Compiler If you want to use a compiler for your platform that isn't the default for your system (or potentially you would like to explicitly state it), you can make use of the system-implicit `CXX` variable like so: From ccdbef56eb4fe69b0debc086a5904737b17329c2 Mon Sep 17 00:00:00 2001 From: Aryeh Date: Sun, 27 Jun 2021 16:42:53 +1000 Subject: [PATCH 3/4] Edited docs to reflect custom macros --- docs/MakefileExplanation.md | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/docs/MakefileExplanation.md b/docs/MakefileExplanation.md index b3c8525..0f14132 100644 --- a/docs/MakefileExplanation.md +++ b/docs/MakefileExplanation.md @@ -35,9 +35,12 @@ objects := $(patsubst src/%, $(buildDir)/%, $(patsubst %.cpp, %.o, $(sources))) depends := $(patsubst %.o, %.d, $(objects)) compileFlags := -std=c++17 -I include linkFlags = -L lib/$(platform) -l raylib +ifdef MACRO_DEFS + macroDefines := -D $(MACRO_DEFS) +endif ``` -In this snippet there are two different assignment operators used, `:=` meaning "instant, static assign", and `=` meaning lazy assign, where the macro will only be assigned on use (this is useful when it relies on another macro that may not yet be defined). The operator `?=` is also used in cases where assignment is contingent on the variable being previously undefined. Finally, the `+=` operator is used to append content to a previously defined macro. +In this snippet there are two different assignment operators used, `:=` meaning "instant, static assign", and `=` meaning lazy assign, where the macro will only be assigned on use (this is useful when it relies on another macro that may not yet be defined). The operator `?=` is also used in cases where assignment is contingent on the variable being previously undefined. Finally, the `+=` operator is used to append content to a previously defined macro. At the very end, it checks to see if any macros were defined in the `Makefile` declaration and adds he macros to our compilation steps. ### Platform-Specific Macros The final grouping of macros in the Makefile relate to those that differ on a per-platform basis. The structure uses nested if-statements to first determine whether the current platform is Windows or not to assign macros. If it is not Windows, it then checks whether the current platform is Linux or macOS and assigns macros accordingly. @@ -157,11 +160,11 @@ $(target): $(objects) $(CXX) $(objects) -o $(target) $(linkFlags) ``` -As such, the target `$(buildDir)/%.o` is responsible for ensuring the creation and update of object files (`.o` files). The target will create all necessary subdirectory structures needed for the files, and then compile each `.cpp` file in the source directory into an object file using a number of rather terse, [automatic variables that you can read up on here](https://www.gnu.org/software/make/manual/html_node/Automatic-Variables.html). +As such, the target `$(buildDir)/%.o` is responsible for ensuring the creation and update of object files (`.o` files). The target will create all necessary subdirectory structures needed for the files, and then compile each `.cpp` file in the source directory into an object file using a number of rather terse, [automatic variables that you can read up on here](https://www.gnu.org/software/make/manual/html_node/Automatic-Variables.html). Finally, it includes any custom macros that we defined into each of these files. ```Makefile $(buildDir)/%.o: src/%.cpp Makefile $(MKDIR) $(call platformpth, $(@D)) - $(CXX) -MMD -MP -c $(compileFlags) $< -o $@ + $(CXX) -MMD -MP -c $(compileFlags) $< -o $@ $(macroDefines) ``` That all being said, there are still two dependancies for the target, the `.cpp` files, and the Makefile itself. One might wonder why either of these need to be dependencies, given that without them, there would be nothing to compile and no instructions with which to compile it, however there is definitely some intention behind this. Firstly, the aforementioned automatic variables of `$<` and `$@` require a list of dependencies to iterate through, and secondly, we want to make sure everything is up-to-date. For instance, changing a `.cpp` file should trigger this step to run again for that file, or changing the Makefile should warrant a full recompilation. From a4d33d4f0c97856b6ab6fd1de966b5c544a5ef0f Mon Sep 17 00:00:00 2001 From: Aryeh Date: Sun, 27 Jun 2021 16:44:41 +1000 Subject: [PATCH 4/4] fixed typos and awkward wording --- docs/MakefileExplanation.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/MakefileExplanation.md b/docs/MakefileExplanation.md index 0f14132..961ecc3 100644 --- a/docs/MakefileExplanation.md +++ b/docs/MakefileExplanation.md @@ -40,7 +40,7 @@ ifdef MACRO_DEFS endif ``` -In this snippet there are two different assignment operators used, `:=` meaning "instant, static assign", and `=` meaning lazy assign, where the macro will only be assigned on use (this is useful when it relies on another macro that may not yet be defined). The operator `?=` is also used in cases where assignment is contingent on the variable being previously undefined. Finally, the `+=` operator is used to append content to a previously defined macro. At the very end, it checks to see if any macros were defined in the `Makefile` declaration and adds he macros to our compilation steps. +In this snippet there are two different assignment operators used, `:=` meaning "instant, static assign", and `=` meaning lazy assign, where the macro will only be assigned on use (this is useful when it relies on another macro that may not yet be defined). The operator `?=` is also used in cases where assignment is contingent on the variable being previously undefined. Finally, the `+=` operator is used to append content to a previously defined macro. At the very end, it checks to see if any macros were defined in the `Makefile` declaration and adds them to our compilation steps. ### Platform-Specific Macros The final grouping of macros in the Makefile relate to those that differ on a per-platform basis. The structure uses nested if-statements to first determine whether the current platform is Windows or not to assign macros. If it is not Windows, it then checks whether the current platform is Linux or macOS and assigns macros accordingly. @@ -160,7 +160,7 @@ $(target): $(objects) $(CXX) $(objects) -o $(target) $(linkFlags) ``` -As such, the target `$(buildDir)/%.o` is responsible for ensuring the creation and update of object files (`.o` files). The target will create all necessary subdirectory structures needed for the files, and then compile each `.cpp` file in the source directory into an object file using a number of rather terse, [automatic variables that you can read up on here](https://www.gnu.org/software/make/manual/html_node/Automatic-Variables.html). Finally, it includes any custom macros that we defined into each of these files. +As such, the target `$(buildDir)/%.o` is responsible for ensuring the creation and update of object files (`.o` files). The target will create all necessary subdirectory structures needed for the files, and then compile each `.cpp` file in the source directory into an object file using a number of rather terse, [automatic variables that you can read up on here](https://www.gnu.org/software/make/manual/html_node/Automatic-Variables.html). Finally, it includes any custom macros that we defined for each of these files. ```Makefile $(buildDir)/%.o: src/%.cpp Makefile $(MKDIR) $(call platformpth, $(@D))