-
Notifications
You must be signed in to change notification settings - Fork 0
/
makefile
81 lines (66 loc) · 1.87 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
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
ifeq ($(OS),Windows_NT) # is Windows_NT on XP, 2000, 7, Vista, 10...
detected_OS := Windows
else
detected_OS := $(shell uname) # same as "uname -s"
endif
# path macros
BIN_PATH := bin
OBJ_PATH := obj
SRC_PATH := src
INC_PATH := inc
# tool macros
CC := gcc
CCFLAGS := \
-O3 -fPIC -I $(INC_PATH) -Wall -Wextra -Wfloat-equal -Wundef -Wshadow \
-Wpointer-arith -Wcast-align -Wstrict-prototypes -Wstrict-overflow=5 \
-Wformat=2 -Wwrite-strings -Waggregate-return -Wcast-qual -Wswitch-default \
-Wswitch-enum -Wconversion -Wunreachable-code
ifeq ($(detected_OS),Darwin ) # Space in "Darwin " is required
CCFLAGS := $(CCFLAGS) -target x86_64-apple-macos12.1
endif
CCOBJFLAGS := $(CCFLAGS) -c
# compile macros
TARGET_NAME := main
ifeq ($(detected_OS),Windows)
TARGET_NAME := $(addsuffix .dll,$(TARGET_NAME))
endif
TARGET := $(BIN_PATH)/$(TARGET_NAME)
# src files & obj files
SRC := $(foreach x, $(SRC_PATH), $(wildcard $(addprefix $(x)/*,.c*)))
OBJ := $(addprefix $(OBJ_PATH)/, $(addsuffix .o, $(notdir $(basename $(SRC)))))
# clean files list
DISTCLEAN_LIST := $(OBJ)
CLEAN_LIST := $(TARGET) \
$(DISTCLEAN_LIST)
CLEAN := @rm -f $(CLEAN_LIST)
DISTCLEAN := @rm -f $(DISTCLEAN_LIST)
ifeq ($(detected_OS),Windows)
SHELL := powershell.exe
.SHELLFLAGS := -NoProfile -Command
CLEAN := "$(CLEAN_LIST)" -split " " | ForEach-Object {Remove-Item $$_}
DISTCLEAN := "$(DISTCLEAN_LIST)" -split " " | ForEach-Object {Remove-Item $$_}
endif
# default rule
default: all
# non-phony targets
$(TARGET): $(OBJ)
$(CC) $(CCFLAGS) -shared -o $@ $(OBJ)
$(OBJ_PATH)/%.o: $(SRC_PATH)/%.c*
$(CC) $(CCOBJFLAGS) -o $@ $<
# phony rules
# .PHONY: makedir
# makedir:
# @mkdir -p $(BIN_PATH) $(OBJ_PATH) $(DBG_PATH)
.PHONY: all
all: $(TARGET)
.PHONY: clean
clean:
@echo CLEAN $(CLEAN_LIST);
$(CLEAN)
.PHONY: distclean
distclean:
@echo CLEAN $(DISTCLEAN_LIST);
$(DISTCLEAN)
.PHONEY: os
os:
echo "$(detected_OS)"