-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
65 lines (46 loc) · 1.96 KB
/
Makefile
File metadata and controls
65 lines (46 loc) · 1.96 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
# SPDX-FileCopyrightText: 2026 SombrAbsol
#
# SPDX-License-Identifier: MIT
CC := $(shell command -v clang >/dev/null 2>&1 && echo clang || echo gcc)
STRIP := $(shell command -v llvm-strip >/dev/null 2>&1 && echo llvm-strip || echo strip)
CFLAGS := -O3 -Wall -Wextra -Werror -MMD -MP
CPPFLAGS := -I include
LDFLAGS :=
LDLIBS :=
SRC_DIR := src
BUILD_DIR := build
PREFIX := /usr/local
TARGET_NAMES := ra2mes ra3mes
EXTENSION := $(if $(filter Windows_NT,$(OS)),.exe)
COMMON_SRCS := $(wildcard $(SRC_DIR)/common/*.c)
COMMON_OBJS := $(patsubst $(SRC_DIR)/common/%.c,$(BUILD_DIR)/common.dir/%.o,$(COMMON_SRCS))
COMMON_DEPS := $(COMMON_OBJS:.o=.d)
.PHONY: all clean install uninstall release $(TARGET_NAMES)
all: $(addprefix $(BUILD_DIR)/,$(addsuffix $(EXTENSION),$(TARGET_NAMES)))
define RULES
$(1): $(BUILD_DIR)/$(1)$(EXTENSION)
$(BUILD_DIR)/$(1)$(EXTENSION): $$(patsubst $(SRC_DIR)/$(1)/%.c,$(BUILD_DIR)/$(1).dir/%.o,$$(wildcard $(SRC_DIR)/$(1)/*.c)) $(COMMON_OBJS)
$(CC) $(LDFLAGS) -o $$@ $$^ $(LDLIBS)
$(BUILD_DIR)/$(1).dir/%.o: $(SRC_DIR)/$(1)/%.c | $(BUILD_DIR)/$(1).dir
$(CC) $(CFLAGS) $(CPPFLAGS) -c $$< -o $$@
$(BUILD_DIR)/$(1).dir:
mkdir -p $$@
DEPS_$(1) := $$(patsubst $(SRC_DIR)/$(1)/%.c,$(BUILD_DIR)/$(1).dir/%.d,$$(wildcard $(SRC_DIR)/$(1)/*.c))
-include $$(DEPS_$(1))
endef
$(foreach t,$(TARGET_NAMES),$(eval $(call RULES,$(t))))
$(BUILD_DIR)/common.dir/%.o: $(SRC_DIR)/common/%.c | $(BUILD_DIR)/common.dir
$(CC) $(CFLAGS) $(CPPFLAGS) -c $< -o $@
$(BUILD_DIR)/common.dir:
mkdir -p $@
-include $(COMMON_DEPS)
release: all
$(foreach t,$(TARGET_NAMES),$(STRIP) $(BUILD_DIR)/$(t)$(EXTENSION);)
install: all
install -d $(DESTDIR)$(PREFIX)/bin
$(foreach t,$(TARGET_NAMES),install -m 755 $(BUILD_DIR)/$(t)$(EXTENSION) $(DESTDIR)$(PREFIX)/bin/$(t)$(EXTENSION);)
$(foreach t,$(TARGET_NAMES),$(STRIP) $(DESTDIR)$(PREFIX)/bin/$(t)$(EXTENSION);)
uninstall:
$(foreach t,$(TARGET_NAMES),rm -f $(DESTDIR)$(PREFIX)/bin/$(t)$(EXTENSION);)
clean:
rm -rf $(BUILD_DIR)