finally cbuild instead of make
This commit is contained in:
@@ -2,6 +2,8 @@
|
|||||||
|
|
||||||
#include "tim.h"
|
#include "tim.h"
|
||||||
|
|
||||||
|
#define TPS 10
|
||||||
|
|
||||||
#define FG 0x10
|
#define FG 0x10
|
||||||
#define BG 0xdd
|
#define BG 0xdd
|
||||||
#define BTN (FG << 16 | BG << 8 | FG)
|
#define BTN (FG << 16 | BG << 8 | FG)
|
||||||
@@ -21,11 +23,11 @@ typedef union {
|
|||||||
|
|
||||||
static struct {
|
static struct {
|
||||||
i32 state; // game state (NEW RUN PAUSE OVER)
|
i32 state; // game state (NEW RUN PAUSE OVER)
|
||||||
i64 tick; // updates every 10 ms
|
i64 tick; // updates every 10 ms
|
||||||
i32 len; // snake length
|
i32 len; // snake length
|
||||||
point body[200]; // snake body
|
|
||||||
point food; // food position
|
point food; // food position
|
||||||
point look; // active direction
|
point look; // active direction
|
||||||
|
point body[200]; // snake body
|
||||||
} snek;
|
} snek;
|
||||||
|
|
||||||
static void start(void) {
|
static void start(void) {
|
||||||
@@ -38,7 +40,7 @@ static void start(void) {
|
|||||||
|
|
||||||
static void game(void) {
|
static void game(void) {
|
||||||
// update game state about every 10 ms
|
// update game state about every 10 ms
|
||||||
i64 tick = tim_time_usec() / 100000;
|
i64 tick = tim_time_usec() / (1000000/TPS);
|
||||||
if (snek.tick != tick) {
|
if (snek.tick != tick) {
|
||||||
snek.tick = tick;
|
snek.tick = tick;
|
||||||
// move one unit
|
// move one unit
|
||||||
|
|||||||
53
makefile
53
makefile
@@ -1,53 +0,0 @@
|
|||||||
CFLAGS+=-Iinclude -Isrc -O2
|
|
||||||
|
|
||||||
all: bin/test bin/string bin/color bin/hello bin/ask bin/snek
|
|
||||||
|
|
||||||
bin/test: test/test.c bin/tim.a
|
|
||||||
$(CC) $< -Wall $(CFLAGS) bin/tim.a -o $@
|
|
||||||
bin/string: test/string.c bin/tim.a
|
|
||||||
$(CC) $< -Wall $(CFLAGS) bin/tim.a -o $@
|
|
||||||
bin/color: test/color.c bin/tim.a
|
|
||||||
$(CC) $< -Wall $(CFLAGS) bin/tim.a -o $@
|
|
||||||
bin/hello: example/hello.c bin/tim.a
|
|
||||||
$(CC) $< -Wall $(CFLAGS) bin/tim.a -o $@
|
|
||||||
bin/ask: example/ask.c bin/tim.a
|
|
||||||
$(CC) $< -Wall $(CFLAGS) bin/tim.a -o $@
|
|
||||||
bin/snek: example/snek.c bin/tim.a
|
|
||||||
$(CC) $< -Wall $(CFLAGS) bin/tim.a -o $@
|
|
||||||
|
|
||||||
bin/tim.a: bin \
|
|
||||||
obj/drawing.c.o obj/edit.c.o obj/event.c.o obj/loop.c.o obj/render.c.o \
|
|
||||||
obj/scope.c.o obj/string.c.o obj/unix.c.o obj/widgets.c.o obj/windows.c.o
|
|
||||||
ar rcs bin/tim.a \
|
|
||||||
obj/drawing.c.o obj/edit.c.o obj/event.c.o obj/loop.c.o obj/render.c.o \
|
|
||||||
obj/scope.c.o obj/string.c.o obj/unix.c.o obj/widgets.c.o obj/windows.c.o
|
|
||||||
|
|
||||||
obj/drawing.c.o: src/drawing.c obj
|
|
||||||
$(CC) $< -Wall $(CFLAGS) -c -o $@
|
|
||||||
obj/edit.c.o: src/edit.c obj
|
|
||||||
$(CC) $< -Wall $(CFLAGS) -c -o $@
|
|
||||||
obj/event.c.o: src/event.c obj
|
|
||||||
$(CC) $< -Wall $(CFLAGS) -c -o $@
|
|
||||||
obj/loop.c.o: src/loop.c obj
|
|
||||||
$(CC) $< -Wall $(CFLAGS) -c -o $@
|
|
||||||
obj/render.c.o: src/render.c obj
|
|
||||||
$(CC) $< -Wall $(CFLAGS) -c -o $@
|
|
||||||
obj/scope.c.o: src/scope.c obj
|
|
||||||
$(CC) $< -Wall $(CFLAGS) -c -o $@
|
|
||||||
obj/string.c.o: src/string.c obj
|
|
||||||
$(CC) $< -Wall $(CFLAGS) -c -o $@
|
|
||||||
obj/unix.c.o: src/unix.c obj
|
|
||||||
$(CC) $< -Wall $(CFLAGS) -c -o $@
|
|
||||||
obj/widgets.c.o: src/widgets.c obj
|
|
||||||
$(CC) $< -Wall $(CFLAGS) -c -o $@
|
|
||||||
obj/windows.c.o: src/windows.c obj
|
|
||||||
$(CC) $< -Wall $(CFLAGS) -c -o $@
|
|
||||||
|
|
||||||
bin:
|
|
||||||
mkdir -p bin
|
|
||||||
|
|
||||||
obj:
|
|
||||||
mkdir -p obj
|
|
||||||
|
|
||||||
clean:
|
|
||||||
rm -rf bin obj
|
|
||||||
140
project.config
Normal file
140
project.config
Normal file
@@ -0,0 +1,140 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
CBUILD_VERSION=2.3.2
|
||||||
|
|
||||||
|
PROJECT="tim"
|
||||||
|
CMP_C="gcc"
|
||||||
|
CMP_CPP="g++"
|
||||||
|
STD_C="c99"
|
||||||
|
STD_CPP="c++11"
|
||||||
|
WARN_C="-Wall -Wextra
|
||||||
|
-Wduplicated-branches
|
||||||
|
-Wduplicated-cond
|
||||||
|
-Wformat=2
|
||||||
|
-Wmissing-include-dirs
|
||||||
|
-Wshadow
|
||||||
|
-Werror=return-type
|
||||||
|
-Werror=pointer-arith
|
||||||
|
-Werror=init-self
|
||||||
|
-Werror=incompatible-pointer-types"
|
||||||
|
WARN_CPP="$WARN_C"
|
||||||
|
SRC_C="$(find src -name '*.c')"
|
||||||
|
SRC_CPP="$(find src -name '*.cpp')"
|
||||||
|
|
||||||
|
# Directory with dependency configs.
|
||||||
|
# See cbuild/example_dependency_configs
|
||||||
|
DEPENDENCY_CONFIGS_DIR='dependencies'
|
||||||
|
# List of dependency config files in DEPENDENCY_CONFIGS_DIR separated by space.
|
||||||
|
ENABLED_DEPENDENCIES=''
|
||||||
|
|
||||||
|
# OBJDIR structure:
|
||||||
|
# ├── objects/ - Compiled object files. Cleans on each call of build task
|
||||||
|
# ├── static_libs/ - Symbolic links to static libraries used by linker. Cleans on each call of build task.
|
||||||
|
# ├── static_libs/ - Symbolic links to dynamic libraries used by linker. Cleans on each call of build task.
|
||||||
|
# └── profile/ - gcc *.gcda profiling info files
|
||||||
|
OBJDIR="obj"
|
||||||
|
OUTDIR="bin"
|
||||||
|
STATIC_LIB_FILE="$PROJECT.a"
|
||||||
|
|
||||||
|
# example: "-I./include -I$DEPENDENCIES_DIR/libexample"
|
||||||
|
INCLUDE="-Iinclude -Isrc"
|
||||||
|
|
||||||
|
# OS-specific options
|
||||||
|
case "$OS" in
|
||||||
|
WINDOWS)
|
||||||
|
EXEC_FILE="snek.exe"
|
||||||
|
SHARED_LIB_FILE="$PROJECT.dll"
|
||||||
|
INCLUDE="$INCLUDE "
|
||||||
|
# example: "-lSDL2 -lSDL2_image"
|
||||||
|
LINKER_LIBS=""
|
||||||
|
;;
|
||||||
|
LINUX)
|
||||||
|
EXEC_FILE="snek"
|
||||||
|
SHARED_LIB_FILE="$PROJECT.so"
|
||||||
|
INCLUDE="$INCLUDE "
|
||||||
|
LINKER_LIBS=""
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
error "operating system $OS has no configuration variants"
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
# TASKS
|
||||||
|
case "$TASK" in
|
||||||
|
# creates executable using profiling info if it exists
|
||||||
|
build_exec)
|
||||||
|
SRC_C="$SRC_C example/snek.c"
|
||||||
|
# -flto applies more optimizations across object files
|
||||||
|
# -flto=auto is needed to multithreaded copilation
|
||||||
|
# -fuse-linker-plugin is required to use static libs with lto
|
||||||
|
# -fprofile-use enables compiler to use profiling info files to optimize executable
|
||||||
|
# -fprofile-prefix-path sets path where profiling info about objects are be saved
|
||||||
|
# -fdata-sections -ffunction-sections -Wl,--gc-sections removes unused code
|
||||||
|
C_ARGS="-O2 -flto=auto -fuse-linker-plugin -fprofile-use -fprofile-prefix-path=$(realpath $OBJDIR)/objects -fdata-sections -ffunction-sections -Wl,--gc-sections"
|
||||||
|
CPP_ARGS="$C_ARGS"
|
||||||
|
LINKER_ARGS="$CPP_ARGS $LINKER_LIBS"
|
||||||
|
PRE_TASK_SCRIPT=""
|
||||||
|
TASK_SCRIPT="@cbuild/default_tasks/build_exec.sh"
|
||||||
|
POST_TASK_SCRIPT="@cbuild/default_tasks/strip_exec.sh"
|
||||||
|
;;
|
||||||
|
# creates executable with debug info and no optimizations
|
||||||
|
build_exec_dbg)
|
||||||
|
SRC_C="$SRC_C example/snek.c"
|
||||||
|
C_ARGS="-O0 -g3"
|
||||||
|
CPP_ARGS="$C_ARGS"
|
||||||
|
LINKER_ARGS="$CPP_ARGS $LINKER_LIBS"
|
||||||
|
PRE_TASK_SCRIPT=""
|
||||||
|
TASK_SCRIPT="@cbuild/default_tasks/build_exec.sh"
|
||||||
|
POST_TASK_SCRIPT=""
|
||||||
|
;;
|
||||||
|
# creates shared library
|
||||||
|
build_shared_lib)
|
||||||
|
C_ARGS="-O2 -fpic -flto -shared"
|
||||||
|
CPP_ARGS="$C_ARGS"
|
||||||
|
LINKER_ARGS="$CPP_ARGS $LINKER_LIBS -Wl,-soname,$SHARED_LIB_FILE"
|
||||||
|
PRE_TASK_SCRIPT=""
|
||||||
|
TASK_SCRIPT="@cbuild/default_tasks/build_shared_lib.sh"
|
||||||
|
POST_TASK_SCRIPT=""
|
||||||
|
;;
|
||||||
|
# creates shared library with debug symbols and no optimizations
|
||||||
|
build_shared_lib_dbg)
|
||||||
|
C_ARGS="-O0 -g3 -fpic -shared"
|
||||||
|
CPP_ARGS="$C_ARGS"
|
||||||
|
LINKER_ARGS="$CPP_ARGS $LINKER_LIBS -Wl,-soname,$SHARED_LIB_FILE"
|
||||||
|
PRE_TASK_SCRIPT=""
|
||||||
|
TASK_SCRIPT="@cbuild/default_tasks/build_shared_lib.sh"
|
||||||
|
POST_TASK_SCRIPT=""
|
||||||
|
;;
|
||||||
|
# creates static library
|
||||||
|
build_static_lib)
|
||||||
|
C_ARGS="-O2 -fpic -fdata-sections -ffunction-sections"
|
||||||
|
CPP_ARGS="$C_ARGS"
|
||||||
|
PRE_TASK_SCRIPT=""
|
||||||
|
TASK_SCRIPT="@cbuild/default_tasks/build_static_lib.sh"
|
||||||
|
POST_TASK_SCRIPT=""
|
||||||
|
;;
|
||||||
|
# creates static library with debug symbols and no optimizations
|
||||||
|
build_static_lib_dbg)
|
||||||
|
C_ARGS="-O0 -g3"
|
||||||
|
CPP_ARGS="$C_ARGS"
|
||||||
|
PRE_TASK_SCRIPT=""
|
||||||
|
TASK_SCRIPT="@cbuild/default_tasks/build_static_lib.sh"
|
||||||
|
POST_TASK_SCRIPT=""
|
||||||
|
;;
|
||||||
|
# rebuilds specified dependencies
|
||||||
|
# EXAMPLE: `cbuild rebuild_dependencies=libexample1,fonts`
|
||||||
|
# 'all' can be specified to rebuild all dependencies
|
||||||
|
rebuild_dependencies)
|
||||||
|
TASK_SCRIPT="@cbuild/default_tasks/rebuild_dependencies.sh"
|
||||||
|
;;
|
||||||
|
# deletes generated files
|
||||||
|
clean)
|
||||||
|
TASK_SCRIPT="@cbuild/default_tasks/clean.sh"
|
||||||
|
;;
|
||||||
|
# nothing to do
|
||||||
|
"" | no_task)
|
||||||
|
;;
|
||||||
|
# unknown task
|
||||||
|
*)
|
||||||
|
error "task <$PROJECT/$TASK> not found"
|
||||||
|
;;
|
||||||
|
esac
|
||||||
11
project.config.user.default
Executable file
11
project.config.user.default
Executable file
@@ -0,0 +1,11 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
# Project user config is ignored by git.
|
||||||
|
# Here you can add variables that users might want to change
|
||||||
|
# on their local machine, without commiting to the repository.
|
||||||
|
|
||||||
|
# Directory where you install dependencies.
|
||||||
|
# Do not confuse with DEPENDENCY_CONFIGS_DIR
|
||||||
|
# Example:
|
||||||
|
# libexample source code is at `../libexample`, and dependency config
|
||||||
|
# that specifies how to build this lib is at `dependencies/libexample.config`
|
||||||
|
DEPENDENCIES_DIR=".."
|
||||||
Reference in New Issue
Block a user