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
)
16 CFLAGS
= -O2
-finline-functions
-fno-strict-aliasing
-g
17 CFLAGS
+= -Wall
-Wwrite-strings
18 LDFLAGS
+= -g
-lm
-lsqlite3
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 HAVE_LLVM_VERSION
:=$(shell $(LLVM_CONFIG
) --version | grep
"^[3-9].*" >/dev
/null
2>&1 && echo yes
)
38 LLVM_VERSION
:=$(shell $(LLVM_CONFIG
) --version
)
40 GCC_BASE
= $(shell $(CC
) --print-file-name
=)
41 BASIC_CFLAGS
= -DGCC_BASE
=\"$(GCC_BASE
)\"
43 ifeq ($(HAVE_GCC_DEP
),yes
)
44 BASIC_CFLAGS
+= -Wp
,-MD
,$(@D
)/.
$(@F
).d
51 MANDIR
=$(PREFIX
)/share
/man
52 MAN1DIR
=$(MANDIR
)/man1
53 INCLUDEDIR
=$(PREFIX
)/include
54 PKGCONFIGDIR
=$(LIBDIR
)/pkgconfig
55 SMATCHDATADIR
=$(PREFIX
)/share
/smatch
57 SMATCH_FILES
=smatch_flow.o smatch_conditions.o smatch_slist.o smatch_states.o \
58 smatch_helper.o smatch_type.o smatch_hooks.o smatch_function_hooks.o \
59 smatch_modification_hooks.o smatch_extra.o smatch_estate.o smatch_math.o \
60 smatch_sval.o smatch_ranges.o smatch_implied.o smatch_ignore.o smatch_project.o \
61 smatch_var_sym.o smatch_tracker.o smatch_files.o smatch_expression_stacks.o \
62 smatch_equiv.o smatch_buf_size.o smatch_strlen.o smatch_capped.o smatch_db.o \
63 smatch_expressions.o smatch_returns.o smatch_parse_call_math.o \
64 smatch_param_limit.o smatch_param_filter.o \
65 smatch_param_set.o smatch_comparison.o smatch_local_values.o \
66 smatch_function_ptrs.o smatch_annotate.o smatch_string_list.o \
67 smatch_param_cleared.o smatch_start_states.o \
68 smatch_recurse.o smatch_data_source.o smatch_type_val.o \
69 smatch_common_functions.o smatch_struct_assignment.o \
70 smatch_unknown_value.o smatch_stored_conditions.o avl.o \
71 smatch_function_info.o smatch_links.o smatch_auto_copy.o \
72 smatch_type_links.o smatch_untracked_param.o smatch_impossible.o \
75 SMATCH_CHECKS
=$(shell ls check_
*.c | sed
-e
's/\.c/.o/')
76 SMATCH_DATA
=smatch_data
/kernel.allocation_funcs smatch_data
/kernel.balanced_funcs \
77 smatch_data
/kernel.frees_argument smatch_data
/kernel.puts_argument \
78 smatch_data
/kernel.dev_queue_xmit smatch_data
/kernel.returns_err_ptr \
79 smatch_data
/kernel.dma_funcs smatch_data
/kernel.returns_held_funcs \
80 smatch_data
/kernel.no_return_funcs
82 PROGRAMS
=test-lexing test-parsing obfuscate compile graph sparse \
83 test-linearize example test-unssa test-dissect ctags
84 INST_PROGRAMS
=smatch cgcc
86 INST_MAN1
=sparse
.1 cgcc
.1
88 ifeq ($(HAVE_LIBXML
),yes
)
91 c2xml_EXTRA_OBJS
= `$(PKG_CONFIG) --libs libxml-2.0`
93 $(warning Your system does not have libxml
, disabling c2xml
)
96 ifeq ($(HAVE_GTK2
),yes
)
97 GTK2_CFLAGS
:= $(shell $(PKG_CONFIG
) --cflags gtk
+-2.0)
98 GTK2_LIBS
:= $(shell $(PKG_CONFIG
) --libs gtk
+-2.0)
99 PROGRAMS
+= test-inspect
100 INST_PROGRAMS
+= test-inspect
101 test-inspect_EXTRA_DEPS
:= ast-model.o ast-view.o ast-inspect.o
102 test-inspect.o
$(test-inspect_EXTRA_DEPS
): BASIC_CFLAGS
+= $(GTK2_CFLAGS
)
103 test-inspect_EXTRA_OBJS
:= $(GTK2_LIBS
)
105 $(warning Your system does not have libgtk2
, disabling test-inspect
)
108 ifneq ($(HAVE_LLVM
),yes
)
109 $(warning Your system does not have llvm
, disabling sparse-llvm
)
111 ifneq ($(HAVE_LLVM_VERSION
),yes
)
112 $(warning LLVM
3.0 or later required. Your system has version
$(LLVM_VERSION
) installed.
)
115 LLVM_PROGS
:= sparse-llvm
116 $(LLVM_PROGS
): LD
:= g
++
117 LLVM_LDFLAGS
:= $(shell $(LLVM_CONFIG
) --ldflags)
118 LLVM_CFLAGS
:= $(shell $(LLVM_CONFIG
) --cflags | sed
-e
"s/-DNDEBUG//g")
119 LLVM_LIBS
:= $(shell $(LLVM_CONFIG
) --libs
)
120 LLVM_LIBS
+= $(shell $(LLVM_CONFIG
) --system-libs
2>/dev
/null
)
121 PROGRAMS
+= $(LLVM_PROGS
)
122 INST_PROGRAMS
+= sparse-llvm sparsec
123 sparse-llvm.o
: BASIC_CFLAGS
+= $(LLVM_CFLAGS
)
124 sparse-llvm_EXTRA_OBJS
:= $(LLVM_LIBS
) $(LLVM_LDFLAGS
)
128 LIB_H
= token.h parse.h lib.h symbol.h scope.h expression.h target.h \
129 linearize.h bitmap.h ident-list.h compat.h flow.h allocate.h \
130 storage.h ptrlist.h dissect.h
132 LIB_OBJS
= target.o parse.o tokenize.o pre-process.o symbol.o lib.o scope.o \
133 expression.o show-parse.o evaluate.o expand.o inline.o linearize.o \
134 char.o
sort.o allocate.o compat-
$(OS
).o ptrlist.o \
135 flow.o cse.o simplify.o memops.o liveness.o storage.o unssa.o \
136 dissect.o macro_table.o token_store.o cwchash
/hashtable.o
138 LIB_FILE
= libsparse.a
139 SLIB_FILE
= libsparse.so
141 # If you add $(SLIB_FILE) to this, you also need to add -fpic to BASIC_CFLAGS above.
142 # Doing so incurs a noticeable performance hit, and Sparse does not have a
143 # stable shared library interface, so this does not occur by default. If you
144 # really want a shared library, you may want to build Sparse twice: once
145 # without -fpic to get all the Sparse tools, and again with -fpic to get the
154 QUIET_CC
= $(Q
:@
=@echo
' CC '$@
;)
155 QUIET_AR
= $(Q
:@
=@echo
' AR '$@
;)
156 QUIET_GEN
= $(Q
:@
=@echo
' GEN '$@
;)
157 QUIET_LINK
= $(Q
:@
=@echo
' LINK '$@
;)
158 # We rely on the -v switch of install to print 'file -> $install_dir/file'
159 QUIET_INST_SH
= $(Q
:@
=echo
-n
' INSTALL ';)
160 QUIET_INST
= $(Q
:@
=@echo
-n
' INSTALL ';)
163 $(QUIET_INST
)install -v
$1 $(DESTDIR
)$2/$1 || exit
1;
168 $(QUIET_INST
)install -v
-m
644 $1 $(DESTDIR
)$2/$1 || exit
1;
172 SED_PC_CMD
= 's|@version@|$(VERSION)|g; \
173 s|@prefix@|$(PREFIX)|g; \
174 s|@libdir@|$(LIBDIR)|g; \
175 s|@includedir@|$(INCLUDEDIR)|g'
179 # Allow users to override build settings without dirtying their trees
183 all: $(PROGRAMS
) sparse.
pc smatch
185 all-installable
: $(INST_PROGRAMS
) $(LIBS
) $(LIB_H
) sparse.
pc
187 install: all-installable
188 $(Q
)install -d
$(DESTDIR
)$(BINDIR
)
189 $(Q
)install -d
$(DESTDIR
)$(LIBDIR
)
190 $(Q
)install -d
$(DESTDIR
)$(MAN1DIR
)
191 $(Q
)install -d
$(DESTDIR
)$(INCLUDEDIR
)/sparse
192 $(Q
)install -d
$(DESTDIR
)$(PKGCONFIGDIR
)
193 $(Q
)install -d
$(DESTDIR
)$(SMATCHDATADIR
)/smatch_data
194 $(foreach f
,$(INST_PROGRAMS
),$(call INSTALL_EXEC
,$f,$(BINDIR
)))
195 $(foreach f
,$(INST_MAN1
),$(call INSTALL_FILE
,$f,$(MAN1DIR
)))
196 $(foreach f
,$(LIBS
),$(call INSTALL_FILE
,$f,$(LIBDIR
)))
197 $(foreach f
,$(LIB_H
),$(call INSTALL_FILE
,$f,$(INCLUDEDIR
)/sparse
))
198 $(call INSTALL_FILE
,sparse.
pc,$(PKGCONFIGDIR
))
199 $(foreach f
,$(SMATCH_DATA
),$(call INSTALL_FILE
,$f,$(SMATCHDATADIR
)))
201 sparse.
pc: sparse.
pc.in
202 $(QUIET_GEN
)sed
$(SED_PC_CMD
) sparse.
pc.in
> sparse.
pc
205 compile_EXTRA_DEPS
= compile-i386.o
207 $(foreach p
,$(PROGRAMS
),$(eval
$(p
): $($(p
)_EXTRA_DEPS
) $(LIBS
)))
209 $(QUIET_LINK
)$(LD
) -o
$@
$^
$($@_EXTRA_OBJS
) $(LDFLAGS
)
211 smatch
: smatch.o
$(SMATCH_FILES
) $(SMATCH_CHECKS
) $(LIBS
)
212 $(CC
) -o
$@
$< $(SMATCH_FILES
) $(SMATCH_CHECKS
) $(LIBS
) $(LDFLAGS
)
214 $(LIB_FILE
): $(LIB_OBJS
)
215 $(QUIET_AR
)$(AR
) rcs
$@
$(LIB_OBJS
)
217 $(SLIB_FILE
): $(LIB_OBJS
)
218 $(QUIET_LINK
)$(CC
) -Wl
,-soname
,$@
-shared
-o
$@
$(LIB_OBJS
) $(LDFLAGS
)
221 touch check_list_local.h
223 smatch.o
: smatch.c
$(LIB_H
) smatch.h check_list.h check_list_local.h
224 $(CC
) -c smatch.c
-DSMATCHDATADIR
='"$(SMATCHDATADIR)"'
225 $(SMATCH_CHECKS
): smatch.h smatch_slist.h smatch_extra.h avl.h
226 DEP_FILES
:= $(wildcard .
*.o.d
)
227 $(if
$(DEP_FILES
),$(eval
include $(DEP_FILES
)))
229 c2xml.o
: c2xml.c
$(LIB_H
)
230 $(QUIET_CC
)$(CC
) `$(PKG_CONFIG) --cflags libxml-2.0` -o
$@
-c
$(ALL_CFLAGS
) $<
232 compat-linux.o
: compat
/strtold.c compat
/mmap-blob.c
$(LIB_H
)
233 compat-solaris.o
: compat
/mmap-blob.c
$(LIB_H
)
234 compat-mingw.o
: $(LIB_H
)
235 compat-cygwin.o
: $(LIB_H
)
238 $(QUIET_CC
)$(CC
) -o
$@
-c
$(ALL_CFLAGS
) $<
241 rm -f
*.
[oa
] .
*.d
*.so cwchash
/*.o cwchash
/.
*.d cwchash
/tester \
242 $(PROGRAMS
) $(SLIB_FILE
) pre-process.h sparse.
pc
245 @if
test "$(SPARSE_VERSION)" != "v$(VERSION)" ; then \
246 echo
'Update VERSION in the Makefile before running "make dist".' ; \
249 git archive
--format
=tar --prefix=sparse-
$(VERSION
)/ HEAD^
{tree
} | gzip
-9 > sparse-
$(VERSION
).
tar.gz
252 $(Q
)cd validation
&& .
/test-suite
255 find validation
/ \
( -name
"*.c.output.expected" \
256 -o
-name
"*.c.output.got" \
257 -o
-name
"*.c.output.diff" \
258 -o
-name
"*.c.error.expected" \
259 -o
-name
"*.c.error.got" \
260 -o
-name
"*.c.error.diff" \