#!/usr/bin/env zsh

#LOC=$(find . -name '*.c' -o -name '*.h' | xargs grep -hv '^\s*//' | grep -v '^\s*$' | grep -v '^$' | wc -l);
LOC=$(find . -name '*.cpp' -o -name '*.h' | xargs grep -hv '^\s*//' | grep -v '^\s*$' | grep -v '^$' | wc -l);
DATE=$(date +%s);
TOKENS=$(python3 count_tokens.py);

#echo $DATE,$LOC >> build-stats.csv;
echo $DATE,$LOC,$TOKENS >> build-stats.csv;

#make clean;
#{ time make } 2>time.txt;
#mv game game_gcc;
#BUILD_TIME=$(awk '{print $8}' time.txt);
#echo $BUILD_TIME;
#echo $CLANG_BUILD_TIME;
#TIMESTAMP=$(date +%s);
#LOC=$(cat *.h *.c | egrep -v "^[[:space:]]*//" | egrep -v "^$" | wc -l);
#LUA_LOC=$(cat *.lua | egrep -v "^[[:space:]]*--" | egrep -v "^$" | wc -l);
#GCC_SIZE=$(ls -al game_gcc | awk '{print $5}');
#GCC_LIBSIZE=$(ls -al libgame.so | awk '{print $5}');
#make clean;	
#echo $TIMESTAMP,$SIZE,$LIBSIZE,$LOC,$BUILD_TIME;
#echo $TIMESTAMP,$GCC_SIZE,$CLANG_SIZE,$LIBSIZE,$LOC,$LUA_LOC,$BUILD_TIME >> build-stats.csv
#{ time make CC=clang } 2>time_clang.txt;
#mv game game_clang;
#CLANG_BUILD_TIME=$(awk '{print $9}' time_clang.txt);
#CLANG_SIZE=$(ls -al game_clang | awk '{print $5}');
#CLANG_LIBSIZE=$(ls -al libgame.so | awk '{print $5}');
#{ time make index.html } 2>time_emcc.txt;
#EMCC_BUILD_TIME=$(awk '{print $9}' time_emcc.txt);
#EMCC_DATA_SIZE=$(ls -al index.data | awk '{print $5}');
#EMCC_HTML_SIZE=$(ls -al index.html | awk '{print $5}');
#EMCC_JS_SIZE=$(ls -al index.js | awk '{print $5}');
#EMCC_WASM_SIZE=$(ls -al index.wasm | awk '{print $5}');
#echo build time: $BUILD_TIME;
#echo timestamp: $TIMESTAMP;
#echo loc: $LOC;
#echo lua_loc: $LUA_LOC;
#echo gcc_size: $GCC_SIZE;
#echo gcc_libsize: $GCC_LIBSIZE;
#echo clang build time: $CLANG_BUILD_TIME;
#echo clang size: $CLANG_SIZE;
#echo clang libsize: $CLANG_LIBSIZE;
#echo emcc build time: $EMCC_BUILD_TIME;
#echo emcc data size: $EMCC_DATA_SIZE;
#echo emcc html size: $EMCC_HTML_SIZE;
#echo emcc js size: $EMCC_JS_SIZE;
#echo emcc wasm size: $EMCC_WASM_SIZE;
#make clean;
#echo $TIMESTAMP,$GCC_SIZE,$CLANG_SIZE,$GCC_LIBSIZE,$CLANG_LIBSIZE,$EMCC_DATA_SIZE,$EMCC_HTML_SIZE,$EMCC_JS_SIZE,$EMCC_WASM_SIZE,$LOC,$LUA_LOC,$BUILD_TIME,$CLANG_BUILD_TIME,$EMCC_BUILD_TIME >> build-stats.csv
#echo "Building graphs...";
#python3 graph_loc.py build-stats.csv LOC loc 2>/dev/null;
#echo "Built loc graph";
#python3 graph_loc.py build-stats.csv LOC lua_loc 2>/dev/null;
#echo "Built lua_loc graph";
#python3 graph_loc.py build-stats.csv loc lua_loc 2>/dev/null;
#python3 graph_loc.py build-stats.csv seconds gcc_build_time clang_build_time emcc_build_time 2>/dev/null;
#echo "Built build time graph";
#python3 graph_loc.py build-stats.csv bytes gcc_size clang_size 2>/dev/null;
#echo "Built size graph";
#python3 graph_loc.py build-stats.csv bytes gcc_libsize clang_libsize 2>/dev/null;
#echo "Built libsize graph";
##python3 graph_loc.py build-stats.csv emcc_build_time 2>/dev/null;
#python3 graph_loc.py build-stats.csv bytes emcc_data_size 2>/dev/null;
#echo "Built emcc data size graph";
#python3 graph_loc.py build-stats.csv bytes emcc_html_size 2>/dev/null;
#echo "Built emcc html size graph";
#python3 graph_loc.py build-stats.csv bytes emcc_js_size 2>/dev/null;
#echo "Built emcc js size graph";
#python3 graph_loc.py build-stats.csv bytes emcc_wasm_size 2>/dev/null;
#echo "Built emcc wasm size graph";
#rm -rf time.txt time_clang.txt time_emcc.txt;
