f72bf8e2562f6d941bc18a5984c0bab21a2c6f6e
[fio.git] / Makefile
1 CC      = gcc
2 DEBUGFLAGS = -D_FORTIFY_SOURCE=2 -DFIO_INC_DEBUG
3 CPPFLAGS= -D_GNU_SOURCE -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 \
4         $(DEBUGFLAGS)
5 OPTFLAGS= -O3 -fno-omit-frame-pointer -g $(EXTFLAGS)
6 CFLAGS  = -std=gnu99 -Wwrite-strings -Wall $(OPTFLAGS)
7 LIBS    = -lm $(EXTLIBS)
8 PROGS   = fio
9 SCRIPTS = fio_generate_plots
10 UNAME  := $(shell uname)
11
12 SOURCE := gettime.c fio.c ioengines.c init.c stat.c log.c time.c filesetup.c \
13                 eta.c verify.c memory.c io_u.c parse.c mutex.c options.c \
14                 rbtree.c smalloc.c filehash.c profile.c debug.c lib/rand.c \
15                 lib/num2str.c lib/ieee754.c $(wildcard crc/*.c) engines/cpu.c \
16                 engines/mmap.c engines/sync.c engines/null.c engines/net.c \
17                 memalign.c server.c client.c iolog.c backend.c libfio.c flow.c
18
19 ifeq ($(UNAME), Linux)
20   SOURCE += diskutil.c fifo.c blktrace.c helpers.c cgroup.c trim.c \
21                 engines/libaio.c engines/posixaio.c engines/sg.c \
22                 engines/splice.c engines/syslet-rw.c engines/guasi.c \
23                 engines/binject.c engines/rdma.c profiles/tiobench.c
24   LIBS += -lpthread -ldl -lrt -laio
25   LDFLAGS += -rdynamic
26 endif
27 ifeq ($(UNAME), SunOS)
28   SOURCE += fifo.c lib/strsep.c helpers.c engines/posixaio.c \
29                 engines/solarisaio.c
30   LIBS   += -lpthread -ldl -laio -lrt -lnsl -lsocket
31   CPPFLAGS += -D__EXTENSIONS__
32 endif
33 ifeq ($(UNAME), FreeBSD)
34   SOURCE += helpers.c engines/posixaio.c
35   LIBS   += -lpthread -lrt
36   LDFLAGS += -rdynamic
37 endif
38 ifeq ($(UNAME), NetBSD)
39   SOURCE += helpers.c engines/posixaio.c
40   LIBS   += -lpthread -lrt
41   LDFLAGS += -rdynamic
42 endif
43 ifeq ($(UNAME), AIX)
44   SOURCE += fifo.c helpers.c lib/getopt_long.c engines/posixaio.c
45   LIBS   += -lpthread -ldl -lrt
46   CPPFLAGS += -D_LARGE_FILES -D__ppc__
47   LDFLAGS += -L/opt/freeware/lib -Wl,-blibpath:/opt/freeware/lib:/usr/lib:/lib -Wl,-bmaxdata:0x80000000
48 endif
49 ifeq ($(UNAME), HP-UX)
50   SOURCE += fifo.c helpers.c lib/getopt_long.c lib/strsep.c engines/posixaio.c
51   LIBS   += -lpthread -ldl -lrt
52   CFLAGS += -D_LARGEFILE64_SOURCE
53 endif
54 ifeq ($(UNAME), Darwin)
55   SOURCE += helpers.c engines/posixaio.c
56   LIBS   += -lpthread -ldl
57 endif
58 ifneq (,$(findstring CYGWIN,$(UNAME)))
59   SOURCE := $(filter-out engines/mmap.c,$(SOURCE))
60   SOURCE += engines/windowsaio.c os/windows/posix.c
61   LIBS   += -lpthread -lpsapi -lws2_32
62   CFLAGS += -DPSAPI_VERSION=1 -Ios/windows/posix/include -Wno-format
63   CC      = x86_64-w64-mingw32-gcc
64 endif
65
66 OBJS = $(SOURCE:.c=.o)
67
68 T_SMALLOC_OBJS = t/stest.o
69 T_SMALLOC_OBJS += mutex.o smalloc.o t/log.o
70 T_SMALLOC_PROGS = t/stest
71
72 T_IEEE_OBJS = t/ieee754.o
73 T_IEEE_OBJS += ieee754.o
74 T_IEEE_PROGS = t/ieee754
75
76 T_OBJS = $(T_SMALLOC_OBJS)
77 T_OBJS += $(T_IEEE_OBJS)
78
79 ifneq ($(findstring $(MAKEFLAGS),s),s)
80 ifndef V
81         QUIET_CC        = @echo '   ' CC $@;
82         QUIET_DEP       = @echo '   ' DEP $@;
83 endif
84 endif
85
86 INSTALL = install
87 prefix = /usr/local
88 bindir = $(prefix)/bin
89
90 ifeq ($(UNAME), Darwin)
91 mandir = /usr/share/man
92 else
93 mandir = $(prefix)/man
94 endif
95
96 all: .depend $(PROGS) $(SCRIPTS) FORCE
97
98 .PHONY: all install clean
99 .PHONY: FORCE cscope
100
101 FIO-VERSION-FILE: FORCE
102         @$(SHELL) ./FIO-VERSION-GEN
103 -include FIO-VERSION-FILE
104
105 CFLAGS += -DFIO_VERSION='"$(FIO_VERSION)"'
106
107 .c.o: .depend FORCE
108         $(QUIET_CC)$(CC) -o $@ -c $(CFLAGS) $(CPPFLAGS) $<
109
110 init.o: FIO-VERSION-FILE
111         $(QUIET_CC)$(CC) -o init.o -c $(CFLAGS) $(CPPFLAGS) -c init.c
112
113 t/stest: $(T_SMALLOC_OBJS)
114         $(QUIET_CC)$(CC) $(LDFLAGS) $(CFLAGS) -o $@ $(T_SMALLOC_OBJS) $(LIBS) $(LDFLAGS)
115
116 t/ieee754: $(T_IEEE_OBJS)
117         $(QUIET_CC)$(CC) $(LDFLAGS) $(CFLAGS) -o $@ $(T_IEEE_OBJS) $(LIBS) $(LDFLAGS)
118
119 fio: $(OBJS)
120         $(QUIET_CC)$(CC) $(LDFLAGS) $(CFLAGS) -o $@ $(OBJS) $(LIBS) $(LDFLAGS)
121
122 .depend: $(SOURCE)
123         $(QUIET_DEP)$(CC) -MM $(CFLAGS) $(CPPFLAGS) $(SOURCE) 1> .depend
124
125 $(PROGS): .depend
126
127 clean: FORCE
128         -rm -f .depend $(OBJS) $(T_OBJS) $(PROGS) $(T_PROGS) core.* core FIO-VERSION-FILE
129
130 cscope:
131         @cscope -b -R
132
133 install: $(PROGS) $(SCRIPTS) FORCE
134         $(INSTALL) -m 755 -d $(DESTDIR)$(bindir)
135         $(INSTALL) $(PROGS) $(SCRIPTS) $(DESTDIR)$(bindir)
136         $(INSTALL) -m 755 -d $(DESTDIR)$(mandir)/man1
137         $(INSTALL) -m 644 fio.1 $(DESTDIR)$(mandir)/man1
138         $(INSTALL) -m 644 fio_generate_plots.1 $(DESTDIR)$(mandir)/man1
139
140 ifneq ($(wildcard .depend),)
141 include .depend
142 endif