fix crash in rewrite_branch()
[smatch.git] / Makefile
blob96e81c4fbc4bbf9d9e327b50016bc8480e7df9ff
1 VERSION=0.5.1-rc4
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)
9 endif
11 OS = linux
14 CC = gcc
15 CFLAGS = -O2 -finline-functions -fno-strict-aliasing -g
16 CFLAGS += -Wall -Wwrite-strings
17 LDFLAGS += -g
18 LD = gcc
19 AR = ar
20 PKG_CONFIG = pkg-config
22 ALL_CFLAGS = $(CFLAGS) $(BASIC_CFLAGS)
24 # For debugging, put this in local.mk:
26 # CFLAGS += -O0 -DDEBUG -g3 -gdwarf-2
29 HAVE_LIBXML:=$(shell $(PKG_CONFIG) --exists libxml-2.0 2>/dev/null && echo 'yes')
30 HAVE_GCC_DEP:=$(shell touch .gcc-test.c && \
31 $(CC) -c -Wp,-MD,.gcc-test.d .gcc-test.c 2>/dev/null && \
32 echo 'yes'; rm -f .gcc-test.d .gcc-test.o .gcc-test.c)
33 HAVE_GTK2:=$(shell $(PKG_CONFIG) --exists gtk+-2.0 2>/dev/null && echo 'yes')
34 LLVM_CONFIG:=llvm-config
35 HAVE_LLVM:=$(shell $(LLVM_CONFIG) --version >/dev/null 2>&1 && echo 'yes')
37 GCC_BASE = $(shell $(CC) --print-file-name=)
38 BASIC_CFLAGS = -DGCC_BASE=\"$(GCC_BASE)\"
40 MULTIARCH_TRIPLET = $(shell $(CC) -print-multiarch 2>/dev/null)
41 BASIC_CFLAGS += -DMULTIARCH_TRIPLET=\"$(MULTIARCH_TRIPLET)\"
43 ifeq ($(HAVE_GCC_DEP),yes)
44 BASIC_CFLAGS += -Wp,-MD,$(@D)/.$(@F).d
45 endif
47 DESTDIR=
48 PREFIX=$(HOME)
49 BINDIR=$(PREFIX)/bin
50 LIBDIR=$(PREFIX)/lib
51 MANDIR=$(PREFIX)/share/man
52 MAN1DIR=$(MANDIR)/man1
53 INCLUDEDIR=$(PREFIX)/include
54 PKGCONFIGDIR=$(LIBDIR)/pkgconfig
56 PROGRAMS=test-lexing test-parsing obfuscate compile graph sparse \
57 test-linearize example test-unssa test-dissect ctags
58 INST_PROGRAMS=sparse cgcc
59 INST_MAN1=sparse.1 cgcc.1
61 ifeq ($(HAVE_LIBXML),yes)
62 PROGRAMS+=c2xml
63 INST_PROGRAMS+=c2xml
64 c2xml_EXTRA_OBJS = `$(PKG_CONFIG) --libs libxml-2.0`
65 else
66 $(warning Your system does not have libxml, disabling c2xml)
67 endif
69 ifeq ($(HAVE_GTK2),yes)
70 GTK2_CFLAGS := $(shell $(PKG_CONFIG) --cflags gtk+-2.0)
71 GTK2_LIBS := $(shell $(PKG_CONFIG) --libs gtk+-2.0)
72 PROGRAMS += test-inspect
73 INST_PROGRAMS += test-inspect
74 test-inspect_EXTRA_DEPS := ast-model.o ast-view.o ast-inspect.o
75 test-inspect.o $(test-inspect_EXTRA_DEPS): BASIC_CFLAGS += $(GTK2_CFLAGS)
76 test-inspect_EXTRA_OBJS := $(GTK2_LIBS)
77 else
78 $(warning Your system does not have libgtk2, disabling test-inspect)
79 endif
81 ifeq ($(HAVE_LLVM),yes)
82 LLVM_VERSION:=$(shell $(LLVM_CONFIG) --version)
83 ifeq ($(shell expr "$(LLVM_VERSION)" : '[3-9]\.'),2)
84 LLVM_PROGS := sparse-llvm
85 $(LLVM_PROGS): LD := g++
86 LLVM_LDFLAGS := $(shell $(LLVM_CONFIG) --ldflags)
87 LLVM_CFLAGS := $(shell $(LLVM_CONFIG) --cflags | sed -e "s/-DNDEBUG//g" | sed -e "s/-pedantic//g")
88 LLVM_LIBS := $(shell $(LLVM_CONFIG) --libs)
89 LLVM_LIBS += $(shell $(LLVM_CONFIG) --system-libs 2>/dev/null)
90 PROGRAMS += $(LLVM_PROGS)
91 INST_PROGRAMS += sparse-llvm sparsec
92 sparse-llvm.o: BASIC_CFLAGS += $(LLVM_CFLAGS)
93 sparse-llvm_EXTRA_OBJS := $(LLVM_LIBS) $(LLVM_LDFLAGS)
94 else
95 $(warning LLVM 3.0 or later required. Your system has version $(LLVM_VERSION) installed.)
96 endif
97 else
98 $(warning Your system does not have llvm, disabling sparse-llvm)
99 endif
101 LIB_H= token.h parse.h lib.h symbol.h scope.h expression.h target.h \
102 linearize.h bitmap.h ident-list.h compat.h flow.h allocate.h \
103 storage.h ptrlist.h dissect.h
105 LIB_OBJS= target.o parse.o tokenize.o pre-process.o symbol.o lib.o scope.o \
106 expression.o show-parse.o evaluate.o expand.o inline.o linearize.o \
107 char.o sort.o allocate.o compat-$(OS).o ptrlist.o \
108 builtin.o \
109 stats.o \
110 flow.o cse.o simplify.o memops.o liveness.o storage.o unssa.o dissect.o
112 LIB_FILE= libsparse.a
113 SLIB_FILE= libsparse.so
115 # If you add $(SLIB_FILE) to this, you also need to add -fpic to BASIC_CFLAGS above.
116 # Doing so incurs a noticeable performance hit, and Sparse does not have a
117 # stable shared library interface, so this does not occur by default. If you
118 # really want a shared library, you may want to build Sparse twice: once
119 # without -fpic to get all the Sparse tools, and again with -fpic to get the
120 # shared library.
121 LIBS=$(LIB_FILE)
124 # Pretty print
126 V = @
127 Q = $(V:1=)
128 QUIET_CC = $(Q:@=@echo ' CC '$@;)
129 QUIET_AR = $(Q:@=@echo ' AR '$@;)
130 QUIET_GEN = $(Q:@=@echo ' GEN '$@;)
131 QUIET_LINK = $(Q:@=@echo ' LINK '$@;)
132 # We rely on the -v switch of install to print 'file -> $install_dir/file'
133 QUIET_INST_SH = $(Q:@=echo -n ' INSTALL ';)
134 QUIET_INST = $(Q:@=@echo -n ' INSTALL ';)
136 define INSTALL_EXEC
137 $(QUIET_INST)install -v $1 $(DESTDIR)$2/$1 || exit 1;
139 endef
141 define INSTALL_FILE
142 $(QUIET_INST)install -v -m 644 $1 $(DESTDIR)$2/$1 || exit 1;
144 endef
146 SED_PC_CMD = 's|@version@|$(VERSION)|g; \
147 s|@prefix@|$(PREFIX)|g; \
148 s|@libdir@|$(LIBDIR)|g; \
149 s|@includedir@|$(INCLUDEDIR)|g'
153 # Allow users to override build settings without dirtying their trees
154 -include local.mk
157 all: $(PROGRAMS) sparse.pc
159 all-installable: $(INST_PROGRAMS) $(LIBS) $(LIB_H) sparse.pc
161 install: all-installable
162 $(Q)install -d $(DESTDIR)$(BINDIR)
163 $(Q)install -d $(DESTDIR)$(LIBDIR)
164 $(Q)install -d $(DESTDIR)$(MAN1DIR)
165 $(Q)install -d $(DESTDIR)$(INCLUDEDIR)/sparse
166 $(Q)install -d $(DESTDIR)$(PKGCONFIGDIR)
167 $(foreach f,$(INST_PROGRAMS),$(call INSTALL_EXEC,$f,$(BINDIR)))
168 $(foreach f,$(INST_MAN1),$(call INSTALL_FILE,$f,$(MAN1DIR)))
169 $(foreach f,$(LIBS),$(call INSTALL_FILE,$f,$(LIBDIR)))
170 $(foreach f,$(LIB_H),$(call INSTALL_FILE,$f,$(INCLUDEDIR)/sparse))
171 $(call INSTALL_FILE,sparse.pc,$(PKGCONFIGDIR))
173 sparse.pc: sparse.pc.in
174 $(QUIET_GEN)sed $(SED_PC_CMD) sparse.pc.in > sparse.pc
177 compile_EXTRA_DEPS = compile-i386.o
179 $(foreach p,$(PROGRAMS),$(eval $(p): $($(p)_EXTRA_DEPS) $(LIBS)))
180 $(PROGRAMS): % : %.o
181 $(QUIET_LINK)$(LD) $(LDFLAGS) -o $@ $^ $($@_EXTRA_OBJS)
183 $(LIB_FILE): $(LIB_OBJS)
184 $(QUIET_AR)$(AR) rcs $@ $(LIB_OBJS)
186 $(SLIB_FILE): $(LIB_OBJS)
187 $(QUIET_LINK)$(CC) $(LDFLAGS) -Wl,-soname,$@ -shared -o $@ $(LIB_OBJS)
189 DEP_FILES := $(wildcard .*.o.d)
190 $(if $(DEP_FILES),$(eval include $(DEP_FILES)))
192 c2xml.o: c2xml.c $(LIB_H)
193 $(QUIET_CC)$(CC) `$(PKG_CONFIG) --cflags libxml-2.0` -o $@ -c $(ALL_CFLAGS) $<
195 compat-linux.o: compat/strtold.c compat/mmap-blob.c $(LIB_H)
196 compat-solaris.o: compat/mmap-blob.c $(LIB_H)
197 compat-mingw.o: $(LIB_H)
198 compat-cygwin.o: $(LIB_H)
200 %.o: %.c
201 $(QUIET_CC)$(CC) -o $@ -c $(ALL_CFLAGS) $<
203 clean: clean-check
204 rm -f *.[oa] .*.d *.so $(PROGRAMS) $(SLIB_FILE) pre-process.h sparse.pc
206 dist:
207 @if test "$(SPARSE_VERSION)" != "v$(VERSION)" ; then \
208 echo 'Update VERSION in the Makefile before running "make dist".' ; \
209 exit 1 ; \
211 git archive --format=tar --prefix=sparse-$(VERSION)/ HEAD^{tree} | gzip -9 > sparse-$(VERSION).tar.gz
213 check: all
214 $(Q)cd validation && ./test-suite
216 clean-check:
217 find validation/ \( -name "*.c.output.expected" \
218 -o -name "*.c.output.got" \
219 -o -name "*.c.output.diff" \
220 -o -name "*.c.error.expected" \
221 -o -name "*.c.error.got" \
222 -o -name "*.c.error.diff" \
223 \) -exec rm {} \;