20

I am installing MOOG, and when I make -f Makefile.maclap I get the error:

$ make -f Makefile.maclap
g77 -w   -c -o Abfind.o Abfind.f
make: g77: No such file or directory
make: *** [Abfind.o] Error 1

After research online, I think that, since I have gcc-5, the command g77 doesn't exist on my computer.

So I used, based on a stack exchange question, alias g77=/usr/local/bin/gfortran-5 to try to compile the fortran code with gfortran.

Now, when I g77 I see gfortran-5: fatal error: no input files compilation terminated, indicating that g77 is working as a compiled.

But when I make -f Makefile.maclap I still get the error:

$ make -f Makefile.maclap
g77 -w   -c -o Abfind.o Abfind.f
make: g77: No such file or directory
make: *** [Abfind.o] Error 1

How can I get the make command to use fortran-5 to compile the file Abfind.o and Abfind.f?

How can I successfully complete the make and make install steps to get this software package running?

3 Answers 3

9

If you don't want to make a symlink like @Thomas suggested, you can basically make an alias right in the Makefile like so by placing this line somewhere near the top of the Makefile:

G77 := /usr/local/bin/gfortran-5

and then, in your target somewhere, use it like:

$(G77) -w -c -o Abfind.o Abfind.f
3
  • 1
    This answer leaves a lot to be desired. If I create the alias to fix the problem on one host, then what about the other hosts that don't have the problem (and lack the compiler at the hard coded location)?
    – jww
    Commented Aug 17, 2017 at 16:11
  • You could take a look at Makefile conditionals and change what the G77 variable is depending on what does/doesn't exist on the host system.
    – mdszy
    Commented Aug 19, 2017 at 3:08
  • @jww This is the right solution. I would rather update one line of code depending on the system than 8. And like mentioned, conditionals are a thing and was not what was requested in the question.
    – Akaisteph7
    Commented Jan 27, 2023 at 18:10
9

The make program is only going to see names that are actually files (or directories). It does not know anything about shell aliases.

Rather than an alias, if you had g77 in your $PATH as a symbolic link, that would work. In many environments, if you have a $HOME/bin directory, that is automatically added to your $PATH. (If not, it is simple to do this manually, details depending upon your shell).

If it is the simpler case:

cd
mkdir bin
cd bin
ln -s /usr/local/bin/gfortran-5 g77

Then log out, and log in again (to let the shell's initialization scripts update the path, etc.)

1

Just use make's shell command.

$(g77 -w -c -o Abfind.o Abfind.f)

by wrapping the entire command in $() it executes it how the shell would execute it. If you run it on a machine with an alias, like yours, the alias will work. If you run it on a machine that has g77 installed natively then that will work also.

This is the portable way to solve your problem and does not require any machine specific changes to your makefile.

The symbolic link trick will only work with trivial aliases that just change the name of the command. If you have a non-trial alias that includes some default arguments then the symbolic link trick will not work.

You must log in to answer this question.