handle assignments like: foo = x < 1;
[smatch.git] / Makefile
blob67c485df033d9879f3b25036ad8cb90709f18eb4
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 \
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 cwchash/hashtable.o
44 SMATCH_CHECKS=$(shell ls check_*.c | sed -e 's/\.c/.o/')
45 SMATCH_DATA=smatch_data/kernel.allocation_funcs smatch_data/kernel.balanced_funcs \
46 smatch_data/kernel.frees_argument smatch_data/kernel.puts_argument \
47 smatch_data/kernel.dev_queue_xmit smatch_data/kernel.returns_err_ptr \
48 smatch_data/kernel.dma_funcs smatch_data/kernel.returns_held_funcs \
49 smatch_data/kernel.no_return_funcs
51 PROGRAMS=test-lexing test-parsing obfuscate compile graph sparse \
52 test-linearize example test-unssa test-dissect ctags
53 INST_PROGRAMS=sparse cgcc smatch
55 INST_MAN1=sparse.1 cgcc.1
57 ifeq ($(HAVE_LIBXML),yes)
58 PROGRAMS+=c2xml
59 INST_PROGRAMS+=c2xml
60 c2xml_EXTRA_OBJS = `pkg-config --libs libxml-2.0`
61 endif
63 LIB_H= token.h parse.h lib.h symbol.h scope.h expression.h target.h \
64 linearize.h bitmap.h ident-list.h compat.h flow.h allocate.h \
65 storage.h ptrlist.h dissect.h
67 LIB_OBJS= target.o parse.o tokenize.o pre-process.o symbol.o lib.o scope.o \
68 expression.o show-parse.o evaluate.o expand.o inline.o linearize.o \
69 sort.o allocate.o compat-$(OS).o ptrlist.o \
70 flow.o cse.o simplify.o memops.o liveness.o storage.o unssa.o dissect.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_flow.o: $(LIB_H) smatch.h smatch_expression_stacks.h smatch_extra.h
153 smatch_conditions.o: $(LIB_H) smatch.h smatch_slist.h
154 smatch_extra.o: $(LIB_H) smatch.h smatch_extra.h
155 smatch_ranges.o: $(LIB_H) smatch.h smatch_extra.h
156 smatch_implied.o: $(LIB_H) smatch.h smatch_slist.h smatch_extra.h
157 smatch_ignore.o: $(LIB_H) smatch.h
158 smatch_tracker.o: $(LIB_H) smatch.h
159 smatch_files.o: $(LIB_H) smatch.h
160 smatch_hooks.o: $(LIB_H) smatch.h
161 smatch_function_hooks.o: $(LIB_H) smatch.h smatch_slist.h smatch_extra.h
162 smatch_modification_hooks.o: $(LIB_H) smatch.h
163 smatch_helper.o: $(LIB_H) smatch.h
164 smatch_type.o: $(LIB_H) smatch.h
165 smatch_slist.o: $(LIB_H) smatch.h smatch_slist.h
166 smatch_states.o: $(LIB_H) smatch.h smatch_slist.h smatch_extra.h
167 smatch_expression_stacks.o: $(LIB_H) smatch.h
168 smatch_oom.c: $(LIB_H) smatch.h
169 smatch_redefine.c: $(LIB_H) smatch.h
170 smatch.o: smatch.c $(LIB_H) smatch.h check_list.h
171 $(CC) -c smatch.c -DSMATCHDATADIR='"$(SMATCHDATADIR)"'
172 $(SMATCH_CHECKS): smatch.h smatch_slist.h smatch_extra.h
173 test-unssa.o: $(LIB_H)
174 ctags.o: $(LIB_H)
175 compile.o: $(LIB_H) compile.h
176 compile-i386.o: $(LIB_H) compile.h
177 tokenize.o: $(LIB_H)
178 sparse.o: $(LIB_H)
179 obfuscate.o: $(LIB_H)
180 example.o: $(LIB_H)
181 storage.o: $(LIB_H)
182 dissect.o: $(LIB_H)
183 graph.o: $(LIB_H)
184 DEP_FILES := $(wildcard .*.o.d)
185 $(if $(DEP_FILES),$(eval include $(DEP_FILES)))
187 c2xml.o: c2xml.c $(LIB_H)
188 $(QUIET_CC)$(CC) `pkg-config --cflags libxml-2.0` -o $@ -c $(CFLAGS) $<
190 compat-linux.o: compat/strtold.c compat/mmap-blob.c $(LIB_H)
191 compat-solaris.o: compat/mmap-blob.c $(LIB_H)
192 compat-mingw.o: $(LIB_H)
193 compat-cygwin.o: $(LIB_H)
195 .c.o:
196 $(QUIET_CC)$(CC) -o $@ -c $(CFLAGS) $<
198 clean: clean-check
199 rm -f *.[oa] .*.d *.so cwchash/*.o cwchash/.*.d cwchash/tester \
200 $(PROGRAMS) $(SLIB_FILE) pre-process.h sparse.pc
202 dist:
203 @if test "`git describe`" != "v$(VERSION)" ; then \
204 echo 'Update VERSION in the Makefile before running "make dist".' ; \
205 exit 1 ; \
207 git archive --format=tar --prefix=sparse-$(VERSION)/ HEAD^{tree} | gzip -9 > sparse-$(VERSION).tar.gz
209 check: all
210 $(Q)cd validation && ./test-suite
212 clean-check:
213 find validation/ \( -name "*.c.output.expected" \
214 -o -name "*.c.output.got" \
215 -o -name "*.c.output.diff" \
216 -o -name "*.c.error.expected" \
217 -o -name "*.c.error.got" \
218 -o -name "*.c.error.diff" \
219 \) -exec rm {} \;