sval: take the type into consideration when doing an sval_cmp_val().
[smatch.git] / Makefile
blob3a15f20e3056383305dc5fcb0d5b87316bf1d1ea
1 VERSION=0.4.4
3 OS = linux
5 CC = gcc
6 CFLAGS = -O2 -finline-functions -fno-strict-aliasing -g
7 CFLAGS += -Wall -Wwrite-strings
8 LDFLAGS += -g -lm -lsqlite3
9 LD = gcc
10 AR = ar
12 ALL_CFLAGS = $(CFLAGS) $(BASIC_CFLAGS)
14 # For debugging, put this in local.mk:
16 # CFLAGS += -O0 -DDEBUG -g3 -gdwarf-2
19 HAVE_LIBXML:=$(shell pkg-config --exists libxml-2.0 2>/dev/null && echo 'yes')
20 HAVE_GCC_DEP:=$(shell touch .gcc-test.c && \
21 $(CC) -c -Wp,-MD,.gcc-test.d .gcc-test.c 2>/dev/null && \
22 echo 'yes'; rm -f .gcc-test.d .gcc-test.o .gcc-test.c)
23 HAVE_GTK2:=$(shell pkg-config --exists gtk+-2.0 2>/dev/null && echo 'yes')
24 HAVE_LLVM:=$(shell llvm-config --version >/dev/null 2>&1 && echo 'yes')
25 HAVE_LLVM_VERSION:=$(shell llvm-config --version | grep "^[3-9].*" >/dev/null 2>&1 && echo yes)
26 LLVM_VERSION=$(shell llvm-config --version)
28 GCC_BASE = $(shell $(CC) --print-file-name=)
29 BASIC_CFLAGS = -DGCC_BASE=\"$(GCC_BASE)\"
31 ifeq ($(HAVE_GCC_DEP),yes)
32 BASIC_CFLAGS += -Wp,-MD,$(@D)/.$(@F).d
33 endif
35 DESTDIR=
36 PREFIX=$(HOME)
37 BINDIR=$(PREFIX)/bin
38 LIBDIR=$(PREFIX)/lib
39 MANDIR=$(PREFIX)/share/man
40 MAN1DIR=$(MANDIR)/man1
41 INCLUDEDIR=$(PREFIX)/include
42 PKGCONFIGDIR=$(LIBDIR)/pkgconfig
43 SMATCHDATADIR=$(PREFIX)/share/smatch
45 SMATCH_FILES=smatch_flow.o smatch_conditions.o smatch_slist.o smatch_states.o \
46 smatch_helper.o smatch_type.o smatch_hooks.o smatch_function_hooks.o \
47 smatch_modification_hooks.o smatch_extra.o smatch_estate.o smatch_math.o \
48 smatch_sval.o smatch_ranges.o smatch_implied.o smatch_ignore.o smatch_project.o \
49 smatch_tracker.o smatch_files.o smatch_expression_stacks.o \
50 smatch_constraints.o smatch_buf_size.o smatch_capped.o smatch_db.o \
51 smatch_expressions.o smatch_returns.o smatch_parse_call_math.o \
52 smatch_absolute.o
54 SMATCH_CHECKS=$(shell ls check_*.c | sed -e 's/\.c/.o/')
55 SMATCH_DATA=smatch_data/kernel.allocation_funcs smatch_data/kernel.balanced_funcs \
56 smatch_data/kernel.frees_argument smatch_data/kernel.puts_argument \
57 smatch_data/kernel.dev_queue_xmit smatch_data/kernel.returns_err_ptr \
58 smatch_data/kernel.dma_funcs smatch_data/kernel.returns_held_funcs \
59 smatch_data/kernel.no_return_funcs
61 PROGRAMS=test-lexing test-parsing obfuscate compile graph sparse \
62 test-linearize example test-unssa test-dissect ctags
63 INST_PROGRAMS=smatch cgcc
65 INST_MAN1=sparse.1 cgcc.1
67 ifeq ($(HAVE_LIBXML),yes)
68 PROGRAMS+=c2xml
69 INST_PROGRAMS+=c2xml
70 c2xml_EXTRA_OBJS = `pkg-config --libs libxml-2.0`
71 else
72 $(warning Your system does not have libxml, disabling c2xml)
73 endif
75 ifeq ($(HAVE_GTK2),yes)
76 GTK2_CFLAGS := $(shell pkg-config --cflags gtk+-2.0)
77 GTK2_LIBS := $(shell pkg-config --libs gtk+-2.0)
78 PROGRAMS += test-inspect
79 INST_PROGRAMS += test-inspect
80 test-inspect_EXTRA_DEPS := ast-model.o ast-view.o ast-inspect.o
81 test-inspect.o $(test-inspect_EXTRA_DEPS): BASIC_CFLAGS += $(GTK2_CFLAGS)
82 test-inspect_EXTRA_OBJS := $(GTK2_LIBS)
83 else
84 $(warning Your system does not have libgtk2, disabling test-inspect)
85 endif
87 ifneq ($(HAVE_LLVM),yes)
88 $(warning Your system does not have llvm, disabling sparse-llvm)
89 else
90 ifneq ($(HAVE_LLVM_VERSION),yes)
91 $(warning LLVM 3.0 or later required. Your system has version $(LLVM_VERSION) installed.)
92 HAVE_LLVM=no
93 else
94 LLVM_PROGS := sparse-llvm
95 $(LLVM_PROGS): LD := g++
96 LDFLAGS += $(shell llvm-config --ldflags)
97 LLVM_CFLAGS := $(shell llvm-config --cflags | sed -e "s/-DNDEBUG//g")
98 LLVM_LIBS := $(shell llvm-config --libs)
99 PROGRAMS += $(LLVM_PROGS)
100 INST_PROGRAMS += sparse-llvm sparsec
101 sparse-llvm_EXTRA_DEPS := sparse-llvm.o
102 sparse-llvm.o $(sparse-llvm_EXTRA_DEPS): BASIC_CFLAGS += $(LLVM_CFLAGS)
103 sparse-llvm_EXTRA_OBJS := $(LLVM_LIBS)
104 endif
105 endif
107 LIB_H= token.h parse.h lib.h symbol.h scope.h expression.h target.h \
108 linearize.h bitmap.h ident-list.h compat.h flow.h allocate.h \
109 storage.h ptrlist.h dissect.h
111 LIB_OBJS= target.o parse.o tokenize.o pre-process.o symbol.o lib.o scope.o \
112 expression.o show-parse.o evaluate.o expand.o inline.o linearize.o \
113 sort.o allocate.o compat-$(OS).o ptrlist.o \
114 flow.o cse.o simplify.o memops.o liveness.o storage.o unssa.o \
115 dissect.o macro_table.o token_store.o cwchash/hashtable.o
117 LIB_FILE= libsparse.a
118 SLIB_FILE= libsparse.so
120 # If you add $(SLIB_FILE) to this, you also need to add -fpic to BASIC_CFLAGS above.
121 # Doing so incurs a noticeable performance hit, and Sparse does not have a
122 # stable shared library interface, so this does not occur by default. If you
123 # really want a shared library, you may want to build Sparse twice: once
124 # without -fpic to get all the Sparse tools, and again with -fpic to get the
125 # shared library.
126 LIBS=$(LIB_FILE)
129 # Pretty print
131 V = @
132 Q = $(V:1=)
133 QUIET_CC = $(Q:@=@echo ' CC '$@;)
134 QUIET_AR = $(Q:@=@echo ' AR '$@;)
135 QUIET_GEN = $(Q:@=@echo ' GEN '$@;)
136 QUIET_LINK = $(Q:@=@echo ' LINK '$@;)
137 # We rely on the -v switch of install to print 'file -> $install_dir/file'
138 QUIET_INST_SH = $(Q:@=echo -n ' INSTALL ';)
139 QUIET_INST = $(Q:@=@echo -n ' INSTALL ';)
141 define INSTALL_EXEC
142 $(QUIET_INST)install -v $1 $(DESTDIR)$2/$1 || exit 1;
144 endef
146 define INSTALL_FILE
147 $(QUIET_INST)install -v -m 644 $1 $(DESTDIR)$2/$1 || exit 1;
149 endef
151 SED_PC_CMD = 's|@version@|$(VERSION)|g; \
152 s|@prefix@|$(PREFIX)|g; \
153 s|@libdir@|$(LIBDIR)|g; \
154 s|@includedir@|$(INCLUDEDIR)|g'
158 # Allow users to override build settings without dirtying their trees
159 -include local.mk
162 all: $(PROGRAMS) sparse.pc smatch
164 all-installable: $(INST_PROGRAMS) $(LIBS) $(LIB_H) sparse.pc
166 install: all-installable
167 $(Q)install -d $(DESTDIR)$(BINDIR)
168 $(Q)install -d $(DESTDIR)$(LIBDIR)
169 $(Q)install -d $(DESTDIR)$(MAN1DIR)
170 $(Q)install -d $(DESTDIR)$(INCLUDEDIR)/sparse
171 $(Q)install -d $(DESTDIR)$(PKGCONFIGDIR)
172 $(Q)install -d $(DESTDIR)$(SMATCHDATADIR)/smatch_data
173 $(foreach f,$(INST_PROGRAMS),$(call INSTALL_EXEC,$f,$(BINDIR)))
174 $(foreach f,$(INST_MAN1),$(call INSTALL_FILE,$f,$(MAN1DIR)))
175 $(foreach f,$(LIBS),$(call INSTALL_FILE,$f,$(LIBDIR)))
176 $(foreach f,$(LIB_H),$(call INSTALL_FILE,$f,$(INCLUDEDIR)/sparse))
177 $(call INSTALL_FILE,sparse.pc,$(PKGCONFIGDIR))
178 $(foreach f,$(SMATCH_DATA),$(call INSTALL_FILE,$f,$(SMATCHDATADIR)))
180 sparse.pc: sparse.pc.in
181 $(QUIET_GEN)sed $(SED_PC_CMD) sparse.pc.in > sparse.pc
184 compile_EXTRA_DEPS = compile-i386.o
186 $(foreach p,$(PROGRAMS),$(eval $(p): $($(p)_EXTRA_DEPS) $(LIBS)))
187 $(PROGRAMS): % : %.o
188 $(QUIET_LINK)$(LD) -o $@ $^ $($@_EXTRA_OBJS) $(LDFLAGS)
190 smatch: smatch.o $(SMATCH_FILES) $(SMATCH_CHECKS) $(LIBS)
191 $(CC) -o $@ $< $(SMATCH_FILES) $(SMATCH_CHECKS) $(LIBS) $(LDFLAGS)
193 $(LIB_FILE): $(LIB_OBJS)
194 $(QUIET_AR)$(AR) rcs $@ $(LIB_OBJS)
196 $(SLIB_FILE): $(LIB_OBJS)
197 $(QUIET_LINK)$(CC) -Wl,-soname,$@ -shared -o $@ $(LIB_OBJS) $(LDFLAGS)
199 check_list_local.h:
200 touch check_list_local.h
202 smatch.o: smatch.c $(LIB_H) smatch.h check_list.h check_list_local.h
203 $(CC) -c smatch.c -DSMATCHDATADIR='"$(SMATCHDATADIR)"'
204 $(SMATCH_CHECKS): smatch.h smatch_slist.h smatch_extra.h
205 DEP_FILES := $(wildcard .*.o.d)
206 $(if $(DEP_FILES),$(eval include $(DEP_FILES)))
208 c2xml.o: c2xml.c $(LIB_H)
209 $(QUIET_CC)$(CC) `pkg-config --cflags libxml-2.0` -o $@ -c $(ALL_CFLAGS) $<
211 compat-linux.o: compat/strtold.c compat/mmap-blob.c $(LIB_H)
212 compat-solaris.o: compat/mmap-blob.c $(LIB_H)
213 compat-mingw.o: $(LIB_H)
214 compat-cygwin.o: $(LIB_H)
216 %.o: %.c
217 $(QUIET_CC)$(CC) -o $@ -c $(ALL_CFLAGS) $<
219 clean: clean-check
220 rm -f *.[oa] .*.d *.so cwchash/*.o cwchash/.*.d cwchash/tester \
221 $(PROGRAMS) $(SLIB_FILE) pre-process.h sparse.pc
223 dist:
224 @if test "`git describe`" != "v$(VERSION)" ; then \
225 echo 'Update VERSION in the Makefile before running "make dist".' ; \
226 exit 1 ; \
228 git archive --format=tar --prefix=sparse-$(VERSION)/ HEAD^{tree} | gzip -9 > sparse-$(VERSION).tar.gz
230 check: all
231 $(Q)cd validation && ./test-suite
233 clean-check:
234 find validation/ \( -name "*.c.output.expected" \
235 -o -name "*.c.output.got" \
236 -o -name "*.c.output.diff" \
237 -o -name "*.c.error.expected" \
238 -o -name "*.c.error.got" \
239 -o -name "*.c.error.diff" \
240 \) -exec rm {} \;