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

feat: Use shell values for defaults #4

Conversation

matthewfeickert
Copy link
Contributor

@matthewfeickert matthewfeickert commented Dec 4, 2024

  • Use the ?= Make syntax to default to the environment variables for FC and FFLAGS, but provide defaults if they are not set.

@matthewfeickert
Copy link
Contributor Author

@APN-Pucky this is ready for review. It is mainly to make it easier for conda-forge packaging so that I don't need to do sed injection on the Makefile, but let me know if you have any questions.

Makefile Outdated
Comment on lines 11 to 14
FC := $(shell echo $$FC)
ifndef FC
FC := gfortran
endif
Copy link
Owner

Choose a reason for hiding this comment

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

What is the benefit of this over FC ?= gfortran? I have some alternative modifications in mind to shrink the makefile a bit more.

Copy link
Owner

Choose a reason for hiding this comment

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

ah, it defaults to f77 then...

Copy link
Owner

Choose a reason for hiding this comment

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

You can also just run make FC=flang or make FC=${FC} as it is right now.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, FC ?= gfortran should work, so I can just do that.

Makefile Outdated
FC := gfortran
endif

FFLAGS := $(shell echo $$FFLAGS) -fno-automatic -O2 -funroll-all-loops -std=legacy -fPIC
Copy link
Owner

Choose a reason for hiding this comment

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

That won't allow you to go to -O3 if you like, so I'd rather put it behind.
Again with

FFLAGS = -fno-automatic -O2 -funroll-all-loops -std=legacy -fPIC $(FFLAGS)

You could call it with make FFLAGS=${FFLAGS}. To my understanding that is the default way Makefiles behave/are designed.

Copy link
Owner

Choose a reason for hiding this comment

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

For reference I found https://www.gnu.org/software/make/manual/html_node/Complex-Makefile.html where also CC and CFLAGS are directly set, but since we set some defaults lets prepend our default.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Is there a reason to not just do

FFLAGS ?= -fno-automatic -O2 -funroll-all-loops -std=legacy -fPIC

instead? (I'm asking here as I don't deeply know Make syntax beyond the basics.)

Copy link
Owner

@APN-Pucky APN-Pucky Dec 5, 2024

Choose a reason for hiding this comment

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

