3 ########################################################################
4 # The following variables can be overwritten from the command line
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 ########################################################################
34 LIB_OBJS
+= allocate.o
37 LIB_OBJS
+= compat-
$(OS
).o
40 LIB_OBJS
+= dominate.o
41 LIB_OBJS
+= evaluate.o
43 LIB_OBJS
+= expression.o
45 LIB_OBJS
+= flowgraph.o
49 LIB_OBJS
+= linearize.o
50 LIB_OBJS
+= liveness.o
53 LIB_OBJS
+= optimize.o
55 LIB_OBJS
+= pre-process.o
59 LIB_OBJS
+= show-parse.o
60 LIB_OBJS
+= simplify.o
68 LIB_OBJS
+= tokenize.o
71 LIB_OBJS
+= macro_table.o
72 LIB_OBJS
+= token_store.o
73 LIB_OBJS
+= cwchash
/hashtable.o
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
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
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
)
129 c2xml-ldlibs
:= $(shell $(PKG_CONFIG
) --libs libxml-2.0
)
130 c2xml-cflags
:= $(shell $(PKG_CONFIG
) --cflags libxml-2.0
)
132 $(warning Your system does not have libxml
, disabling c2xml
)
135 # Can we use gtk (needed for test-inspect)
137 HAVE_GTK
:=$(shell $(PKG_CONFIG
) --exists gtk
+-$(GTK_VERSION
) 2>/dev
/null
&& echo
'yes')
138 ifneq ($(HAVE_GTK
),yes
)
140 HAVE_GTK
:=$(shell $(PKG_CONFIG
) --exists gtk
+-$(GTK_VERSION
) 2>/dev
/null
&& echo
'yes')
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
154 $(warning Your system does not have gtk3
/gtk2
, disabling test-inspect
)
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
)
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
)
181 $(warning LLVM
3.0 or later required. Your system has version
$(LLVM_VERSION
) installed.
)
184 $(warning sparse-llvm disabled on
${arch})
187 $(warning Your system does not have llvm
, disabling sparse-llvm
)
190 ########################################################################
192 OBJS
:= $(LIB_OBJS
) $(EXTRA_OBJS
) $(PROGRAMS
:%=%.o
)
198 ########################################################################
200 SMATCHDATADIR
=$(INSTALL_PREFIX
)/share
/smatch
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
)
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
)
331 $(Q
)$(LD
) $(ldflags) $^
$(ldlibs
) -o
$@
333 libsparse.a
: $(LIB_OBJS
)
338 cflags += $($(*)-cflags) $(CPPFLAGS
) $(CFLAGS
)
341 $(Q
)$(CC
) $(cflags) -c
-o
$@
$<
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)')
353 @echo
'#define SPARSE_VERSION "$(SPARSE_VERSION)"' > version.h.tmp
354 @if cmp
-s version.h version.h.tmp
; then \
358 mv version.h.tmp version.h
; \
363 $(Q
)cd validation
&& .
/test-suite
364 validation
/%.t
: $(PROGRAMS
)
365 @validation
/test-suite single
$*.c
369 @
rm -f
*.
[oa
] .
*.d
$(PROGRAMS
) version.h smatch
372 @find validation
/ \
( -name
"*.c.output.*" \
373 -o
-name
"*.c.error.*" \
378 install: install-bin install-man
379 install-bin
: $(INST_PROGRAMS
:%=$(bindir)/%)
380 install-man
: $(INST_MAN1
:%=$(man1dir)/%)
384 $(Q
)install -D
$< $@ || exit
1;
387 $(Q
)install -D
-m
644 $< $@ || exit
1;
392 -include $(OBJS
:%.o
=.
%.o.d
)