This repository has been archived by the owner on Sep 27, 2023. It is now read-only.
forked from erofs/erofs-utils
-
Notifications
You must be signed in to change notification settings - Fork 8
/
Makefile
executable file
·283 lines (236 loc) · 6.94 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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
CC = clang
CXX = clang++
AR = ar rcs
STRIP = strip
LD = clang++
LDFLAGS =
SHELL = bash
RM = rm -rf
CP = cp -f
CFLAGS = -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64
CXXFLAGS =
ifeq ($(shell uname -s | cut -d "-" -f 1 | cut -d "_" -f 2), NT)
ext = .exe
else
ext =
endif
ifeq ($(shell uname -m | tr -d "\n"), x86_64)
arch = x64
else
ifeq ($(shell uname -m | tr -d "\n"), i686)
arch = x86
else
arch = unknow
endif
endif
EROFS_DEF_DEFINES = \
-Wall \
-Werror \
-Wno-error=\#warnings \
-Wno-ignored-qualifiers \
-Wno-pointer-arith \
-Wno-unused-parameter \
-Wno-unused-function \
-DHAVE_FALLOCATE \
-DHAVE_LINUX_TYPES_H \
-DHAVE_LIBSELINUX \
-DHAVE_LIBUUID \
-DLZ4_ENABLED \
-DLZ4HC_ENABLED \
-DWITH_ANDROID \
-DHAVE_MEMRCHR \
-DHAVE_SYS_IOCTL_H \
-DHAVE_LLISTXATTR \
-DHAVE_LGETXATTR
ifeq ($(shell [ -e "/usr/local/lib/liblzma.a" ] && echo "true"), true)
# if installed xz from source then enabled liblzma
EROFS_DEF_DEFINES += -DHAVE_LIBLZMA
LDFLAGS += -L/usr/local/lib -llzma
endif
# Add cygwin remove unsupport flags
ifeq ($(shell uname -s | cut -d "-" -f 1), CYGWIN_NT)
EROFS_DEF_REMOVE = -DHAVE_LINUX_TYPES_H -DHAVE_FALLOCATE
EROFS_DEF_DEFINES += -Wno-address-of-temporary
ifeq ($(shell uname -o | tr -d "\n"), Cygwin)
ifeq ($(shell [ -d "winfsp" ] && echo "true"), true)
EROFS_DEF_DEFINES += -DCYGFUSE -Wno-missing-braces
endif
endif
override EROFS_DEF_DEFINES := $(filter-out $(EROFS_DEF_REMOVE),$(EROFS_DEF_DEFINES))
LDFLAGS += -liconv
endif
# Add on for extract.erofs
CXXFLAGS += -DNDEBUG
ifeq ($(shell uname -s | cut -d "-" -f 1), CYGWIN_NT)
CXXFLAGS += -stdlib=libc++ -static -DHAVE_UTIMENSAT
endif
ifeq ($(shell uname), Linux)
# [[likely]] [[unlikely]]
CXXFLAGS += -Wno-unknown-attributes
endif
override CFLAGS := $(CFLAGS) $(EROFS_DEF_DEFINES)
override CXXFLAGS := $(CXXFLAGS) $(EROFS_DEF_DEFINES) -std=c++17
INCLUDES = \
-I./include \
-I./libext2_uuid \
-include"erofs-utils-version.h" \
-I./lz4/lib \
-I./libselinux/include \
-I./libcutils/include \
-I./extract/extract/include
ifeq ($(shell uname -o | tr -d "\n"), Cygwin)
ifeq ($(shell [ -d "winfsp" ] && echo "true"), true)
INCLUDES += -I./winfsp/$(arch)/usr/include/fuse
endif
endif
liberofs_src = $(shell find lib -name \*.c)
liberofs_obj = $(patsubst %.c,obj/%.o,$(liberofs_src))
mkfs_src = $(shell find mkfs -name \*.c)
mkfs_obj = $(patsubst %.c,obj/%.o,$(mkfs_src))
fsck_src = $(shell find fsck -name \*.c)
fsck_obj = $(patsubst %.c,obj/%.o,$(fsck_src))
dump_src = $(shell find dump -name \*.c)
dump_obj = $(patsubst %.c,obj/%.o,$(dump_src))
fuse_src = $(shell find fuse -name \*.c)
fuse_obj = $(patsubst %.c,obj/%.o,$(fuse_src))
# Addon extract.erofs
ifeq ($(shell [ -d "extract" ] && echo "true"), true)
extract_src = $(shell find extract/extract -name \*.cpp)
extract_obj = $(patsubst %.cpp,obj/%.o,$(extract_src))
endif
version_header = erofs-utils-version.h
all_lib_prefix = \
erofs \
cutils \
base \
ext2_uuid \
log \
lz4 \
selinux
all_lib_prefix += pcre
all_lib = $(patsubst %,.lib/lib%.a,$(all_lib_prefix))
all_bin_prefix = \
mkfs \
fsck \
dump
ifeq ($(shell [ -d "extract" ] && echo "true"), true)
all_bin_prefix += extract
endif
ifeq ($(shell uname -o | tr -d "\n"), Cygwin)
ifeq ($(shell [ -d "winfsp" ] && echo "true"), true)
all_bin_prefix += fuse
endif
all_bin = $(patsubst %,bin/%.erofs$(ext),$(all_bin_prefix))
ifeq ($(shell uname -s | cut -d "-" -f 1), CYGWIN_NT)
all_bin += bin/cygwin1.dll
endif
ifeq ($(shell [ -d "winfsp" ] && echo "true"), true)
all_bin+= bin/cygfuse-2.8.dll
endif
endif
strip_bin = $(filter-out %.dll,$(all_bin))
.PHONY: all
all: lib bin
lib: $(version_header) $(all_lib)
bin: $(all_bin)
strip-all: bin
@for i in $(strip_bin); do \
echo -e "\tSTRIP \t$$i"; \
$(STRIP) --strip-unneeded $$i; \
done
obj/%.o: %.c
@mkdir -p `dirname $@`
@echo -e "\t CC\t $@"
@$(CC) $(CFLAGS) $(INCLUDES) -c $< -o $@
obj/%.o: %.cpp
@mkdir -p `dirname $@`
@echo -e "\t CC\t $@"
@$(CXX) $(CXXFLAGS) $(INCLUDES) -include"cygprefix.h" -c $< -o $@
erofs-utils-version.h:
@echo -e "\tGEN \t$@"
@echo "#define PACKAGE_VERSION \"$(shell ./scripts/cyg-get-version-number)\"" > $@
.lib/liberofs.a: $(liberofs_obj)
@mkdir -p `dirname $@`
@echo -e "\tAR \t$@"
@$(AR) $@ $^
.lib/libbase.a:
@mkdir -p `dirname $@`
@$(MAKE) -C libbase
@$(CP) ./libbase/$@ $@
.lib/libcutils.a:
@mkdir -p `dirname $@`
@$(MAKE) -C libcutils
@$(CP) ./libcutils/$@ $@
.lib/libext2_uuid.a:
@mkdir -p `dirname $@`
@$(MAKE) -C libext2_uuid
@$(CP) ./libext2_uuid/$@ $@
.lib/liblog.a:
@mkdir -p `dirname $@`
@$(MAKE) -C logging
@$(CP) ./logging/$@ $@
.lib/liblz4.a:
@mkdir -p `dirname $@`
@$(MAKE) -C lz4 lib
@$(CP) ./lz4/lib/`basename $@` $@
# I have no interest support this on cygwin
# cause aosp is also not support lzma compression
# you fan fill this up if you want lzma compression
.lib/liblzma.a:
.lib/libselinux.a:
@mkdir -p `dirname $@`
@$(MAKE) -C libselinux
@$(CP) ./libselinux/$@ $@
# Cygwin does not support libpcre.a
# We can only link dynamicly
# But with libpcre source, we still can
# link this program static
.lib/libpcre.a:
@mkdir -p `dirname $@`
@cd libpcre && ./autogen.sh && ./configure && $(MAKE) libpcre.la
@$(CP) libpcre/.libs/`basename $@` $@
bin/mkfs.erofs$(ext): $(mkfs_obj) $(all_lib)
@mkdir -p `dirname $@`
@echo -e "\tLD\t $@"
@$(LD) $(CXXFLAGS) -o $@ $^ $(LDFLAGS)
bin/fsck.erofs$(ext): $(fsck_obj) $(all_lib)
@mkdir -p `dirname $@`
@echo -e "\tLD\t $@"
@$(LD) $(CXXFLAGS) -o $@ $^ $(LDFLAGS)
bin/dump.erofs$(ext): $(dump_obj) $(all_lib)
@mkdir -p `dirname $@`
@echo -e "\tLD\t $@"
@$(LD) $(CXXFLAGS) -o $@ $^ $(LDFLAGS)
# Add on unoffical extract program
bin/extract.erofs$(ext): $(extract_obj) $(all_lib)
@mkdir -p `dirname $@`
@echo -e "\tLD\t $@"
@$(LD) $(CXXFLAGS) -o $@ $^ $(LDFLAGS) -lntdll
fuse_lib_a = winfsp/$(arch)/usr/lib/libfuse-2.8.dll.a
# No nesseary to build fuse but cygwin provide cygfuse we can still use this
bin/fuse.erofs$(ext): $(fuse_obj) $(all_lib) $(fuse_lib_a)
@mkdir -p `dirname $@`
@echo -e "\tLD\t $@"
@$(LD) $(CXXFLAGS) -o $@ $^ $(LDFLAGS)
# cygfuse-2.8.dll is for fuse.erofs
bin/cygfuse-2.8.dll:
@mkdir -p `dirname $@`
@echo -e "\tCOPY \t$@"
@$(CP) winfsp/$(arch)/usr/$@ $@
# cygwin1.dll is needed
bin/cygwin1.dll:
@mkdir -p `dirname $@`
@echo -e "\tCOPY \t$@"
@$(CP) /$@ $@
clean:
@echo -e "\tRM \tobj .lib bin"
@$(RM) obj .lib bin erofs-utils-version.h
@$(MAKE) -C libbase clean
@$(MAKE) -C libcutils clean
@$(MAKE) -C libext2_uuid clean
@$(MAKE) -C logging clean
@$(MAKE) -C lz4 clean
@$(MAKE) -C libselinux clean
ifeq ($(shell [ -e "libpcre/Makefile" ] && echo "true"), true)
@$(MAKE) -C libpcre clean
endif