buf_size: ignore certain assignments
[smatch.git] / Makefile
blobec3a5a84ff7dd1a3563310581be225b2a3c9a228
1 VERSION=0.6.1-rc1
3 ########################################################################
4 # The following variables can be overwritten from the command line
5 OS = linux
8 CC ?= gcc
9 LD = $(CC)
10 AR = ar
12 CFLAGS ?= -g
14 DESTDIR ?=
15 PREFIX ?= $(HOME)
16 BINDIR ?= $(PREFIX)/bin
17 MANDIR ?= $(PREFIX)/share/man
19 PKG_CONFIG ?= pkg-config
21 CHECKER_FLAGS ?= -Wno-vla
23 # Allow users to override build settings without dirtying their trees
24 # For debugging, put this in local.mk:
26 # CFLAGS += -O0 -DDEBUG -g3 -gdwarf-2
28 SPARSE_LOCAL_CONFIG ?= local.mk
29 -include ${SPARSE_LOCAL_CONFIG}
30 ########################################################################
33 LIB_OBJS :=
34 LIB_OBJS += allocate.o
35 LIB_OBJS += builtin.o
36 LIB_OBJS += char.o
37 LIB_OBJS += compat-$(OS).o
38 LIB_OBJS += cse.o
39 LIB_OBJS += dissect.o
40 LIB_OBJS += dominate.o
41 LIB_OBJS += evaluate.o
42 LIB_OBJS += expand.o
43 LIB_OBJS += expression.o
44 LIB_OBJS += flow.o
45 LIB_OBJS += flowgraph.o
46 LIB_OBJS += inline.o
47 LIB_OBJS += ir.o
48 LIB_OBJS += lib.o
49 LIB_OBJS += linearize.o
50 LIB_OBJS += liveness.o
51 LIB_OBJS += memops.o
52 LIB_OBJS += opcode.o
53 LIB_OBJS += optimize.o
54 LIB_OBJS += parse.o
55 LIB_OBJS += pre-process.o
56 LIB_OBJS += ptrlist.o
57 LIB_OBJS += ptrmap.o
58 LIB_OBJS += scope.o
59 LIB_OBJS += show-parse.o
60 LIB_OBJS += simplify.o
61 LIB_OBJS += sort.o
62 LIB_OBJS += ssa.o
63 LIB_OBJS += sset.o
64 LIB_OBJS += stats.o
65 LIB_OBJS += storage.o
66 LIB_OBJS += symbol.o
67 LIB_OBJS += target.o
68 LIB_OBJS += tokenize.o
69 LIB_OBJS += unssa.o
70 LIB_OBJS += utils.o
71 LIB_OBJS += macro_table.o
72 LIB_OBJS += token_store.o
73 LIB_OBJS += cwchash/hashtable.o
75 PROGRAMS :=
76 PROGRAMS += compile
77 PROGRAMS += ctags
78 PROGRAMS += example
79 PROGRAMS += graph
80 PROGRAMS += obfuscate
81 PROGRAMS += sparse
82 PROGRAMS += test-dissect
83 PROGRAMS += test-lexing
84 PROGRAMS += test-linearize
85 PROGRAMS += test-parsing
86 PROGRAMS += test-unssa
88 INST_PROGRAMS=smatch sparse cgcc
89 INST_MAN1=sparse.1 cgcc.1
92 all:
94 ########################################################################
95 # common flags/options/...
97 cflags = -fno-strict-aliasing
98 cflags += -Wall -Wwrite-strings -Wno-switch -Wno-psabi
100 GCC_BASE := $(shell $(CC) --print-file-name=)
101 cflags += -DGCC_BASE=\"$(GCC_BASE)\"
103 MULTIARCH_TRIPLET := $(shell $(CC) -print-multiarch 2>/dev/null)
104 cflags += -DMULTIARCH_TRIPLET=\"$(MULTIARCH_TRIPLET)\"
107 bindir := $(DESTDIR)$(BINDIR)
108 man1dir := $(DESTDIR)$(MANDIR)/man1
110 ########################################################################
111 # target specificities
113 compile: compile-i386.o
114 EXTRA_OBJS += compile-i386.o
116 # Can we use GCC's generated dependencies?
117 HAVE_GCC_DEP:=$(shell touch .gcc-test.c && \
118 $(CC) -c -Wp,-MP,-MMD,.gcc-test.d .gcc-test.c 2>/dev/null && \
119 echo 'yes'; rm -f .gcc-test.d .gcc-test.o .gcc-test.c)
120 ifeq ($(HAVE_GCC_DEP),yes)
121 cflags += -Wp,-MP,-MMD,$(@D)/.$(@F).d
122 endif
124 # Can we use libxml (needed for c2xml)?
125 HAVE_LIBXML:=$(shell $(PKG_CONFIG) --exists libxml-2.0 2>/dev/null && echo 'yes')
126 ifeq ($(HAVE_LIBXML),yes)
127 PROGRAMS+=c2xml
128 INST_PROGRAMS+=c2xml
129 c2xml-ldlibs := $(shell $(PKG_CONFIG) --libs libxml-2.0)
130 c2xml-cflags := $(shell $(PKG_CONFIG) --cflags libxml-2.0)
131 else
132 $(warning Your system does not have libxml, disabling c2xml)
133 endif
135 # Can we use gtk (needed for test-inspect)
136 GTK_VERSION:=3.0
137 HAVE_GTK:=$(shell $(PKG_CONFIG) --exists gtk+-$(GTK_VERSION) 2>/dev/null && echo 'yes')
138 ifneq ($(HAVE_GTK),yes)
139 GTK_VERSION:=2.0
140 HAVE_GTK:=$(shell $(PKG_CONFIG) --exists gtk+-$(GTK_VERSION) 2>/dev/null && echo 'yes')
141 endif
142 ifeq ($(HAVE_GTK),yes)
143 GTK_CFLAGS := $(shell $(PKG_CONFIG) --cflags gtk+-$(GTK_VERSION))
144 ast-view-cflags := $(GTK_CFLAGS)
145 ast-model-cflags := $(GTK_CFLAGS)
146 ast-inspect-cflags := $(GTK_CFLAGS)
147 test-inspect-cflags := $(GTK_CFLAGS)
148 test-inspect-ldlibs := $(shell $(PKG_CONFIG) --libs gtk+-$(GTK_VERSION))
149 test-inspect: ast-model.o ast-view.o ast-inspect.o
150 EXTRA_OBJS += ast-model.o ast-view.o ast-inspect.o
151 PROGRAMS += test-inspect
152 INST_PROGRAMS += test-inspect
153 else
154 $(warning Your system does not have gtk3/gtk2, disabling test-inspect)
155 endif
157 # Can we use LLVM (needed for ... sparse-llvm)?
158 LLVM_CONFIG:=llvm-config
159 HAVE_LLVM:=$(shell $(LLVM_CONFIG) --version >/dev/null 2>&1 && echo 'yes')
160 ifeq ($(HAVE_LLVM),yes)
161 arch := $(shell uname -m)
162 ifeq (${MULTIARCH_TRIPLET},x86_64-linux-gnux32)
163 arch := x32
164 endif
165 ifneq ($(filter ${arch},i386 i486 i586 i686 x86_64 amd64),)
166 LLVM_VERSION:=$(shell $(LLVM_CONFIG) --version)
167 ifeq ($(shell expr "$(LLVM_VERSION)" : '[3-9]\.'),2)
168 LLVM_PROGS := sparse-llvm
169 $(LLVM_PROGS): LD := g++
170 LLVM_LDFLAGS := $(shell $(LLVM_CONFIG) --ldflags)
171 LLVM_CFLAGS := -I$(shell $(LLVM_CONFIG) --includedir)
172 LLVM_LIBS := $(shell $(LLVM_CONFIG) --libs)
173 LLVM_LIBS += $(shell $(LLVM_CONFIG) --system-libs 2>/dev/null)
174 LLVM_LIBS += $(shell $(LLVM_CONFIG) --cxxflags | grep -F -q -e '-stdlib=libc++' && echo -lc++)
175 PROGRAMS += $(LLVM_PROGS)
176 INST_PROGRAMS += sparse-llvm sparsec
177 sparse-llvm-cflags := $(LLVM_CFLAGS) -D__STDC_CONSTANT_MACROS -D__STDC_LIMIT_MACROS
178 sparse-llvm-ldflags := $(LLVM_LDFLAGS)
179 sparse-llvm-ldlibs := $(LLVM_LIBS)
180 else
181 $(warning LLVM 3.0 or later required. Your system has version $(LLVM_VERSION) installed.)
182 endif
183 else
184 $(warning sparse-llvm disabled on ${arch})
185 endif
186 else
187 $(warning Your system does not have llvm, disabling sparse-llvm)
188 endif
190 ########################################################################
191 LIBS := libsparse.a
192 OBJS := $(LIB_OBJS) $(EXTRA_OBJS) $(PROGRAMS:%=%.o)
194 # Pretty print
195 V := @
196 Q := $(V:1=)
198 ########################################################################
200 SMATCHDATADIR=$(INSTALL_PREFIX)/share/smatch
202 SMATCH_OBJS :=
203 SMATCH_OBJS += avl.o
204 SMATCH_OBJS += smatch_about_fn_ptr_arg.o
205 SMATCH_OBJS += smatch_address.o
206 SMATCH_OBJS += smatch_annotate.o
207 SMATCH_OBJS += smatch_array_values.o
208 SMATCH_OBJS += smatch_assigned_expr.o
209 SMATCH_OBJS += smatch_bits.o
210 SMATCH_OBJS += smatch_buf_comparison.o
211 SMATCH_OBJS += smatch_buf_size.o
212 SMATCH_OBJS += smatch_capped.o
213 SMATCH_OBJS += smatch_common_functions.o
214 SMATCH_OBJS += smatch_comparison.o
215 SMATCH_OBJS += smatch_conditions.o
216 SMATCH_OBJS += smatch_constraints.o
217 SMATCH_OBJS += smatch_constraints_required.o
218 SMATCH_OBJS += smatch_container_of.o
219 SMATCH_OBJS += smatch_data_source.o
220 SMATCH_OBJS += smatch_db.o
221 SMATCH_OBJS += smatch_equiv.o
222 SMATCH_OBJS += smatch_estate.o
223 SMATCH_OBJS += smatch_expressions.o
224 SMATCH_OBJS += smatch_expression_stacks.o
225 SMATCH_OBJS += smatch_extra.o
226 SMATCH_OBJS += smatch_files.o
227 SMATCH_OBJS += smatch_flow.o
228 SMATCH_OBJS += smatch_fn_arg_link.o
229 SMATCH_OBJS += smatch_fresh_alloc.o
230 SMATCH_OBJS += smatch_function_hooks.o
231 SMATCH_OBJS += smatch_function_info.o
232 SMATCH_OBJS += smatch_function_ptrs.o
233 SMATCH_OBJS += smatch_helper.o
234 SMATCH_OBJS += smatch_hooks.o
235 SMATCH_OBJS += smatch_ignore.o
236 SMATCH_OBJS += smatch_imaginary_absolute.o
237 SMATCH_OBJS += smatch_implied.o
238 SMATCH_OBJS += smatch_impossible.o
239 SMATCH_OBJS += smatch_integer_overflow.o
240 SMATCH_OBJS += smatch_kernel_user_data.o
241 SMATCH_OBJS += smatch_links.o
242 SMATCH_OBJS += smatch_math.o
243 SMATCH_OBJS += smatch_mem_tracker.o
244 SMATCH_OBJS += smatch_modification_hooks.o
245 SMATCH_OBJS += smatch_mtag_data.o
246 SMATCH_OBJS += smatch_mtag_map.o
247 SMATCH_OBJS += smatch_mtag.o
248 SMATCH_OBJS += smatch_nul_terminator.o
249 SMATCH_OBJS += smatch_param_cleared.o
250 SMATCH_OBJS += smatch_param_compare_limit.o
251 SMATCH_OBJS += smatch_parameter_names.o
252 SMATCH_OBJS += smatch_param_filter.o
253 SMATCH_OBJS += smatch_param_limit.o
254 SMATCH_OBJS += smatch_param_set.o
255 SMATCH_OBJS += smatch_param_to_mtag_data.o
256 SMATCH_OBJS += smatch_param_used.o
257 SMATCH_OBJS += smatch_parse_call_math.o
258 SMATCH_OBJS += smatch_parsed_conditions.o
259 SMATCH_OBJS += smatch_passes_array_size.o
260 SMATCH_OBJS += smatch_project.o
261 SMATCH_OBJS += smatch_ranges.o
262 SMATCH_OBJS += smatch_real_absolute.o
263 SMATCH_OBJS += smatch_recurse.o
264 SMATCH_OBJS += smatch_returns.o
265 SMATCH_OBJS += smatch_return_to_param.o
266 SMATCH_OBJS += smatch_scope.o
267 SMATCH_OBJS += smatch_slist.o
268 SMATCH_OBJS += smatch_start_states.o
269 SMATCH_OBJS += smatch_statement_count.o
270 SMATCH_OBJS += smatch_states.o
271 SMATCH_OBJS += smatch_stored_conditions.o
272 SMATCH_OBJS += smatch_string_list.o
273 SMATCH_OBJS += smatch_strings.o
274 SMATCH_OBJS += smatch_strlen.o
275 SMATCH_OBJS += smatch_struct_assignment.o
276 SMATCH_OBJS += smatch_sval.o
277 SMATCH_OBJS += smatch_tracker.o
278 SMATCH_OBJS += smatch_type_links.o
279 SMATCH_OBJS += smatch_type.o
280 SMATCH_OBJS += smatch_type_val.o
281 SMATCH_OBJS += smatch_unknown_value.o
282 SMATCH_OBJS += smatch_untracked_param.o
283 SMATCH_OBJS += smatch_var_sym.o
285 SMATCH_CHECKS=$(shell ls check_*.c | sed -e 's/\.c/.o/')
286 SMATCH_DATA=smatch_data/kernel.allocation_funcs \
287 smatch_data/kernel.frees_argument smatch_data/kernel.puts_argument \
288 smatch_data/kernel.dev_queue_xmit smatch_data/kernel.returns_err_ptr \
289 smatch_data/kernel.dma_funcs smatch_data/kernel.returns_held_funcs \
290 smatch_data/kernel.no_return_funcs
292 SMATCH_SCRIPTS=smatch_scripts/add_gfp_to_allocations.sh \
293 smatch_scripts/build_kernel_data.sh \
294 smatch_scripts/call_tree.pl smatch_scripts/filter_kernel_deref_check.sh \
295 smatch_scripts/find_expanded_holes.pl smatch_scripts/find_null_params.sh \
296 smatch_scripts/follow_params.pl smatch_scripts/gen_allocation_list.sh \
297 smatch_scripts/gen_bit_shifters.sh smatch_scripts/gen_dma_funcs.sh \
298 smatch_scripts/generisize.pl smatch_scripts/gen_err_ptr_list.sh \
299 smatch_scripts/gen_expects_err_ptr.sh smatch_scripts/gen_frees_list.sh \
300 smatch_scripts/gen_gfp_flags.sh smatch_scripts/gen_no_return_funcs.sh \
301 smatch_scripts/gen_puts_list.sh smatch_scripts/gen_returns_held.sh \
302 smatch_scripts/gen_rosenberg_funcs.sh smatch_scripts/gen_sizeof_param.sh \
303 smatch_scripts/gen_unwind_functions.sh smatch_scripts/kchecker \
304 smatch_scripts/kpatch.sh smatch_scripts/new_bugs.sh \
305 smatch_scripts/show_errs.sh smatch_scripts/show_ifs.sh \
306 smatch_scripts/show_unreachable.sh smatch_scripts/strip_whitespace.pl \
307 smatch_scripts/summarize_errs.sh smatch_scripts/test_kernel.sh \
308 smatch_scripts/trace_params.pl smatch_scripts/unlocked_paths.pl \
309 smatch_scripts/whitespace_only.sh smatch_scripts/wine_checker.sh \
311 SMATCH_LDFLAGS := -lsqlite3 -lssl -lcrypto -lm
313 smatch: smatch.o $(SMATCH_OBJS) $(SMATCH_CHECKS) $(LIBS)
314 $(Q)$(LD) -o $@ $< $(SMATCH_OBJS) $(SMATCH_CHECKS) $(LIBS) $(SMATCH_LDFLAGS)
316 check_list_local.h:
317 touch check_list_local.h
319 smatch.o: smatch.c $(LIB_H) smatch.h check_list.h check_list_local.h
320 $(CC) $(CFLAGS) -c smatch.c -DSMATCHDATADIR='"$(SMATCHDATADIR)"'
322 $(SMATCH_OBJS) $(SMATCH_CHECKS): smatch.h smatch_slist.h smatch_extra.h avl.h
324 ########################################################################
325 all: $(PROGRAMS) smatch
327 ldflags += $($(@)-ldflags) $(LDFLAGS)
328 ldlibs += $($(@)-ldlibs) $(LDLIBS) -lm
329 $(PROGRAMS): % : %.o $(LIBS)
330 @echo " LD $@"
331 $(Q)$(LD) $(ldflags) $^ $(ldlibs) -o $@
333 libsparse.a: $(LIB_OBJS)
334 @echo " AR $@"
335 $(Q)$(AR) rcs $@ $^
338 cflags += $($(*)-cflags) $(CPPFLAGS) $(CFLAGS)
339 %.o: %.c
340 @echo " CC $@"
341 $(Q)$(CC) $(cflags) -c -o $@ $<
343 %.sc: %.c sparse
344 @echo " CHECK $<"
345 $(Q)CHECK=./sparse ./cgcc -no-compile $(CHECKER_FLAGS) $(cflags) -c $<
347 selfcheck: $(OBJS:.o=.sc)
350 SPARSE_VERSION:=$(shell git describe --dirty 2>/dev/null || echo '$(VERSION)')
351 lib.o: version.h
352 version.h: FORCE
353 @echo '#define SPARSE_VERSION "$(SPARSE_VERSION)"' > version.h.tmp
354 @if cmp -s version.h version.h.tmp; then \
355 rm version.h.tmp; \
356 else \
357 echo " GEN $@"; \
358 mv version.h.tmp version.h; \
362 check: all
363 $(Q)cd validation && ./test-suite
364 validation/%.t: $(PROGRAMS)
365 @validation/test-suite single $*.c
368 clean: clean-check
369 @rm -f *.[oa] .*.d $(PROGRAMS) version.h smatch
370 clean-check:
371 @echo " CLEAN"
372 @find validation/ \( -name "*.c.output.*" \
373 -o -name "*.c.error.*" \
374 -o -name "*.o" \
375 \) -exec rm {} \;
378 install: install-bin install-man
379 install-bin: $(INST_PROGRAMS:%=$(bindir)/%)
380 install-man: $(INST_MAN1:%=$(man1dir)/%)
382 $(bindir)/%: %
383 @echo " INSTALL $@"
384 $(Q)install -D $< $@ || exit 1;
385 $(man1dir)/%: %
386 @echo " INSTALL $@"
387 $(Q)install -D -m 644 $< $@ || exit 1;
389 .PHONY: FORCE
391 # GCC's dependencies
392 -include $(OBJS:%.o=.%.o.d)