buf_size: first get the size in bytes then convert to elements
[smatch.git] / Makefile
blob0879454de0a57197492017a344c2cf89253f1fb3
1 VERSION=0.4.3
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 AR = ar
12 # For debugging, put this in local.mk:
14 # CFLAGS += -O0 -DDEBUG -g3 -gdwarf-2
17 HAVE_LIBXML:=$(shell pkg-config --exists libxml-2.0 2>/dev/null && echo 'yes')
18 HAVE_GCC_DEP:=$(shell touch .gcc-test.c && \
19 $(CC) -c -Wp,-MD,.gcc-test.d .gcc-test.c 2>/dev/null && \
20 echo 'yes'; rm -f .gcc-test.d .gcc-test.o .gcc-test.c)
21 HAVE_GTK2:=$(shell pkg-config --exists gtk+-2.0 2>/dev/null && echo 'yes')
23 CFLAGS += -DGCC_BASE=\"$(shell $(CC) --print-file-name=)\"
25 ifeq ($(HAVE_GCC_DEP),yes)
26 CFLAGS += -Wp,-MD,$(@D)/.$(@F).d
27 endif
29 DESTDIR=
30 PREFIX=$(HOME)
31 BINDIR=$(PREFIX)/bin
32 LIBDIR=$(PREFIX)/lib
33 MANDIR=$(PREFIX)/share/man
34 MAN1DIR=$(MANDIR)/man1
35 INCLUDEDIR=$(PREFIX)/include
36 PKGCONFIGDIR=$(LIBDIR)/pkgconfig
37 SMATCHDATADIR=$(PREFIX)/share/smatch/
39 SMATCH_FILES=smatch_flow.o smatch_conditions.o smatch_slist.o smatch_states.o \
40 smatch_helper.o smatch_type.o smatch_hooks.o smatch_function_hooks.o \
41 smatch_modification_hooks.o smatch_extra.o smatch_estate.o smatch_math.o \
42 smatch_ranges.o smatch_implied.o smatch_ignore.o smatch_project.o \
43 smatch_tracker.o smatch_files.o smatch_expression_stacks.o \
44 smatch_constraints.o smatch_buf_size.o smatch_capped.o smatch_db.o \
45 smatch_expressions.o smatch_returns.o
47 SMATCH_CHECKS=$(shell ls check_*.c | sed -e 's/\.c/.o/')
48 SMATCH_DATA=smatch_data/kernel.allocation_funcs smatch_data/kernel.balanced_funcs \
49 smatch_data/kernel.frees_argument smatch_data/kernel.puts_argument \
50 smatch_data/kernel.dev_queue_xmit smatch_data/kernel.returns_err_ptr \
51 smatch_data/kernel.dma_funcs smatch_data/kernel.returns_held_funcs \
52 smatch_data/kernel.no_return_funcs
54 PROGRAMS=test-lexing test-parsing obfuscate compile graph sparse \
55 test-linearize example test-unssa test-dissect ctags
56 INST_PROGRAMS=smatch
58 INST_MAN1=sparse.1 cgcc.1
60 ifeq ($(HAVE_LIBXML),yes)
61 PROGRAMS+=c2xml
62 INST_PROGRAMS+=c2xml
63 c2xml_EXTRA_OBJS = `pkg-config --libs libxml-2.0`
64 endif
66 ifeq ($(HAVE_GTK2),yes)
67 GTK2_CFLAGS := $(shell pkg-config --cflags gtk+-2.0)
68 GTK2_LIBS := $(shell pkg-config --libs gtk+-2.0)
69 PROGRAMS += test-inspect
70 INST_PROGRAMS += test-inspect
71 test-inspect_EXTRA_DEPS := ast-model.o ast-view.o ast-inspect.o
72 test-inspect.o $(test-inspect_EXTRA_DEPS): CFLAGS += $(GTK2_CFLAGS)
73 test-inspect_EXTRA_OBJS := $(GTK2_LIBS)
74 endif
76 LIB_H= token.h parse.h lib.h symbol.h scope.h expression.h target.h \
77 linearize.h bitmap.h ident-list.h compat.h flow.h allocate.h \
78 storage.h ptrlist.h dissect.h
80 LIB_OBJS= target.o parse.o tokenize.o pre-process.o symbol.o lib.o scope.o \
81 expression.o show-parse.o evaluate.o expand.o inline.o linearize.o \
82 sort.o allocate.o compat-$(OS).o ptrlist.o \
83 flow.o cse.o simplify.o memops.o liveness.o storage.o unssa.o \
84 dissect.o macro_table.o token_store.o cwchash/hashtable.o
86 LIB_FILE= libsparse.a
87 SLIB_FILE= libsparse.so
89 # If you add $(SLIB_FILE) to this, you also need to add -fpic to CFLAGS above.
90 # Doing so incurs a noticeable performance hit, and Sparse does not have a
91 # stable shared library interface, so this does not occur by default. If you
92 # really want a shared library, you may want to build Sparse twice: once
93 # without -fpic to get all the Sparse tools, and again with -fpic to get the
94 # shared library.
95 LIBS=$(LIB_FILE)
98 # Pretty print
100 V = @
101 Q = $(V:1=)
102 QUIET_CC = $(Q:@=@echo ' CC '$@;)
103 QUIET_AR = $(Q:@=@echo ' AR '$@;)
104 QUIET_GEN = $(Q:@=@echo ' GEN '$@;)
105 QUIET_LINK = $(Q:@=@echo ' LINK '$@;)
106 # We rely on the -v switch of install to print 'file -> $install_dir/file'
107 QUIET_INST_SH = $(Q:@=echo -n ' INSTALL ';)
108 QUIET_INST = $(Q:@=@echo -n ' INSTALL ';)
110 define INSTALL_EXEC
111 $(QUIET_INST)install -v $1 $(DESTDIR)$2/$1 || exit 1;
113 endef
115 define INSTALL_FILE
116 $(QUIET_INST)install -v -m 644 $1 $(DESTDIR)$2/$1 || exit 1;
118 endef
120 SED_PC_CMD = 's|@version@|$(VERSION)|g; \
121 s|@prefix@|$(PREFIX)|g; \
122 s|@libdir@|$(LIBDIR)|g; \
123 s|@includedir@|$(INCLUDEDIR)|g'
127 # Allow users to override build settings without dirtying their trees
128 -include local.mk
131 all: $(PROGRAMS) sparse.pc smatch
133 install: $(INST_PROGRAMS) $(LIBS) $(LIB_H) sparse.pc
134 $(Q)install -d $(DESTDIR)$(BINDIR)
135 $(Q)install -d $(DESTDIR)$(LIBDIR)
136 $(Q)install -d $(DESTDIR)$(MAN1DIR)
137 $(Q)install -d $(DESTDIR)$(INCLUDEDIR)/sparse
138 $(Q)install -d $(DESTDIR)$(PKGCONFIGDIR)
139 $(Q)install -d $(DESTDIR)$(SMATCHDATADIR)/smatch_data/
140 $(foreach f,$(INST_PROGRAMS),$(call INSTALL_EXEC,$f,$(BINDIR)))
141 $(foreach f,$(INST_MAN1),$(call INSTALL_FILE,$f,$(MAN1DIR)))
142 $(foreach f,$(LIBS),$(call INSTALL_FILE,$f,$(LIBDIR)))
143 $(foreach f,$(LIB_H),$(call INSTALL_FILE,$f,$(INCLUDEDIR)/sparse))
144 $(call INSTALL_FILE,sparse.pc,$(PKGCONFIGDIR))
145 $(foreach f,$(SMATCH_DATA),$(call INSTALL_FILE,$f,$(SMATCHDATADIR)))
147 sparse.pc: sparse.pc.in
148 $(QUIET_GEN)sed $(SED_PC_CMD) sparse.pc.in > sparse.pc
151 compile_EXTRA_DEPS = compile-i386.o
153 $(foreach p,$(PROGRAMS),$(eval $(p): $($(p)_EXTRA_DEPS) $(LIBS)))
154 $(PROGRAMS): % : %.o
155 $(QUIET_LINK)$(CC) -o $@ $^ $($@_EXTRA_OBJS) $(LDFLAGS)
157 smatch: smatch.o $(SMATCH_FILES) $(SMATCH_CHECKS) $(LIBS)
158 $(CC) -o $@ $< $(SMATCH_FILES) $(SMATCH_CHECKS) $(LIBS) $(LDFLAGS)
160 $(LIB_FILE): $(LIB_OBJS)
161 $(QUIET_AR)$(AR) rcs $@ $(LIB_OBJS)
163 $(SLIB_FILE): $(LIB_OBJS)
164 $(QUIET_LINK)$(CC) -Wl,-soname,$@ -shared -o $@ $(LIB_OBJS) $(LDFLAGS)
166 check_list_local.h:
167 touch check_list_local.h
169 smatch.o: smatch.c $(LIB_H) smatch.h check_list.h check_list_local.h
170 $(CC) -c smatch.c -DSMATCHDATADIR='"$(SMATCHDATADIR)"'
171 $(SMATCH_CHECKS): smatch.h smatch_slist.h smatch_extra.h
172 DEP_FILES := $(wildcard .*.o.d)
173 $(if $(DEP_FILES),$(eval include $(DEP_FILES)))
175 c2xml.o: c2xml.c $(LIB_H)
176 $(QUIET_CC)$(CC) `pkg-config --cflags libxml-2.0` -o $@ -c $(CFLAGS) $<
178 compat-linux.o: compat/strtold.c compat/mmap-blob.c $(LIB_H)
179 compat-solaris.o: compat/mmap-blob.c $(LIB_H)
180 compat-mingw.o: $(LIB_H)
181 compat-cygwin.o: $(LIB_H)
183 %.o: %.c
184 $(QUIET_CC)$(CC) -o $@ -c $(CFLAGS) $<
186 clean: clean-check
187 rm -f *.[oa] .*.d *.so cwchash/*.o cwchash/.*.d cwchash/tester \
188 $(PROGRAMS) $(SLIB_FILE) pre-process.h sparse.pc
190 dist:
191 @if test "`git describe`" != "v$(VERSION)" ; then \
192 echo 'Update VERSION in the Makefile before running "make dist".' ; \
193 exit 1 ; \
195 git archive --format=tar --prefix=sparse-$(VERSION)/ HEAD^{tree} | gzip -9 > sparse-$(VERSION).tar.gz
197 check: all
198 $(Q)cd validation && ./test-suite
200 clean-check:
201 find validation/ \( -name "*.c.output.expected" \
202 -o -name "*.c.output.got" \
203 -o -name "*.c.output.diff" \
204 -o -name "*.c.error.expected" \
205 -o -name "*.c.error.got" \
206 -o -name "*.c.error.diff" \
207 \) -exec rm {} \;