-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
89 lines (72 loc) · 1.95 KB
/
Makefile
File metadata and controls
89 lines (72 loc) · 1.95 KB
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
CC = cc
# Detect operating system
UNAME_S := $(shell uname -s)
# SDL2 configuration
SDL_CONFIG := $(shell which sdl2-config 2>/dev/null)
ifeq ($(SDL_CONFIG),)
SDL_CONFIG := $(shell which sdl-config 2>/dev/null)
endif
SDL_CFLAGS ?= $(if $(SDL_CONFIG),$(shell $(SDL_CONFIG) --cflags 2>/dev/null))
SDL_LIBS ?= $(if $(SDL_CONFIG),$(shell $(SDL_CONFIG) --libs 2>/dev/null))
ifeq ($(SDL_CFLAGS),)
SDL_CFLAGS := $(shell pkg-config --cflags sdl2 2>/dev/null)
SDL_LIBS := $(shell pkg-config --libs sdl2 2>/dev/null)
endif
# macOS Homebrew support
ifeq ($(UNAME_S),Darwin)
# Check for Homebrew installation paths
# Apple Silicon Macs
ifneq (,$(wildcard /opt/homebrew/include))
SDL_CFLAGS += -I/opt/homebrew/include
SDL_LIBS += -L/opt/homebrew/lib
endif
# Intel Macs
ifneq (,$(wildcard /usr/local/include))
SDL_CFLAGS += -I/usr/local/include
SDL_LIBS += -L/usr/local/lib
endif
endif
ifneq ($(SDL_CFLAGS),)
CFLAGS += $(SDL_CFLAGS)
endif
ifneq ($(SDL_LIBS),)
LDFLAGS += $(SDL_LIBS)
endif
# Include directories
CFLAGS += -std=c11 -Wall -Wextra -pedantic -O2 -Isrc -Iinclude
# Platform-specific linker flags
ifeq ($(UNAME_S),Darwin)
LDFLAGS += -lm
else
LDFLAGS += -lm -lutil
endif
TARGET = tty-space-station
MAPEDITOR = mapeditor
# Source files
SOURCES = src/main.c \
src/game.c \
src/player.c \
src/map.c \
src/cabinet.c \
src/display.c \
src/terminal.c \
src/renderer.c \
src/ui.c \
src/texture.c \
src/utils.c
# Object files
OBJECTS = $(SOURCES:.c=.o)
.PHONY: all clean run editor
all: $(TARGET) $(MAPEDITOR)
$(TARGET): $(OBJECTS)
$(CC) $(OBJECTS) $(LDFLAGS) -o $(TARGET)
$(MAPEDITOR): tools/mapeditor.c
$(CC) $(CFLAGS) tools/mapeditor.c $(LDFLAGS) -o $(MAPEDITOR)
%.o: %.c
$(CC) $(CFLAGS) -c $< -o $@
run: $(TARGET)
./$(TARGET)
editor: $(MAPEDITOR)
./$(MAPEDITOR) maps/palace.map
clean:
rm -f $(TARGET) $(MAPEDITOR) $(OBJECTS)