Browse Source

Add Makefile and example main.c file

Evgeniy Parfenyuk 2 tháng trước cách đây
mục cha
commit
598bd03f60
2 tập tin đã thay đổi với 105 bổ sung0 xóa
  1. 77 0
      Makefile
  2. 28 0
      src/main.c

+ 77 - 0
Makefile

@@ -0,0 +1,77 @@
+# Compiler and flags
+CC = gcc
+CFLAGS = -Wall -Wextra -Wpedantic -Werror -std=c99 \
+	     -O2 -Iexternal/raylib/src
+LDFLAGS = -Lexternal/raylib/ -lraylib -lm -lpthread
+
+# Directories
+SRC_DIR = src
+OBJ_DIR = .obj
+RAYLIB_SRC_DIR = external/raylib/src
+RAYLIB_LIB = external/raylib/libraylib.a
+
+# Target executable
+TARGET = vinora 
+
+# Source and object files
+C_SOURCES = $(wildcard $(SRC_DIR)/*.c)
+OBJECTS = $(C_SOURCES:$(SRC_DIR)/%.c=$(OBJ_DIR)/%.o)
+
+# Default target
+all: $(TARGET)
+
+# Build Raylib library
+raylib: $(RAYLIB_LIB)
+
+$(RAYLIB_LIB):
+	@echo 
+	@echo "BUILDING RAYLIB..."
+	@echo
+	$(MAKE) -C $(RAYLIB_SRC_DIR) 
+
+# Goal to download raylib binary from Github
+fetch-raylib:
+	@echo "Downloading Raylib from GitHub..."
+	@mkdir -p external/raylib
+	@cd external && \
+	if [ "$$(uname -s)" = "Linux" ]; then \
+		if [ "$$(uname -m)" = "x86_64" ]; then \
+			wget https://github.com/raysan5/raylib/releases/download/5.5/raylib-5.5_linux_amd64.tar.gz && \
+			tar -xzf raylib-5.5_linux_amd64.tar.gz && mv raylib-5.5_linux_amd64/lib/libraylib.a raylib/ && rm -rf raylib-5.5_linux_amd64 raylib-5.5_linux_amd64.tar.gz; \
+		else \
+			wget https://github.com/raysan5/raylib/releases/download/5.5/raylib-5.5_linux_i386.tar.gz && \
+			tar -xzf raylib-5.5_linux_i386.tar.gz && mv raylib-5.5_linux_i386/lib/libraylib.a raylib/ && rm -rf raylib-5.5_linux_i386 raylib-5.5_linux_i386.tar.gz; \
+		fi \
+	else \
+		if [ "$$(uname -s)" = "Darwin" ]; then \
+			wget https://github.com/raysan5/raylib/releases/download/5.5/raylib-5.5_macos.tar.gz && \
+			tar -xzf raylib-5.5_macos.tar.gz && mv raylib-5.5_macos/lib/libraylib.a raylib/ && rm -rf raylib-5.5_macos raylib-5.5_macos.tar.gz; \
+		else \
+			echo "Unsupported OS"; exit 1; \
+		fi \
+	fi
+
+
+# Link object files to create executable
+$(TARGET): $(OBJECTS) | $(RAYLIB_LIB) $(OBJ_DIR)
+	$(CC) $(OBJECTS) -o $@ $(LDFLAGS)
+
+# Compile C source files
+$(OBJ_DIR)/%.o: $(SRC_DIR)/%.c | $(OBJ_DIR)
+	$(CC) $(CFLAGS) -c $< -o $@
+
+# Create object directory if it doesn't exist
+$(OBJ_DIR):
+	mkdir -p $(OBJ_DIR)
+
+run: $(TARGET)
+	./$(TARGET)
+
+# Clean up
+clean:
+	rm -rf $(OBJ_DIR) $(TARGET)
+	$(MAKE) -C $(RAYLIB_SRC_DIR) clean
+	rm -f $(RAYLIB_LIB)
+
+# Phony targets
+.PHONY: all clean run raylib

+ 28 - 0
src/main.c

@@ -0,0 +1,28 @@
+#include <raylib.h>
+#include <string.h>
+
+int main(void)
+{
+    const int screenWidth = 800;
+    const int screenHeight = 600;
+
+    InitWindow(screenWidth, screenHeight,
+               "Vinora Engine");
+
+    SetTargetFPS(60);   
+    
+    char *text = "Hello, World!";
+    while (!WindowShouldClose())   
+    {
+        BeginDrawing();
+            ClearBackground(RAYWHITE);
+            DrawText(text, screenWidth/2  - (strlen(text)*40/2)/2,
+                           screenHeight/2 - 40, 40, GRAY);
+
+        EndDrawing();
+    }
+
+    CloseWindow(); 
+
+    return 0;
+}