-
Notifications
You must be signed in to change notification settings - Fork 92
/
Makefile
153 lines (128 loc) · 3.99 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
# OS detection. Not used in CI builds
ifndef TARGET_OS
ifeq ($(OS),Windows_NT)
TARGET_OS := win32
else
UNAME_S := $(shell uname -s)
ifeq ($(UNAME_S),Linux)
UNAME_M := $(shell uname -m)
ifeq ($(UNAME_M),x86_64)
TARGET_OS := linux64
endif
ifeq ($(UNAME_M),i686)
TARGET_OS := linux32
endif
ifeq ($(UNAME_M),armv6l)
TARGET_OS := linux-armhf
endif
endif
ifeq ($(UNAME_S),Darwin)
TARGET_OS := osx
endif
ifeq ($(UNAME_S),FreeBSD)
TARGET_OS := freebsd
endif
endif
endif # TARGET_OS
# OS-specific settings and build flags
ifeq ($(TARGET_OS),win32)
ARCHIVE ?= zip
TARGET := mkspiffs.exe
TARGET_CFLAGS = -mno-ms-bitfields
TARGET_LDFLAGS = -Wl,-static -static-libgcc -static-libstdc++
else
ARCHIVE ?= tar
TARGET := mkspiffs
endif
ifeq ($(TARGET_OS),osx)
TARGET_CFLAGS = -mmacosx-version-min=10.7 -arch i386 -arch x86_64
TARGET_CXXFLAGS = -mmacosx-version-min=10.7 -arch i386 -arch x86_64 -stdlib=libc++
TARGET_LDFLAGS = -mmacosx-version-min=10.7 -arch i386 -arch x86_64 -stdlib=libc++
endif
# Packaging into archive (for 'dist' target)
ifeq ($(ARCHIVE), zip)
ARCHIVE_CMD := zip -r
ARCHIVE_EXTENSION := zip
endif
ifeq ($(ARCHIVE), tar)
ARCHIVE_CMD := tar czf
ARCHIVE_EXTENSION := tar.gz
endif
VERSION ?= $(shell git describe --always)
SPIFFS_VERSION := $(shell git -C spiffs describe --tags || echo "unknown")
BUILD_CONFIG_NAME ?= -generic
OBJ := main.o \
spiffs/src/spiffs_cache.o \
spiffs/src/spiffs_check.o \
spiffs/src/spiffs_gc.o \
spiffs/src/spiffs_hydrogen.o \
spiffs/src/spiffs_nucleus.o \
INCLUDES := -Itclap -Iinclude -Ispiffs/src -I.
FILES_TO_FORMAT := $(shell find . -not -path './spiffs/*' \( -name '*.c' -o -name '*.cpp' \))
DIFF_FILES := $(addsuffix .diff,$(FILES_TO_FORMAT))
# clang doesn't seem to handle -D "ARG=\"foo bar\"" correctly, so replace spaces with \x20:
BUILD_CONFIG_STR := $(shell echo $(CPPFLAGS) | sed 's- -\\\\x20-g')
override CPPFLAGS := \
$(INCLUDES) \
-D VERSION=\"$(VERSION)\" \
-D SPIFFS_VERSION=\"$(SPIFFS_VERSION)\" \
-D BUILD_CONFIG=\"$(BUILD_CONFIG_STR)\" \
-D BUILD_CONFIG_NAME=\"$(BUILD_CONFIG_NAME)\" \
-D __NO_INLINE__ \
$(CPPFLAGS)
override CFLAGS := -std=gnu99 -Os -Wall $(TARGET_CFLAGS) $(CFLAGS)
override CXXFLAGS := -std=gnu++11 -Os -Wall $(TARGET_CXXFLAGS) $(CXXFLAGS)
override LDFLAGS := $(TARGET_LDFLAGS) $(LDFLAGS)
DIST_NAME := mkspiffs-$(VERSION)$(BUILD_CONFIG_NAME)-$(TARGET_OS)
DIST_DIR := $(DIST_NAME)
DIST_ARCHIVE := $(DIST_NAME).$(ARCHIVE_EXTENSION)
all: $(TARGET)
dist: $(DIST_ARCHIVE)
ifndef SKIP_TESTS
dist: test
endif
$(DIST_ARCHIVE): $(TARGET) $(DIST_DIR)
cp $(TARGET) $(DIST_DIR)/
$(ARCHIVE_CMD) $(DIST_ARCHIVE) $(DIST_DIR)
$(TARGET): $(OBJ)
$(CXX) $^ -o $@ $(LDFLAGS)
strip $(TARGET)
$(DIST_DIR):
@mkdir -p $@
clean:
@rm -f $(TARGET) $(OBJ) $(DIFF_FILES)
SPIFFS_TEST_FS_CONFIG := -s 0x100000 -p 512 -b 0x2000
test: $(TARGET)
mkdir -p spiffs_t
cp spiffs/src/*.h spiffs_t/
cp spiffs/src/*.c spiffs_t/
rm -rf spiffs_t/.git
rm -f spiffs_t/.DS_Store
ls -1 spiffs_t > out.list0
touch spiffs_t/.DS_Store
mkdir -p spiffs_t/.git
touch spiffs_t/.git/foo
./mkspiffs -c spiffs_t $(SPIFFS_TEST_FS_CONFIG) out.spiffs_t | sort | sed s/^\\/// > out.list1
./mkspiffs -u spiffs_u $(SPIFFS_TEST_FS_CONFIG) out.spiffs_t | sort | sed s/^\\/// > out.list_u
./mkspiffs -l $(SPIFFS_TEST_FS_CONFIG) out.spiffs_t | cut -f 2 | sort | sed s/^\\/// > out.list2
awk 'BEGIN{RS="\1";ORS="";getline;gsub("\r","");print>ARGV[1]}' out.list0 out.list1 out.list2
diff out.list0 out.list1
diff out.list0 out.list2
rm -rf spiffs_t/.git
rm -f spiffs_t/.DS_Store
diff spiffs_t spiffs_u
rm -f out.{list0,list1,list2,list_u,spiffs_t}
rm -R spiffs_u spiffs_t
format-check: $(DIFF_FILES)
@rm -f $(DIFF_FILES)
$(DIFF_FILES): %.diff: %
@./format.sh < $< >$<.new
@diff $<.new $< >$@ || ( \
echo "File $^ not formatted correctly. Please use format.sh to re-format it." && \
echo "Here's the diff that caused an error:" && \
echo "" && \
cat $@ && \
rm $@ $<.new && \
exit 1 )
@rm -f $@ $<.new
.PHONY: all clean dist format-check