Login
Username:

Password:

Remember me



Lost Password?

Register now!

Sections

Who's Online
104 user(s) are online (59 user(s) are browsing Forums)

Members: 0
Guests: 104

more...

Headlines

 
  Register To Post  

howto : Fortran for amigaos4
Home away from home
Home away from home


See User information
...Intro...

Resized Image

Lately when i play with new version of gcc from adtools repo, i enabled not only c/c++ languages, but also objc, and obj-c++ , as they reported to work fine (at least they passed necessary tests). Then i think why not try something else, like ADA or Fortran, as they supported by GCC and updated all the time, and can be the same enabled as any other languages. Sure, on amigaos4 even objc and obj-c++ support is "as it", as Sebastian alone can't mantain everything, but there is also ADA, Fortran, GO, D and some other languages which is in GCC, which can also works "as it". And while with C family its understandable that it can and might work, with others it needs more stuff to be handled outside of C famility skope, that include at least another compiller, if not linker's code.

Resized Image

So, for sake of tests i go for Fortran firstly, as it language which i touch a bit some many years ago.

All the tests at this time done on Cygwin (to avoid worring with win32 absolute&relative patches in MSYS2 environment about which i wrote few days ago). Cygwin's gcc for building crosscompiler (i.e. compilator on which i build our cross-compiler) are 7.3.0.

Probably there is no needs to describe how to prepare, download and start to build gcc8.2.0 from adtools repo, as all described on adtools repo page in the readme by Sebastian, and copy of steps are in my previous post there: http://www.amigans.net/modules/xforum ... hp?topic_id=7883&forum=25

...Building

Enabling support of Fortran in our gcc 8.2.0 from adtools page is it only matter of touching again /amiga/adtools/gcc-build/features.mk file, which now will be looks like this:

MAJOR_VERSION:=$(word 1, $(subst ., , $(VERSION)))

FEATURES=\
    
--enable-languages=c,c++,objc,obj-c++,fortran \
    
--enable-haifa            \
    
--enable-sjlj-exceptions  \
    
--disable-libstdcxx-pch \
    
--disable-tls

# Check, if major version is greater than or equals to 8
ifeq ($(shell test $(MAJOR_VERSION) -ge 8; echo $$?), 0)
FEATURES+=--enable-threads=amigaos
endif


Then, you will meet one single error when compilation of fortran related objects in the gcc will happens (at least on gcc 7.3.0 on cygwin when build gcc 8.2.0 from adtools repo): undefined ULONG_MAX in the /amiga/adtools/gcc/repo/libgfortran/runtime/memory.c

So we just add at top of that file:

Quote:

#define ULONG_MAX 0xFFFFFFFFUL


And all compiles then fine till end. Phew! That what we will have in the /usr/local/amiga/bin/

