Grafx2 compilation and installation
===================================

=== Requirements ===

* gcc C compiler (other compilers may work, but are not officially supported)
* GNU make (other similar "make" tools may work, but are not supported)
* SDL library v1.2.x, or v2.0.x
* SDL_image library
* libpng
* tiff
* SDL_ttf library (optional, for truetype fonts)
* FreeType library (optional, for truetype fonts)
* Lua library v5.3, (v5.1 or v5.2 are also supported)
  (optional, for Lua scripting)

Note: on some platforms it is possible to build without SDL :
  using GDI API under Windows
  using X11 under Linux/FreeBSD/etc.
see usage of API= variable below.

Extra requirements for Windows:
* a POSIX environment: MSYS is fine, maybe Cygwin would work as well.
* use Mingw C compiler instead of gcc
* MS Visual Studio project files are also provided in project/msvc/
  but are not officially supported

Extra requirements for UNIX/X11 (Linux, FreeBSD, ...):
* pkg-config
* Xlib headers

On Debian-based distributions you should be able to get all these files by
simply running the following commands from a terminal :
$ sudo apt-get install gcc make libfreetype6-dev liblua5.3-dev libtiff5-dev libpng-dev
$ sudo apt-get install libsdl1.2-dev libsdl-image1.2-dev libsdl-ttf2.0-dev
or if you want to use SDL 2.0.x :
$ sudo apt-get install libsdl2-dev libsdl2-image-dev libsdl2-ttf-dev

On macOS, we suggest to use macports https://www.macports.org/ :
$ sudo port install lua libpng tiff
$ sudo port install libsdl libsdl_image libsdl_ttf
or
$ sudo port install libsdl2 libsdl2_image libsdl2_ttf

It is also possible to use the Makefile in 3rdparty/ directory to build
the required lib. This has been developped for win32 cross compilation
but may work for other platforms.

=== Instructions ===

Open a shell/Terminal, enter the directory where you have the project tree, and
type:
  cd src
  make
If all goes well, it should build grafx2-sdl (the main program) in the "bin"
directory. Voilà.

If you don't have FreeType and SDL_ttf, type make NOTTF=1 instead. It will
build a version without TrueType support : the Text tool will be limited to
bitmap fonts, proportional fonts with .ttf extension won't be available.

If you don't have lua available, type `make NOLUA=1`. You will not be able to
use lua scripts to generate and alter brush and pictures.

These options can be combined, for example for a build without ttf nor lua type
make NOTTF=1 NOLUA=1


=== Build variants ===

By default GrafX2 is built for SDL 1.2.x. use API=x11 API=sdl2 or API=win32
to change that.

The default compilation is optimized ( -O ), with debugging symbols for GDB.
Compile with OPTIM=0 to disable optimizations, if you have some real debugging
to do.
Compile with OPTIM=3 to use maximum optimizations.
Type "make release" if you don't want the debugging symbols.

Compile with USE_JOYSTICK=1 to enable joystick input : Only useful for
developers, to check the input code for platforms that don't have a mouse.

Compile with NOLAYERS=1 to make a version of Grafx2 that can't display 
several layers at a time: You will still be able to edit layered images,
but you will only see one layer at a time. This option is designed for slow
platforms, as it makes the program faster.

Compile with NORECOIL=1 to disable support of the RECOIL (REtro COmputer Image
Library) for loading images. This is advised on memory constrained platforms.

=== Other compilation targets ===
  make clean
Erases all generated files (intermediate objects, and executable)

  make depend
Re-compute the dependencies (makefile.dep).

Other compilation targets (make version, make ziprelease) require git
and are only useful to contributors to the git repository of Grafx2.

=== System specifics ===

== Unix/Linux ==

  sudo make install
This copies the executable and data files in your system, in the /usr/local/bin
and /usr/local/share directories. You then no longer need the compilation
directory.

  sudo make uninstall
Removes the copied files from your system, keeps your configuration.

For both options, you can specify prefix=something to choose the target
directory root: For example prefix=/usr or prefix=./test-install

== gp2x ==

