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

problem with gnu Make in Makefile.manual #589

Closed
fiolj opened this issue Dec 6, 2021 · 2 comments · Fixed by #591
Closed

problem with gnu Make in Makefile.manual #589

fiolj opened this issue Dec 6, 2021 · 2 comments · Fixed by #591
Labels
bug Something isn't working build: make Issue with stdlib's manual makefile build

Comments

@fiolj
Copy link
Contributor

fiolj commented Dec 6, 2021

When using a recent version of make: GNU Make 4.3 in linux.

Using the instructions:

make -f Makefile.manual FYPPFLAGS=-DMAXRANK=4

compilation fails because the variable FYPPFLAGS may not be modified after being set in the command line.
Details are given in override directive

A possible solution is to use a different variable name. I've solved it by making the following changes:

Makefile.manual     | 6 ++++--
src/Makefile.manual | 2 +-

modified   Makefile.manual
@@ -5,14 +5,16 @@ FFLAGS ?= -Wall -Wextra -Wimplicit-interface -fPIC -g -fcheck=all
 FYPPFLAGS ?=
 
 VERSION := $(subst ., ,$(file < VERSION))
-FYPPFLAGS += \
+VERS_FYPPFLAGS = \
              -DPROJECT_VERSION_MAJOR=$(word 1,$(VERSION)) \
              -DPROJECT_VERSION_MINOR=$(word 2,$(VERSION)) \
              -DPROJECT_VERSION_PATCH=$(word 3,$(VERSION))
 
+ALL_FYPPFLAGS := $(FYPPFLAGS) $(VERS_FYPPFLAGS)
+
 export FC
 export FFLAGS
-export FYPPFLAGS
+export ALL_FYPPFLAGS
 
 .PHONY: all clean test
 
modified   src/Makefile.manual
@@ -72,7 +72,7 @@ clean:
 	$(FC) $(FFLAGS) -c $<
 
 $(SRCGEN): %.f90: %.fypp common.fypp
-	fypp $(FYPPFLAGS) $< $@
+	fypp $(ALL_FYPPFLAGS) $< $@
 
 # Fortran module dependencies
 f18estop.o: stdlib_error.o
@awvwgk awvwgk added bug Something isn't working build: make Issue with stdlib's manual makefile build labels Dec 6, 2021
@awvwgk
Copy link
Member

awvwgk commented Dec 6, 2021

Thanks for sharing, do you mind opening a PR with your patch?

@fiolj
Copy link
Contributor Author

fiolj commented Dec 7, 2021

Ok, some further test show that also makefiles in the tests directory must be modified in the same way. I can do that if there is consensus.
Alternatively, we can modify the command line with a different name for the variable. This way we only change the top directory makefile.manual but the instructions must be modified accordingly. The change to the makefile is small:

modified   Makefile.manual
@@ -2,14 +2,16 @@
 
 FC ?= gfortran
 FFLAGS ?= -Wall -Wextra -Wimplicit-interface -fPIC -g -fcheck=all
-FYPPFLAGS ?=
+ADD_FYPPFLAGS ?=
 
 VERSION := $(subst ., ,$(file < VERSION))
-FYPPFLAGS += \
+VERSION_FYPPFLAGS += \
              -DPROJECT_VERSION_MAJOR=$(word 1,$(VERSION)) \
              -DPROJECT_VERSION_MINOR=$(word 2,$(VERSION)) \
              -DPROJECT_VERSION_PATCH=$(word 3,$(VERSION))
 
+FYPPFLAGS := $(ADD_FYPPFLAGS) $(VERSION_FYPPFLAGS)
+
 export FC
 export FFLAGS
 export FYPPFLAGS

And in the README.md we must change the name of the variable:

modified   README.md
@@ -176,15 +176,15 @@ Alternatively, you can build using provided Makefiles:
 make -f Makefile.manual

-You can limit the maximum rank by setting -DMAXRANK=<num> in the FYPPFLAGS environment variable (which can reduce the compilation time):
+You can limit the maximum rank by setting -DMAXRANK=<num> in the ADD_FYPPFLAGS environment variable (which can reduce the compilation time):

-make -f Makefile.manual FYPPFLAGS=-DMAXRANK=4
+make -f Makefile.manual ADD_FYPPFLAGS=-DMAXRANK=4

You can also specify the compiler and compiler-flags by setting the FC and FFLAGS environmental variables. Among other things, this facilitates use of compiler optimizations that are not specified in the Makefile.manual defaults.

-make -f Makefile.manual FYPPFLAGS=-DMAXRANK=4 FC=gfortran FFLAGS="-O3 -flto"
+make -f Makefile.manual ADD_FYPPFLAGS=-DMAXRANK=4 FC=gfortran FFLAGS="-O3 -flto"

Build with fortran-lang/fpm

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working build: make Issue with stdlib's manual makefile build
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants