< index < 0. Compiling with libtcod | ===================================== 0.5 GCC on Linux ===================================== |

Use this method if you're using Linux.

### Pre-requisites

You need to install following packages to be able to use libtcod :
gcc g++ make zlib libpng12 libsdl1.2
If you want to compile a fresh libtcod that you checked out from the subversion repository, you need following additional packaged :
libpng12-dev libsdl1.2-dev upx electric-fence

### Creating the makefile for C language

In the following chapters, replace ${LIBTCODDIR} by the Doryen library's root directory, and ${FLAGS} by any additional compilation flags.
For example, for a debug version, replace ${FLAGS} by -g. For a release version, replace it by -O3.
If your program's source code is in a single file, you can directly compile and link with a single command (you can put it in a .sh file ) :

    C++ : g++ samples_cpp.cpp ${FLAGS} -Wall -o samples_cpp -L${LIBTCODDIR} -ltcod -ltcod++ -I${LIBTCODDIR}/include
    C   : gcc samples_c.c ${FLAGS} -Wall -o samples_c -L${LIBTCODDIR} -ltcod -ltcod++ -I${LIBTCODDIR}/include

If you have several source files and you don't want to recompile everything everytime, you'd better use a makefile :
If you're using the C language copy and paste this into a 'makefile' file in your source directory (replace ${LIBTCODDIR} by its real value):

    SRCDIR=.
    INCDIR=${LIBTCODDIR}/include
    CFLAGS=$(FLAGS) -I$(INCDIR) -I$(SRCDIR) -Wall
    CC=gcc
    .SUFFIXES: .o .h .c

    $(TEMP)/%.o : $(SRCDIR)/%.c
    	$(CC) $(CFLAGS) -o $@ -c $<

    C_OBJS=$(TEMP)/samples_c.o

    all : samples_c

    samples_c : $(C_OBJS)
    	$(CC) $(C_OBJS) $(CFLAGS) -o $@ -L${LIBTCODDIR} -ltcod -Wl,-rpath,.

    clean :
    	\rm -f $(C_OBJS) samples_c

Important! Every indented line in the makefile must begin with a tabulation, not spaces.
I won't explain the whole makefile syntax here, but basically :
List all your sources files in the C_OBJS variable with a space between each name. You can use a multiline provided you put a backslash at the end of the line and a tabulation as the first character of the new line. Exemple :
If your have 5 source files : file1.c, file2.c, file3.c, file4.c and file5.c :

    C_OBJS=$(TEMP)/file1.o $(TEMP)/file2.o \
      $(TEMP)/file3.o $(TEMP)/file4.o \
      $(TEMP)/file5.o

Also replace samples_c by your program name.

### Compiling

Now you can build your program by running this command :

    make

You can rebuild the whole program with :

    make clean all

You can choose to build either the debug or the release configuration :

    debug : make FLAGS='-g' clean all
    release : make FLAGS='-O3' clean all

### Creating the makefile for C++ language

If you're using C++, you may have .cpp file or mixed .c and .cpp files. Use this makefile instead :

    SRCDIR=.
    INCDIR=${LIBTCODDIR}/include
    CFLAGS=$(FLAGS) -I$(INCDIR) -I$(SRCDIR) -Wall
    CC=gcc
    CPP=g++
    .SUFFIXES: .o .h .c .hpp .cpp

    $(TEMP)/%.o : $(SRCDIR)/%.cpp
    	$(CPP) $(CFLAGS) -o $@ -c $<
    $(TEMP)/%.o : $(SRCDIR)/%.c
    	$(CC) $(CFLAGS) -o $@ -c $<

    CPP_OBJS=$(TEMP)/samples_cpp.o

    all : samples_cpp

    samples_cpp : $(CPP_OBJS)
    	$(CPP) $(CPP_OBJS) -o $@ -L${LIBTCODDIR} -ltcod -ltcod++ -Wl,-rpath,.

    clean :
    	\rm -f $(CPP_OBJS) samples_cpp

List all your C and CPP source files in the CPP_OBJS variable, replace samples_cpp by your program name. This makefile won't work if you have a .c and a .cpp file with the same basename (exemple myfile.c and myfile.cpp). You'll have to rename at least one of them.