The gp2x build is very similar to the Linux one. TTF is always disabled because 
there is no X11 support on the gp2x.
To compile a gp2x executable, type
	make GP2XCROSS=1
This will only work on an UNIXsystem (Linux or FreeBSD).

== Windows ==

It is also possible to compile from linux, with this command :
 $ make WIN32CROSS=1 [API=win32]
You will need the mingw cross-compiler, and all the librairies listed above.
Variables CROSS_CC, CROSS_PKGCONFIG and CROSS_SDLCONFIG can be set :
 $ CROSS_CC=mingw32-gcc CROSS_PKGCONFIG=mingw32-pkg-config CROSS_SDLCONFIG=/path/to/ming32/sdl-config WIN32CROSS=1 NOTTF=1 make
You will probably first need to build dependencies by running
 $ make WIN32CROSS=1
from the 3rdparty/ directory.


Here is a list of the resources used to build the Windows version:

4DOS
  with an alias make=mingw32-make

MSYS
  installed in C:\MSYS

Mingw
  installed in C:\MSYS\mingw

SDL:
  SDL-devel-1.2.13-mingw32.tar.gz
  Uncompress in temporary directory
  make
  make install (no effect?)
  Headers are in /usr/mingw/include/SDL, copy them to /usr/include/SDL

Zlib:
  http://gnuwin32.sourceforge.net/downlinks/zlib.php
  zlib-1.2.3.exe
  Install in c:\msys\mingw
  
Libpng
  Requires: Zlib
  http://www.mirrorservice.org/sites/download.sourceforge.net/pub/sourceforge/l/li/libpng/
  libpng-1.4.2.tar.gz (Before June 2010, we were using libpng-1.0.23.tar.gz)
  Uncompress in temporary directory
  ./configure
  make
  make install (long)
  Files created in /usr/local/include and /usr/local/lib ....
  
