#Storm has a bit weird concept of release and debug configurations.
#The default debug configuration is acutally a release configuration,
#but with some debug flags added. This is since Storm is painfully slow
#without compiler optimizations on, and when using other debug features
#like the debug heap. There is a mode, called "slow" that will enable
#the actual debug mode (i.e. no optimizations etc.)

[project]
#Only build targets containing .mymake-files.
explicitTargets=yes

[project,release,!dist]
input+=Main
input+=Test

[project,release]
execute=no

[build,!slow,!release]
#Always 'release' mode, except when 'slow' is specified here.
all+=release
all+=storm_debug

[build,release]
#When compiling in release mode, use link-time code generation.
all+=release
all+=storm_release

[build,slow]
all+=storm_slow

# Forward build flags:
[build,dist]
all+=dist
[build,nostatic]
all+=nostatic
[build,noskia]
Gui+=noskia
[build,cairogl]
Gui+=usecairogl
[build,nobacktrace]
Utils+=nobacktrace

# Compatibility flag. For various backwards-compatibility fixes.
# Currently, we disable large file support in SQLite, since that causes issues on Ubuntu 18.04 LTS.
# We will phase this out eventually.
[build,compat]
all+=compat
[compat]
define+=STORM_COMPAT

[build]

#Regular libraries linked into Storm and/or any storm libraries.
Core+=lib
Code+=lib
Compiler+=lib
OS+=lib
Shared+=lib
Gc+=lib
Utils+=lib
SoundLib+=lib
SoundLib+=extern_lib

#Libraries that need the storm preprocessor to be run.
Compiler+=stormpp
TestLib+=stormpp
Gui+=stormpp
Graphics+=stormpp
Sound+=stormpp
SQL+=stormpp
Crypto+=stormpp

#Libraries linked into shared libraries loaded by Storm at runtime.
TestLib+=sharedlib
Gui+=sharedlib
Graphics+=sharedlib
Sound+=sharedlib
SQL+=sharedlib
Crypto+=sharedlib

#Libraries that require position independent code on some platforms. If you intend to put the compiler itself
#inside a shared library, add 'Compiler+=pic' and 'Gc+=pic' here.
Core+=pic
OS+=pic
Shared+=pic
Utils+=pic

[deps]
TestLib+=CppTypes
Gui+=CppTypes
Compiler+=CppTypes
Sound+=CppTypes
Graphics+=CppTypes
SQL+=CppTypes
Crypto+=CppTypes

[!dist]
#To make sure everything is built.
#When building for Debian we want a bit more control of what we are building.
Compiler+=TestLib
Compiler+=Gui
Compiler+=Graphics
Compiler+=Sound
Compiler+=SQL
Compiler+=Crypto

#Selection GC to use.
[build,mps]
all+=mps

[build,smm]
all+=smm

#Add variables that indicate the GC choice. We add them to the entire project, even though
#it is only necessary for Gc, Test and Main
[mps]
gcSuffix=_mps

[smm]
gcSuffix=_smm

[!extern_lib]
#Global build parameters
pch=stdafx.h
include+=./
include+=../

[storm_debug]
buildDir=build/
execDir=../debug/

#Turn on some runtime checks (implemented purely in Storm).
define+=FAST_DEBUG

[storm_debug,windows]
#Generate pdb file.
flags+=/Zi /Fd<path|buildDir>
linkFlags+=/DEBUG /INCREMENTAL:NO /PDB:<path|execDir><titleNoExt|output>.pdb

[unix]
flags=-std=c++11
flags+=<opt>


[storm_debug,unix]
#We do not need that aggressive optimizations...
opt+=-O1
#Generate debug information.
flags+=-g
cflags+=-g

[storm_release]
buildDir=release/
execDir=../release/

[storm_release,windows]
#Enable link-time code generation. Too slow to use regularly, but gives good performance!
flags+=/GL
linkFlags+=/LTCG

[storm_release,lib,windows]
#Need extra flag to the linker...
link=lib /LTCG <files> /nologo /OUT:<output>