ls -la /usr/local/amiga/bin/
total 75276
drwxr
-xr-x1 user user       0 Nov 10 14:53 .
drwxr-xr-x1 user user       0 Nov 10 14:53 ..
-
rwxr-xr-x  1 user user 1202623 Nov 10 14:05 ppc-amigaos-addr2line.exe
-rwxr-xr-x  2 user user 1243035 Nov 10 14:05 ppc-amigaos-ar.exe
-rwxr-xr-x  2 user user 1760568 Nov 10 14:05 ppc-amigaos-as.exe
-rwxr-xr-x  2 user user 6706868 Nov 10 14:53 ppc-amigaos-c++.exe
-rwxr-xr-x  1 user user 1197021 Nov 10 14:05 ppc-amigaos-c++filt.exe
-rwxr-xr-x  1 user user 6701295 Nov 10 14:53 ppc-amigaos-cpp.exe
-rwxr-xr-x  1 user user  244345 Nov 10 14:05 ppc-amigaos-elfedit.exe
-rwxr-xr-x  2 user user 6706868 Nov 10 14:53 ppc-amigaos-g++.exe
-rwxr-xr-x  2 user user 6667764 Nov 10 14:53 ppc-amigaos-gcc.exe
-rwxr-xr-x  2 user user 6667764 Nov 10 14:53 ppc-amigaos-gcc-8.2.0.exe
-rwxr-xr-x  1 user user  338561 Nov 10 14:53 ppc-amigaos-gcc-ar.exe
-rwxr-xr-x  1 user user  338049 Nov 10 14:53 ppc-amigaos-gcc-nm.exe
-rwxr-xr-x  1 user user  338049 Nov 10 14:53 ppc-amigaos-gcc-ranlib.exe
-rwxr-xr-x  1 user user 6448225 Nov 10 14:53 ppc-amigaos-gcov.exe
-rwxr-xr-x  1 user user 4344719 Nov 10 14:53 ppc-amigaos-gcov-dump.exe
-rwxr-xr-x  1 user user 4731028 Nov 10 14:53 ppc-amigaos-gcov-tool.exe
-rwxr-xr-x  1 user user 6707183 Nov 10 14:53 ppc-amigaos-gfortran.exe
-rwxr-xr-x  1 user user 1301110 Nov 10 14:05 ppc-amigaos-gprof.exe
-rwxr-xr-x  4 user user 1594401 Nov 10 14:05 ppc-amigaos-ld.bfd.exe
-rwxr-xr-x  4 user user 1594401 Nov 10 14:05 ppc-amigaos-ld.exe
-rwxr-xr-x  2 user user 1217860 Nov 10 14:05 ppc-amigaos-nm.exe
-rwxr-xr-x  2 user user 1447433 Nov 10 14:05 ppc-amigaos-objcopy.exe
-rwxr-xr-x  2 user user 1762605 Nov 10 14:05 ppc-amigaos-objdump.exe
-rwxr-xr-x  2 user user 1243035 Nov 10 14:05 ppc-amigaos-ranlib.exe
-rwxr-xr-x  1 user user  663533 Nov 10 14:05 ppc-amigaos-readelf.exe
-rwxr-xr-x  1 user user 1204110 Nov 10 14:05 ppc-amigaos-size.exe
-rwxr-xr-x  1 user user 1203725 Nov 10 14:05 ppc-amigaos-strings.exe
-rwxr-xr-x  2 user user 1447433 Nov 10 14:05 ppc-amigaos-strip.exe


See there some new binaries including gfortran ? it is !

So, it builds, but did it work at all ?

...Testing...

For first tests i choice simple helloworld of course, on Fortran 77, but not just print, but with subroutine and passing a variable to it (so to know if basics works):

program hello_world3
      implicit none
      character
*32 text
c
      text 
'Hello World'
c
      call printtext
(text)

      
end

      subroutine printtext
(tekst)
      
implicit none
      character
*32 tekst
c
      write 
(*,*) tekst
c
      end


And we have 2 varians to compile it to the .exe :

1. Compile object via gfortran , and then link via gcc , ie:

Quote:

$ ppc-amigaos-gfortran.exe -c helloworld.f -o helloworld.o
$ ppc-amigaos-gcc -athread=native helloworld.o -o helloworld -lgfortran



2. Just made a binary right away with ppc-amigaos-gfortran:

Quote:

$ ppc-amigaos-gfortran -athread=native helloworld.f -o helloworld


(remember there we use -athread=native, as for c++11 and stuff it is necessary now, and once it will be well tested, Sebastian probabaly will make it as default).

We also can it strip a little, so to make binary smaller:

Quote:

$ ppc-amigaos-strip helloworld
$ ls -la helloworld
-rwxr-xr-x 1 user user 277004 Nov 11 23:58 helloworld


And so, surprise, it works !

Resized Image
(press open in new tab for full size)

Well, some primitive basics works, what about something more heavy ? I going to github, and found https://github.com/Aerodlyn/Mazer
That what author says about:

Quote:

