-
Notifications
You must be signed in to change notification settings - Fork 3
/
Makefile
165 lines (124 loc) · 3.48 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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
# SPDX-License-Identifier: CC0-1.0
#
# SPDX-FileContributor: Antonio Niño Díaz, 2023-2024
# Source code paths
# -----------------
INCLUDEDIRS := cldib extlib libgrit libplum srcgrit
# Source files
# ------------
SOURCES_C := \
libplum/libplum.c
SOURCES_CPP := \
cldib/cldib_adjust.cpp \
cldib/cldib_conv.cpp \
cldib/cldib_core.cpp \
cldib/cldib_tmap.cpp \
cldib/cldib_tools.cpp \
cldib/cldib_wu.cpp \
libgrit/cprs.cpp \
libgrit/cprs_huff.cpp \
libgrit/cprs_lz.cpp \
libgrit/cprs_rle.cpp \
libgrit/grit_core.cpp \
libgrit/grit_misc.cpp \
libgrit/grit_prep.cpp \
libgrit/grit_shared.cpp \
libgrit/grit_xp.cpp \
libgrit/logger.cpp \
libgrit/pathfun.cpp \
extlib/plum.cpp \
srcgrit/cli.cpp \
srcgrit/grit_main.cpp
# Defines passed to all files
# ---------------------------
DEFINES := -DPACKAGE_VERSION=\"0.9.2\"
# Libraries
# ---------
LIBS :=
LIBDIRS :=
# Build artifacts
# ---------------
NAME := grit
BUILDDIR := build
ELF := $(NAME)
# Tools
# -----
STRIP := -s
BINMODE := 755
HOSTCC ?= gcc
HOSTCXX ?= g++
CP := cp
MKDIR := mkdir
RM := rm -rf
MAKE := make
INSTALL := install
# Verbose flag
# ------------
ifeq ($(VERBOSE),1)
V :=
else
V := @
endif
# Compiler and linker flags
# -------------------------
WARNFLAGS_C := -Wall \
-Wno-maybe-uninitialized -Wno-dangling-else -Wno-parentheses
# As of GCC 14, implicit function declarations are considered errors.
# However, libplum in some cases tries to call the C11 standard function
# aligned_alloc, which is not provided on MinGW nor is it necessary there.
# This is a workaround which demotes the relevant error back to a warning.
# If it ever becomes necessary, the linking will fail regardless.
WARNFLAGS_C += -Wno-implicit-function-declaration
WARNFLAGS_CXX := -Wall -Wno-misleading-indentation -Wno-unused-result \
-Wno-comment -Wno-unused-variable -Wno-sign-compare \
-Wno-parentheses -Wno-format-truncation \
-Wno-class-memaccess -Wno-unused-value \
-Wno-unused-but-set-variable -Wno-maybe-uninitialized
ifeq ($(SOURCES_CPP),)
HOSTLD := $(HOSTCC)
else
HOSTLD := $(HOSTCXX)
endif
INCLUDEFLAGS := $(foreach path,$(INCLUDEDIRS),-I$(path)) \
$(foreach path,$(LIBDIRS),-I$(path)/include)
LIBDIRSFLAGS := $(foreach path,$(LIBDIRS),-L$(path)/lib)
CFLAGS += -std=gnu17 $(WARNFLAGS_C) $(DEFINES) $(INCLUDEFLAGS) -O3
CXXFLAGS += -std=gnu++14 $(WARNFLAGS_CXX) $(DEFINES) $(INCLUDEFLAGS) -O3
LDFLAGS := $(LIBDIRSFLAGS) $(LIBS)
# Intermediate build files
# ------------------------
OBJS := $(addsuffix .o,$(addprefix $(BUILDDIR)/,$(SOURCES_C))) \
$(addsuffix .o,$(addprefix $(BUILDDIR)/,$(SOURCES_CPP)))
DEPS := $(OBJS:.o=.d)
# Targets
# -------
.PHONY: all clean install
all: $(ELF)
$(ELF): $(OBJS)
@echo " HOSTLD $@"
$(V)$(HOSTLD) -o $@ $(OBJS) $(LDFLAGS)
clean:
@echo " CLEAN "
$(V)$(RM) $(ELF) $(BUILDDIR)
INSTALLDIR ?= /opt/blocksds/core/tools/grit
INSTALLDIR_ABS := $(abspath $(INSTALLDIR))
install: all
@echo " INSTALL $(INSTALLDIR_ABS)"
@test $(INSTALLDIR_ABS)
$(V)$(RM) $(INSTALLDIR_ABS)
$(V)$(INSTALL) -d $(INSTALLDIR_ABS)
$(V)$(INSTALL) $(STRIP) -m $(BINMODE) $(NAME) $(INSTALLDIR_ABS)
$(V)$(CP) COPYING $(INSTALLDIR_ABS)
# Rules
# -----
$(BUILDDIR)/%.c.o : %.c
@echo " HOSTCC $<"
@$(MKDIR) -p $(@D)
$(V)$(HOSTCC) $(CFLAGS) -MMD -MP -c -o $@ $<
$(BUILDDIR)/%.cpp.o : %.cpp
@echo " HOSTCXX $<"
@$(MKDIR) -p $(@D)
$(V)$(HOSTCXX) $(CXXFLAGS) -MMD -MP -c -o $@ $<
# Include dependency files if they exist
# --------------------------------------
-include $(DEPS)