From 95aecd2be930ffa72350a06c10480bf0c9ea5546 Mon Sep 17 00:00:00 2001 From: xolatile Date: Fri, 29 Dec 2023 07:41:35 -0500 Subject: [PATCH] Making... --- make.sh | 44 ++++++++++++++++++++++++++++++++++++++++++++ makefile | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 77 insertions(+) create mode 100644 make.sh create mode 100644 makefile diff --git a/make.sh b/make.sh new file mode 100644 index 0000000..6d2ff7a --- /dev/null +++ b/make.sh @@ -0,0 +1,44 @@ +#!/bin/bash + +set -xe + +CC=clang +CFLAGS="-std=gnu17 -Weverything -Werror" +LDLIBS="-lraylib" + +TARGET=umorna + +build_type="$1" + +if [ -z "$build_type" ] || \ + [ "$build_type" = debug ]; then + CFLAGS+=" -O0 -g" +elif [ "$build_type" = "release" ]; then + CFLAGS+=" -O3 -flto" +fi + +sources=( + "source/engine.c" + "source/render.c" + "source/game.c" + "source/menu.c" + "source/main.c" +) + +objects=() + +updated="" + +for source in "${sources[@]}"; do + obj="${source%.*}.o" + objects+=("$obj") + + if [ "$source" -nt "$obj" ]; then + "$CC" $CFLAGS -c "$source" -o "$obj" + updated="y" + fi +done + +if [ ! -f "$TARGET" ] || [ -n "$updated" ]; then + "$CC" $CFLAGS $LDLIBS "${objects[@]}" -o "$TARGET" +fi diff --git a/makefile b/makefile new file mode 100644 index 0000000..d29f106 --- /dev/null +++ b/makefile @@ -0,0 +1,33 @@ +.PHONY: all debug release clean + +CFLAGS := -std=gnu17 -pedantic -Wall -Wextra ${CFLAGS} +LDLIBS := + +sources := source/engine.c \ + source/game.c \ + source/main.c \ + source/menu.c \ + source/render.c \ + source/source.c \ + source/system.c + +obj = ${sources:.c=.o} +dep = ${sources:.c=.d} + +.c.o: + $(CC) -MD -MP $(CFLAGS) -c $< -o $@ + +all: debug + +debug: CFLAGS += -g +release: CFLAGS += -O3 + +debug release: umorna + +umorna: $(obj) + $(CC) $(LDLIBS) $< -o $@ + +clean: + rm -f umorna ${obj} ${dep} + +-include ${dep}