configure: add endian check
[fio.git] / Makefile
1 DEBUGFLAGS = -D_FORTIFY_SOURCE=2 -DFIO_INC_DEBUG
2 CPPFLAGS= -D_GNU_SOURCE -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 \
3         $(DEBUGFLAGS)
4 OPTFLAGS= -O3 -g -ffast-math $(EXTFLAGS)
5 CFLAGS  = -std=gnu99 -Wwrite-strings -Wall $(OPTFLAGS)
6 LIBS    = -lm $(EXTLIBS)
7 PROGS   = fio
8 SCRIPTS = fio_generate_plots
9 UNAME  := $(shell uname)
10
11 ifneq ($(wildcard config-host.mak),)
12 all:
13 include config-host.mak
14 config-host-mak: configure
15         @echo $@ is out-of-date, running configure
16         @sed -n "/.*Configured with/s/[^:]*: //p" $@ | sh
17 else
18 config-host.mak:
19         @echo "Running configure for you..."
20         @./configure
21 all:
22 include config-host.mak
23 endif
24
25 SOURCE := gettime.c fio.c ioengines.c init.c stat.c log.c time.c filesetup.c \
26                 eta.c verify.c memory.c io_u.c parse.c mutex.c options.c \
27                 rbtree.c smalloc.c filehash.c profile.c debug.c lib/rand.c \
28                 lib/num2str.c lib/ieee754.c $(wildcard crc/*.c) engines/cpu.c \
29                 engines/mmap.c engines/sync.c engines/null.c engines/net.c \
30                 memalign.c server.c client.c iolog.c backend.c libfio.c flow.c \
31                 json.c lib/zipf.c lib/axmap.c lib/lfsr.c gettime-thread.c \
32                 helpers.c lib/flist_sort.c lib/hweight.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_BIG_ENDIAN
44   CFLAGS += -DCONFIG_BIG_ENDIAN
45 endif
46 ifdef CONFIG_LITTLE_ENDIAN
47   CFLAGS += -DCONFIG_LITTLE_ENDIAN
48 endif
49 ifdef CONFIG_LIBAIO
50   CFLAGS += -DCONFIG_LIBAIO
51   SOURCE += engines/libaio.c
52 endif
53 ifdef CONFIG_RDMA
54   CFLAGS += -DCONFIG_RDMA
55   SOURCE += engines/rdma.c
56 endif
57 ifdef CONFIG_POSIXAIO
58   CFLAGS += -DCONFIG_POSIXAIO
59   SOURCE += engines/posixaio.c
60 endif
61 ifdef CONFIG_LINUX_FALLOCATE
62   SOURCE += engines/falloc.c
63 endif
64 ifdef CONFIG_LINUX_EXT4_MOVE_EXTENT
65   SOURCE += engines/e4defrag.c
66 endif
67 ifdef CONFIG_LINUX_SPLICE
68   CFLAGS += -DCONFIG_LINUX_SPLICE
69   SOURCE += engines/splice.c
70 endif
71 ifdef CONFIG_GUASI
72   CFLAGS += -DCONFIG_GUASI
73   SOURCE += engines/guasi.c
74 endif
75 ifdef CONFIG_FUSION_AW
76   CFLAGS += -DCONFIG_FUSION_AW
77   SOURCE += engines/fusion-aw.c
78 endif
79 ifdef CONFIG_SOLARISAIO
80   CFLAGS += -DCONFIG_SOLARISAIO
81   SOURCE += engines/solarisaio.c
82 endif
83
84 ifndef CONFIG_STRSEP
85   CFLAGS += -DCONFIG_STRSEP
86   SOURCE += lib/strsep.c
87 endif
88 ifndef CONFIG_GETOPT_LONG_ONLY
89   CFLAGS += -DCONFIG_GETOPT_LONG_ONLY
90   SOURCE += lib/getopt_long.c
91 endif
92
93 ifndef CONFIG_INET_ATON
94   CFLAGS += -DCONFIG_INET_ATON
95   SOURCE += lib/inet_aton.c
96 endif
97 ifdef CONFIG_CLOCK_GETTIME
98   CFLAGS += -DCONFIG_CLOCK_GETTIME
99 endif
100 ifdef CONFIG_POSIXAIO_FSYNC
101   CFLAGS += -DCONFIG_POSIXAIO_FSYNC
102 endif
103 ifdef CONFIG_FADVISE
104   CFLAGS += -DCONFIG_FADVISE
105 endif
106 ifdef CONFIG_CLOCK_MONOTONIC
107   CFLAGS += -DCONFIG_CLOCK_MONOTONIC
108 endif
109 ifdef CONFIG_CLOCK_MONOTONIC_PRECISE
110   CFLAGS += -DCONFIG_CLOCK_MONOTONIC_PRECISE
111 endif
112 ifdef CONFIG_GETTIMEOFDAY
113   CFLAGS += -DCONFIG_GETTIMEOFDAY
114 endif
115 ifdef CONFIG_SOCKLEN_T
116   CFLAGS += -DCONFIG_SOCKLEN_T
117 endif
118 ifdef CONFIG_SFAA
119   CFLAGS += -DCONFIG_SFAA
120 endif
121 ifdef CONFIG_FDATASYNC
122   CFLAGS += -DCONFIG_FDATASYNC
123 endif
124 ifdef CONFIG_3ARG_AFFINITY
125   CFLAGS += -DCONFIG_3ARG_AFFINITY
126 endif
127 ifdef CONFIG_2ARG_AFFINITY
128   CFLAGS += -DCONFIG_2ARG_AFFINITY
129 endif
130 ifdef CONFIG_SYNC_FILE_RANGE
131   CFLAGS += -DCONFIG_SYNC_FILE_RANGE
132 endif
133 ifdef CONFIG_LIBNUMA
134   CFLAGS += -DCONFIG_LIBNUMA
135 endif
136 ifdef CONFIG_TLS_THREAD
137   CFLAGS += -DCONFIG_TLS_THREAD
138 endif
139 ifdef CONFIG_POSIX_FALLOCATE
140   CFLAGS += -DCONFIG_POSIX_FALLOCATE
141 endif
142 ifdef CONFIG_LINUX_FALLOCATE
143   CFLAGS += -DCONFIG_LINUX_FALLOCATE
144 endif
145
146 ifeq ($(UNAME), Linux)
147   SOURCE += diskutil.c fifo.c blktrace.c cgroup.c trim.c engines/sg.c \
148                 engines/binject.c profiles/tiobench.c
149   LIBS += -lpthread -ldl
150   LDFLAGS += -rdynamic
151 endif
152 ifeq ($(UNAME), Android)
153   SOURCE += diskutil.c fifo.c blktrace.c trim.c profiles/tiobench.c
154   LIBS += -ldl
155   LDFLAGS += -rdynamic
156   CPPFLAGS += -DFIO_NO_HAVE_SHM_H
157 endif
158 ifeq ($(UNAME), SunOS)
159   LIBS   += -lpthread -ldl -laio -lrt -lnsl -lsocket
160   CPPFLAGS += -D__EXTENSIONS__
161 endif
162 ifeq ($(UNAME), FreeBSD)
163   LIBS   += -lpthread -lrt
164   LDFLAGS += -rdynamic
165 endif
166 ifeq ($(UNAME), NetBSD)
167   LIBS   += -lpthread -lrt
168   LDFLAGS += -rdynamic
169 endif
170 ifeq ($(UNAME), AIX)
171   LIBS   += -lpthread -ldl -lrt
172   CPPFLAGS += -D_LARGE_FILES -D__ppc__
173   LDFLAGS += -L/opt/freeware/lib -Wl,-blibpath:/opt/freeware/lib:/usr/lib:/lib -Wl,-bmaxdata:0x80000000
174 endif
175 ifeq ($(UNAME), HP-UX)
176   LIBS   += -lpthread -ldl -lrt
177   CFLAGS += -D_LARGEFILE64_SOURCE -D_XOPEN_SOURCE_EXTENDED
178 endif
179 ifeq ($(UNAME), Darwin)
180   LIBS   += -lpthread -ldl
181 endif
182 ifneq (,$(findstring CYGWIN,$(UNAME)))
183   SOURCE := $(filter-out engines/mmap.c,$(SOURCE))
184   SOURCE += engines/windowsaio.c os/windows/posix.c
185   LIBS   += -lpthread -lpsapi -lws2_32
186   CFLAGS += -DPSAPI_VERSION=1 -Ios/windows/posix/include -Wno-format
187 endif
188
189 OBJS = $(SOURCE:.c=.o)
190
191 T_SMALLOC_OBJS = t/stest.o
192 T_SMALLOC_OBJS += gettime.o mutex.o smalloc.o t/log.o
193 T_SMALLOC_PROGS = t/stest
194
195 T_IEEE_OBJS = t/ieee754.o
196 T_IEEE_OBJS += lib/ieee754.o
197 T_IEEE_PROGS = t/ieee754
198
199 T_ZIPF_OBS = t/genzipf.o
200 T_ZIPF_OBJS += t/log.o lib/ieee754.o lib/rand.o lib/zipf.o t/genzipf.o
201 T_ZIPF_PROGS = t/genzipf
202
203 T_AXMAP_OBJS = t/axmap.o
204 T_AXMAP_OBJS += lib/lfsr.o lib/axmap.o
205 T_AXMAP_PROGS = t/axmap
206
207 T_OBJS = $(T_SMALLOC_OBJS)
208 T_OBJS += $(T_IEEE_OBJS)
209 T_OBJS += $(T_ZIPF_OBJS)
210 T_OBJS += $(T_AXMAP_OBJS)
211
212 T_PROGS = $(T_SMALLOC_PROGS)
213 T_PROGS += $(T_IEEE_PROGS)
214 T_PROGS += $(T_ZIPF_PROGS)
215 T_PROGS += $(T_AXMAP_PROGS)
216
217 ifneq ($(findstring $(MAKEFLAGS),s),s)
218 ifndef V
219         QUIET_CC        = @echo '   ' CC $@;
220         QUIET_DEP       = @echo '   ' DEP $@;
221 endif
222 endif
223
224 INSTALL = install
225 prefix = /usr/local
226 bindir = $(prefix)/bin
227
228 ifeq ($(UNAME), Darwin)
229 mandir = /usr/share/man
230 else
231 mandir = $(prefix)/man
232 endif
233
234 all: .depend $(PROGS) $(SCRIPTS) FORCE
235
236 .PHONY: all install clean
237 .PHONY: FORCE cscope
238
239 FIO-VERSION-FILE: FORCE
240         @$(SHELL) ./FIO-VERSION-GEN
241 -include FIO-VERSION-FILE
242
243 CFLAGS += -DFIO_VERSION='"$(FIO_VERSION)"'
244
245 .c.o: .depend FORCE
246         $(QUIET_CC)$(CC) -o $@ -c $(CFLAGS) $(CPPFLAGS) $<
247
248 init.o: FIO-VERSION-FILE
249         $(QUIET_CC)$(CC) -o init.o -c $(CFLAGS) $(CPPFLAGS) -c init.c
250
251 t/stest: $(T_SMALLOC_OBJS)
252         $(QUIET_CC)$(CC) $(LDFLAGS) $(CFLAGS) -o $@ $(T_SMALLOC_OBJS) $(LIBS) $(LDFLAGS)
253
254 t/ieee754: $(T_IEEE_OBJS)
255         $(QUIET_CC)$(CC) $(LDFLAGS) $(CFLAGS) -o $@ $(T_IEEE_OBJS) $(LIBS) $(LDFLAGS)
256
257 t/genzipf: $(T_ZIPF_OBJS)
258         $(QUIET_CC)$(CC) $(LDFLAGS) $(CFLAGS) -o $@ $(T_ZIPF_OBJS) $(LIBS) $(LDFLAGS)
259
260 t/axmap: $(T_AXMAP_OBJS)
261         $(QUIET_CC)$(CC) $(LDFLAGS) $(CFLAGS) -o $@ $(T_AXMAP_OBJS) $(LIBS) $(LDFLAGS)
262
263 fio: $(OBJS)
264         $(QUIET_CC)$(CC) $(LDFLAGS) $(CFLAGS) -o $@ $(OBJS) $(LIBS) $(LDFLAGS)
265
266 .depend: $(SOURCE)
267         $(QUIET_DEP)$(CC) -MM $(CFLAGS) $(CPPFLAGS) $(SOURCE) 1> .depend
268
269 $(PROGS): .depend
270
271 clean: FORCE
272         -rm -f .depend $(OBJS) $(T_OBJS) $(PROGS) $(T_PROGS) core.* core FIO-VERSION-FILE config-host.mak config-host.ld cscope.out
273
274 cscope:
275         @cscope -b -R
276
277 install: $(PROGS) $(SCRIPTS) FORCE
278         $(INSTALL) -m 755 -d $(DESTDIR)$(bindir)
279         $(INSTALL) $(PROGS) $(SCRIPTS) $(DESTDIR)$(bindir)
280         $(INSTALL) -m 755 -d $(DESTDIR)$(mandir)/man1
281         $(INSTALL) -m 644 fio.1 $(DESTDIR)$(mandir)/man1
282         $(INSTALL) -m 644 fio_generate_plots.1 $(DESTDIR)$(mandir)/man1
283
284 ifneq ($(wildcard .depend),)
285 include .depend
286 endif