#!/bin/sh
#
#                     Compiling, Linking, Profiling: Flysimu
#
#----------------------------------------------------------------------------

# Compiler
CC="/usr/bin/gcc"
CPP="/usr/bin/g++"
GP="/usr/bin/gprof"

# Option
DUMPS="-O0 -dm -MMD"
MARCH="-mmmx -msse -msse2 -mssse3"
GDBS="-g2 -ggdb"
CFLAGS="-Wall -pedantic"

# Linker
LDFLAGS1="-lm -lX11 -lGLEW -lGL -lGLU -lpng"
LDFLAGS2="-lm -lX11 -lGLEW -lGL -lGLU -lpng"

#----------------------------------------------------------------------------

# Standard C
STD1="-std=gnu89"
STD2="-std=c89"
STD3="-std=gnu90"
STD4="-std=gnu99"
STD5="-std=c99"
STD6="-std=gnu11"
STD7="-std=c11"
STD8="-std=gnu17"
STD9="-std=c17"

# Standard CPP
STD10="-std=gnu++98"
STD11="-std=c++98"
STD12="-std=gnu++11"
STD13="-std=c++11"
STD14="-std=gnu++17"
STD15="-std=c++17"

#----------------------------------------------------------------------------

# Main Programm
MAINC1="main.c"
DIRSC1="WIN/help.c WIN/win.c WIN/fps.c NET/network.c NET/point.c"
DIRSC2="TEX/texture.c CONF/uniform.c FONT/font.c"
DIRSC3="OGL/move.c OGL/cube.c OGL/flybox.c OGL/opengl.c OGL/cockpit.c"

# Output File
OBJC1="help.o win.o fps.o network.o point.o" 
OBJC2="texture.o uniform.o font.o"
OBJC3="move.o cube.o flybox.o opengl.o cockpit.o"
OBJC4="main.o"

# Compiling Fsimulator
cd C/
$CC $MARCH $DUMPS $GDBS $CFLAGS -S $MAINC1 $DIRSC1 $DIRSC2 $DIRSC3 $LDFLAGS1 $STD6
$CC $MARCH $DUMPS $GDBS $CFLAGS -c $MAINC1 $DIRSC1 $DIRSC2 $DIRSC3 $LDFLAGS1 $STD6
$CC $MARCH $DUMPS $GDBS $CFLAGS -o flysimu $OBJC1 $OBJC2 $OBJC3 $OBJC4 $LDFLAGS1 $STD6

# Profiling Flysimulator
$CC $MARCH $DUMPS $GDBS $OBJC1 $OBJC2 $OBJC3 $OBJC4 $LDFLAGS1 $STD6
./a.out
$GP ./a.out > DATA/fly.txt
cd ..

#----------------------------------------------------------------------------

# Main Programm
MAIN1="main.cpp"
DIRS1="WIN/help.cpp WIN/win.cpp WIN/fps.cpp NET/network.cpp NET/point.cpp"
DIRS2="TEX/targa.cpp TEX/encoder.cpp TEX/decoder.cpp TEX/image.cpp"
DIRS3="TEX/texture.cpp CONF/uniform.cpp  FONT/font.cpp"
DIRS4="OGL/move.cpp OGL/cube.cpp OGL/flybox.cpp OGL/opengl.cpp OGL/cockpit.cpp"

# Output File
OBJ1="help.o win.o fps.o network.o point.o"
OBJ2="targa.o encoder.o decoder.o image.o"
OBJ3="texture.o uniform.o font.o"
OBJ4="move.o cube.o flybox.o opengl.o cockpit.o"
OBJ5="main.o"

# Compiling Fsimulator
cd CPP/
$CPP $MARCH $DUMPS $GDBS $CFLAGS -S $MAIN1 $DIRS1 $DIRS2 $DIRS3 $DIRS4 $LDFLAGS2 $STD12
$CPP $MARCH $DUMPS $GDBS $CFLAGS -c $MAIN1 $DIRS1 $DIRS2 $DIRS3 $DIRS4 $LDFLAGS2 $STD12
$CPP $MARCH $DUMPS $GDBS $CFLAGS -o flysimu-cpp $OBJ1 $OBJ2 $OBJ3 $OBJ4 $OBJ5 $LDFLAGS2 $STD12

# Profiling Flysimulator
$CPP $MARCH $DUMPS $GDBS $OBJ1 $OBJ2 $OBJ3 $OBJ4 $OBJ5 $LDFLAGS2 $STD12
./a.out
$GP ./a.out > DATA/fly.txt
cd ..

#----------------------------------------------------------------------------


