The back end and libraries are now up for general testing on a variety of boxes and operating systems. The tarball is usually updated as the web page is. To download and install g95 on unix systems, run the following command (originally from Joost Vandevondele):

wget -O - http://ftp.g95.org/g95-x86-
linux.tgz | tar xvfz -

This will create a directory named 'g95-install' in the current directory. Run (or better yet make an appropriate symbolic link to) ./g95-
install/bin/i686-pc-linux-gnu-
g95 in order to run g95.

Compiling G95

Quick Links:

General
Platform Notes


G95 uses the 4.x release version of GCC. The 4.0.1, 4.0.2 and 4.0.3 stable versions are known to work, other versions might not.

This version is known to work, but other versions might not.

  • Download gcc from ftp://gcc.gnu.org/pub/gcc/releases/gcc-4.0.3/gcc-core-4.0.3.tar.gz
  • This version of GCC stores object files in a directory distinct from the source directories. G95 expects to find gcc object files and libraries in a directory named 'g95' under the main 'gcc-4.0.3' directory. Run the commands:
    cd gcc-4.0.3
    mkdir g95
    cd g95
  • The gcc 'configure' script must be run in the directory that you expect to receive the object files. Configure gcc with
    ../configure --enable-languages=c
  • Run 'make' to build gcc. A full build isn't necessary. If you end up with libbackend.a, and libgcc.a, you've got enough to build g95. If libgcc.a isn't present, try 'make libgcc.a'.
  • Download the g95 source and unpack it in some convenient directory.
  • Change to the main g95 directory and configure with
    ./configure --prefix=<installation directory> \
    --with-gcc-dir=<path of your GCC directory>
  • Build g95 with 'make' or 'make install' to install in the installation directory.
  • Unpack the libf95.a-0.91.tgz, configure and build it to get libf95.a. Make sure --prefix is the same as with g95.
  • Do 'make install' to build and install the library.
  • The exact name of the executable depends on the platform. Create a convenient symbolic link to this.
  • You should now be able to compile fortran 95 programs with g95.

Configure the compiler and library with --enable-F=yes to compile g95 with the F restrictions.

The build process is still pretty crude though I am sure it will be smoothed over as time goes by.


Platform notes

OSX

Compile g95 with CFLAGS=-no-cpp-precomp. This prevents the special preprocessor from kicking in and messing things up.

AIX

It may be necessary to configure with CFLAGS=-liconv.

MinGW