My though process was to aim for as little modifactions necessary on the gentoo side, which automatically sets FFLAGS. By default e.g. -std=legacy is not set and then it would have to be set/appended again on the ebuild/conda side. So the question is are the FFLAGS on our side mandatory for the program to work (can't be overwritten) or optional/defaults (can be overwritten). cernlib for example has some weird flags that are necessary and does only work with -O1.

Copy link
Contributor Author

@matthewfeickert matthewfeickert Dec 5, 2024

Choose a reason for hiding this comment

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

By default e.g. -std=legacy is not set and then it would have to be set/appended again on the ebuild/conda side. So the question is are the FFLAGS on our side mandatory for the program to work (can't be overwritten) or optional/defaults (can be overwritten).

Good question RE: the FFLAGS which I don't know the answer to (which is part of the reason I opened Issue #2).

Do you know that for Gentoo all of

FFLAGS = -fno-automatic -O2 -funroll-all-loops -std=legacy -fPIC

are explicitly required? In the example below I'm using

# echo $FC
/example/.pixi/envs/default/bin/x86_64-conda-linux-gnu-gfortran
# echo $FFLAGS
-march=nocona -mtune=haswell -ftree-vectorize -fPIC -fstack-protector-strong -fno-plt -O2 -ffunction-sections -pipe -isystem /example/.pixi/envs/default/include -I/example/.pixi/envs/default/include

and everything builds fine, as far as I can tell.

(I'm using a python Docker container only because I know it has curl installed already and so I don't have to apt install anything.)

$ docker run --rm -ti python:3.12 bash
root@7178225de27f:/# curl -fsSL https://pixi.sh/install.sh | bash && . /root/.bashrc
root@7178225de27f:/# mkdir -p example && cd $_
root@7178225de27f:/example# pixi init
✔ Created /example/pixi.toml
root@7178225de27f:/example# pixi add fortran-compiler make git
✔ Added fortran-compiler >=1.8.0,<2
✔ Added make >=4.4.1,<5
✔ Added git >=2.47.1,<3
root@7178225de27f:/example# pixi shell
(example) root@7178225de27f:/example# git clone https://github.com/matthewfeickert/mpfun90.git && cd mpfun90
(example) root@7178225de27f:/example/mpfun90# git checkout origin/feat/use-shell-information-for-defaults -b feat/use-shell-information-for-defaults
(example) root@7178225de27f:/example/mpfun90# echo $FC
/example/.pixi/envs/default/bin/x86_64-conda-linux-gnu-gfortran
(example) root@7178225de27f:/example/mpfun90# echo $FFLAGS
-march=nocona -mtune=haswell -ftree-vectorize -fPIC -fstack-protector-strong -fno-plt -O2 -ffunction-sections -pipe -isystem /example/.pixi/envs/default/include -I/example/.pixi/envs/default/include
(example) root@7178225de27f:/example/mpfun90# make dynamic
/example/.pixi/envs/default/bin/x86_64-conda-linux-gnu-gfortran -march=nocona -mtune=haswell -ftree-vectorize -fPIC -fstack-protector-strong -fno-plt -O2 -ffunction-sections -pipe -isystem /example/.pixi/envs/default/include -I/example/.pixi/envs/default/include -c mpfun90.f90
/example/.pixi/envs/default/bin/x86_64-conda-linux-gnu-ar -rv libmpfun90.a mpfun90.o
/example/.pixi/envs/default/bin/x86_64-conda-linux-gnu-ar: creating libmpfun90.a
a - mpfun90.o
/example/.pixi/envs/default/bin/x86_64-conda-linux-gnu-gfortran -march=nocona -mtune=haswell -ftree-vectorize -fPIC -fstack-protector-strong -fno-plt -O2 -ffunction-sections -pipe -isystem /example/.pixi/envs/default/include -I/example/.pixi/envs/default/include -c mpmod90.f90
/example/.pixi/envs/default/bin/x86_64-conda-linux-gnu-ar -rv libmpfun90.a mpmod90.o
a - mpmod90.o
/example/.pixi/envs/default/bin/x86_64-conda-linux-gnu-gfortran -march=nocona -mtune=haswell -ftree-vectorize -fPIC -fstack-protector-strong -fno-plt -O2 -ffunction-sections -pipe -isystem /example/.pixi/envs/default/include -I/example/.pixi/envs/default/include -c mpmodm90.f90
/example/.pixi/envs/default/bin/x86_64-conda-linux-gnu-ar -rv libmpfun90.a mpmodm90.o
a - mpmodm90.o
/example/.pixi/envs/default/bin/x86_64-conda-linux-gnu-gfortran -march=nocona -mtune=haswell -ftree-vectorize -fPIC -fstack-protector-strong -fno-plt -O2 -ffunction-sections -pipe -isystem /example/.pixi/envs/default/include -I/example/.pixi/envs/default/include -c mpmodx90.f90
/example/.pixi/envs/default/bin/x86_64-conda-linux-gnu-ar -rv libmpfun90.a mpmodx90.o
a - mpmodx90.o
/example/.pixi/envs/default/bin/x86_64-conda-linux-gnu-ar -x libmpfun90.a
g++ -shared *.o -o libmpfun90.so
(example) root@7178225de27f:/example/mpfun90# ls libmpfun90.*
libmpfun90.a  libmpfun90.so
(example) root@7178225de27f:/example/mpfun90#

We can also set your flags, and things build as well

(example) root@7178225de27f:/example/mpfun90# rm -f *.a *.so *.o *.mod
(example) root@7178225de27f:/example/mpfun90# make dynamic FFLAGS="-fno-automatic -funroll-all-loops -std=legacy $FFLAGS"
/example/.pixi/envs/default/bin/x86_64-conda-linux-gnu-gfortran -fno-automatic -funroll-all-loops -std=legacy -march=nocona -mtune=haswell -ftree-vectorize -fPIC -fstack-protector-strong -fno-plt -O2 -ffunction-sections -pipe -isystem /example/.pixi/envs/default/include -I/example/.pixi/envs/default/include -c mpfun90.f90
/example/.pixi/envs/default/bin/x86_64-conda-linux-gnu-ar -rv libmpfun90.a mpfun90.o
/example/.pixi/envs/default/bin/x86_64-conda-linux-gnu-ar: creating libmpfun90.a
a - mpfun90.o
/example/.pixi/envs/default/bin/x86_64-conda-linux-gnu-gfortran -fno-automatic -funroll-all-loops -std=legacy -march=nocona -mtune=haswell -ftree-vectorize -fPIC -fstack-protector-strong -fno-plt -O2 -ffunction-sections -pipe -isystem /example/.pixi/envs/default/include -I/example/.pixi/envs/default/include -c mpmod90.f90
/example/.pixi/envs/default/bin/x86_64-conda-linux-gnu-ar -rv libmpfun90.a mpmod90.o
a - mpmod90.o
/example/.pixi/envs/default/bin/x86_64-conda-linux-gnu-gfortran -fno-automatic -funroll-all-loops -std=legacy -march=nocona -mtune=haswell -ftree-vectorize -fPIC -fstack-protector-strong -fno-plt -O2 -ffunction-sections -pipe -isystem /example/.pixi/envs/default/include -I/example/.pixi/envs/default/include -c mpmodm90.f90
/example/.pixi/envs/default/bin/x86_64-conda-linux-gnu-ar -rv libmpfun90.a mpmodm90.o
a - mpmodm90.o
/example/.pixi/envs/default/bin/x86_64-conda-linux-gnu-gfortran -fno-automatic -funroll-all-loops -std=legacy -march=nocona -mtune=haswell -ftree-vectorize -fPIC -fstack-protector-strong -fno-plt -O2 -ffunction-sections -pipe -isystem /example/.pixi/envs/default/include -I/example/.pixi/envs/default/include -c mpmodx90.f90
/example/.pixi/envs/default/bin/x86_64-conda-linux-gnu-ar -rv libmpfun90.a mpmodx90.o
a - mpmodx90.o
/example/.pixi/envs/default/bin/x86_64-conda-linux-gnu-ar -x libmpfun90.a
g++ -shared *.o -o libmpfun90.so
(example) root@7178225de27f:/example/mpfun90# ls libmpfun90.*
libmpfun90.a  libmpfun90.so
(example) root@7178225de27f:/example/mpfun90#

Copy link
Owner

@APN-Pucky APN-Pucky Dec 5, 2024

Choose a reason for hiding this comment

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

I think I took the -fno-automatic -O2 -funroll-all-loops -std=legacy -fPIC from the cuttools code, where they set these flags in the top most makefile. Also using FC = instead of FC ?= comes from there.

But since cuttools applies them to all the code, not just mpfun90, it might not be necessary.

Copy link
Owner

@APN-Pucky APN-Pucky Dec 5, 2024

Choose a reason for hiding this comment

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

I'd be in favor of dropping all but -fPIC (pre-/apended) so that we are consistent with mpfun2020's (very simple) compile script.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

My thought process was to aim for as little modifications necessary on the gentoo side

Does Gentoo build from hashes? Or would any modification to this repository immediately get picked up and break builds?

It would be ideal in my mind if we could harcode the minimum set of required flags in the Makefile and have the rest be passed by the user to make things explicit about the build and not have people guess at flag choice. Though for conda-forge/staged-recipes#28415 I'll just start doing

make dynamic FC="$FC" FFLAGS="$FFLAGS"

Copy link
Owner

@APN-Pucky APN-Pucky Dec 5, 2024

Choose a reason for hiding this comment

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

Gentoo uses the tagged release (I set the date YYYY.MM.DD as release version). The repo can be modified freely without breaking stuff.

Copy link
Owner

Choose a reason for hiding this comment

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

I modified the repo directly now only one QA complaint remains:

 * QA Notice: Missing soname symlink(s):
 * 
 * 	usr/lib64/mpfun90.so.0 -> libmpfun90.so
 *

should be easy enough to fix (Gentoo ideally want shared libraries to have a soname and since we are already modifying the Makefile here).

* Use the '?=' Make syntax to default to the environment variables for FC
  and FFLAGS, but provide defaults if they are not set.
@matthewfeickert matthewfeickert force-pushed the feat/use-shell-information-for-defaults branch from e8fed5a to de16f63 Compare December 5, 2024 00:33
@matthewfeickert
Copy link
Contributor Author

matthewfeickert commented Dec 5, 2024

@APN-Pucky As it seems that you're taking care of things on master ( 👍 ) I'm going to close this. You've also demonstrated in #4 (comment) that as a user I can always override defaults easily and make it explicitly clear what I'm doing in the build.

@matthewfeickert matthewfeickert deleted the feat/use-shell-information-for-defaults branch December 5, 2024 07:03
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.

2 participants