cc8164b27d56766d48de8c22c8860df10dba2f62
[fio.git] / Makefile
1 ifeq ($(SRCDIR),)
2 SRCDIR := .
3 endif
4
5 VPATH := $(SRCDIR)
6
7 all: fio
8
9 config-host.mak: configure
10         @if [ ! -e "$@" ]; then                                 \
11           echo "Running configure ...";                         \
12           ./configure;                                          \
13         else                                                    \
14           echo "$@ is out-of-date, running configure";          \
15           sed -n "/.*Configured with/s/[^:]*: //p" "$@" | sh;   \
16         fi
17
18 ifneq ($(MAKECMDGOALS),clean)
19 include config-host.mak
20 endif
21
22 DEBUGFLAGS = -DFIO_INC_DEBUG
23 CPPFLAGS+= -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -DFIO_INTERNAL $(DEBUGFLAGS)
24 OPTFLAGS= -g -ffast-math
25 FIO_CFLAGS= -std=gnu99 -Wwrite-strings -Wall -Wdeclaration-after-statement $(OPTFLAGS) $(EXTFLAGS) $(BUILD_CFLAGS) -I. -I$(SRCDIR)
26 LIBS    += -lm $(EXTLIBS)
27 PROGS   = fio
28 SCRIPTS = $(addprefix $(SRCDIR)/,tools/fio_generate_plots tools/plot/fio2gnuplot tools/genfio tools/fiologparser.py tools/hist/fiologparser_hist.py tools/hist/fio-histo-log-pctiles.py tools/fio_jsonplus_clat2csv)
29
30 ifndef CONFIG_FIO_NO_OPT
31   FIO_CFLAGS += -O3
32 endif
33 ifdef CONFIG_BUILD_NATIVE
34   FIO_CFLAGS += -march=native
35 endif
36
37 ifdef CONFIG_PDB
38   LINK_PDBFILE ?= -Wl,-pdb,$(dir $@)/$(basename $(@F)).pdb
39   FIO_CFLAGS += -gcodeview
40   LDFLAGS += -fuse-ld=lld $(LINK_PDBFILE)
41 endif
42
43 # If clang, do not use builtin stpcpy as it breaks the build
44 ifeq ($(CC),clang)
45   FIO_CFLAGS += -fno-builtin-stpcpy
46 endif
47
48 ifdef CONFIG_GFIO
49   PROGS += gfio
50 endif
51
52 SOURCE :=       $(sort $(patsubst $(SRCDIR)/%,%,$(wildcard $(SRCDIR)/crc/*.c)) \
53                 $(patsubst $(SRCDIR)/%,%,$(wildcard $(SRCDIR)/lib/*.c))) \
54                 gettime.c ioengines.c init.c stat.c log.c time.c filesetup.c \
55                 eta.c verify.c memory.c io_u.c parse.c fio_sem.c rwlock.c \
56                 pshared.c options.c \
57                 smalloc.c filehash.c profile.c debug.c engines/cpu.c \
58                 engines/mmap.c engines/sync.c engines/null.c engines/net.c \
59                 engines/ftruncate.c engines/fileoperations.c \
60                 engines/exec.c \
61                 server.c client.c iolog.c backend.c libfio.c flow.c cconv.c \
62                 gettime-thread.c helpers.c json.c idletime.c td_error.c \
63                 profiles/tiobench.c profiles/act.c io_u_queue.c filelock.c \
64                 workqueue.c rate-submit.c optgroup.c helper_thread.c \
65                 steadystate.c zone-dist.c zbd.c dedupe.c fdp.c
66
67 ifdef CONFIG_LIBHDFS
68   HDFSFLAGS= -I $(JAVA_HOME)/include -I $(JAVA_HOME)/include/linux -I $(FIO_LIBHDFS_INCLUDE)
69   HDFSLIB= -Wl,-rpath $(JAVA_HOME)/lib/$(FIO_HDFS_CPU)/server -L$(JAVA_HOME)/lib/$(FIO_HDFS_CPU)/server $(FIO_LIBHDFS_LIB)/libhdfs.a -ljvm
70   FIO_CFLAGS += $(HDFSFLAGS)
71   SOURCE += engines/libhdfs.c
72 endif
73
74 ifdef CONFIG_LIBISCSI
75   libiscsi_SRCS = engines/libiscsi.c
76   libiscsi_LIBS = $(LIBISCSI_LIBS)
77   libiscsi_CFLAGS = $(LIBISCSI_CFLAGS)
78   ENGINES += libiscsi
79 endif
80
81 ifdef CONFIG_LIBNBD
82   nbd_SRCS = engines/nbd.c
83   nbd_LIBS = $(LIBNBD_LIBS)
84   nbd_CFLAGS = $(LIBNBD_CFLAGS)
85   ENGINES += nbd
86 endif
87
88 ifdef CONFIG_LIBNFS
89   CFLAGS += $(LIBNFS_CFLAGS)
90   LIBS += $(LIBNFS_LIBS)
91   SOURCE += engines/nfs.c
92 endif
93
94 ifdef CONFIG_64BIT
95   CPPFLAGS += -DBITS_PER_LONG=64
96 else ifdef CONFIG_32BIT
97   CPPFLAGS += -DBITS_PER_LONG=32
98 endif
99 ifdef CONFIG_LIBAIO
100   libaio_SRCS = engines/libaio.c
101   cmdprio_SRCS = engines/cmdprio.c
102   LIBS += -laio
103   libaio_LIBS = -laio
104   ENGINES += libaio
105 endif
106 ifdef CONFIG_RDMA
107   rdma_SRCS = engines/rdma.c
108   rdma_LIBS = -libverbs -lrdmacm
109   ENGINES += rdma
110 endif
111 ifdef CONFIG_LIBRPMA_APM
112   librpma_apm_SRCS = engines/librpma_apm.c
113   librpma_fio_SRCS = engines/librpma_fio.c
114   ifdef CONFIG_LIBPMEM2_INSTALLED
115     librpma_apm_LIBS = -lrpma -lpmem2
116   else
117     librpma_apm_LIBS = -lrpma -lpmem
118   endif
119   ENGINES += librpma_apm
120 endif
121 ifdef CONFIG_LIBRPMA_GPSPM
122   librpma_gpspm_SRCS = engines/librpma_gpspm.c engines/librpma_gpspm_flush.pb-c.c
123   librpma_fio_SRCS = engines/librpma_fio.c
124   ifdef CONFIG_LIBPMEM2_INSTALLED
125     librpma_gpspm_LIBS = -lrpma -lpmem2 -lprotobuf-c
126   else
127     librpma_gpspm_LIBS = -lrpma -lpmem -lprotobuf-c
128   endif
129   ENGINES += librpma_gpspm
130 endif
131 ifdef librpma_fio_SRCS
132   SOURCE += $(librpma_fio_SRCS)
133 endif
134 ifdef CONFIG_POSIXAIO
135   SOURCE += engines/posixaio.c
136 endif
137 ifdef CONFIG_LINUX_FALLOCATE
138   SOURCE += engines/falloc.c
139 endif
140 ifdef CONFIG_LINUX_EXT4_MOVE_EXTENT
141   SOURCE += engines/e4defrag.c
142 endif
143 ifdef CONFIG_LIBCUFILE
144   SOURCE += engines/libcufile.c
145 endif
146 ifdef CONFIG_LINUX_SPLICE
147   SOURCE += engines/splice.c
148 endif
149 ifdef CONFIG_SOLARISAIO
150   SOURCE += engines/solarisaio.c
151 endif
152 ifdef CONFIG_WINDOWSAIO
153   SOURCE += engines/windowsaio.c
154 endif
155 ifdef CONFIG_RADOS
156   rados_SRCS = engines/rados.c
157   rados_LIBS = -lrados
158   ENGINES += rados
159 endif
160 ifdef CONFIG_RBD
161   rbd_SRCS = engines/rbd.c
162   rbd_LIBS = -lrbd -lrados
163   ENGINES += rbd
164 endif
165 ifdef CONFIG_HTTP
166   http_SRCS = engines/http.c
167   http_LIBS = -lcurl -lssl -lcrypto
168   ENGINES += http
169 endif
170 ifdef CONFIG_DFS
171   dfs_SRCS = engines/dfs.c
172   dfs_LIBS = -luuid -ldaos -ldfs
173   ENGINES += dfs
174 endif
175 SOURCE += oslib/asprintf.c
176 ifndef CONFIG_STRSEP
177   SOURCE += oslib/strsep.c
178 endif
179 ifndef CONFIG_STRCASESTR
180   SOURCE += oslib/strcasestr.c
181 endif
182 ifndef CONFIG_STRLCAT
183   SOURCE += oslib/strlcat.c
184 endif
185 ifndef CONFIG_HAVE_STRNDUP
186   SOURCE += oslib/strndup.c
187 endif
188 ifndef CONFIG_GETOPT_LONG_ONLY
189   SOURCE += oslib/getopt_long.c
190 endif
191 ifndef CONFIG_INET_ATON
192   SOURCE += oslib/inet_aton.c
193 endif
194 ifndef CONFIG_HAVE_STATX
195   SOURCE += oslib/statx.c
196 endif
197 ifdef CONFIG_GFAPI
198   SOURCE += engines/glusterfs.c
199   SOURCE += engines/glusterfs_sync.c
200   SOURCE += engines/glusterfs_async.c
201   LIBS += -lgfapi -lglusterfs
202   ifdef CONFIG_GF_FADVISE
203     FIO_CFLAGS += "-DGFAPI_USE_FADVISE"
204   endif
205 endif
206 ifdef CONFIG_MTD
207   SOURCE += engines/mtd.c
208   SOURCE += oslib/libmtd.c
209   SOURCE += oslib/libmtd_legacy.c
210 endif
211 ifdef CONFIG_LINUX_DEVDAX
212   dev-dax_SRCS = engines/dev-dax.c
213   dev-dax_LIBS = -lpmem
214   ENGINES += dev-dax
215 endif
216 ifdef CONFIG_LIBPMEM
217   libpmem_SRCS = engines/libpmem.c
218   libpmem_LIBS = -lpmem
219   ENGINES += libpmem
220 endif
221 ifdef CONFIG_IME
222   SOURCE += engines/ime.c
223 endif
224 ifdef CONFIG_LIBZBC
225   libzbc_SRCS = engines/libzbc.c
226   libzbc_LIBS = -lzbc
227   ENGINES += libzbc
228 endif
229 ifdef CONFIG_LIBXNVME
230   xnvme_SRCS = engines/xnvme.c
231   xnvme_LIBS = $(LIBXNVME_LIBS)
232   xnvme_CFLAGS = $(LIBXNVME_CFLAGS)
233   ENGINES += xnvme
234 endif
235 ifdef CONFIG_LIBBLKIO
236   libblkio_SRCS = engines/libblkio.c
237   libblkio_LIBS = $(LIBBLKIO_LIBS)
238   libblkio_CFLAGS = $(LIBBLKIO_CFLAGS)
239   ENGINES += libblkio
240 endif
241 ifeq ($(CONFIG_TARGET_OS), Linux)
242   SOURCE += diskutil.c fifo.c blktrace.c cgroup.c trim.c engines/sg.c \
243                 oslib/linux-dev-lookup.c engines/io_uring.c engines/nvme.c
244   cmdprio_SRCS = engines/cmdprio.c
245 ifdef CONFIG_HAS_BLKZONED
246   SOURCE += oslib/linux-blkzoned.c
247 endif
248   LIBS += -lpthread -ldl
249   LDFLAGS += -rdynamic
250 endif
251 ifeq ($(CONFIG_TARGET_OS), Android)
252   SOURCE += diskutil.c fifo.c blktrace.c cgroup.c trim.c profiles/tiobench.c \
253                 oslib/linux-dev-lookup.c engines/io_uring.c engines/nvme.c \
254                 engines/sg.c
255   cmdprio_SRCS = engines/cmdprio.c
256 ifdef CONFIG_HAS_BLKZONED
257   SOURCE += oslib/linux-blkzoned.c
258 endif
259   LIBS += -ldl -llog
260   LDFLAGS += -rdynamic
261 endif
262 ifeq ($(CONFIG_TARGET_OS), SunOS)
263   LIBS   += -lpthread -ldl
264   CPPFLAGS += -D__EXTENSIONS__
265 endif
266 ifeq ($(CONFIG_TARGET_OS), FreeBSD)
267   SOURCE += trim.c
268   LIBS   += -lpthread -lrt
269   LDFLAGS += -rdynamic
270 endif
271 ifeq ($(CONFIG_TARGET_OS), OpenBSD)
272   LIBS   += -lpthread
273   LDFLAGS += -rdynamic
274 endif
275 ifeq ($(CONFIG_TARGET_OS), NetBSD)
276   LIBS   += -lpthread -lrt
277   LDFLAGS += -rdynamic
278 endif
279 ifeq ($(CONFIG_TARGET_OS), DragonFly)
280   SOURCE += trim.c
281   LIBS   += -lpthread -lrt
282   LDFLAGS += -rdynamic
283 endif
284 ifeq ($(CONFIG_TARGET_OS), AIX)
285   LIBS   += -lpthread -ldl -lrt
286   CPPFLAGS += -D_LARGE_FILES -D__ppc__
287   LDFLAGS += -L/opt/freeware/lib -Wl,-blibpath:/opt/freeware/lib:/usr/lib:/lib -Wl,-bmaxdata:0x80000000
288 endif
289 ifeq ($(CONFIG_TARGET_OS), HP-UX)
290   LIBS   += -lpthread -ldl -lrt
291   FIO_CFLAGS += -D_LARGEFILE64_SOURCE -D_XOPEN_SOURCE_EXTENDED
292 endif
293 ifeq ($(CONFIG_TARGET_OS), Darwin)
294   LIBS   += -lpthread -ldl
295 endif
296 ifneq (,$(findstring CYGWIN,$(CONFIG_TARGET_OS)))
297   SOURCE += os/windows/cpu-affinity.c os/windows/posix.c os/windows/dlls.c
298   WINDOWS_OBJS = os/windows/cpu-affinity.o os/windows/posix.o os/windows/dlls.o lib/hweight.o
299   LIBS   += -lpthread -lpsapi -lws2_32 -lssp
300   FIO_CFLAGS += -DPSAPI_VERSION=1 -Ios/windows/posix/include -Wno-format
301 endif
302
303 ifdef cmdprio_SRCS
304   SOURCE += $(cmdprio_SRCS)
305 endif
306
307 ifdef CONFIG_DYNAMIC_ENGINES
308  DYNAMIC_ENGS := $(ENGINES)
309 define engine_template =
310 $(1)_OBJS := $$($(1)_SRCS:.c=.o)
311 $$($(1)_OBJS): CFLAGS := -fPIC $$($(1)_CFLAGS) $(CFLAGS)
312 engines/fio-$(1).so: $$($(1)_OBJS)
313         $$(QUIET_LINK)$(CC) $(LDFLAGS) -shared -rdynamic -fPIC -Wl,-soname,fio-$(1).so.1 -o $$@ $$< $$($(1)_LIBS)
314 ENGS_OBJS += engines/fio-$(1).so
315 endef
316 else # !CONFIG_DYNAMIC_ENGINES
317 define engine_template =
318 SOURCE += $$($(1)_SRCS)
319 LIBS += $$($(1)_LIBS)
320 override CFLAGS += $$($(1)_CFLAGS)
321 endef
322 endif
323
324 FIO-VERSION-FILE: FORCE
325         @$(SHELL) $(SRCDIR)/FIO-VERSION-GEN
326 -include FIO-VERSION-FILE
327
328 override CFLAGS := -DFIO_VERSION='"$(FIO_VERSION)"' $(FIO_CFLAGS) $(CFLAGS)
329
330 $(foreach eng,$(ENGINES),$(eval $(call engine_template,$(eng))))
331
332 OBJS := $(SOURCE:.c=.o)
333
334 FIO_OBJS = $(OBJS) fio.o
335
336 GFIO_OBJS = $(OBJS) gfio.o graph.o tickmarks.o ghelpers.o goptions.o gerror.o \
337                         gclient.o gcompat.o cairo_text_helpers.o printing.o
338
339 ifdef CONFIG_ARITHMETIC
340 FIO_OBJS += lex.yy.o y.tab.o
341 GFIO_OBJS += lex.yy.o y.tab.o
342 endif
343
344 -include $(OBJS:.o=.d)
345
346 T_SMALLOC_OBJS = t/stest.o
347 T_SMALLOC_OBJS += gettime.o fio_sem.o pshared.o smalloc.o t/log.o t/debug.o \
348                   t/arch.o
349 T_SMALLOC_PROGS = t/stest
350
351 T_IEEE_OBJS = t/ieee754.o
352 T_IEEE_OBJS += lib/ieee754.o
353 T_IEEE_PROGS = t/ieee754
354
355 T_ZIPF_OBS = t/genzipf.o
356 T_ZIPF_OBJS += t/log.o lib/ieee754.o lib/rand.o lib/pattern.o lib/zipf.o \
357                 lib/strntol.o lib/gauss.o t/genzipf.o oslib/strcasestr.o \
358                 oslib/strndup.o
359 T_ZIPF_PROGS = t/fio-genzipf
360
361 T_AXMAP_OBJS = t/axmap.o
362 T_AXMAP_OBJS += lib/lfsr.o lib/axmap.o
363 T_AXMAP_PROGS = t/axmap
364
365 T_LFSR_TEST_OBJS = t/lfsr-test.o
366 T_LFSR_TEST_OBJS += lib/lfsr.o gettime.o fio_sem.o pshared.o \
367                     t/log.o t/debug.o t/arch.o
368 T_LFSR_TEST_PROGS = t/lfsr-test
369
370 T_GEN_RAND_OBJS = t/gen-rand.o
371 T_GEN_RAND_OBJS += t/log.o t/debug.o lib/rand.o lib/pattern.o lib/strntol.o \
372                         oslib/strcasestr.o oslib/strndup.o
373 T_GEN_RAND_PROGS = t/gen-rand
374
375 ifeq ($(CONFIG_TARGET_OS), Linux)
376 T_BTRACE_FIO_OBJS = t/btrace2fio.o
377 T_BTRACE_FIO_OBJS += fifo.o lib/flist_sort.o t/log.o oslib/linux-dev-lookup.o
378 T_BTRACE_FIO_PROGS = t/fio-btrace2fio
379 endif
380
381 T_DEDUPE_OBJS = t/dedupe.o
382 T_DEDUPE_OBJS += lib/rbtree.o t/log.o fio_sem.o pshared.o smalloc.o gettime.o \
383                 crc/md5.o lib/memalign.o lib/bloom.o t/debug.o crc/xxhash.o \
384                 t/arch.o crc/murmur3.o crc/crc32c.o crc/crc32c-intel.o \
385                 crc/crc32c-arm64.o crc/fnv.o
386 T_DEDUPE_PROGS = t/fio-dedupe
387
388 T_VS_OBJS = t/verify-state.o t/log.o crc/crc32c.o crc/crc32c-intel.o crc/crc32c-arm64.o t/debug.o
389 T_VS_PROGS = t/fio-verify-state
390
391 T_PIPE_ASYNC_OBJS = t/read-to-pipe-async.o
392 T_PIPE_ASYNC_PROGS = t/read-to-pipe-async
393
394 T_IOU_RING_OBJS = t/io_uring.o lib/rand.o lib/pattern.o lib/strntol.o
395 T_IOU_RING_PROGS = t/io_uring
396
397 T_MEMLOCK_OBJS = t/memlock.o
398 T_MEMLOCK_PROGS = t/memlock
399
400 T_TT_OBJS = t/time-test.o
401 T_TT_PROGS = t/time-test
402
403 ifneq (,$(findstring -DFUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION,$(CFLAGS)))
404 T_FUZZ_OBJS = t/fuzz/fuzz_parseini.o
405 T_FUZZ_OBJS += $(OBJS)
406 ifdef CONFIG_ARITHMETIC
407 T_FUZZ_OBJS += lex.yy.o y.tab.o
408 endif
409 # For proper fio code teardown CFLAGS needs to include -DFUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION
410 # in case there is no fuzz driver defined by environment variable LIB_FUZZING_ENGINE, use a simple one
411 # For instance, with compiler clang, address sanitizer and libFuzzer as a fuzzing engine, you should define
412 # export CFLAGS="-fsanitize=address,fuzzer-no-link -DFUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION"
413 # export LIB_FUZZING_ENGINE="-fsanitize=address"
414 # export CC=clang
415 # before running configure && make
416 # You can adapt this with different compilers, sanitizers, and fuzzing engines
417 ifndef LIB_FUZZING_ENGINE
418 T_FUZZ_OBJS += t/fuzz/onefile.o
419 endif
420 T_FUZZ_PROGS = t/fuzz/fuzz_parseini
421 else    # CFLAGS includes -DFUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION
422 T_FUZZ_OBJS =
423 T_FUZZ_PROGS =
424 endif
425
426 T_OBJS = $(T_SMALLOC_OBJS)
427 T_OBJS += $(T_IEEE_OBJS)
428 T_OBJS += $(T_ZIPF_OBJS)
429 T_OBJS += $(T_AXMAP_OBJS)
430 T_OBJS += $(T_LFSR_TEST_OBJS)
431 T_OBJS += $(T_GEN_RAND_OBJS)
432 T_OBJS += $(T_BTRACE_FIO_OBJS)
433 T_OBJS += $(T_DEDUPE_OBJS)
434 T_OBJS += $(T_VS_OBJS)
435 T_OBJS += $(T_PIPE_ASYNC_OBJS)
436 T_OBJS += $(T_MEMLOCK_OBJS)
437 T_OBJS += $(T_TT_OBJS)
438 T_OBJS += $(T_IOU_RING_OBJS)
439 T_OBJS += $(T_FUZZ_OBJS)
440
441 ifneq (,$(findstring CYGWIN,$(CONFIG_TARGET_OS)))
442     T_DEDUPE_OBJS += $(WINDOWS_OBJS)
443     T_SMALLOC_OBJS += $(WINDOWS_OBJS)
444     T_LFSR_TEST_OBJS += $(WINDOWS_OBJS)
445 endif
446
447 T_TEST_PROGS = $(T_SMALLOC_PROGS)
448 T_TEST_PROGS += $(T_IEEE_PROGS)
449 T_PROGS += $(T_ZIPF_PROGS)
450 T_TEST_PROGS += $(T_AXMAP_PROGS)
451 T_TEST_PROGS += $(T_LFSR_TEST_PROGS)
452 T_TEST_PROGS += $(T_GEN_RAND_PROGS)
453 T_PROGS += $(T_BTRACE_FIO_PROGS)
454 ifdef CONFIG_ZLIB
455 T_PROGS += $(T_DEDUPE_PROGS)
456 endif
457 T_PROGS += $(T_VS_PROGS)
458 T_TEST_PROGS += $(T_MEMLOCK_PROGS)
459 ifdef CONFIG_PREAD
460 T_TEST_PROGS += $(T_PIPE_ASYNC_PROGS)
461 endif
462 ifneq (,$(findstring Linux,$(CONFIG_TARGET_OS)))
463 T_TEST_PROGS += $(T_IOU_RING_PROGS)
464 endif
465 T_TEST_PROGS += $(T_FUZZ_PROGS)
466
467 PROGS += $(T_PROGS)
468
469 ifdef CONFIG_HAVE_CUNIT
470 UT_OBJS = unittests/unittest.o
471 UT_OBJS += unittests/lib/memalign.o
472 UT_OBJS += unittests/lib/num2str.o
473 UT_OBJS += unittests/lib/strntol.o
474 UT_OBJS += unittests/oslib/strlcat.o
475 UT_OBJS += unittests/oslib/strndup.o
476 UT_OBJS += unittests/oslib/strcasestr.o
477 UT_OBJS += unittests/oslib/strsep.o
478 UT_TARGET_OBJS = lib/memalign.o
479 UT_TARGET_OBJS += lib/num2str.o
480 UT_TARGET_OBJS += lib/strntol.o
481 UT_TARGET_OBJS += oslib/strlcat.o
482 UT_TARGET_OBJS += oslib/strndup.o
483 UT_TARGET_OBJS += oslib/strcasestr.o
484 UT_TARGET_OBJS += oslib/strsep.o
485 UT_PROGS = unittests/unittest
486 else
487 UT_OBJS =
488 UT_TARGET_OBJS =
489 UT_PROGS =
490 endif
491
492 ifneq ($(findstring $(MAKEFLAGS),s),s)
493 ifndef V
494         QUIET_CC        = @echo '   ' CC $@;
495         QUIET_LINK      = @echo ' ' LINK $@;
496         QUIET_DEP       = @echo '  ' DEP $@;
497         QUIET_YACC      = @echo ' ' YACC $@;
498         QUIET_LEX       = @echo '  ' LEX $@;
499 endif
500 endif
501
502 ifeq ($(CONFIG_TARGET_OS), SunOS)
503         INSTALL = ginstall
504 else
505         INSTALL = install
506 endif
507 prefix = $(INSTALL_PREFIX)
508 bindir = $(prefix)/bin
509 libdir = $(prefix)/lib/fio
510
511 ifeq ($(CONFIG_TARGET_OS), Darwin)
512 mandir = /usr/share/man
513 sharedir = /usr/share/fio
514 else
515 mandir = $(prefix)/man
516 sharedir = $(prefix)/share/fio
517 endif
518
519 all: $(PROGS) $(T_TEST_PROGS) $(UT_PROGS) $(SCRIPTS) $(ENGS_OBJS) FORCE
520
521 .PHONY: all install clean test
522 .PHONY: FORCE cscope
523
524 %.o : %.c
525         @mkdir -p $(dir $@)
526         $(QUIET_CC)$(CC) -o $@ $(CFLAGS) $(CPPFLAGS) -c $<
527         @$(CC) -MM $(CFLAGS) $(CPPFLAGS) $(SRCDIR)/$*.c > $*.d
528         @mv -f $*.d $*.d.tmp
529         @sed -e 's|.*:|$*.o:|' < $*.d.tmp > $*.d
530         @if type -p fmt >/dev/null 2>&1; then                           \
531                 sed -e 's/.*://' -e 's/\\$$//' < $*.d.tmp | fmt -w 1 |  \
532                 sed -e 's/^ *//' -e 's/$$/:/' >> $*.d;                  \
533         else                                                            \
534                 sed -e 's/.*://' -e 's/\\$$//' < $*.d.tmp |             \
535                 tr -cs "[:graph:]" "\n" |                               \
536                 sed -e 's/^ *//' -e '/^$$/ d' -e 's/$$/:/' >> $*.d;     \
537         fi
538         @rm -f $*.d.tmp
539
540 ifdef CONFIG_ARITHMETIC
541 lex.yy.c: exp/expression-parser.l
542 ifdef CONFIG_LEX_USE_O
543         $(QUIET_LEX)$(LEX) -o $@ $<
544 else
545         $(QUIET_LEX)$(LEX) $<
546 endif
547
548 ifneq (,$(findstring -Wimplicit-fallthrough,$(CFLAGS)))
549 LEX_YY_CFLAGS := -Wno-implicit-fallthrough
550 endif
551
552 ifdef CONFIG_HAVE_NO_STRINGOP
553 YTAB_YY_CFLAGS := -Wno-stringop-truncation
554 endif
555
556 lex.yy.o: lex.yy.c y.tab.h
557         $(QUIET_CC)$(CC) -o $@ $(CFLAGS) $(CPPFLAGS) $(LEX_YY_CFLAGS) -c $<
558
559 y.tab.o: y.tab.c y.tab.h
560         $(QUIET_CC)$(CC) -o $@ $(CFLAGS) $(CPPFLAGS) $(YTAB_YY_CFLAGS) -c $<
561
562 y.tab.c: exp/expression-parser.y
563         $(QUIET_YACC)$(YACC) -o $@ -l -d -b y $<
564
565 y.tab.h: y.tab.c
566
567 lexer.h: lex.yy.c
568
569 exp/test-expression-parser.o: exp/test-expression-parser.c
570         $(QUIET_CC)$(CC) -o $@ $(CFLAGS) $(CPPFLAGS) -c $<
571 exp/test-expression-parser: exp/test-expression-parser.o
572         $(QUIET_LINK)$(CC) $(LDFLAGS) $< y.tab.o lex.yy.o -o $@ $(LIBS)
573
574 parse.o: lex.yy.o y.tab.o
575 endif
576
577 init.o: init.c FIO-VERSION-FILE
578
579 gcompat.o: gcompat.c gcompat.h
580         $(QUIET_CC)$(CC) $(CFLAGS) $(GTK_CFLAGS) $(CPPFLAGS) -c $<
581
582 goptions.o: goptions.c goptions.h
583         $(QUIET_CC)$(CC) $(CFLAGS) $(GTK_CFLAGS) $(CPPFLAGS) -c $<
584
585 ghelpers.o: ghelpers.c ghelpers.h
586         $(QUIET_CC)$(CC) $(CFLAGS) $(GTK_CFLAGS) $(CPPFLAGS) -c $<
587
588 gerror.o: gerror.c gerror.h
589         $(QUIET_CC)$(CC) $(CFLAGS) $(GTK_CFLAGS) $(CPPFLAGS) -c $<
590
591 gclient.o: gclient.c gclient.h
592         $(QUIET_CC)$(CC) $(CFLAGS) $(GTK_CFLAGS) $(CPPFLAGS) -c $<
593
594 gfio.o: gfio.c ghelpers.c
595         $(QUIET_CC)$(CC) $(CFLAGS) $(GTK_CFLAGS) $(CPPFLAGS) -c $<
596
597 graph.o: graph.c graph.h
598         $(QUIET_CC)$(CC) $(CFLAGS) $(GTK_CFLAGS) $(CPPFLAGS) -c $<
599
600 cairo_text_helpers.o: cairo_text_helpers.c cairo_text_helpers.h
601         $(QUIET_CC)$(CC) $(CFLAGS) $(GTK_CFLAGS) $(CPPFLAGS) -c $<
602
603 printing.o: printing.c printing.h
604         $(QUIET_CC)$(CC) $(CFLAGS) $(GTK_CFLAGS) $(CPPFLAGS) -c $<
605
606 t/io_uring.o: os/linux/io_uring.h
607 t/io_uring: $(T_IOU_RING_OBJS)
608         $(QUIET_LINK)$(CC) $(LDFLAGS) -o $@ $(T_IOU_RING_OBJS) $(LIBS)
609
610 t/read-to-pipe-async: $(T_PIPE_ASYNC_OBJS)
611         $(QUIET_LINK)$(CC) $(LDFLAGS) -o $@ $(T_PIPE_ASYNC_OBJS) $(LIBS)
612
613 t/memlock: $(T_MEMLOCK_OBJS)
614         $(QUIET_LINK)$(CC) $(LDFLAGS) -o $@ $(T_MEMLOCK_OBJS) $(LIBS)
615
616 t/stest: $(T_SMALLOC_OBJS)
617         $(QUIET_LINK)$(CC) $(LDFLAGS) -o $@ $(T_SMALLOC_OBJS) $(LIBS)
618
619 t/ieee754: $(T_IEEE_OBJS)
620         $(QUIET_LINK)$(CC) $(LDFLAGS) -o $@ $(T_IEEE_OBJS) $(LIBS)
621
622 fio: $(FIO_OBJS)
623         $(QUIET_LINK)$(CC) $(LDFLAGS) -o $@ $(FIO_OBJS) $(LIBS) $(HDFSLIB)
624
625 t/fuzz/fuzz_parseini: $(T_FUZZ_OBJS)
626 ifndef LIB_FUZZING_ENGINE
627         $(QUIET_LINK)$(CC) $(LDFLAGS) -o $@ $(T_FUZZ_OBJS) $(LIBS) $(HDFSLIB)
628 else
629         $(QUIET_LINK)$(CXX) $(LDFLAGS) -o $@ $(T_FUZZ_OBJS) $(LIB_FUZZING_ENGINE) $(LIBS) $(HDFSLIB)
630 endif
631
632 gfio: $(GFIO_OBJS)
633         $(QUIET_LINK)$(CC) $(filter-out -static, $(LDFLAGS)) -o gfio $(GFIO_OBJS) $(LIBS) $(GFIO_LIBS) $(GTK_LDFLAGS) $(HDFSLIB)
634
635 t/fio-genzipf: $(T_ZIPF_OBJS)
636         $(QUIET_LINK)$(CC) $(LDFLAGS) -o $@ $(T_ZIPF_OBJS) $(LIBS)
637
638 t/axmap: $(T_AXMAP_OBJS)
639         $(QUIET_LINK)$(CC) $(LDFLAGS) -o $@ $(T_AXMAP_OBJS) $(LIBS)
640
641 t/lfsr-test: $(T_LFSR_TEST_OBJS)
642         $(QUIET_LINK)$(CC) $(LDFLAGS) -o $@ $(T_LFSR_TEST_OBJS) $(LIBS)
643
644 t/gen-rand: $(T_GEN_RAND_OBJS)
645         $(QUIET_LINK)$(CC) $(LDFLAGS) -o $@ $(T_GEN_RAND_OBJS) $(LIBS)
646
647 ifeq ($(CONFIG_TARGET_OS), Linux)
648 t/fio-btrace2fio: $(T_BTRACE_FIO_OBJS)
649         $(QUIET_LINK)$(CC) $(LDFLAGS) -o $@ $(T_BTRACE_FIO_OBJS) $(LIBS)
650 endif
651
652 ifdef CONFIG_ZLIB
653 t/fio-dedupe: $(T_DEDUPE_OBJS)
654         $(QUIET_LINK)$(CC) $(LDFLAGS) -o $@ $(T_DEDUPE_OBJS) $(LIBS)
655 endif
656
657 t/fio-verify-state: $(T_VS_OBJS)
658         $(QUIET_LINK)$(CC) $(LDFLAGS) -o $@ $(T_VS_OBJS) $(LIBS)
659
660 t/time-test: $(T_TT_OBJS)
661         $(QUIET_LINK)$(CC) $(LDFLAGS) -o $@ $(T_TT_OBJS) $(LIBS)
662
663 ifdef CONFIG_HAVE_CUNIT
664 unittests/unittest: $(UT_OBJS) $(UT_TARGET_OBJS)
665         $(QUIET_LINK)$(CC) $(LDFLAGS) -o $@ $(UT_OBJS) $(UT_TARGET_OBJS) -lcunit $(LIBS)
666 endif
667
668 clean: FORCE
669         @rm -f .depend $(FIO_OBJS) $(GFIO_OBJS) $(OBJS) $(T_OBJS) $(UT_OBJS) $(PROGS) $(T_PROGS) $(T_TEST_PROGS) core.* core gfio unittests/unittest FIO-VERSION-FILE *.[do] lib/*.d oslib/*.[do] crc/*.d engines/*.[do] engines/*.so profiles/*.[do] t/*.[do] t/*/*.[do] unittests/*.[do] unittests/*/*.[do] config-host.mak config-host.h y.tab.[ch] lex.yy.c exp/*.[do] lexer.h
670         @rm -f t/fio-btrace2fio t/io_uring t/read-to-pipe-async
671         @rm -rf  doc/output
672
673 distclean: clean FORCE
674         @rm -f cscope.out fio.pdf fio_generate_plots.pdf fio2gnuplot.pdf fiologparser_hist.pdf
675
676 cscope:
677         @cscope -b -R
678
679 tools/plot/fio2gnuplot.1:
680         @cat tools/plot/fio2gnuplot.manpage | txt2man -t fio2gnuplot >  tools/plot/fio2gnuplot.1
681
682 doc: tools/plot/fio2gnuplot.1
683         @man -t ./fio.1 | ps2pdf - fio.pdf
684         @man -t tools/fio_generate_plots.1 | ps2pdf - fio_generate_plots.pdf
685         @man -t tools/plot/fio2gnuplot.1 | ps2pdf - fio2gnuplot.pdf
686         @man -t tools/hist/fiologparser_hist.py.1 | ps2pdf - fiologparser_hist.pdf
687
688 test: fio
689         ./fio --minimal --thread --exitall_on_error --runtime=1s --name=nulltest --ioengine=null --rw=randrw --iodepth=2 --norandommap --random_generator=tausworthe64 --size=16T --name=verifyfstest --filename=fiotestfile.tmp --unlink=1 --rw=write --verify=crc32c --verify_state_save=0 --size=16K
690
691 fulltest:
692         sudo modprobe null_blk &&                                       \
693         if [ ! -e /usr/include/libzbc/zbc.h ]; then                     \
694           git clone https://github.com/westerndigitalcorporation/libzbc && \
695           (cd libzbc &&                                                 \
696            ./autogen.sh &&                                              \
697            ./configure --prefix=/usr &&                                 \
698            make -j &&                                                   \
699            sudo make install)                                           \
700         fi &&                                                           \
701         sudo t/zbd/run-tests-against-nullb -s 1 &&                      \
702         if [ -e /sys/module/null_blk/parameters/zoned ]; then           \
703                 sudo t/zbd/run-tests-against-nullb -s 2;                \
704                 sudo t/zbd/run-tests-against-nullb -s 4;                \
705         fi
706
707 install: $(PROGS) $(SCRIPTS) $(ENGS_OBJS) tools/plot/fio2gnuplot.1 FORCE
708         $(INSTALL) -m 755 -d $(DESTDIR)$(bindir)
709         $(INSTALL) $(PROGS) $(SCRIPTS) $(DESTDIR)$(bindir)
710 ifdef CONFIG_DYNAMIC_ENGINES
711         $(INSTALL) -m 755 -d $(DESTDIR)$(libdir)
712         $(INSTALL) -m 755 $(SRCDIR)/engines/*.so $(DESTDIR)$(libdir)
713 endif
714         $(INSTALL) -m 755 -d $(DESTDIR)$(mandir)/man1
715         $(INSTALL) -m 644 $(SRCDIR)/fio.1 $(DESTDIR)$(mandir)/man1
716         $(INSTALL) -m 644 $(SRCDIR)/tools/fio_generate_plots.1 $(DESTDIR)$(mandir)/man1
717         $(INSTALL) -m 644 $(SRCDIR)/tools/plot/fio2gnuplot.1 $(DESTDIR)$(mandir)/man1
718         $(INSTALL) -m 644 $(SRCDIR)/tools/hist/fiologparser_hist.py.1 $(DESTDIR)$(mandir)/man1
719         $(INSTALL) -m 755 -d $(DESTDIR)$(sharedir)
720         $(INSTALL) -m 644 $(SRCDIR)/tools/plot/*gpm $(DESTDIR)$(sharedir)/
721
722 .PHONY: test fulltest