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