*new* check_macros: find macro precedence bugs
[smatch.git] / Makefile
blobd64143e3f1fa9f514b65bde004a1e1530e208abb
1 VERSION=0.4.2
3 OS = linux
5 CC = gcc
6 CFLAGS = -O2 -finline-functions -fno-strict-aliasing -g
7 CFLAGS += -Wall -Wwrite-strings
8 LDFLAGS += -g -lm
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)
22 CFLAGS += -DGCC_BASE=\"$(shell $(CC) --print-file-name=)\"
24 ifeq ($(HAVE_GCC_DEP),yes)
25 CFLAGS += -Wp,-MD,$(@D)/.$(@F).d
26 endif
28 DESTDIR=
29 PREFIX=$(HOME)
30 BINDIR=$(PREFIX)/bin
31 LIBDIR=$(PREFIX)/lib
32 MANDIR=$(PREFIX)/share/man
33 MAN1DIR=$(MANDIR)/man1
34 INCLUDEDIR=$(PREFIX)/include
35 PKGCONFIGDIR=$(LIBDIR)/pkgconfig
36 SMATCHDATADIR=$(PREFIX)/share/smatch/
38 SMATCH_FILES=smatch_flow.o smatch_conditions.o smatch_slist.o smatch_states.o \
39 smatch_helper.o smatch_type.o smatch_hooks.o smatch_function_hooks.o \
40 smatch_modification_hooks.o smatch_extra.o smatch_math.o \
41 smatch_ranges.o smatch_implied.o smatch_ignore.o smatch_project.o \
42 smatch_tracker.o smatch_files.o smatch_expression_stacks.o smatch_oom.o
43 SMATCH_CHECKS=$(shell ls check_*.c | sed -e 's/\.c/.o/')
44 SMATCH_DATA=smatch_data/kernel.allocation_funcs smatch_data/kernel.balanced_funcs \
45 smatch_data/kernel.frees_argument smatch_data/kernel.puts_argument \
46 smatch_data/kernel.dev_queue_xmit smatch_data/kernel.returns_err_ptr \
47 smatch_data/kernel.dma_funcs smatch_data/kernel.returns_held_funcs \
48 smatch_data/kernel.no_return_funcs
50 PROGRAMS=test-lexing test-parsing obfuscate compile graph sparse \
51 test-linearize example test-unssa test-dissect ctags
52 INST_PROGRAMS=sparse cgcc smatch
54 INST_MAN1=sparse.1 cgcc.1
56 ifeq ($(HAVE_LIBXML),yes)
57 PROGRAMS+=c2xml
58 INST_PROGRAMS+=c2xml
59 c2xml_EXTRA_OBJS = `pkg-config --libs libxml-2.0`
60 endif
62 LIB_H= token.h parse.h lib.h symbol.h scope.h expression.h target.h \
63 linearize.h bitmap.h ident-list.h compat.h flow.h allocate.h \
64 storage.h ptrlist.h dissect.h
66 LIB_OBJS= target.o parse.o tokenize.o pre-process.o symbol.o lib.o scope.o \
67 expression.o show-parse.o evaluate.o expand.o inline.o linearize.o \
68 sort.o allocate.o compat-$(OS).o ptrlist.o \
69 flow.o cse.o simplify.o memops.o liveness.o storage.o unssa.o \
70 dissect.o macro_table.o cwchash/hashtable.o
72 LIB_FILE= libsparse.a
73 SLIB_FILE= libsparse.so
75 # If you add $(SLIB_FILE) to this, you also need to add -fpic to CFLAGS above.
76 # Doing so incurs a noticeable performance hit, and Sparse does not have a
77 # stable shared library interface, so this does not occur by default. If you
78 # really want a shared library, you may want to build Sparse twice: once
79 # without -fpic to get all the Sparse tools, and again with -fpic to get the
80 # shared library.
81 LIBS=$(LIB_FILE)
84 # Pretty print
86 V = @
87 Q = $(V:1=)
88 QUIET_CC = $(Q:@=@echo ' CC '$@;)
89 QUIET_AR = $(Q:@=@echo ' AR '$@;)
90 QUIET_GEN = $(Q:@=@echo ' GEN '$@;)
91 QUIET_LINK = $(Q:@=@echo ' LINK '$@;)
92 # We rely on the -v switch of install to print 'file -> $install_dir/file'
93 QUIET_INST_SH = $(Q:@=echo -n ' INSTALL ';)
94 QUIET_INST = $(Q:@=@echo -n ' INSTALL ';)
96 define INSTALL_EXEC
97 $(QUIET_INST)install -v $1 $(DESTDIR)$2/$1 || exit 1;
99 endef
101 define INSTALL_FILE
102 $(QUIET_INST)install -v -m 644 $1 $(DESTDIR)$2/$1 || exit 1;
104 endef
106 SED_PC_CMD = 's|@version@|$(VERSION)|g; \
107 s|@prefix@|$(PREFIX)|g; \
108 s|@libdir@|$(LIBDIR)|g; \
109 s|@includedir@|$(INCLUDEDIR)|g'
113 # Allow users to override build settings without dirtying their trees
114 -include local.mk
117 all: $(PROGRAMS) sparse.pc smatch
119 install: $(INST_PROGRAMS) $(LIBS) $(LIB_H) sparse.pc
120 $(Q)install -d $(DESTDIR)$(BINDIR)
121 $(Q)install -d $(DESTDIR)$(LIBDIR)
122 $(Q)install -d $(DESTDIR)$(MAN1DIR)
123 $(Q)install -d $(DESTDIR)$(INCLUDEDIR)/sparse
124 $(Q)install -d $(DESTDIR)$(PKGCONFIGDIR)
125 $(Q)install -d $(DESTDIR)$(SMATCHDATADIR)/smatch_data/
126 $(foreach f,$(INST_PROGRAMS),$(call INSTALL_EXEC,$f,$(BINDIR)))
127 $(foreach f,$(INST_MAN1),$(call INSTALL_FILE,$f,$(MAN1DIR)))
128 $(foreach f,$(LIBS),$(call INSTALL_FILE,$f,$(LIBDIR)))
129 $(foreach f,$(LIB_H),$(call INSTALL_FILE,$f,$(INCLUDEDIR)/sparse))
130 $(call INSTALL_FILE,sparse.pc,$(PKGCONFIGDIR))
131 $(foreach f,$(SMATCH_DATA),$(call INSTALL_FILE,$f,$(SMATCHDATADIR)))
133 sparse.pc: sparse.pc.in
134 $(QUIET_GEN)sed $(SED_PC_CMD) sparse.pc.in > sparse.pc
137 compile_EXTRA_DEPS = compile-i386.o
139 $(foreach p,$(PROGRAMS),$(eval $(p): $($(p)_EXTRA_DEPS) $(LIBS)))
140 $(PROGRAMS): % : %.o
141 $(QUIET_LINK)$(CC) $(LDFLAGS) -o $@ $^ $($@_EXTRA_OBJS)
143 smatch: smatch.o $(SMATCH_FILES) $(SMATCH_CHECKS) $(LIBS)
144 $(CC) $(LDFLAGS) -o $@ $< $(SMATCH_FILES) $(SMATCH_CHECKS) $(LIBS)
146 $(LIB_FILE): $(LIB_OBJS)
147 $(QUIET_AR)$(AR) rcs $@ $(LIB_OBJS)
149 $(SLIB_FILE): $(LIB_OBJS)
150 $(QUIET_LINK)$(CC) $(LDFLAGS) -Wl,-soname,$@ -shared -o $@ $(LIB_OBJS)
152 smatch.o: smatch.c $(LIB_H) smatch.h check_list.h
153 $(CC) -c smatch.c -DSMATCHDATADIR='"$(SMATCHDATADIR)"'
154 $(SMATCH_CHECKS): smatch.h smatch_slist.h smatch_extra.h
155 DEP_FILES := $(wildcard .*.o.d)
156 $(if $(DEP_FILES),$(eval include $(DEP_FILES)))
158 c2xml.o: c2xml.c $(LIB_H)
159 $(QUIET_CC)$(CC) `pkg-config --cflags libxml-2.0` -o $@ -c $(CFLAGS) $<
161 compat-linux.o: compat/strtold.c compat/mmap-blob.c $(LIB_H)
162 compat-solaris.o: compat/mmap-blob.c $(LIB_H)
163 compat-mingw.o: $(LIB_H)
164 compat-cygwin.o: $(LIB_H)
166 .c.o:
167 $(QUIET_CC)$(CC) -o $@ -c $(CFLAGS) $<
169 clean: clean-check
170 rm -f *.[oa] .*.d *.so cwchash/*.o cwchash/.*.d cwchash/tester \
171 $(PROGRAMS) $(SLIB_FILE) pre-process.h sparse.pc
173 dist:
174 @if test "`git describe`" != "v$(VERSION)" ; then \
175 echo 'Update VERSION in the Makefile before running "make dist".' ; \
176 exit 1 ; \
178 git archive --format=tar --prefix=sparse-$(VERSION)/ HEAD^{tree} | gzip -9 > sparse-$(VERSION).tar.gz
180 check: all
181 $(Q)cd validation && ./test-suite
183 clean-check:
184 find validation/ \( -name "*.c.output.expected" \
185 -o -name "*.c.output.got" \
186 -o -name "*.c.output.diff" \
187 -o -name "*.c.error.expected" \
188 -o -name "*.c.error.got" \
189 -o -name "*.c.error.diff" \
190 \) -exec rm {} \;