ultimecia

A ps1 emulator in c
Log | Files | Refs

makefile (1470B)


      1 # ===========================================================
      2 # Ultimecia PSX Emulator Makefile (fixed obj directory)
      3 # ===========================================================
      4 
      5 # Compiler
      6 CC      := clang
      7 
      8 # Flags
      9 CFLAGS  := -std=c99 -O3 -g -Wall -Wextra -Werror -pedantic \
     10 		   -Ivendor $(shell /opt/homebrew/bin/pkg-config --cflags sdl2 lua) \
     11 					               -DLOG_USE_COLOR
     12 
     13 LDFLAGS := $(shell /opt/homebrew/bin/pkg-config --libs sdl2 lua)
     14 
     15 # Directories
     16 SRC_DIR := src
     17 OBJ_DIR := obj
     18 BIN_DIR := bin
     19 THIRD_DIR := vendor
     20 
     21 # Source files
     22 SRC := $(wildcard $(SRC_DIR)/**/*.c) $(wildcard $(SRC_DIR)/*.c) $(wildcard $(THIRD_DIR)/*.c)
     23 
     24 # Turn src/foo/bar.c → obj/foo/bar.o
     25 OBJ := $(patsubst $(SRC_DIR)/%.c,$(OBJ_DIR)/%.o,$(filter $(SRC_DIR)/%.c,$(SRC))) \
     26 	          $(patsubst $(THIRD_DIR)/%.c,$(OBJ_DIR)/vendor/%.o,$(filter $(THIRD_DIR)/%.c,$(SRC)))
     27 
     28 # Output binary
     29 BIN := $(BIN_DIR)/ultimecia
     30 
     31 # ===========================================================
     32 # Build rules
     33 # ===========================================================
     34 
     35 all: $(BIN)
     36 
     37 # Link binary
     38 $(BIN): $(OBJ)
     39 		@mkdir -p $(dir $@)
     40 			$(CC) $(OBJ) -o $@ $(LDFLAGS)
     41 
     42 # Compile .c → .o (preserve folder structure under obj/)
     43 $(OBJ_DIR)/%.o: $(SRC_DIR)/%.c
     44 		@mkdir -p $(dir $@)
     45 			$(CC) $(CFLAGS) -c $< -o $@
     46 
     47 # Compile third-party sources
     48 $(OBJ_DIR)/vendor/%.o: $(THIRD_DIR)/%.c
     49 		@mkdir -p $(dir $@)
     50 			$(CC) $(CFLAGS) -c $< -o $@
     51 
     52 
     53 clean:
     54 		rm -rf $(OBJ_DIR) $(BIN_DIR)
     55 
     56 .PHONY: all clean