aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gitignore1
-rw-r--r--Makefile31
-rw-r--r--Makefile.dep30
-rwxr-xr-xbuild.sh68
-rw-r--r--config.def.mk22
5 files changed, 84 insertions, 68 deletions
diff --git a/.gitignore b/.gitignore
index 0eb6564..21d0083 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,4 +1,5 @@
*.[ao]
*.so
*~
+config.mk
demonchime
diff --git a/Makefile b/Makefile
new file mode 100644
index 0000000..a5d1c86
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,31 @@
+include config.mk
+
+SRC=$(wildcard **/*.c)
+SRC+=$(wildcard teensy/platform/${PLATFORM}/**/*.c)
+SRC+=$(wildcard teensy/platform/${PLATFORM}/*.c)
+OBJ=$(SRC:%.c=.obj/%.o)
+
+.PHONY: all run clean
+
+all: Makefile.dep ${OUT}
+
+${OUT}: ${OBJ}
+ ${CC} -o $@ ${LDFLAGS} ${OBJ}
+
+.obj/%.o: %.c
+ @mkdir -p ${@D}
+ ${CC} -c -o $@ ${CFLAGS} $<
+
+config.mk:
+ cp config.def.mk config.mk
+
+Makefile.dep: ${SRC}
+ ${CC} ${CFLAGS} ${SRC} -MM > $@
+
+run: all
+ ${RUN_CMD} ./${OUT}
+
+clean:
+ rm -f ${OBJ} ${OUT}
+
+include Makefile.dep
diff --git a/Makefile.dep b/Makefile.dep
new file mode 100644
index 0000000..b4778de
--- /dev/null
+++ b/Makefile.dep
@@ -0,0 +1,30 @@
+dc.o: dc/dc.c teensy/teensy.h teensy/teensy_common.h teensy/teensy_log.h \
+ teensy/teensy_mem.h teensy/teensy_list.h teensy/teensy_ui.h \
+ teensy/teensy.h dc/third/qoi.h
+teensy_common.o: teensy/teensy_common.c teensy/teensy_common.h \
+ teensy/teensy_log.h teensy/teensy_mem.h
+teensy_context.o: teensy/teensy_context.c teensy/teensy_context.h \
+ teensy/teensy_common.h teensy/teensy_log.h teensy/teensy_mem.h \
+ teensy/teensy_renderer.h teensy/teensy.h teensy/teensy_list.h \
+ teensy/teensy_platform.h
+teensy_list.o: teensy/teensy_list.c teensy/teensy_list.h \
+ teensy/teensy_common.h teensy/teensy_log.h teensy/teensy_mem.h
+teensy_log.o: teensy/teensy_log.c teensy/teensy_log.h \
+ teensy/teensy_common.h teensy/teensy_mem.h
+teensy_math.o: teensy/teensy_math.c teensy/teensy.h \
+ teensy/teensy_common.h teensy/teensy_log.h teensy/teensy_mem.h \
+ teensy/teensy_list.h
+teensy_mem.o: teensy/teensy_mem.c teensy/teensy_mem.h \
+ teensy/teensy_common.h teensy/teensy_log.h teensy/teensy_list.h
+teensy_renderer.o: teensy/teensy_renderer.c teensy/teensy_renderer.h \
+ teensy/teensy_common.h teensy/teensy_log.h teensy/teensy_mem.h \
+ teensy/teensy.h teensy/teensy_list.h teensy/teensy_context.h
+teensy_ui.o: teensy/teensy_ui.c teensy/teensy_ui.h teensy/teensy_common.h \
+ teensy/teensy_log.h teensy/teensy_mem.h teensy/teensy.h \
+ teensy/teensy_list.h
+glad.o: teensy/platform/gl/glad/glad.c teensy/platform/gl/glad/glad.h
+gl.o: teensy/platform/gl/gl.c teensy/platform/gl/glad/glad.h \
+ teensy/platform/gl/GLFW/glfw3.h teensy/teensy.h teensy/teensy_common.h \
+ teensy/teensy_log.h teensy/teensy_mem.h teensy/teensy_list.h \
+ teensy/teensy_common.h teensy/teensy_platform.h teensy/teensy.h \
+ teensy/teensy_context.h teensy/teensy_renderer.h
diff --git a/build.sh b/build.sh
deleted file mode 100755
index 2690406..0000000
--- a/build.sh
+++ /dev/null
@@ -1,68 +0,0 @@
-#!/bin/bash
-
-cc=cc
-cflags=(-Wall -Wextra -std=c99 -D_XOPEN_SOURCE=700 -O2)
-ldflags=(-lm)
-
-platform=gl
-debug=
-run=
-clean=
-tags=
-
-for flag in $@; do
- case "$flag" in
- '-run') run=true ;;
- '-debug') debug=true ;;
- '-clean') clean=true ;;
- '-use-x11') platform=x11 ;;
- '-use-gl') platform=gl ;;
- esac
-done
-
-if [ ! -z "$clean" ]; then
- rm demonchime
- rm libteensy.so
- exit
-fi
-
-[ ! -z "$debug" ] && cflags+=(-g -ggdb -rdynamic)
-
-teensy_cflags=(${cflags[@]} -fPIC -Iteensy -Iteensy/platform/$platform)
-[ ! -z "$debug" ] && teensy_cflags+=(-DTEENSY_DEBUG)
-teensy_ldflags=(${ldflags[@]})
-
-case "$platform" in
- 'x11')
- teensy_ldflags+=(-lX11)
- ;;
- 'gl')
- teensy_ldflags+=(./libglfw3.a)
- ;;
-esac
-
-dc_cflags=(${cflags[@]} -Iteensy -Idc)
-[ ! -z "$debug" ] && teensy_cflags+=(-DDC_DEBUG)
-dc_ldflags=(${ldflags[@]} -L. -l:libteensy.so -Wl,-rpath,$PWD)
-
-dc_src=$(find dc -name '*.c')
-teensy_src=$(find teensy -name '*.c' -not -path '*platform*')
-platform_src=$(find teensy/platform/$platform -name '*.c')
-
-echo -e "dc:\t\t$(tr '\n' ' ' <<< "$dc_src")"
-echo -e "teensy:\t\t$(tr '\n' ' ' <<< "$teensy_src")"
-echo -e "platform:\t$(tr '\n' ' ' <<< "$platform_src")"
-
-time (
- set -x
- $cc -shared -o libteensy.so \
- ${teensy_src[@]} ${platform_src[@]} \
- ${teensy_ldflags[@]} \
- ${teensy_cflags[@]} || exit 1
- $cc -o demonchime \
- ${dc_src[@]} \
- ${dc_ldflags[@]} \
- ${dc_cflags[@]} || exit 1
-)
-
-[ $? -eq 0 ] && [ ! -z "$run" ] && $RUN_CMD ./demonchime
diff --git a/config.def.mk b/config.def.mk
new file mode 100644
index 0000000..f2821ab
--- /dev/null
+++ b/config.def.mk
@@ -0,0 +1,22 @@
+CC=cc
+PLATFORM=gl
+
+OUT=demonchime
+
+DBFLAGS=-g -ggdb -rdynamic -DTEENSY_DEBUG
+
+INCS=-Iteensy -Iteensy/platform/${PLATFORM}
+CFLAGS=${INCS} -Wall -Wextra -std=c99 -D_XOPEN_SOURCE=700 -O2
+LDFLAGS=-lm
+
+ifeq (${CONFIG},debug)
+ CFLAGS+=${DBFLAGS}
+endif
+
+ifeq (${PLATFORM},gl)
+ LDFLAGS+=-lglfw
+endif
+
+ifeq (${PLATFORM},x11)
+ LDFLAGS+=-lX11
+endif