#!/bin/bash set -eu for arg in "$@"; do declare $arg="1"; done if [ ! -v clang ]; then gcc=1; fi if [ ! -v release ]; then debug=1; fi if [ -v debug ]; then echo "[debug mode]"; fi if [ -v release ]; then echo "[release mode]"; fi if [ -v gcc ]; then compiler="${CC:-gcc}"; cpp_compiler="g++"; echo "[gcc compiler]"; fi if [ -v clang ]; then compiler="${CC:-clang}"; cpp_compiler="clang++"; echo "[clang compiler]"; fi if [ -v vulkan ]; then render_flag="-DSTG_VULKAN_RENDERER"; echo "[vulkan renderer]"; fi if [ -v opengl ] && [ ! -v render_flag ]; then render_flag="-DSTG_OPENGL_RENDERER"; echo "[opengl renderer]"; fi if [ -v webgl ] && [ ! -v render_flag ]; then render_flag="-DSTG_WEBGL_RENDERER"; echo "[webgl renderer]"; fi if [ -v dx11 ] && [ ! -v render_flag ]; then render_flag="-DSTG_DX11_RENDERER"; echo "[dx11 renderer]"; fi if [ ! -v render_flag ]; then render_flag="-DSTG_VULKAN_RENDERER"; vulkan="vulkan"; echo "[default renderer - vulkan]"; fi # for command line build args auto_compile_flags="${render_flag}" # source files source_files="../src/entry_linux.c" # includes include_flags="-I../src/ -I../external/ -L." # executable name out_name="Gears" # vma flags vma_source_files="../external/vma/vma.cpp" vma_compile_flags="-std=c++20 -I../external/vma -c" vma_out="-o" vma_obj="vma.o" # glslc glsl_compile="glslc" glsl_flags="--target-spv=spv1.6 -std=460" glsl_stage_vert="-fshader-stage=vert" glsl_stage_frag="-fshader-stage=frag" glsl_stage_tesc="-fshader-stage=tesc" glsl_stage_tese="-fshader-stage=tese" glsl_stage_geom="-fshader-stage=geom" glsl_stage_comp="-fshader-stage=comp" glsl_out="-o./shaders/glsl/" clang_common="${include_flags} -Xclang -flto-visibility-public-std -Wno-unknown-warning-option -fdiagnostics-absolute-paths -Wall -Wno-missing-braces -Wno-unused-function -Wno-writable-strings -Wno-unused-value -Wno-unused-variable -Wno-unused-local-typedef -Wno-deprecated-register -Wno-deprecated-declarations -Wno-unused-but-set-variable -Wno-single-bit-bitfield-constant-conversion -Wno-compare-distinct-pointer-types -Wno-initializer-overrides -Wno-incompatible-pointer-types-discards-qualifiers -Wno-for-loop-analysis" clang_debug="$compiler -g -O0 -DBUILD_DEBUG=1 ${clang_common} ${auto_compile_flags}" clang_release="$compiler -O2 ${clang_common} ${auto_compile_flags}" clang_link="-lpthread -lm -lrt -ldl -l:libvma.a" clang_out="-o" gcc_common="${include_flags} -std=c99 -fuse-ld=mold -Wno-unknown-warning-option -Wall -Wno-missing-braces -Wno-unused-function -Wno-attributes -Wno-unused-value -Wno-unused-variable -Wno-unused-local-typedef -Wno-deprecated-declarations -Wno-unused-but-set-variable -Wno-compare-distinct-pointer-types -D_USE_MATH_DEFINES -Dstrdup=_strdup -Dgnu_printf=printf" gcc_debug="$compiler -g -O0 -DBUILD_DEBUG=1 ${gcc_common} ${auto_compile_flags}" gcc_release="$compiler -O2 ${gcc_common} ${auto_compile_flags}" gcc_link="-lpthread -lm -lrt -ldl -l:libvma.a -lstdc++" gcc_out="-o" link_dll="-fPIC" link_os_gfx="-lxcb -lX11 -lX11-xcb -lvulkan" if [ -v gcc ]; then compile_debug="$gcc_debug"; fi if [ -v gcc ]; then compile_release="$gcc_release"; fi if [ -v gcc ]; then compile_link="$gcc_link"; fi if [ -v gcc ]; then out="$gcc_out"; fi if [ -v clang ]; then compile_debug="$clang_debug"; fi if [ -v clang ]; then compile_release="$clang_release"; fi if [ -v clang ]; then compile_link="$clang_link"; fi if [ -v clang ]; then out="$clang_out"; fi if [ -v debug ]; then compile="$compile_debug"; fi if [ -v release ]; then compile="$compile_release"; fi mkdir -p build cd build if [ -v vulkan ]; then mkdir -p ./shaders/glsl mkdir -p ../src/file_data for file in ../src/shaders/glsl/*.glsl; do base_name=$(basename -- "$file" .glsl) case "$base_name" in *.vert) glsl_stage="${glsl_stage_vert}" ;; *.frag) glsl_stage="${glsl_stage_frag}" ;; *.tesc) glsl_stage="${glsl_stage_tesc}" ;; *.tese) glsl_stage="${glsl_stage_tese}" ;; *.geom) glsl_stage="${glsl_stage_geom}" ;; *.comp) glsl_stage="${glsl_stage_comp}" ;; *) continue ;; esac $glsl_compile $glsl_flags $glsl_stage $file "${glsl_out}${base_name}.spv" done rm -f ../src/file_data/spv.c touch ../src/file_data/spv.c for file in ./shaders/glsl/*.spv; do base_name=$(basename -- "$file" .spv) xxd -n "shader_${base_name}" -i $file >> ../src/file_data/spv.c done fi $cpp_compiler $vma_compile_flags $vma_source_files $vma_out $vma_obj ar rcs libvma.a vma.o $compile $source_files $compile_link $link_os_gfx $out $out_name