14

I have been compiling some command line programs to run on the classic Commodore Amiga. I started with GCC on WinUAE which worked but I realised I didn't have the understanding of the memory stack and more to avoid difficulties ("software failure" crashes) presumably due to me not being careful with the limited resources. I then thought about cross-compiling instead using a host with more resources, installed CygWin on Windows, but eventually settled on Raspbian on a Pi and different flavo(u)rs of GCC following what I was reading online.

From Google and this below from here on Retrocomputing Stack Exchange:

Are there any modern compilers that can generate Amiga/m68k executables?

I could see much appreciation for this GCC set with Amiga output support:

https://github.com/bebbo/amiga-gcc

Using the created m68k-amigaos-gcc / m68k-amigaos-c++ / m68k-amigaos-cpp worked great 👍 for simple programs tried so far. I'm on the learning curve with make / cmake from others' more complex code and amended CMakeLists.txt / CMakeCache.txt to the appropriate paths for the alternative Amiga compilers but making steady progress.

There is a C++ program I'd like to try cross-compiling that has some dependencies that use Fortran (it's doing some data processing.) I can build and run it in Raspbian, but Bebbo's amiga-gcc doesn't have a Fortran compiler (understandable as it's rather niche) so I can't make an Amiga version this way. I then found this other GCC "with M68K regparm support" which does seem to contain a Fortran compiler but I'm not clear if this is what I want:

https://github.com/mooli/gcc-amiga/

I'm struggling how to configure the build of this GCC for an Amiga target without more specific documentation - commenters on Github have already asked for details on functionality and how to build. Trying with a target listed in the documentation but no other arguments:

 ../configure --target=m68k-elf

../../gcc/config/m68k/m68k.c:1514:21: error: ‘mode’ was not declared in this scope; did you mean ‘Pmode’?
 1514 |  return gen_rtx_REG(mode, reg);
      |                     ^~~~
      |                     Pmode
../../gcc/config/m68k/m68k.c: In function ‘void m68k_function_arg_advance(cumulative_args_t, const function_arg_info&)’:
../../gcc/config/m68k/m68k.c:1528:8: error: no match for ‘operator+=’ (operand types are ‘CUMULATIVE_ARGS’ {aka ‘m68k_args’} and ‘long long int’)
 1528 |   *cum += (arg.promoted_size_in_bytes () + 3) & ~3;
      |   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
../../gcc/config/m68k/m68k.c: In function ‘tree_node* m68k_handle_cconv_attribute(tree_node**, tree, tree, int, bool*)’:
../../gcc/config/m68k/m68k.c:358:7: warning: control reaches end of non-void function [-Wreturn-type]
  358 |  sorry("m68k_handle_cconv_attribute saw unexpected attribute %qE", name);
      |  ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
make[2]: *** [Makefile:2404: m68k.o] Error 1
make[2]: Leaving directory '/home/pi/gcc-amiga/objdir/gcc'
make[1]: *** [Makefile:4428: all-gcc] Error 2
make[1]: Leaving directory '/home/pi/gcc-amiga/objdir'
make: *** [Makefile:957: all] Error 2

and troubleshooting this may be beyond me.

I also spotted GCC with Fortran running directly on Amiga PowerPC / OS4, but I wanted to stick with M68k era. https://www.amigans.net/modules/newbb/viewtopic.php?post_id=111858 I also briefly looked at converting the Fortran into something else, but that may not be the easiest path either.

So after all that, are there any pointers or suggestions for how to generate classic Amiga executables from C++/Fortran code. Should I stick with cross compiling, or go back to compiling direct on the machine or WinUAE? Or am I reaching too far? Thank-you.

1
  • 1
    That "m68k regparm support" repository is mine, and contains a few hacks to the C/C++ compiler to add registers to function signatures so one can write AmigaOS libraries in it. I couldn't say why you can't build it; perhaps I broke something which only Fortran uses. In any case, the hacks are unlikely to be useful to Fortran programmers and you should stick with the upstream compiler directly from the FSF.
    – pndc
    Nov 18, 2022 at 15:33

1 Answer 1

18

Workaround: Don't try to compile f77 code on your Amiga, just convert your code into C automagically

Because C compilers are much more widespread than FORTRAN compilers a faithful FORTRAN to C translator exists, it's called f2c and it's widely available. Quoting the wikipedia page (emphasis mine)

f2c is a program to convert Fortran 77 to C code, developed at Bell Laboratories. The standalone f2c program was based on the core of the first complete Fortran 77 compiler to be implemented, the "f77" program by Feldman and Weinberger.

The f2c program was released as free software and subsequently became one of the most common means to compile Fortran code on many systems where native Fortran compilers were unavailable or expensive. Several large Fortran libraries, such as LAPACK, were made available as C libraries via conversion with f2c

Also

the f77 compiler was itself written in C and relied on a C compiler back end to complete its final compilation step

Which explains why f2c is so good at turning any f77 fortran source code into the equivalent C code that can be then compiled with an existing C compiler: it exposes the intermediate C file that was actually used when direct fortran to machine code compilers weren't available.

Note that the produced C code isn't maintainable and must be seen as a throwaway file (all constants are resolved as literals and all computation of constants as well for instance), so the FORTRAN source code remains the source to maintain. When using a makefile, the generated object file depends on the generated C file, which depends on the f77 file.

Also stick to cross-compilation. Compiling on WinUAE with old gcc is just too fragile as you have experienced, and the editors/build toolchains are way better/faster/more stable and maintained on modern machines (also true for assembly language, where vasm interfaces nicely with gcc).

5
  • 1
    Thank-you for this. I've installed f2c and successfully converted and run the typical 'hello world' type examples. Checking again unfortunately the Fortran I wished to convert have .f90 suffixes. Apologies I'd not mentioned Fortran 90 originally despite trying to explain carefully. But for F77 examples it sounds a great solution and your other comments are useful to keep me on a preferred path. Nov 16, 2022 at 10:18
  • 1
    I've used f2c along with fortran 90, but it needs a bit of pre & post-processing to make f2c accept the f90 code / to fix the generated code (or just convert f90 to f77 which is easier than recoding in C). It's possible to some extent. Nov 16, 2022 at 13:09
  • 2
    f2c is so hopelessly obsolete that it only can compile hopelessly obsolete code. Even codes like LAPACK have used Fortran 90+ features for decades. Alas, it is 2022, FORTRAN 77 is 50 years old and was deemed insufficient even already in the 1980s. Many people here were not even yet born. And good luck re-coding non-trivial non-ancient Fortran code in f77. Nov 16, 2022 at 13:36
  • Quite an interesting answer. Having done very little FORTRAN (and long ago), this is not only helpful to know but historically relevant as well. Thanks.
    – Raffzahn
    Nov 16, 2022 at 13:56
  • 1
    Even with the quirks, and some extra work needed for f90 - it sounds like converting the Fortran and continuing to cross compile using the established bebbo amiga-gcc is the path to take. I'll continue this way. Thanks @jean-françois-fabre Nov 16, 2022 at 15:54

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .