sparse: add built-in byte swap identifiers
[smatch.git] / Makefile
blobb195528e6784de26d469f9596a45a6cb82f5bbc8
1 VERSION=0.4.4
3 OS = linux
6 CC = gcc
7 CFLAGS = -O2 -finline-functions -fno-strict-aliasing -g
8 CFLAGS += -Wall -Wwrite-strings
9 LDFLAGS += -g
10 LD = gcc
11 AR = ar
13 ALL_CFLAGS = $(CFLAGS) $(BASIC_CFLAGS)
15 # For debugging, put this in local.mk:
17 # CFLAGS += -O0 -DDEBUG -g3 -gdwarf-2
20 HAVE_LIBXML:=$(shell pkg-config --exists libxml-2.0 2>/dev/null && echo 'yes')
21 HAVE_GCC_DEP:=$(shell touch .gcc-test.c && \
22 $(CC) -c -Wp,-MD,.gcc-test.d .gcc-test.c 2>/dev/null && \
23 echo 'yes'; rm -f .gcc-test.d .gcc-test.o .gcc-test.c)
24 HAVE_GTK2:=$(shell pkg-config --exists gtk+-2.0 2>/dev/null && echo 'yes')
25 HAVE_LLVM:=$(shell llvm-config --version >/dev/null 2>&1 && echo 'yes')
26 HAVE_LLVM_VERSION:=$(shell llvm-config --version | grep "^[3-9].*" >/dev/null 2>&1 && echo yes)
27 LLVM_VERSION=$(shell llvm-config --version)
29 GCC_BASE = $(shell $(CC) --print-file-name=)
30 BASIC_CFLAGS = -DGCC_BASE=\"$(GCC_BASE)\"
32 ifeq ($(HAVE_GCC_DEP),yes)
33 BASIC_CFLAGS += -Wp,-MD,$(@D)/.$(@F).d
34 endif
36 DESTDIR=
37 PREFIX=$(HOME)
38 BINDIR=$(PREFIX)/bin
39 LIBDIR=$(PREFIX)/lib
40 MANDIR=$(PREFIX)/share/man
41 MAN1DIR=$(MANDIR)/man1
42 INCLUDEDIR=$(PREFIX)/include
43 PKGCONFIGDIR=$(LIBDIR)/pkgconfig
45 PROGRAMS=test-lexing test-parsing obfuscate compile graph sparse \
46 test-linearize example test-unssa test-dissect ctags
47 INST_PROGRAMS=sparse cgcc
48 INST_MAN1=sparse.1 cgcc.1
50 ifeq ($(HAVE_LIBXML),yes)
51 PROGRAMS+=c2xml
52 INST_PROGRAMS+=c2xml
53 c2xml_EXTRA_OBJS = `pkg-config --libs libxml-2.0`
54 else
55 $(warning Your system does not have libxml, disabling c2xml)
56 endif
58 ifeq ($(HAVE_GTK2),yes)
59 GTK2_CFLAGS := $(shell pkg-config --cflags gtk+-2.0)
60 GTK2_LIBS := $(shell pkg-config --libs gtk+-2.0)
61 PROGRAMS += test-inspect
62 INST_PROGRAMS += test-inspect
63 test-inspect_EXTRA_DEPS := ast-model.o ast-view.o ast-inspect.o
64 test-inspect.o $(test-inspect_EXTRA_DEPS): BASIC_CFLAGS += $(GTK2_CFLAGS)
65 test-inspect_EXTRA_OBJS := $(GTK2_LIBS)
66 else
67 $(warning Your system does not have libgtk2, disabling test-inspect)
68 endif
70 ifneq ($(HAVE_LLVM),yes)
71 $(warning Your system does not have llvm, disabling sparse-llvm)
72 else
73 ifneq ($(HAVE_LLVM_VERSION),yes)
74 $(warning LLVM 3.0 or later required. Your system has version $(LLVM_VERSION) installed.)
75 HAVE_LLVM=no
76 else
77 LLVM_PROGS := sparse-llvm
78 $(LLVM_PROGS): LD := g++
79 LDFLAGS += $(shell llvm-config --ldflags)
80 LLVM_CFLAGS := $(shell llvm-config --cflags | sed -e "s/-DNDEBUG//g")
81 LLVM_LIBS := $(shell llvm-config --libs)
82 PROGRAMS += $(LLVM_PROGS)
83 INST_PROGRAMS += sparse-llvm sparsec
84 sparse-llvm_EXTRA_DEPS := sparse-llvm.o
85 sparse-llvm.o $(sparse-llvm_EXTRA_DEPS): BASIC_CFLAGS += $(LLVM_CFLAGS)
86 sparse-llvm_EXTRA_OBJS := $(LLVM_LIBS)
87 endif
88 endif
90 LIB_H= token.h parse.h lib.h symbol.h scope.h expression.h target.h \
91 linearize.h bitmap.h ident-list.h compat.h flow.h allocate.h \
92 storage.h ptrlist.h dissect.h
94 LIB_OBJS= target.o parse.o tokenize.o pre-process.o symbol.o lib.o scope.o \
95 expression.o show-parse.o evaluate.o expand.o inline.o linearize.o \
96 char.o sort.o allocate.o compat-$(OS).o ptrlist.o \
97 flow.o cse.o simplify.o memops.o liveness.o storage.o unssa.o dissect.o
99 LIB_FILE= libsparse.a
100 SLIB_FILE= libsparse.so
102 # If you add $(SLIB_FILE) to this, you also need to add -fpic to BASIC_CFLAGS above.
103 # Doing so incurs a noticeable performance hit, and Sparse does not have a
104 # stable shared library interface, so this does not occur by default. If you
105 # really want a shared library, you may want to build Sparse twice: once
106 # without -fpic to get all the Sparse tools, and again with -fpic to get the
107 # shared library.
108 LIBS=$(LIB_FILE)
111 # Pretty print
113 V = @
114 Q = $(V:1=)
115 QUIET_CC = $(Q:@=@echo ' CC '$@;)
116 QUIET_AR = $(Q:@=@echo ' AR '$@;)
117 QUIET_GEN = $(Q:@=@echo ' GEN '$@;)
118 QUIET_LINK = $(Q:@=@echo ' LINK '$@;)
119 # We rely on the -v switch of install to print 'file -> $install_dir/file'
120 QUIET_INST_SH = $(Q:@=echo -n ' INSTALL ';)
121 QUIET_INST = $(Q:@=@echo -n ' INSTALL ';)
123 define INSTALL_EXEC
124 $(QUIET_INST)install -v $1 $(DESTDIR)$2/$1 || exit 1;
126 endef
128 define INSTALL_FILE
129 $(QUIET_INST)install -v -m 644 $1 $(DESTDIR)$2/$1 || exit 1;
131 endef
133 SED_PC_CMD = 's|@version@|$(VERSION)|g; \
134 s|@prefix@|$(PREFIX)|g; \
135 s|@libdir@|$(LIBDIR)|g; \
136 s|@includedir@|$(INCLUDEDIR)|g'
140 # Allow users to override build settings without dirtying their trees
141 -include local.mk
144 all: $(PROGRAMS) sparse.pc
146 all-installable: $(INST_PROGRAMS) $(LIBS) $(LIB_H) sparse.pc
148 install: all-installable
149 $(Q)install -d $(DESTDIR)$(BINDIR)
150 $(Q)install -d $(DESTDIR)$(LIBDIR)
151 $(Q)install -d $(DESTDIR)$(MAN1DIR)
152 $(Q)install -d $(DESTDIR)$(INCLUDEDIR)/sparse
153 $(Q)install -d $(DESTDIR)$(PKGCONFIGDIR)
154 $(foreach f,$(INST_PROGRAMS),$(call INSTALL_EXEC,$f,$(BINDIR)))
155 $(foreach f,$(INST_MAN1),$(call INSTALL_FILE,$f,$(MAN1DIR)))
156 $(foreach f,$(LIBS),$(call INSTALL_FILE,$f,$(LIBDIR)))
157 $(foreach f,$(LIB_H),$(call INSTALL_FILE,$f,$(INCLUDEDIR)/sparse))
158 $(call INSTALL_FILE,sparse.pc,$(PKGCONFIGDIR))
160 sparse.pc: sparse.pc.in
161 $(QUIET_GEN)sed $(SED_PC_CMD) sparse.pc.in > sparse.pc
164 compile_EXTRA_DEPS = compile-i386.o
166 $(foreach p,$(PROGRAMS),$(eval $(p): $($(p)_EXTRA_DEPS) $(LIBS)))
167 $(PROGRAMS): % : %.o
168 $(QUIET_LINK)$(LD) $(LDFLAGS) -o $@ $^ $($@_EXTRA_OBJS)
170 $(LIB_FILE): $(LIB_OBJS)
171 $(QUIET_AR)$(AR) rcs $@ $(LIB_OBJS)
173 $(SLIB_FILE): $(LIB_OBJS)
174 $(QUIET_LINK)$(CC) $(LDFLAGS) -Wl,-soname,$@ -shared -o $@ $(LIB_OBJS)
176 DEP_FILES := $(wildcard .*.o.d)
177 $(if $(DEP_FILES),$(eval include $(DEP_FILES)))
179 c2xml.o: c2xml.c $(LIB_H)
180 $(QUIET_CC)$(CC) `pkg-config --cflags libxml-2.0` -o $@ -c $(ALL_CFLAGS) $<
182 compat-linux.o: compat/strtold.c compat/mmap-blob.c $(LIB_H)
183 compat-solaris.o: compat/mmap-blob.c $(LIB_H)
184 compat-mingw.o: $(LIB_H)
185 compat-cygwin.o: $(LIB_H)
187 %.o: %.c
188 $(QUIET_CC)$(CC) -o $@ -c $(ALL_CFLAGS) $<
190 clean: clean-check
191 rm -f *.[oa] .*.d *.so $(PROGRAMS) $(SLIB_FILE) pre-process.h sparse.pc
193 dist:
194 @if test "`git describe`" != "v$(VERSION)" ; then \
195 echo 'Update VERSION in the Makefile before running "make dist".' ; \
196 exit 1 ; \
198 git archive --format=tar --prefix=sparse-$(VERSION)/ HEAD^{tree} | gzip -9 > sparse-$(VERSION).tar.gz
200 check: all
201 $(Q)cd validation && ./test-suite
203 clean-check:
204 find validation/ \( -name "*.c.output.expected" \
205 -o -name "*.c.output.got" \
206 -o -name "*.c.output.diff" \
207 -o -name "*.c.error.expected" \
208 -o -name "*.c.error.got" \
209 -o -name "*.c.error.diff" \
210 \) -exec rm {} \;