[storm_release,unix]
#We do not need O3
opt=-O2

[pic,unix]
#All libraries need to be compiled with the -fPIC flag. At least on X86-64.
flags+=-fPIC
cflags+=-fPIC


[storm_slow]
buildDir=slow/
execDir=../slow/

[nostatic]
define+=NOSTATIC_BUILD

[windows]
#Tell the Win32 API we're working with UTF16.
define+=_UNICODE
define+=UNICODE

#Compile asm files on X86
ext+=asm
noIncludes+=*.asm
compile+=*.asm:1!ml /c /nologo /Fo<output> /safeseh /W3 /Zi <file>

[unix]
flags+=-Wno-unknown-pragmas
flags+=-Wno-reorder
flags+=-Wno-terminate
flags+=-Wno-unused-parameter
flags+=-Wno-missing-field-initializers
flags+=-Wno-pmf-conversions
flags+=-Wno-switch
flags+=-Wno-parentheses
flags+=-Wno-unused-function
flags+=-Wno-pragmas
#Gives out of bounds warnings due to "dynamic arrays" at the end of structs.
flags+=-Wno-stringop-overflow
#We need to align functions to even addresses, otherwise they will be seen as vtable offsets.
flags+=-falign-functions=2
#Do not export all symbols from .so-files. Storm assumes that functions and variables in different
#modules are different variables and may thus contain different values. This is not the default on UNIX
#systems, at least not when using GCC.
flags+=-fvisibility=hidden
cflags+=-fvisibility=hidden

linkFlags+=-pthread

# Note: We exclude ".s" since we want to use the preprocessor in general.
ext+=S
noIncludes+=*.s
noIncludes+=*.S
compile+=*.S:gcc -g <file> <includes> -c -o <output>

[stormpp]
stormpp=CppTypes
stormppUses=--use 
stormProvides=./
stormUses=../Core/
stormppUsing=--using 
packagePath=../root/
docName=doc
preBuild+=<execpath|stormpp> <stormProvides> <stormppUses*stormUses> --template ../Core/Gen/CppTypes.cpp --out Gen/CppTypes.cpp --asm <stormppAsmTemplate> <stormppAsmOut> --doc <path|packagePath><docName> <stormppUsing*stormUsingNamespace> <stormppFlags>
preBuildCreates+=Gen/CppTypes.cpp

[stormpp,windows]
stormppAsmTemplate=../Core/Gen/CppVTables.VS_X86
stormppAsmOut=Gen/CppVTables.asm
preBuildCreates+=Gen/CppVTables.asm

[stormpp,unix]
stormppAsmTemplate=../Core/Gen/CppVTables.GCC
stormppAsmOut=Gen/CppVTables.S
preBuildCreates+=Gen/CppVTables.S

[sharedlib]
packagePath=../root/<package>/
docName=<titleNoExt|output>_doc

[sharedlib,!unix]
postBuild+=if not exist "<path|packagePath>" mkdir <path|packagePath>
postBuild+=1!copy <output> <path|packagePath><libPrefix><title|output>

[sharedlib,unix]
flags+=-fPIC
cflags+=-fPIC
linkFlags+=-Wl,-z,defs
postBuild+=mkdir -p <path|packagePath>
postBuild+=cp <output> <path|packagePath><libPrefix><title|output>

[sharedlib,storm_debug]
libPrefix=Debug
[sharedlib,storm_release]
libPrefix=Release
[sharedlib,storm_slow]
libPrefix=Slow

# No prefix on Dist releases.
[sharedlib,storm_release,dist]
libPrefix=

#No PCH for c-files.
[windows]
compile+=*.c:cl <defines> <file> <includes> <flags> <warnings> /c /Fo<output>

[unix]
compile+=*.c:gcc -Wno-unknown-pragmas -Wno-pragmas -std=c99 -O3 <cflags> <defines> <warnings> -Wno-maybe-uninitialized <file> -c <includes> -o <output>
