simplify comparisons followed by an equality test against 0 or 1
[smatch.git] / Makefile
blobf59993f7c4b38fcefe85bd813ce59ed44bb07475
1 VERSION=0.5.0
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 flow.o cse.o simplify.o memops.o liveness.o storage.o unssa.o dissect.o
110 LIB_FILE= libsparse.a
111 SLIB_FILE= libsparse.so
113 # If you add $(SLIB_FILE) to this, you also need to add -fpic to BASIC_CFLAGS above.
114 # Doing so incurs a noticeable performance hit, and Sparse does not have a
115 # stable shared library interface, so this does not occur by default. If you
116 # really want a shared library, you may want to build Sparse twice: once
117 # without -fpic to get all the Sparse tools, and again with -fpic to get the
118 # shared library.
119 LIBS=$(LIB_FILE)
122 # Pretty print
124 V = @
125 Q = $(V:1=)
126 QUIET_CC = $(Q:@=@echo ' CC '$@;)
127 QUIET_AR = $(Q:@=@echo ' AR '$@;)
128 QUIET_GEN = $(Q:@=@echo ' GEN '$@;)
129 QUIET_LINK = $(Q:@=@echo ' LINK '$@;)
130 # We rely on the -v switch of install to print 'file -> $install_dir/file'
131 QUIET_INST_SH = $(Q:@=echo -n ' INSTALL ';)
132 QUIET_INST = $(Q:@=@echo -n ' INSTALL ';)
134 define INSTALL_EXEC
135 $(QUIET_INST)install -v $1 $(DESTDIR)$2/$1 || exit 1;
137 endef
139 define INSTALL_FILE
140 $(QUIET_INST)install -v -m 644 $1 $(DESTDIR)$2/$1 || exit 1;
142 endef
144 SED_PC_CMD = 's|@version@|$(VERSION)|g; \
145 s|@prefix@|$(PREFIX)|g; \
146 s|@libdir@|$(LIBDIR)|g; \
147 s|@includedir@|$(INCLUDEDIR)|g'
151 # Allow users to override build settings without dirtying their trees
152 -include local.mk
155 all: $(PROGRAMS) sparse.pc
157 all-installable: $(INST_PROGRAMS) $(LIBS) $(LIB_H) sparse.pc
159 install: all-installable
160 $(Q)install -d $(DESTDIR)$(BINDIR)
161 $(Q)install -d $(DESTDIR)$(LIBDIR)
162 $(Q)install -d $(DESTDIR)$(MAN1DIR)
163 $(Q)install -d $(DESTDIR)$(INCLUDEDIR)/sparse
164 $(Q)install -d $(DESTDIR)$(PKGCONFIGDIR)
165 $(foreach f,$(INST_PROGRAMS),$(call INSTALL_EXEC,$f,$(BINDIR)))
166 $(foreach f,$(INST_MAN1),$(call INSTALL_FILE,$f,$(MAN1DIR)))
167 $(foreach f,$(LIBS),$(call INSTALL_FILE,$f,$(LIBDIR)))
168 $(foreach f,$(LIB_H),$(call INSTALL_FILE,$f,$(INCLUDEDIR)/sparse))
169 $(call INSTALL_FILE,sparse.pc,$(PKGCONFIGDIR))
171 sparse.pc: sparse.pc.in
172 $(QUIET_GEN)sed $(SED_PC_CMD) sparse.pc.in > sparse.pc
175 compile_EXTRA_DEPS = compile-i386.o
177 $(foreach p,$(PROGRAMS),$(eval $(p): $($(p)_EXTRA_DEPS) $(LIBS)))
178 $(PROGRAMS): % : %.o
179 $(QUIET_LINK)$(LD) $(LDFLAGS) -o $@ $^ $($@_EXTRA_OBJS)
181 $(LIB_FILE): $(LIB_OBJS)
182 $(QUIET_AR)$(AR) rcs $@ $(LIB_OBJS)
184 $(SLIB_FILE): $(LIB_OBJS)
185 $(QUIET_LINK)$(CC) $(LDFLAGS) -Wl,-soname,$@ -shared -o $@ $(LIB_OBJS)
187 DEP_FILES := $(wildcard .*.o.d)
188 $(if $(DEP_FILES),$(eval include $(DEP_FILES)))
190 c2xml.o: c2xml.c $(LIB_H)
191 $(QUIET_CC)$(CC) `$(PKG_CONFIG) --cflags libxml-2.0` -o $@ -c $(ALL_CFLAGS) $<
193 compat-linux.o: compat/strtold.c compat/mmap-blob.c $(LIB_H)
194 compat-solaris.o: compat/mmap-blob.c $(LIB_H)
195 compat-mingw.o: $(LIB_H)
196 compat-cygwin.o: $(LIB_H)
198 %.o: %.c
199 $(QUIET_CC)$(CC) -o $@ -c $(ALL_CFLAGS) $<
201 clean: clean-check
202 rm -f *.[oa] .*.d *.so $(PROGRAMS) $(SLIB_FILE) pre-process.h sparse.pc
204 dist:
205 @if test "$(SPARSE_VERSION)" != "v$(VERSION)" ; then \
206 echo 'Update VERSION in the Makefile before running "make dist".' ; \
207 exit 1 ; \
209 git archive --format=tar --prefix=sparse-$(VERSION)/ HEAD^{tree} | gzip -9 > sparse-$(VERSION).tar.gz
211 check: all
212 $(Q)cd validation && ./test-suite
214 clean-check:
215 find validation/ \( -name "*.c.output.expected" \
216 -o -name "*.c.output.got" \
217 -o -name "*.c.output.diff" \
218 -o -name "*.c.error.expected" \
219 -o -name "*.c.error.got" \
220 -o -name "*.c.error.diff" \
221 \) -exec rm {} \;