-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
56 lines (39 loc) · 1.04 KB
/
Makefile
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
#Thanks to https://www.matansilver.com/2017/08/29/universal-makefile/
CC = gcc
TARGET_EXEC ?= JEngine
BUILD_DIR ?= bin
SRC_DIRS ?= src lib
#Thanks to https://stackoverflow.com/a/18258352
rwildcard=$(foreach d,$(wildcard $(1:=/*)),$(call rwildcard,$d,$2) $(filter $(subst *,%,$2),$d))
SRCS := $(call rwildcard,$(SRC_DIRS),*.cpp *.c)
OBJS := $(SRCS:%=$(BUILD_DIR)/%.o)
CFLAGS = -I./src -I. -I./lib -O0 -g3
CXXFLAGS = -std=c++14
LDFLAGS =
#if shared library target
#CFLAGS += -shared -undefined dynamic_lookup
ifeq ($(OS),Windows_NT)
#Windows
LDFLAGS += -lgdi32 -lopengl32
else
#Linux
LDFLAGS += -lX11 -lGL
endif
all: $(BUILD_DIR)/$(TARGET_EXEC)
# main target (C++)
$(BUILD_DIR)/$(TARGET_EXEC): $(OBJS)
$(CXX) $(OBJS) -o $@ $(LDFLAGS)
# c source
$(BUILD_DIR)/%.c.o: %.c
$(MKDIR_P) $(dir $@)
$(CC) $(CFLAGS) -c $< -o $@
# c++ source
$(BUILD_DIR)/%.cpp.o: %.cpp
$(MKDIR_P) $(dir $@)
$(CXX) $(CFLAGS) $(CXXFLAGS) -c $< -o $@
.PHONY: clean run all
clean:
$(RM) -r $(BUILD_DIR)
MKDIR_P ?= mkdir -p
run: $(BIN)
./$(BUILD_DIR)/$(TARGET_EXEC)