sparse, llvm: Add output_op_binary() stub
[smatch.git] / Makefile
bloba9f9b3525e15a00b89345b383b096472460cb8ad
1 VERSION=0.4.4-rc1
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')
27 GCC_BASE = $(shell $(CC) --print-file-name=)
28 BASIC_CFLAGS = -DGCC_BASE=\"$(GCC_BASE)\"
30 ifeq ($(HAVE_GCC_DEP),yes)
31 BASIC_CFLAGS += -Wp,-MD,$(@D)/.$(@F).d
32 endif
34 DESTDIR=
35 PREFIX=$(HOME)
36 BINDIR=$(PREFIX)/bin
37 LIBDIR=$(PREFIX)/lib
38 MANDIR=$(PREFIX)/share/man
39 MAN1DIR=$(MANDIR)/man1
40 INCLUDEDIR=$(PREFIX)/include
41 PKGCONFIGDIR=$(LIBDIR)/pkgconfig
43 PROGRAMS=test-lexing test-parsing obfuscate compile graph sparse \
44 test-linearize example test-unssa test-dissect ctags
45 INST_PROGRAMS=sparse cgcc
46 INST_MAN1=sparse.1 cgcc.1
48 ifeq ($(HAVE_LIBXML),yes)
49 PROGRAMS+=c2xml
50 INST_PROGRAMS+=c2xml
51 c2xml_EXTRA_OBJS = `pkg-config --libs libxml-2.0`
52 else
53 $(warning Your system does not have libxml, disabling c2xml)
54 endif
56 ifeq ($(HAVE_GTK2),yes)
57 GTK2_CFLAGS := $(shell pkg-config --cflags gtk+-2.0)
58 GTK2_LIBS := $(shell pkg-config --libs gtk+-2.0)
59 PROGRAMS += test-inspect
60 INST_PROGRAMS += test-inspect
61 test-inspect_EXTRA_DEPS := ast-model.o ast-view.o ast-inspect.o
62 test-inspect.o $(test-inspect_EXTRA_DEPS): BASIC_CFLAGS += $(GTK2_CFLAGS)
63 test-inspect_EXTRA_OBJS := $(GTK2_LIBS)
64 else
65 $(warning Your system does not have libgtk2, disabling test-inspect)
66 endif
68 ifeq ($(HAVE_LLVM),yes)
69 LD = g++
70 LDFLAGS += $(shell llvm-config --ldflags)
71 LLVM_CFLAGS := $(shell llvm-config --cflags | sed -e "s/-DNDEBUG//g")
72 LLVM_LIBS := $(shell llvm-config --libs)
73 PROGRAMS += sparse-llvm
74 INST_PROGRAMS += sparse-llvm sparsec
75 sparse-llvm_EXTRA_DEPS := sparse-llvm.o
76 sparse-llvm.o $(sparse-llvm_EXTRA_DEPS): BASIC_CFLAGS += $(LLVM_CFLAGS)
77 sparse-llvm_EXTRA_OBJS := $(LLVM_LIBS)
78 else
79 $(warning Your system does not have llvm, disabling sparse-llvm)
80 endif
82 LIB_H= token.h parse.h lib.h symbol.h scope.h expression.h target.h \
83 linearize.h bitmap.h ident-list.h compat.h flow.h allocate.h \
84 storage.h ptrlist.h dissect.h
86 LIB_OBJS= target.o parse.o tokenize.o pre-process.o symbol.o lib.o scope.o \
87 expression.o show-parse.o evaluate.o expand.o inline.o linearize.o \
88 sort.o allocate.o compat-$(OS).o ptrlist.o \
89 flow.o cse.o simplify.o memops.o liveness.o storage.o unssa.o dissect.o
91 LIB_FILE= libsparse.a
92 SLIB_FILE= libsparse.so
94 # If you add $(SLIB_FILE) to this, you also need to add -fpic to BASIC_CFLAGS above.
95 # Doing so incurs a noticeable performance hit, and Sparse does not have a
96 # stable shared library interface, so this does not occur by default. If you
97 # really want a shared library, you may want to build Sparse twice: once
98 # without -fpic to get all the Sparse tools, and again with -fpic to get the
99 # shared library.
100 LIBS=$(LIB_FILE)
103 # Pretty print
105 V = @
106 Q = $(V:1=)
107 QUIET_CC = $(Q:@=@echo ' CC '$@;)
108 QUIET_AR = $(Q:@=@echo ' AR '$@;)
109 QUIET_GEN = $(Q:@=@echo ' GEN '$@;)
110 QUIET_LINK = $(Q:@=@echo ' LINK '$@;)
111 # We rely on the -v switch of install to print 'file -> $install_dir/file'
112 QUIET_INST_SH = $(Q:@=echo -n ' INSTALL ';)
113 QUIET_INST = $(Q:@=@echo -n ' INSTALL ';)
115 define INSTALL_EXEC
116 $(QUIET_INST)install -v $1 $(DESTDIR)$2/$1 || exit 1;
118 endef
120 define INSTALL_FILE
121 $(QUIET_INST)install -v -m 644 $1 $(DESTDIR)$2/$1 || exit 1;
123 endef
125 SED_PC_CMD = 's|@version@|$(VERSION)|g; \
126 s|@prefix@|$(PREFIX)|g; \
127 s|@libdir@|$(LIBDIR)|g; \
128 s|@includedir@|$(INCLUDEDIR)|g'
132 # Allow users to override build settings without dirtying their trees
133 -include local.mk
136 all: $(PROGRAMS) sparse.pc
138 all-installable: $(INST_PROGRAMS) $(LIBS) $(LIB_H) sparse.pc
140 install: all-installable
141 $(Q)install -d $(DESTDIR)$(BINDIR)
142 $(Q)install -d $(DESTDIR)$(LIBDIR)
143 $(Q)install -d $(DESTDIR)$(MAN1DIR)
144 $(Q)install -d $(DESTDIR)$(INCLUDEDIR)/sparse
145 $(Q)install -d $(DESTDIR)$(PKGCONFIGDIR)
146 $(foreach f,$(INST_PROGRAMS),$(call INSTALL_EXEC,$f,$(BINDIR)))
147 $(foreach f,$(INST_MAN1),$(call INSTALL_FILE,$f,$(MAN1DIR)))
148 $(foreach f,$(LIBS),$(call INSTALL_FILE,$f,$(LIBDIR)))
149 $(foreach f,$(LIB_H),$(call INSTALL_FILE,$f,$(INCLUDEDIR)/sparse))
150 $(call INSTALL_FILE,sparse.pc,$(PKGCONFIGDIR))
152 sparse.pc: sparse.pc.in
153 $(QUIET_GEN)sed $(SED_PC_CMD) sparse.pc.in > sparse.pc
156 compile_EXTRA_DEPS = compile-i386.o
158 $(foreach p,$(PROGRAMS),$(eval $(p): $($(p)_EXTRA_DEPS) $(LIBS)))
159 $(PROGRAMS): % : %.o
160 $(QUIET_LINK)$(LD) $(LDFLAGS) -o $@ $^ $($@_EXTRA_OBJS)
162 $(LIB_FILE): $(LIB_OBJS)
163 $(QUIET_AR)$(AR) rcs $@ $(LIB_OBJS)
165 $(SLIB_FILE): $(LIB_OBJS)
166 $(QUIET_LINK)$(CC) $(LDFLAGS) -Wl,-soname,$@ -shared -o $@ $(LIB_OBJS)
168 DEP_FILES := $(wildcard .*.o.d)
169 $(if $(DEP_FILES),$(eval include $(DEP_FILES)))
171 c2xml.o: c2xml.c $(LIB_H)
172 $(QUIET_CC)$(CC) `pkg-config --cflags libxml-2.0` -o $@ -c $(ALL_CFLAGS) $<
174 compat-linux.o: compat/strtold.c compat/mmap-blob.c $(LIB_H)
175 compat-solaris.o: compat/mmap-blob.c $(LIB_H)
176 compat-mingw.o: $(LIB_H)
177 compat-cygwin.o: $(LIB_H)
179 %.o: %.c
180 $(QUIET_CC)$(CC) -o $@ -c $(ALL_CFLAGS) $<
182 clean: clean-check
183 rm -f *.[oa] .*.d *.so $(PROGRAMS) $(SLIB_FILE) pre-process.h sparse.pc
185 dist:
186 @if test "`git describe`" != "v$(VERSION)" ; then \
187 echo 'Update VERSION in the Makefile before running "make dist".' ; \
188 exit 1 ; \
190 git archive --format=tar --prefix=sparse-$(VERSION)/ HEAD^{tree} | gzip -9 > sparse-$(VERSION).tar.gz
192 check: all
193 $(Q)cd validation && ./test-suite
195 clean-check:
196 find validation/ \( -name "*.c.output.expected" \
197 -o -name "*.c.output.got" \
198 -o -name "*.c.output.diff" \
199 -o -name "*.c.error.expected" \
200 -o -name "*.c.error.got" \
201 -o -name "*.c.error.diff" \
202 \) -exec rm {} \;