FIO-VERSION-GEN: use `foo` instead of $(foo)
[fio.git] / Makefile
1 DEBUGFLAGS = -D_FORTIFY_SOURCE=2 -DFIO_INC_DEBUG
2 CPPFLAGS= -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 $(DEBUGFLAGS)
3 OPTFLAGS= -O3 -g -ffast-math $(EXTFLAGS)
4 CFLAGS  = -std=gnu99 -Wwrite-strings -Wall $(OPTFLAGS)
5 LIBS    = -lm $(EXTLIBS)
6 PROGS   = fio
7 SCRIPTS = fio_generate_plots
8 UNAME  := $(shell uname)
9
10 ifneq ($(wildcard config-host.mak),)
11 all:
12 include config-host.mak
13 config-host-mak: configure
14         @echo $@ is out-of-date, running configure
15         @sed -n "/.*Configured with/s/[^:]*: //p" $@ | sh
16 else
17 config-host.mak:
18         @echo "Running configure for you..."
19         @./configure
20 all:
21 include config-host.mak
22 endif
23
24 SOURCE := gettime.c fio.c ioengines.c init.c stat.c log.c time.c filesetup.c \
25                 eta.c verify.c memory.c io_u.c parse.c mutex.c options.c \
26                 rbtree.c smalloc.c filehash.c profile.c debug.c lib/rand.c \
27                 lib/num2str.c lib/ieee754.c $(wildcard crc/*.c) engines/cpu.c \
28                 engines/mmap.c engines/sync.c engines/null.c engines/net.c \
29                 memalign.c server.c client.c iolog.c backend.c libfio.c flow.c \
30                 json.c lib/zipf.c lib/axmap.c lib/lfsr.c gettime-thread.c \
31                 helpers.c lib/flist_sort.c lib/hweight.c lib/getrusage.c \
32                 idletime.c
33
34 ifdef CONFIG_64BIT_LLP64
35   CFLAGS += -DBITS_PER_LONG=32
36 endif
37 ifdef CONFIG_64BIT
38   CFLAGS += -DBITS_PER_LONG=64
39 endif
40 ifdef CONFIG_32BIT
41   CFLAGS += -DBITS_PER_LONG=32
42 endif
43 ifdef CONFIG_LIBAIO
44   SOURCE += engines/libaio.c
45 endif
46 ifdef CONFIG_RDMA
47   SOURCE += engines/rdma.c
48 endif
49 ifdef CONFIG_POSIXAIO
50   SOURCE += engines/posixaio.c
51 endif
52 ifdef CONFIG_LINUX_FALLOCATE
53   SOURCE += engines/falloc.c
54 endif
55 ifdef CONFIG_LINUX_EXT4_MOVE_EXTENT
56   SOURCE += engines/e4defrag.c
57 endif
58 ifdef CONFIG_LINUX_SPLICE
59   SOURCE += engines/splice.c
60 endif
61 ifdef CONFIG_GUASI
62   SOURCE += engines/guasi.c
63 endif
64 ifdef CONFIG_FUSION_AW
65   SOURCE += engines/fusion-aw.c
66 endif
67 ifdef CONFIG_SOLARISAIO
68   SOURCE += engines/solarisaio.c
69 endif
70 ifdef CONFIG_WINDOWSAIO
71   SOURCE += engines/windowsaio.c
72 endif
73 ifndef CONFIG_STRSEP
74   SOURCE += lib/strsep.c
75 endif
76 ifndef CONFIG_GETOPT_LONG_ONLY
77   SOURCE += lib/getopt_long.c
78 endif
79 ifndef CONFIG_INET_ATON
80   SOURCE += lib/inet_aton.c
81 endif
82
83 ifeq ($(UNAME), Linux)
84   SOURCE += diskutil.c fifo.c blktrace.c cgroup.c trim.c engines/sg.c \
85                 engines/binject.c profiles/tiobench.c
86   LIBS += -lpthread -ldl
87   LDFLAGS += -rdynamic
88 endif
89 ifeq ($(UNAME), Android)
90   SOURCE += diskutil.c fifo.c blktrace.c trim.c profiles/tiobench.c
91   LIBS += -ldl
92   LDFLAGS += -rdynamic
93 endif
94 ifeq ($(UNAME), SunOS)
95   LIBS   += -lpthread -ldl -laio -lrt -lnsl -lsocket
96   CPPFLAGS += -D__EXTENSIONS__
97 endif
98 ifeq ($(UNAME), FreeBSD)
99   LIBS   += -lpthread -lrt
100   LDFLAGS += -rdynamic
101 endif
102 ifeq ($(UNAME), NetBSD)
103   LIBS   += -lpthread -lrt
104   LDFLAGS += -rdynamic
105 endif
106 ifeq ($(UNAME), AIX)
107   LIBS   += -lpthread -ldl -lrt
108   CPPFLAGS += -D_LARGE_FILES -D__ppc__
109   LDFLAGS += -L/opt/freeware/lib -Wl,-blibpath:/opt/freeware/lib:/usr/lib:/lib -Wl,-bmaxdata:0x80000000
110 endif
111 ifeq ($(UNAME), HP-UX)
112   LIBS   += -lpthread -ldl -lrt
113   CFLAGS += -D_LARGEFILE64_SOURCE -D_XOPEN_SOURCE_EXTENDED
114 endif
115 ifeq ($(UNAME), Darwin)
116   LIBS   += -lpthread -ldl
117 endif
118 ifneq (,$(findstring CYGWIN,$(UNAME)))
119   SOURCE := $(filter-out engines/mmap.c,$(SOURCE))
120   SOURCE += os/windows/posix.c
121   LIBS   += -lpthread -lpsapi -lws2_32
122   CFLAGS += -DPSAPI_VERSION=1 -Ios/windows/posix/include -Wno-format
123 endif
124
125 OBJS = $(SOURCE:.c=.o)
126 -include $(OBJS:.o=.d)
127
128 T_SMALLOC_OBJS = t/stest.o
129 T_SMALLOC_OBJS += gettime.o mutex.o smalloc.o t/log.o
130 T_SMALLOC_PROGS = t/stest
131
132 T_IEEE_OBJS = t/ieee754.o
133 T_IEEE_OBJS += lib/ieee754.o
134 T_IEEE_PROGS = t/ieee754
135
136 T_ZIPF_OBS = t/genzipf.o
137 T_ZIPF_OBJS += t/log.o lib/ieee754.o lib/rand.o lib/zipf.o t/genzipf.o
138 T_ZIPF_PROGS = t/genzipf
139
140 T_AXMAP_OBJS = t/axmap.o
141 T_AXMAP_OBJS += lib/lfsr.o lib/axmap.o
142 T_AXMAP_PROGS = t/axmap
143
144 T_OBJS = $(T_SMALLOC_OBJS)
145 T_OBJS += $(T_IEEE_OBJS)
146 T_OBJS += $(T_ZIPF_OBJS)
147 T_OBJS += $(T_AXMAP_OBJS)
148
149 T_PROGS = $(T_SMALLOC_PROGS)
150 T_PROGS += $(T_IEEE_PROGS)
151 T_PROGS += $(T_ZIPF_PROGS)
152 T_PROGS += $(T_AXMAP_PROGS)
153
154 ifneq ($(findstring $(MAKEFLAGS),s),s)
155 ifndef V
156         QUIET_CC        = @echo '   ' CC $@;
157         QUIET_LINK      = @echo '   ' LINK $@;
158         QUIET_DEP       = @echo '   ' DEP $@;
159 endif
160 endif
161
162 INSTALL = install
163 prefix = /usr/local
164 bindir = $(prefix)/bin
165
166 ifeq ($(UNAME), Darwin)
167 mandir = /usr/share/man
168 else
169 mandir = $(prefix)/man
170 endif
171
172 all: $(PROGS) $(SCRIPTS) FORCE
173
174 .PHONY: all install clean
175 .PHONY: FORCE cscope
176
177 FIO-VERSION-FILE: FORCE
178         @$(SHELL) ./FIO-VERSION-GEN
179 -include FIO-VERSION-FILE
180
181 override CFLAGS += -DFIO_VERSION='"$(FIO_VERSION)"'
182
183 .c.o: FORCE FIO-VERSION-FILE
184         $(QUIET_CC)$(CC) -o $@ $(CFLAGS) $(CPPFLAGS) -c $<
185         @$(CC) -MM $(CFLAGS) $(CPPFLAGS) $*.c > $*.d
186         @mv -f $*.d $*.d.tmp
187         @sed -e 's|.*:|$*.o:|' < $*.d.tmp > $*.d
188         @sed -e 's/.*://' -e 's/\\$$//' < $*.d.tmp | fmt -1 | \
189                 sed -e 's/^ *//' -e 's/$$/:/' >> $*.d
190         @rm -f $*.d.tmp
191
192 init.o: FIO-VERSION-FILE init.c
193         $(QUIET_CC)$(CC) -o init.o $(CFLAGS) $(CPPFLAGS) -c init.c
194
195 t/stest: $(T_SMALLOC_OBJS)
196         $(QUIET_LINK)$(CC) $(LDFLAGS) $(CFLAGS) -o $@ $(T_SMALLOC_OBJS) $(LIBS) $(LDFLAGS)
197
198 t/ieee754: $(T_IEEE_OBJS)
199         $(QUIET_LINK)$(CC) $(LDFLAGS) $(CFLAGS) -o $@ $(T_IEEE_OBJS) $(LIBS) $(LDFLAGS)
200
201 t/genzipf: $(T_ZIPF_OBJS)
202         $(QUIET_LINK)$(CC) $(LDFLAGS) $(CFLAGS) -o $@ $(T_ZIPF_OBJS) $(LIBS) $(LDFLAGS)
203
204 t/axmap: $(T_AXMAP_OBJS)
205         $(QUIET_LINK)$(CC) $(LDFLAGS) $(CFLAGS) -o $@ $(T_AXMAP_OBJS) $(LIBS) $(LDFLAGS)
206
207 fio: $(OBJS)
208         $(QUIET_LINK)$(CC) $(LDFLAGS) $(CFLAGS) -o $@ $(OBJS) $(LIBS) $(LDFLAGS)
209
210 clean: FORCE
211         -rm -f .depend $(OBJS) $(T_OBJS) $(PROGS) $(T_PROGS) core.* core FIO-VERSION-FILE config-host.mak cscope.out *.d
212
213 cscope:
214         @cscope -b -R
215
216 install: $(PROGS) $(SCRIPTS) FORCE
217         $(INSTALL) -m 755 -d $(DESTDIR)$(bindir)
218         $(INSTALL) $(PROGS) $(SCRIPTS) $(DESTDIR)$(bindir)
219         $(INSTALL) -m 755 -d $(DESTDIR)$(mandir)/man1
220         $(INSTALL) -m 644 fio.1 $(DESTDIR)$(mandir)/man1
221         $(INSTALL) -m 644 fio_generate_plots.1 $(DESTDIR)$(mandir)/man1