Mazer is a relatively simple game that generates a random imperfect maze, stylized in the idea of exploring a dungeon in a retro RPG. The game uses C and SDL for the majority of its logic and entirely for graphics. However, I wanted to implement some logic in another language. Initially I thought about using Assembly (NASM) but I quickly decided that would be more trouble than it would be worth. So, I decided I would either use Fortran or Lua. I chose Fortran as I was more curious about working with it then Lua, given that I have some previous experience with Lua.


If you going to the code of repo, you will find that it is mix of *.c and *.f95 files (fortran95, so kind of another version, not 77 which we test by helloword). Also use SDL (in that exactly case SDL2, thanks to Capehill we have it too). So, good test candidate. All what there need to be done, it just simple change Makefile a bit, so to use ppc-amigaos-gcc and ppc-amigaos-gfortran. All flags like c++11 and co we can keep, as yeah, we on 8.2.0. Also added to linker line -lSDL2 -lpthread. And then:

Quote:

$ make
ppc-amigaos-gcc -c -std=c11 -fms-extensions -Wall -g -IHeaders/ -o Sources/Utils.o Sources/Utils.c
ppc-amigaos-gcc -c -std=c11 -fms-extensions -Wall -g -IHeaders/ -o Sources/Application.o Sources/Application.c
ppc-amigaos-gcc -c -std=c11 -fms-extensions -Wall -g -IHeaders/ -o Sources/Tile.o Sources/Tile.c
ppc-amigaos-gfortran -ffree-form -c Sources/Mazer_Module.f95 -o Sources/Mazer_Module.o
ppc-amigaos-gfortran -ffree-form -c Sources/Determine_Borders.f95 -o Sources/Determine_Borders.o
ppc-amigaos-gfortran -ffree-form -c Sources/Generate_Tiles.f95 -o Sources/Generate_Tiles.o
ppc-amigaos-gfortran -ffree-form -c Sources/Generate_Rooms.f95 -o Sources/Generate_Rooms.o
ppc-amigaos-gfortran -ffree-form -c Sources/Generate_Paths.f95 -o Sources/Generate_Paths.o
ppc-amigaos-gcc -lgfortran -std=c11 -fms-extensions -Wall -g -IHeaders/ -o Mazer Sources/Utils.o Sources/Application.o Sources/Tile.o Sources/Mazer_Module.o Sources/Determine_Borders.o Sources/Generate_Tiles.o Sources/Generate_Rooms.o Sources/Generate_Paths.o -lSDL2 -lpthread
$


Compiles fine ! Surprise indeed, seeing code of those *.f95 inside and that is mix of it with C , + SDL2 on top. And.. it works!

Resized Image
(press open in new tab for full size)


...Outro

Sure, while its not of big use for most of us, and there is not many code flying around and cry loudly to port them , but still, its quite interesting that we can have fortran in our gcc, we can mix it with C, we can use SDL2 with it (or anything else then) and probabaly whatever else. Of course i will keep fortran support in my cross-compiler then, in hope someday it will be any of good use instead of just slash and hacks.

Thanks for reading !




Edited by kas1e on 2018/11/11 21:59:07
Edited by kas1e on 2018/11/11 22:17:08
Join us to improve dopus5!
AmigaOS4 on youtube
Go to top
Re: howto : Fortran for amigaos4
Just popping in
Just popping in


See User information
@kas1e

Wow very cool. Is it that easy to get support for Google GO up and running? (I think 'go' may have a runtime that needs separate development?).

Cheers!

Go to top
Re: howto : Fortran for amigaos4
Quite a regular
Quite a regular


See User information
Hey, cool! I did some Fortran stuff in my former (academic) life - and must admit that I really liked it.

X1000|II/G4|440ep|2000/060|2000/040|1000
Go to top
Re: howto : Fortran for amigaos4
Quite a regular
Quite a regular


See User information
Hey, I was brought up on FORTRAN back in the 60's. My first language ever, at Uni in 1964. That's what started all this computer obsession...

cheers
tony
Go to top

  Register To Post

 




Currently Active Users Viewing This Thread: 1 ( 0 members and 1 Anonymous Users )




Powered by XOOPS 2.0 © 2001-2023 The XOOPS Project