Building with MinGW requires that the "Development" and "MinGW" packages are installed. Also requires gcc-core, gettext, and make. To pull source code from a repository also requires cvs.

  1. Set-up the build tools:
  2. Set-up the build directories and environment:
    • Start an MSys shell and run the following commands:
      mkdir -p /include/sys /src/G95/gcc-4.0.3/g95
      echo "c:/mingw/include/sys /include/sys">>/etc/fstab
      echo "PATH=$PATH:/c/GnuWin32/bin">>/etc/profile
      exit
  3. Get and build GCC:
    • Start an MSys shell and run the following commands:
      # download GCC via FTP:

      ftp://gcc.gnu.org/pub/gcc/releases/gcc-4.0.3/gcc-core-4.0.3.tar.gz


      # configure GCC for G95
      cd /src/G95/gcc-4.0.3/g95
      /src/G95/gcc-4.0.3/configure --with-gcc \
      --with-gnu-ld \
      --with-gnu-as \
      --host=mingw32 \
      --target=mingw32 \
      --prefix=/mingw \
      --enable-threads \
      --disable-nls \
      --enable-languages=c \
      --disable-win32-registry \
      --disable-shared \
      --without-x

      # build GCC for G95
      make
    • If the build fails with the message:
      build/gengtype.exe
      /src/G95/gcc-4.0.3/gcc/input.h: No such file or directory
      make[1]: *** [s-gtype] Error 1
      make[1]: Leaving directory `/src/G95/gcc-4.0.3/g95/gcc'
      make: *** [all-gcc] Error 2
    • Run the following commands:
      cp gcc/gtyp-gen.h gcc/gtyp-gen.h.orig
      sed -e "s/^\"\/src/\"c:\/msys\/1.0\/src/g" \
      gcc/gtyp-gen.h.orig>gcc/gtyp-gen.h
      make
    • If all goes well this will result in MinGW builds of libbackend.a and libgcc.a needed for compiling g95.
  4. Configure the g95 source distribution:
    • Download the g95 source and unpack it within C:\msys\1.0\src\G95
    • Run the following commands:
      cd /src/G95/g95-0.91
      ./configure --prefix=/usr/local --with-gcc-dir=/src/G95/gcc-4.0.3
    • Continue with the g95 compilation instructions.

Cygwin

  1. Set-up the build tools:
    • Install Cygwin to directory C:\cygwin
  2. Set-up the build directory:
    • Start a Cygwin session and run the following command:
       mkdir -p /src/G95/gcc-4.0.3/g95 
  3. Get and build GCC:
  4. If all goes well this will result in Cygwin builds of libbackend.a and libgcc.a needed for compiling g95.
  5. Configure the g95 source distribution:
    • Download the g95 source and unpack it within C:\cygwin\src\G95
    • Within the Cygwin session run the following commands:
      cd /src/G95/g95-0.91
      ./configure --prefix=/usr/local --with-gcc-dir=/src/G95/gcc-4.0.3
    • Continue with the g95 compilation instructions.

Support of MinGW targets under Cygwin

  1. Complete successfully the Cygwin build of G95
  2. Configure the G95 library to support MinGW within Cygwin
    • Start an Cygwin session and run the following command:
       cd /src/G95/g95-0.91/libf95.a-0.91
      ./configure --prefix=/usr/local --with-gcc-dir=/src/G95/gcc-4.0.3 --with-mingw
  3. Build the G95 library to support MinGW within Cygwin
    • Within the Cygwin session run the following command:
      rm *.o *.a
      make
    • This should result in a re-built libf95.a whose members have been compiled under Cygwin with the -mno-cygwin option enabled.
  4. Enable the MinGW compliant library for Cygwin G95:
    • Within the Cygwin session run the following commands:
      mkdir /usr/local/lib/gcc-lib/i686-pc-mingw32/4.0.3/
      ranlib libf95.a
      cp libf95.a /usr/local/lib/gcc-lib/i686-pc-mingw32/4.0.3/
      cd /usr/local/lib/gcc-lib/i686-pc-cygwin/4.0.3/
      g95 -dumpspecs > specs.0
      sed -e '/*startfile:/ {
      n
      s/%{mno-cygwin:dllcrt2%O%s/%{mno-cygwin:\/usr\/lib\/mingw\/dllcrt2%O%s -L\/usr\/local\/lib\/gcc-lib\/i686-pc-mingw32\/4.0.3 -L\/usr\/lib\/mingw/
      s/%{mno-cygwin:crt2%O%s/%{mno-cygwin:\/usr\/lib\/mingw\/crt2%O%s -L\/usr\/local\/lib\/gcc-lib\/i686-pc-mingw32\/4.0.3 -L\/usr\/lib\/mingw/
      }' specs.0 > specs
      rm specs.0
  5. The -mno-cygwin should now be supported by Cygwin g95
    • Following example Cygwin session output to confirm could be:
       dmiles@STACK02 /tmp
      $ uname
      CYGWIN_NT-5.1

      dmiles@STACK02 /tmp
      $ cat hello.f
      program hello
      print *,'hello'
      end

      dmiles@STACK02 /tmp
      $ g95 -o hello_cygwin.exe hello.f

      dmiles@STACK02 /tmp
      $ ./hello_cygwin
      hello

      dmiles@STACK02 /tmp
      $ objdump -x hello_cygwin.exe | grep "DLL Name"
      DLL Name: cygwin1.dll
      DLL Name: cygwin1.dll
      DLL Name: KERNEL32.dll

      dmiles@STACK02 /tmp
      $ g95 -mno-cygwin -o hello_mingw.exe hello.f

      dmiles@STACK02 /tmp
      $ ./hello_mingw
      hello

      dmiles@STACK02 /tmp
      $ objdump -x hello_mingw.exe | grep "DLL Name"
      DLL Name: msvcrt.dll
      DLL Name: msvcrt.dll
      DLL Name: KERNEL32.dl

Build a dll version of g95

A script to download and unpack the g95 source, and build a version of g95 that uses dlls, has been contributed by Dave Miles.

  • Your Cygwin environment should be set up to build g95 as described above.
  • Save the following script in a file named bld-g95.sh.
    #!/bin/sh
    {
    cd /src/G95
    rm -fR g95-0.91
    wget -O - http://www.g95.org/g95_source.tgz | tar xvfz -
    cd g95-0.91
    ./configure --prefix=/usr/local --with-gcc-dir=/src/G95/gcc-4.0.3
    make
    tar -zxf libf95.a-0.91.tar.gz &&\
    cd libf95.a-0.91 &&\
    ./configure --prefix=/usr/local --with-gcc-dir=/src/G95/gcc-4.0.3 &&\
    make
    if [ $? != 0 ]
    then
    exit
    fi
    make install
    mv main.o main.g95
    gcc -mdll -o g95.dll \
    -Wl,--output-def \
    -Wl,g95.def \
    -Wl,--out-implib \
    -Wl,libf95.dll.a \
    -Wl,--export-all-symbols *.o -lws2_32
    if [ -f libf95.dll.a ]
    then
    cp libf95.dll.a /usr/local/lib/gcc-lib/i686-pc-cygwin/4.0.3/
    fi
    if [ -f g95.dll ]
    then
    cp g95.dll /bin
    fi
    cp main.g95 /lib/g95main.o
    cd ..
    make install
    cd ..
    } 2>&1 | tee -a bld-g95.log
  • In a Cygwin bash shell, run the following commands:
    chmod +x bld-g95.sh  
    ./bld-g95.sh
  • When compiling, link to /lib/g95main.o or compile with -shared.