build: disable sparse-llvm on non-x86
[smatch.git] / Makefile
bloba4653aa1b7474922af6016152047b5193edf6b12
1 VERSION=0.5.1
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
21 CHECKER = ./cgcc -no-compile
22 CHECKER_FLAGS =
24 ALL_CFLAGS = $(CFLAGS) $(BASIC_CFLAGS)
26 # For debugging, put this in local.mk:
28 # CFLAGS += -O0 -DDEBUG -g3 -gdwarf-2
31 HAVE_LIBXML:=$(shell $(PKG_CONFIG) --exists libxml-2.0 2>/dev/null && echo 'yes')
32 HAVE_GCC_DEP:=$(shell touch .gcc-test.c && \
33 $(CC) -c -Wp,-MD,.gcc-test.d .gcc-test.c 2>/dev/null && \
34 echo 'yes'; rm -f .gcc-test.d .gcc-test.o .gcc-test.c)
36 GTK_VERSION:=3.0
37 HAVE_GTK:=$(shell $(PKG_CONFIG) --exists gtk+-$(GTK_VERSION) 2>/dev/null && echo 'yes')
38 ifneq ($(HAVE_GTK),yes)
39 GTK_VERSION:=2.0
40 HAVE_GTK:=$(shell $(PKG_CONFIG) --exists gtk+-$(GTK_VERSION) 2>/dev/null && echo 'yes')
41 endif
43 LLVM_CONFIG:=llvm-config
44 HAVE_LLVM:=$(shell $(LLVM_CONFIG) --version >/dev/null 2>&1 && echo 'yes')
46 GCC_BASE := $(shell $(CC) --print-file-name=)
47 BASIC_CFLAGS = -DGCC_BASE=\"$(GCC_BASE)\"
49 MULTIARCH_TRIPLET := $(shell $(CC) -print-multiarch 2>/dev/null)
50 BASIC_CFLAGS += -DMULTIARCH_TRIPLET=\"$(MULTIARCH_TRIPLET)\"
52 ifeq ($(HAVE_GCC_DEP),yes)
53 BASIC_CFLAGS += -Wp,-MD,$(@D)/.$(@F).d
54 endif
56 DESTDIR=
57 PREFIX=$(HOME)
58 BINDIR=$(PREFIX)/bin
59 LIBDIR=$(PREFIX)/lib
60 MANDIR=$(PREFIX)/share/man
61 MAN1DIR=$(MANDIR)/man1
62 INCLUDEDIR=$(PREFIX)/include
63 PKGCONFIGDIR=$(LIBDIR)/pkgconfig
65 PROGRAMS=test-lexing test-parsing obfuscate compile graph sparse \
66 test-linearize example test-unssa test-dissect ctags
67 INST_PROGRAMS=sparse cgcc
68 INST_MAN1=sparse.1 cgcc.1
70 ifeq ($(HAVE_LIBXML),yes)
71 PROGRAMS+=c2xml
72 INST_PROGRAMS+=c2xml
73 c2xml_EXTRA_OBJS = `$(PKG_CONFIG) --libs libxml-2.0`
74 LIBXML_CFLAGS := $(shell $(PKG_CONFIG) --cflags libxml-2.0)
75 else
76 $(warning Your system does not have libxml, disabling c2xml)
77 endif
79 ifeq ($(HAVE_GTK),yes)
80 GTK_CFLAGS := $(shell $(PKG_CONFIG) --cflags gtk+-$(GTK_VERSION))
81 GTK_LIBS := $(shell $(PKG_CONFIG) --libs gtk+-$(GTK_VERSION))
82 PROGRAMS += test-inspect
83 INST_PROGRAMS += test-inspect
84 test-inspect_EXTRA_DEPS := ast-model.o ast-view.o ast-inspect.o
85 test-inspect_OBJS := test-inspect.o $(test-inspect_EXTRA_DEPS)
86 $(test-inspect_OBJS) $(test-inspect_OBJS:.o=.sc): CFLAGS += $(GTK_CFLAGS)
87 test-inspect_EXTRA_OBJS := $(GTK_LIBS)
88 else
89 $(warning Your system does not have gtk3/gtk2, disabling test-inspect)
90 endif
92 ifeq ($(HAVE_LLVM),yes)
93 ifeq ($(shell uname -m | grep -q '\(i386\|x86\)' && echo ok),ok)
94 LLVM_VERSION:=$(shell $(LLVM_CONFIG) --version)
95 ifeq ($(shell expr "$(LLVM_VERSION)" : '[3-9]\.'),2)
96 LLVM_PROGS := sparse-llvm
97 $(LLVM_PROGS): LD := g++
98 LLVM_LDFLAGS := $(shell $(LLVM_CONFIG) --ldflags)
99 LLVM_CFLAGS := $(shell $(LLVM_CONFIG) --cflags | sed -e "s/-DNDEBUG//g" | sed -e "s/-pedantic//g")
100 LLVM_LIBS := $(shell $(LLVM_CONFIG) --libs)
101 LLVM_LIBS += $(shell $(LLVM_CONFIG) --system-libs 2>/dev/null)
102 PROGRAMS += $(LLVM_PROGS)
103 INST_PROGRAMS += sparse-llvm sparsec
104 sparse-llvm.o: BASIC_CFLAGS += $(LLVM_CFLAGS)
105 sparse-llvm_EXTRA_OBJS := $(LLVM_LIBS) $(LLVM_LDFLAGS)
106 else
107 $(warning LLVM 3.0 or later required. Your system has version $(LLVM_VERSION) installed.)
108 endif
109 else
110 $(warning sparse-llvm disabled on $(shell uname -m))
111 endif
112 else
113 $(warning Your system does not have llvm, disabling sparse-llvm)
114 endif
116 LIB_H= token.h parse.h lib.h symbol.h scope.h expression.h target.h \
117 linearize.h bitmap.h ident-list.h compat.h flow.h allocate.h \
118 storage.h ptrlist.h dissect.h
120 LIB_OBJS= target.o parse.o tokenize.o pre-process.o symbol.o lib.o scope.o \
121 expression.o show-parse.o evaluate.o expand.o inline.o linearize.o \
122 char.o sort.o allocate.o compat-$(OS).o ptrlist.o \
123 builtin.o \
124 stats.o \
125 flow.o cse.o simplify.o memops.o liveness.o storage.o unssa.o dissect.o
127 LIB_FILE= libsparse.a
128 SLIB_FILE= libsparse.so
130 # If you add $(SLIB_FILE) to this, you also need to add -fpic to BASIC_CFLAGS above.
131 # Doing so incurs a noticeable performance hit, and Sparse does not have a
132 # stable shared library interface, so this does not occur by default. If you
133 # really want a shared library, you may want to build Sparse twice: once
134 # without -fpic to get all the Sparse tools, and again with -fpic to get the
135 # shared library.
136 LIBS=$(LIB_FILE)
139 # Pretty print
141 V = @
142 Q = $(V:1=)
143 QUIET_CC = $(Q:@=@echo ' CC '$@;)
144 QUIET_CHECK = $(Q:@=@echo ' CHECK '$<;)
145 QUIET_AR = $(Q:@=@echo ' AR '$@;)
146 QUIET_GEN = $(Q:@=@echo ' GEN '$@;)
147 QUIET_LINK = $(Q:@=@echo ' LINK '$@;)
148 # We rely on the -v switch of install to print 'file -> $install_dir/file'
149 QUIET_INST_SH = $(Q:@=echo -n ' INSTALL ';)
150 QUIET_INST = $(Q:@=@echo -n ' INSTALL ';)
152 define INSTALL_EXEC
153 $(QUIET_INST)install -v $1 $(DESTDIR)$2/$1 || exit 1;
155 endef
157 define INSTALL_FILE
158 $(QUIET_INST)install -v -m 644 $1 $(DESTDIR)$2/$1 || exit 1;
160 endef
162 SED_PC_CMD = 's|@version@|$(VERSION)|g; \
163 s|@prefix@|$(PREFIX)|g; \
164 s|@libdir@|$(LIBDIR)|g; \
165 s|@includedir@|$(INCLUDEDIR)|g'
169 # Allow users to override build settings without dirtying their trees
170 -include local.mk
173 all: $(PROGRAMS) sparse.pc
175 all-installable: $(INST_PROGRAMS) $(LIBS) $(LIB_H) sparse.pc
177 install: all-installable
178 $(Q)install -d $(DESTDIR)$(BINDIR)
179 $(Q)install -d $(DESTDIR)$(LIBDIR)
180 $(Q)install -d $(DESTDIR)$(MAN1DIR)
181 $(Q)install -d $(DESTDIR)$(INCLUDEDIR)/sparse
182 $(Q)install -d $(DESTDIR)$(PKGCONFIGDIR)
183 $(foreach f,$(INST_PROGRAMS),$(call INSTALL_EXEC,$f,$(BINDIR)))
184 $(foreach f,$(INST_MAN1),$(call INSTALL_FILE,$f,$(MAN1DIR)))
185 $(foreach f,$(LIBS),$(call INSTALL_FILE,$f,$(LIBDIR)))
186 $(foreach f,$(LIB_H),$(call INSTALL_FILE,$f,$(INCLUDEDIR)/sparse))
187 $(call INSTALL_FILE,sparse.pc,$(PKGCONFIGDIR))
189 sparse.pc: sparse.pc.in
190 $(QUIET_GEN)sed $(SED_PC_CMD) sparse.pc.in > sparse.pc
193 compile_EXTRA_DEPS = compile-i386.o
195 $(foreach p,$(PROGRAMS),$(eval $(p): $($(p)_EXTRA_DEPS) $(LIBS)))
196 $(PROGRAMS): % : %.o
197 $(QUIET_LINK)$(LD) $(LDFLAGS) -o $@ $^ $($@_EXTRA_OBJS)
199 $(LIB_FILE): $(LIB_OBJS)
200 $(QUIET_AR)$(AR) rcs $@ $(LIB_OBJS)
202 $(SLIB_FILE): $(LIB_OBJS)
203 $(QUIET_LINK)$(CC) $(LDFLAGS) -Wl,-soname,$@ -shared -o $@ $(LIB_OBJS)
205 DEP_FILES := $(wildcard .*.o.d)
207 ifneq ($(DEP_FILES),)
208 include $(DEP_FILES)
209 endif
211 c2xml.o c2xml.sc: CFLAGS += $(LIBXML_CFLAGS)
213 pre-process.sc: CHECKER_FLAGS += -Wno-vla
215 %.o: %.c $(LIB_H)
216 $(QUIET_CC)$(CC) -o $@ -c $(ALL_CFLAGS) $<
218 %.sc: %.c sparse
219 $(QUIET_CHECK) $(CHECKER) $(CHECKER_FLAGS) -c $(ALL_CFLAGS) $<
221 ALL_OBJS := $(LIB_OBJS) $(foreach p,$(PROGRAMS),$(p).o $($(p)_EXTRA_DEPS))
222 selfcheck: $(ALL_OBJS:.o=.sc)
225 clean: clean-check
226 rm -f *.[oa] .*.d *.so $(PROGRAMS) $(SLIB_FILE) pre-process.h sparse.pc
228 dist:
229 @if test "$(SPARSE_VERSION)" != "v$(VERSION)" ; then \
230 echo 'Update VERSION in the Makefile before running "make dist".' ; \
231 exit 1 ; \
233 git archive --format=tar --prefix=sparse-$(VERSION)/ HEAD^{tree} | gzip -9 > sparse-$(VERSION).tar.gz
235 check: all
236 $(Q)cd validation && ./test-suite
238 clean-check:
239 find validation/ \( -name "*.c.output.expected" \
240 -o -name "*.c.output.got" \
241 -o -name "*.c.output.diff" \
242 -o -name "*.c.error.expected" \
243 -o -name "*.c.error.got" \
244 -o -name "*.c.error.diff" \
245 \) -exec rm {} \;