diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..8ec4d91 --- /dev/null +++ b/Makefile @@ -0,0 +1,55 @@ +# raylib is built as a static library. After changing its build flags, run +# `make clean` so its objects are rebuilt with the new flags. + +SEXC ?= sexc +CC ?= cc + +BUILD_DIR := build +RAYLIB_LIB := $(BUILD_DIR)/libraylib.a + +RAYLIB_PLATFORM ?= PLATFORM_DESKTOP +RAYLIB_BUILD_MODE ?= RELEASE + +CFLAGS ?= -O2 -g + +RAYLIB_SRC := third-party/raylib/src +RAYGUI_SRC := third-party/raygui/src +RAYTMX_SRC := third-party/raytmx + +INCLUDES := -I$(RAYLIB_SRC) -I$(RAYGUI_SRC) -I$(RAYTMX_SRC) -I$(RAYTMX_SRC)/external + +UNAME_S := $(shell uname -s) +ifeq ($(UNAME_S),Darwin) + RAYLIB_LIBS := -framework OpenGL -framework Cocoa -framework IOKit \ + -framework CoreAudio -framework CoreVideo +else + RAYLIB_LIBS := -lGL -lm -lpthread -ldl -lrt -lX11 +endif + +OBJECTS := main.o + +all: catch-phase + +catch-phase: $(OBJECTS) $(RAYLIB_LIB) + $(CC) $(LDFLAGS) -o $@ $(OBJECTS) $(RAYLIB_LIB) $(RAYLIB_LIBS) + +$(BUILD_DIR): + mkdir -p $@ + +main.o: main.sex | $(OBJ_DIR) + $(SEXC) $< -c -o $@ -- $(CFLAGS) $(INCLUDES) + +# raylib ------------------------------------------------------------ +$(RAYLIB_LIB): + $(MAKE) -C $(RAYLIB_SRC) \ + PLATFORM=$(RAYLIB_PLATFORM) \ + RAYLIB_LIBTYPE=STATIC \ + RAYLIB_BUILD_MODE=$(RAYLIB_BUILD_MODE) \ + RAYLIB_RELEASE_PATH=$(abspath $(BUILD_DIR)) + +clean: + $(MAKE) -C $(RAYLIB_SRC) clean + rm -rf $(BUILD_DIR) + rm -f catch-phase + +.PHONY: all clean diff --git a/main.sex b/main.sex new file mode 100644 index 0000000..af0f93c --- /dev/null +++ b/main.sex @@ -0,0 +1,27 @@ +(include raylib.h) + +(define WIN-WIDTH 1440) +(define WIN-HEIGHT 900) + +(defmacro (call-and-check test msg code fn . args) + `(do + (,fn ,@args) + (if (! (,test)) + (do + (TraceLog LOG-ERROR ,msg) + (return ,code))))) + +(pub fn main ((argc int) (argv [* const char])) int + (TraceLog LOG-INFO "hello from Catch-Phase! initializing resources...") + (call-and-check IsWindowReady "failed to create window" 1 + InitWindow WIN-WIDTH WIN-HEIGHT "Catch-Phase") + (call-and-check IsAudioDeviceReady "failed to init audio" 2 + InitAudioDevice) + (while (! (WindowShouldClose)) + (BeginDrawing) + (ClearBackground BLACK) + (DrawCircle (/ WIN-WIDTH 2) (/ WIN-HEIGHT 2) 100.0f RAYWHITE) + (EndDrawing)) + (CloseAudioDevice) + (CloseWindow) + (return 0))