libjpeg (optional - improves SDL_image with JPEG reading)
  http://www.mirrorservice.org/sites/download.sourceforge.net/pub/sourceforge/l/project/li/libjpeg/libjpeg/
  jpegsr6.zip
  Uncompress in temporary directory
  ./configure --enable-shared
  make
  (make install doesn't work. Copy jpeglib.h, jmorecfg.h, jconfig.h in include, and libjpeg.a in lib)
  
libtiff (optional - improves SDL_image with TIFF reading)
  ftp://ftp.sgi.com/graphics/tiff/
  tiff-v3.4-tar.gz
  Uncompress in temporary directory
  ./configure i686-pc-mingw32
  make
  Don't use 'make install', copy tiff.h libtiff.a manually instead.
  
SDL_image:
  Requires: Libpng
  Requires optionally: libtiff
  Requires optionally: libjpeg
  http://www.mirrorservice.org/sites/download.sourceforge.net/pub/sourceforge/l/li/libsdl/
  SDL_image-1.2.8.zip
  Uncompress in temporary directory
  ./configure
  Check in the messages that png worked
  Optionally check if jpeg worked too
  Optionally check if tiff worked too
  make
  make install prefix=/usr/mingw
  
FreeType:
  http://www.mirrorservice.org/sites/download.sourceforge.net/pub/sourceforge/m/mi/mingw-cross/
  mingw-freetype-2.3.7-2
  Uncompress in c:/mwsys/mingw
  
SDL_ttf:
  No mingw package
  http://www.mirrorservice.org/sites/download.sourceforge.net/pub/sourceforge/l/li/libsdl/
  SDL_ttf-2.0.9-win32.zip for DLLs: libfreetype-6.dll, SDL_ttf.dll, zlib1.dll
  SDL_ttf-2.0.9.tar.gz

Lua:
  (optional)
  http://www.lua.org/ftp/lua-5.2.1.tar.gz
  Uncompress in temporary directory
  Use sh shell
  make mingw
  (make install doesn't work, even with prefix)
  Copy luaconf.h, lualib.h, lua.h, lauxlib.h to c:\msys\mingw\include
  Copy liblua.a to c:\msys\mingw\lib
  Copy lua51.dll to c:\msys\mingw\bin

== Atari TOS machines ==
The Atari build is very similar to the Linux one. The build might work on native machine with gcc 4.3> compiler, 
but it wasn't tested. You can also build binary for Coldfire based machines(e.g. Firebee) by 
replacing '-m68020-60' in makefile to '-mcpu=5475'.
 
Preferable way is to build GRAFX2 with use of cross compiler, you can get one from Vincent Riviere site:
(URL: http://vincent.riviere.free.fr/soft/m68k-atari-mint). There are versions for win32 (Cygwin) and 
debian packages for latest Ubuntu (32/64bit).

Before compilation you have to build all the needed libraries mentioned in requirements. 

To compile a Atari TOS executable, type in
	make ATARICROSS=1 prefix=/usr/m68k-atari-mint
You can also add other options like NOTTF,NOLUA,NOLAYERS,NORECOIL etc. to enable/disable
program features.

If you don't know how build libraries here's some hints. Please note that prefix path in examples below is valid only under Linux, 
in case of Cygwin the path will be '/opt/m68k-atari-mint'. There will be no prefix when building on native machine.
You have to omit 'sudo' under Cygwin and native build. Stick to this order and you will be fine ;> ... 
The versions of libraries were tested, you can also try newer versions. As I mentioned earlier, replace '-m68020-60' with '-mcpu=5475' 
if you want to target Coldfire machines.

libpng [optional](for png reading in SDL_image):
------------------------------------------------
note: you will need libzip too
libpng 1.2.44 
./configure --prefix=/usr/m68k-atari-mint --disable-shared --enable-static --host=m68k-atari-mint CFLAGS="-m68020-60 -O2 -fomit-frame-pointer"
sudo make install 
or 
libpng 1.4.44 
./configure --prefix=/usr/m68k-atari-mint --disable-shared --enable-static --host=m68k-atari-mint CFLAGS="-m68020-60 -O2 -fomit-frame-pointer -DPNG_NO_SETJMP"
sudo make install

libjpeg, libtiff [optional] (for jpeg/tiff support in SDL_image) 
----------------------------------------------------------------
./configure --prefix=/usr/m68k-atari-mint --disable-shared --enable-static --host=m68k-atari-mint CFLAGS="-m68020-60 -O2 -fomit-frame-pointer"
sudo make install

freetype 2.4.4 [optional] (for TTF fonts support, required by SDL_ttf)
----------------------------------------------------------------------
./configure --prefix=/usr/m68k-atari-mint --disable-shared --enable-static --host=m68k-atari-mint CFLAGS="-m68020-60 -O2 -fomit-frame-pointer" 
sudo make install 

lua 5.0.4 [optional] (for LUA scripting support)
------------------------------------------------
Here you have to customize makefiles, add prefixes, platform has to be set as generic. 

SDL 1.2 [mandatory]
--------------------
note: best is to grab it directly from Mercurial repository 
./configure --prefix=/usr/m68k-atari-mint --disable-shared --enable-static --host=m68k-atari-mint --disable-video-opengl --disable-shared --enable-static --disable-threads CFLAGS="-m68020-60 -O2 -fomit-frame-pointer"
sudo make install 

SDL_ttf [optional] (for ttf fonts support, depends on SDL and freetype) 
-------------------------------------------
./configure --prefix=/usr/m68k-atari-mint --disable-shared --enable-static --host=m68k-atari-mint --disable-shared --enable-static --with-sdl-prefix=/usr/m68k-atari-mint --with-freetype-prefix=/usr/m68k-atari-mint CFLAGS=" -m68020-60 -O2 -fomit-frame-pointer"
sudo make install 

SDL_image 1.2.10 [mandatory] 
----------------------------
./configure --prefix=/usr/m68k-atari-mint --disable-shared --enable-static --host=m68k-atari-mint --disable-shared --enable-static --with-sdl-prefix=/usr/m68k-atari-mint CFLAGS="-DHAVE_OPENGL=0 -m68020-60 -O2 -fomit-frame-pointer"
sudo make install 

And that's it! :)

