db: pass the call expression to call_implies callbacks
[smatch.git] / Makefile
blobe806a7be56c3e7142ff840813f639174a4ed0af6
1 VERSION=0.5.0
3 # Generating file version.h if current version has changed
4 SPARSE_VERSION:=$(shell git describe 2>/dev/null || echo '$(VERSION)')
5 VERSION_H := $(shell cat version.h 2>/dev/null)
6 ifneq ($(lastword $(VERSION_H)),"$(SPARSE_VERSION)")
7 $(info $(shell echo ' GEN 'version.h))
8 $(shell echo '#define SPARSE_VERSION "$(SPARSE_VERSION)"' > version.h)
9 endif
11 OS = linux
13 ifeq ($(CC),"")
14 CC = gcc
15 endif
16 CFLAGS = -O2 -finline-functions -fno-strict-aliasing -g
17 CFLAGS += -Wall -Wwrite-strings -Wno-switch
18 LDFLAGS += -g -lm -lsqlite3
19 LD = gcc
20 AR = ar
21 PKG_CONFIG = pkg-config
23 ALL_CFLAGS = $(CFLAGS) $(BASIC_CFLAGS)
25 # For debugging, put this in local.mk:
27 # CFLAGS += -O0 -DDEBUG -g3 -gdwarf-2
30 HAVE_LIBXML:=$(shell $(PKG_CONFIG) --exists libxml-2.0 2>/dev/null && echo 'yes')
31 HAVE_GCC_DEP:=$(shell touch .gcc-test.c && \
32 $(CC) -c -Wp,-MD,.gcc-test.d .gcc-test.c 2>/dev/null && \
33 echo 'yes'; rm -f .gcc-test.d .gcc-test.o .gcc-test.c)
34 HAVE_GTK2:=$(shell $(PKG_CONFIG) --exists gtk+-2.0 2>/dev/null && echo 'yes')
35 LLVM_CONFIG:=llvm-config
36 HAVE_LLVM:=$(shell $(LLVM_CONFIG) --version >/dev/null 2>&1 && echo 'yes')
37 ifeq ($(HAVE_LLVM),yes)
38 HAVE_LLVM_VERSION:=$(shell $(LLVM_CONFIG) --version | grep "^[3-9].*" >/dev/null 2>&1 && echo yes)
39 LLVM_VERSION:=$(shell $(LLVM_CONFIG) --version)
40 endif
42 GCC_BASE = $(shell $(CC) --print-file-name=)
43 BASIC_CFLAGS = -DGCC_BASE=\"$(GCC_BASE)\"
45 ifeq ($(HAVE_GCC_DEP),yes)
46 BASIC_CFLAGS += -Wp,-MD,$(@D)/.$(@F).d
47 endif
49 DESTDIR=
50 INSTALL_PREFIX ?=$(HOME)
51 BINDIR=$(INSTALL_PREFIX)/bin
52 LIBDIR=$(INSTALL_PREFIX)/lib
53 MANDIR=$(INSTALL_PREFIX)/share/man
54 MAN1DIR=$(MANDIR)/man1
55 INCLUDEDIR=$(INSTALL_PREFIX)/include
56 PKGCONFIGDIR=$(LIBDIR)/pkgconfig
57 SMATCHDATADIR=$(INSTALL_PREFIX)/share/smatch
59 SMATCH_FILES=smatch_flow.o smatch_conditions.o smatch_slist.o smatch_states.o \
60 smatch_helper.o smatch_type.o smatch_hooks.o smatch_function_hooks.o \
61 smatch_modification_hooks.o smatch_extra.o smatch_estate.o smatch_math.o \
62 smatch_sval.o smatch_ranges.o smatch_implied.o smatch_ignore.o smatch_project.o \
63 smatch_var_sym.o smatch_tracker.o smatch_files.o smatch_expression_stacks.o \
64 smatch_equiv.o smatch_buf_size.o smatch_strlen.o smatch_capped.o smatch_db.o \
65 smatch_expressions.o smatch_returns.o smatch_parse_call_math.o \
66 smatch_param_limit.o smatch_param_filter.o \
67 smatch_param_set.o smatch_comparison.o smatch_param_compare_limit.o smatch_local_values.o \
68 smatch_function_ptrs.o smatch_annotate.o smatch_string_list.o \
69 smatch_param_cleared.o smatch_start_states.o \
70 smatch_recurse.o smatch_data_source.o smatch_type_val.o \
71 smatch_common_functions.o smatch_struct_assignment.o \
72 smatch_unknown_value.o smatch_stored_conditions.o avl.o \
73 smatch_function_info.o smatch_links.o smatch_auto_copy.o \
74 smatch_type_links.o smatch_untracked_param.o smatch_impossible.o \
75 smatch_strings.o smatch_param_used.o smatch_address.o \
76 smatch_buf_comparison.o smatch_real_absolute.o smatch_scope.o \
77 smatch_imaginary_absolute.o smatch_parameter_names.o \
78 smatch_return_to_param.o smatch_passes_array_size.o \
79 smatch_constraints.o smatch_constraints_required.o \
80 smatch_fn_arg_link.o smatch_about_fn_ptr_arg.o
82 SMATCH_CHECKS=$(shell ls check_*.c | sed -e 's/\.c/.o/')
83 SMATCH_DATA=smatch_data/kernel.allocation_funcs \
84 smatch_data/kernel.frees_argument smatch_data/kernel.puts_argument \
85 smatch_data/kernel.dev_queue_xmit smatch_data/kernel.returns_err_ptr \
86 smatch_data/kernel.dma_funcs smatch_data/kernel.returns_held_funcs \
87 smatch_data/kernel.no_return_funcs
89 SMATCH_SCRIPTS=smatch_scripts/add_gfp_to_allocations.sh \
90 smatch_scripts/build_kernel_data.sh \
91 smatch_scripts/call_tree.pl smatch_scripts/filter_kernel_deref_check.sh \
92 smatch_scripts/find_expanded_holes.pl smatch_scripts/find_null_params.sh \
93 smatch_scripts/follow_params.pl smatch_scripts/gen_allocation_list.sh \
94 smatch_scripts/gen_bit_shifters.sh smatch_scripts/gen_dma_funcs.sh \
95 smatch_scripts/generisize.pl smatch_scripts/gen_err_ptr_list.sh \
96 smatch_scripts/gen_expects_err_ptr.sh smatch_scripts/gen_frees_list.sh \
97 smatch_scripts/gen_gfp_flags.sh smatch_scripts/gen_no_return_funcs.sh \
98 smatch_scripts/gen_puts_list.sh smatch_scripts/gen_returns_held.sh \
99 smatch_scripts/gen_rosenberg_funcs.sh smatch_scripts/gen_sizeof_param.sh \
100 smatch_scripts/gen_unwind_functions.sh smatch_scripts/kchecker \
101 smatch_scripts/kpatch.sh smatch_scripts/new_bugs.sh \
102 smatch_scripts/show_errs.sh smatch_scripts/show_ifs.sh \
103 smatch_scripts/show_unreachable.sh smatch_scripts/strip_whitespace.pl \
104 smatch_scripts/summarize_errs.sh smatch_scripts/test_kernel.sh \
105 smatch_scripts/trace_params.pl smatch_scripts/unlocked_paths.pl \
106 smatch_scripts/whitespace_only.sh smatch_scripts/wine_checker.sh \
108 PROGRAMS=test-lexing test-parsing obfuscate compile graph sparse \
109 test-linearize example test-unssa test-dissect ctags
110 INST_PROGRAMS=smatch cgcc
112 INST_MAN1=sparse.1 cgcc.1
114 ifeq ($(HAVE_LIBXML),yes)
115 PROGRAMS+=c2xml
116 INST_PROGRAMS+=c2xml
117 c2xml_EXTRA_OBJS = `$(PKG_CONFIG) --libs libxml-2.0`
118 else
119 $(warning Your system does not have libxml, disabling c2xml)
120 endif
122 ifeq ($(HAVE_GTK2),yes)
123 GTK2_CFLAGS := $(shell $(PKG_CONFIG) --cflags gtk+-2.0)
124 GTK2_LIBS := $(shell $(PKG_CONFIG) --libs gtk+-2.0)
125 PROGRAMS += test-inspect
126 INST_PROGRAMS += test-inspect
127 test-inspect_EXTRA_DEPS := ast-model.o ast-view.o ast-inspect.o
128 test-inspect.o $(test-inspect_EXTRA_DEPS): BASIC_CFLAGS += $(GTK2_CFLAGS)
129 test-inspect_EXTRA_OBJS := $(GTK2_LIBS)
130 else
131 $(warning Your system does not have libgtk2, disabling test-inspect)
132 endif
134 ifneq ($(HAVE_LLVM),yes)
135 $(warning Your system does not have llvm, disabling sparse-llvm)
136 else
137 ifneq ($(HAVE_LLVM_VERSION),yes)
138 $(warning LLVM 3.0 or later required. Your system has version $(LLVM_VERSION) installed.)
139 HAVE_LLVM=no
140 else
141 LLVM_PROGS := sparse-llvm
142 $(LLVM_PROGS): LD := g++
143 LLVM_LDFLAGS := $(shell $(LLVM_CONFIG) --ldflags)
144 LLVM_CFLAGS := $(shell $(LLVM_CONFIG) --cflags | sed -e "s/-DNDEBUG//g")
145 LLVM_LIBS := $(shell $(LLVM_CONFIG) --libs)
146 LLVM_LIBS += $(shell $(LLVM_CONFIG) --system-libs 2>/dev/null)
147 PROGRAMS += $(LLVM_PROGS)
148 INST_PROGRAMS += sparse-llvm sparsec
149 sparse-llvm.o: BASIC_CFLAGS += $(LLVM_CFLAGS)
150 sparse-llvm_EXTRA_OBJS := $(LLVM_LIBS) $(LLVM_LDFLAGS)
151 endif
152 endif
154 LIB_H= token.h parse.h lib.h symbol.h scope.h expression.h target.h \
155 linearize.h bitmap.h ident-list.h compat.h flow.h allocate.h \
156 storage.h ptrlist.h dissect.h
158 LIB_OBJS= target.o parse.o tokenize.o pre-process.o symbol.o lib.o scope.o \
159 expression.o show-parse.o evaluate.o expand.o inline.o linearize.o \
160 char.o sort.o allocate.o compat-$(OS).o ptrlist.o \
161 flow.o cse.o simplify.o memops.o liveness.o storage.o unssa.o \
162 dissect.o macro_table.o token_store.o cwchash/hashtable.o
164 LIB_FILE= libsparse.a
165 SLIB_FILE= libsparse.so
167 # If you add $(SLIB_FILE) to this, you also need to add -fpic to BASIC_CFLAGS above.
168 # Doing so incurs a noticeable performance hit, and Sparse does not have a
169 # stable shared library interface, so this does not occur by default. If you
170 # really want a shared library, you may want to build Sparse twice: once
171 # without -fpic to get all the Sparse tools, and again with -fpic to get the
172 # shared library.
173 LIBS=$(LIB_FILE)
176 # Pretty print
178 V = @
179 Q = $(V:1=)
180 QUIET_CC = $(Q:@=@echo ' CC '$@;)
181 QUIET_AR = $(Q:@=@echo ' AR '$@;)
182 QUIET_GEN = $(Q:@=@echo ' GEN '$@;)
183 QUIET_LINK = $(Q:@=@echo ' LINK '$@;)
184 # We rely on the -v switch of install to print 'file -> $install_dir/file'
185 QUIET_INST_SH = $(Q:@=echo -n ' INSTALL ';)
186 QUIET_INST = $(Q:@=@echo -n ' INSTALL ';)
188 define INSTALL_EXEC
189 $(QUIET_INST)install -v $1 $(DESTDIR)$2/$1 || exit 1;
191 endef
193 define INSTALL_FILE
194 $(QUIET_INST)install -v -m 644 $1 $(DESTDIR)$2/$1 || exit 1;
196 endef
198 SED_PC_CMD = 's|@version@|$(VERSION)|g; \
199 s|@prefix@|$(INSTALL_PREFIX)|g; \
200 s|@libdir@|$(LIBDIR)|g; \
201 s|@includedir@|$(INCLUDEDIR)|g'
205 # Allow users to override build settings without dirtying their trees
206 -include local.mk
209 all: $(PROGRAMS) sparse.pc smatch
211 all-installable: $(INST_PROGRAMS) $(LIBS) $(LIB_H) sparse.pc
213 install: all-installable
214 $(Q)install -d $(DESTDIR)$(BINDIR)
215 $(Q)install -d $(DESTDIR)$(LIBDIR)
216 $(Q)install -d $(DESTDIR)$(MAN1DIR)
217 $(Q)install -d $(DESTDIR)$(INCLUDEDIR)/sparse
218 $(Q)install -d $(DESTDIR)$(PKGCONFIGDIR)
219 $(Q)install -d $(DESTDIR)$(SMATCHDATADIR)/smatch_data
220 $(Q)install -d $(DESTDIR)$(SMATCHDATADIR)/smatch_scripts
221 $(foreach f,$(INST_PROGRAMS),$(call INSTALL_EXEC,$f,$(BINDIR)))
222 $(foreach f,$(INST_MAN1),$(call INSTALL_FILE,$f,$(MAN1DIR)))
223 $(foreach f,$(LIBS),$(call INSTALL_FILE,$f,$(LIBDIR)))
224 $(foreach f,$(LIB_H),$(call INSTALL_FILE,$f,$(INCLUDEDIR)/sparse))
225 $(call INSTALL_FILE,sparse.pc,$(PKGCONFIGDIR))
226 $(foreach f,$(SMATCH_DATA),$(call INSTALL_FILE,$f,$(SMATCHDATADIR)))
227 $(foreach f,$(SMATCH_SCRIPTS),$(call INSTALL_EXEC,$f,$(SMATCHDATADIR)))
229 sparse.pc: sparse.pc.in
230 $(QUIET_GEN)sed $(SED_PC_CMD) sparse.pc.in > sparse.pc
233 compile_EXTRA_DEPS = compile-i386.o
235 $(foreach p,$(PROGRAMS),$(eval $(p): $($(p)_EXTRA_DEPS) $(LIBS)))
236 $(PROGRAMS): % : %.o
237 $(QUIET_LINK)$(LD) -o $@ $^ $($@_EXTRA_OBJS) $(LDFLAGS)
239 smatch: smatch.o $(SMATCH_FILES) $(SMATCH_CHECKS) $(LIBS)
240 $(QUIET_LINK)$(LD) -o $@ $< $(SMATCH_FILES) $(SMATCH_CHECKS) $(LIBS) $(LDFLAGS)
242 $(LIB_FILE): $(LIB_OBJS)
243 $(QUIET_AR)$(AR) rcs $@ $(LIB_OBJS)
245 $(SLIB_FILE): $(LIB_OBJS)
246 $(QUIET_LINK)$(CC) -Wl,-soname,$@ -shared -o $@ $(LIB_OBJS) $(LDFLAGS)
248 check_list_local.h:
249 touch check_list_local.h
251 smatch.o: smatch.c $(LIB_H) smatch.h check_list.h check_list_local.h
252 $(CC) -c smatch.c -DSMATCHDATADIR='"$(SMATCHDATADIR)"'
253 $(SMATCH_CHECKS): smatch.h smatch_slist.h smatch_extra.h avl.h
254 DEP_FILES := $(wildcard .*.o.d)
255 $(if $(DEP_FILES),$(eval include $(DEP_FILES)))
257 c2xml.o: c2xml.c $(LIB_H)
258 $(QUIET_CC)$(CC) `$(PKG_CONFIG) --cflags libxml-2.0` -o $@ -c $(ALL_CFLAGS) $<
260 compat-linux.o: compat/strtold.c compat/mmap-blob.c $(LIB_H)
261 compat-solaris.o: compat/mmap-blob.c $(LIB_H)
262 compat-mingw.o: $(LIB_H)
263 compat-cygwin.o: $(LIB_H)
265 %.o: %.c
266 $(QUIET_CC)$(CC) -o $@ -c $(ALL_CFLAGS) $<
268 clean: clean-check
269 rm -f *.[oa] .*.d *.so cwchash/*.o cwchash/.*.d cwchash/tester \
270 $(PROGRAMS) $(SLIB_FILE) pre-process.h sparse.pc
272 dist:
273 @if test "$(SPARSE_VERSION)" != "v$(VERSION)" ; then \
274 echo 'Update VERSION in the Makefile before running "make dist".' ; \
275 exit 1 ; \
277 git archive --format=tar --prefix=sparse-$(VERSION)/ HEAD^{tree} | gzip -9 > sparse-$(VERSION).tar.gz
279 check: all
280 $(Q)cd validation && ./test-suite
282 clean-check:
283 find validation/ \( -name "*.c.output.expected" \
284 -o -name "*.c.output.got" \
285 -o -name "*.c.output.diff" \
286 -o -name "*.c.error.expected" \
287 -o -name "*.c.error.got" \
288 -o -name "*.c.error.diff" \
289 \) -exec rm {} \;