summary refs log tree commit diff
path: root/Makefile
blob: 6a009dca9f02fba6679f0df08a7160486339d3b6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
UNAME_S = $(shell uname -s)
CC = clang
CFLAGS = -Wall -Wextra -std=c11
CFLAGS_DEBUG = $(CFLAGS) -g -O0
CFLAGS_RELEASE = $(CFLAGS) -O2
TARGET = ogl
SRC_DIR = src
VENDOR_DIR = vendor
OUT_DIR = out
LIBS = -lglfw -lGLEW -lcglm
DEBUG_DIR = $(OUT_DIR)/debug
RELEASE_DIR = $(OUT_DIR)/release
INSTALL_DIR = /usr/local/bin

# Find all .c files in the src directory
SRCS = $(wildcard $(SRC_DIR)/*.c)

# Generate lists of object files for debug and release builds
OBJS_DEBUG = $(patsubst $(SRC_DIR)/%.c,$(DEBUG_DIR)/%.o,$(SRCS))
OBJS_RELEASE = $(patsubst $(SRC_DIR)/%.c,$(RELEASE_DIR)/%.o,$(SRCS))

# Include paths for vendor libraries
INCLUDES = $(addprefix -I,$(VENDOR_DIR) $(wildcard $(VENDOR_DIR)/*/))

ifeq ($(UNAME_S), Darwin)
    LIBS += -framework OpenGL 
endif
ifeq ($(UNAME_S), Linux)
    LDFLAGS += -lGL
endif

all: debug release

debug: $(DEBUG_DIR)/$(TARGET)
release: $(RELEASE_DIR)/$(TARGET)

# Debug build
$(DEBUG_DIR)/$(TARGET): $(OBJS_DEBUG) | $(DEBUG_DIR)
	$(CC) $(CFLAGS_DEBUG) $(INCLUDES) $(LIBS) -o $@ $(OBJS_DEBUG)

$(DEBUG_DIR)/%.o: $(SRC_DIR)/%.c | $(DEBUG_DIR)
	$(CC) $(CFLAGS_DEBUG) $(INCLUDES) -c $< -o $@

# Release build
$(RELEASE_DIR)/$(TARGET): $(OBJS_RELEASE) | $(RELEASE_DIR)
	$(CC) $(CFLAGS_RELEASE) $(INCLUDES) $(LIBS) -o $@ $(OBJS_RELEASE)

$(RELEASE_DIR)/%.o: $(SRC_DIR)/%.c | $(RELEASE_DIR)
	$(CC) $(CFLAGS_RELEASE) $(INCLUDES) -c $< -o $@

$(DEBUG_DIR) $(RELEASE_DIR):
	mkdir -p $@

clean:
	rm -rf $(OUT_DIR)

install: $(RELEASE_DIR)/$(TARGET)
	install -m 755 $< $(INSTALL_DIR)

.PHONY: all debug release clean install