flow.c: make comment for `dominates' reflect code
[smatch.git] / Makefile
blob701cdc9acca41e3f5cdbe195e52cd5137a5d09b3
1 VERSION=0.4.3
3 OS = linux
6 CC = gcc
7 CFLAGS = -O2 -finline-functions -fno-strict-aliasing -g
8 CFLAGS += -Wall -Wwrite-strings
9 LDFLAGS += -g
10 AR = ar
13 # For debugging, put this in local.mk:
15 # CFLAGS += -O0 -DDEBUG -g3 -gdwarf-2
18 HAVE_LIBXML:=$(shell pkg-config --exists libxml-2.0 2>/dev/null && echo 'yes')
19 HAVE_GCC_DEP:=$(shell touch .gcc-test.c && \
20 $(CC) -c -Wp,-MD,.gcc-test.d .gcc-test.c 2>/dev/null && \
21 echo 'yes'; rm -f .gcc-test.d .gcc-test.o .gcc-test.c)
22 HAVE_GTK2:=$(shell pkg-config --exists gtk+-2.0 2>/dev/null && echo 'yes')
24 CFLAGS += -DGCC_BASE=\"$(shell $(CC) --print-file-name=)\"
26 ifeq ($(HAVE_GCC_DEP),yes)
27 CFLAGS += -Wp,-MD,$(@D)/.$(@F).d
28 endif
30 DESTDIR=
31 PREFIX=$(HOME)
32 BINDIR=$(PREFIX)/bin
33 LIBDIR=$(PREFIX)/lib
34 MANDIR=$(PREFIX)/share/man
35 MAN1DIR=$(MANDIR)/man1
36 INCLUDEDIR=$(PREFIX)/include
37 PKGCONFIGDIR=$(LIBDIR)/pkgconfig
39 PROGRAMS=test-lexing test-parsing obfuscate compile graph sparse \
40 test-linearize example test-unssa test-dissect ctags
41 INST_PROGRAMS=sparse cgcc
42 INST_MAN1=sparse.1 cgcc.1
44 ifeq ($(HAVE_LIBXML),yes)
45 PROGRAMS+=c2xml
46 INST_PROGRAMS+=c2xml
47 c2xml_EXTRA_OBJS = `pkg-config --libs libxml-2.0`
48 else
49 $(warning Your system does not have libxml, disabling c2xml)
50 endif
52 ifeq ($(HAVE_GTK2),yes)
53 GTK2_CFLAGS := $(shell pkg-config --cflags gtk+-2.0)
54 GTK2_LIBS := $(shell pkg-config --libs gtk+-2.0)
55 PROGRAMS += test-inspect
56 INST_PROGRAMS += test-inspect
57 test-inspect_EXTRA_DEPS := ast-model.o ast-view.o ast-inspect.o
58 test-inspect.o $(test-inspect_EXTRA_DEPS): CFLAGS += $(GTK2_CFLAGS)
59 test-inspect_EXTRA_OBJS := $(GTK2_LIBS)
60 else
61 $(warning Your system does not have libgtk2, disabling test-inspect)
62 endif
64 LIB_H= token.h parse.h lib.h symbol.h scope.h expression.h target.h \
65 linearize.h bitmap.h ident-list.h compat.h flow.h allocate.h \
66 storage.h ptrlist.h dissect.h
68 LIB_OBJS= target.o parse.o tokenize.o pre-process.o symbol.o lib.o scope.o \
69 expression.o show-parse.o evaluate.o expand.o inline.o linearize.o \
70 sort.o allocate.o compat-$(OS).o ptrlist.o \
71 flow.o cse.o simplify.o memops.o liveness.o storage.o unssa.o dissect.o
73 LIB_FILE= libsparse.a
74 SLIB_FILE= libsparse.so
76 # If you add $(SLIB_FILE) to this, you also need to add -fpic to CFLAGS above.
77 # Doing so incurs a noticeable performance hit, and Sparse does not have a
78 # stable shared library interface, so this does not occur by default. If you
79 # really want a shared library, you may want to build Sparse twice: once
80 # without -fpic to get all the Sparse tools, and again with -fpic to get the
81 # shared library.
82 LIBS=$(LIB_FILE)
85 # Pretty print
87 V = @
88 Q = $(V:1=)
89 QUIET_CC = $(Q:@=@echo ' CC '$@;)
90 QUIET_AR = $(Q:@=@echo ' AR '$@;)
91 QUIET_GEN = $(Q:@=@echo ' GEN '$@;)
92 QUIET_LINK = $(Q:@=@echo ' LINK '$@;)
93 # We rely on the -v switch of install to print 'file -> $install_dir/file'
94 QUIET_INST_SH = $(Q:@=echo -n ' INSTALL ';)
95 QUIET_INST = $(Q:@=@echo -n ' INSTALL ';)
97 define INSTALL_EXEC
98 $(QUIET_INST)install -v $1 $(DESTDIR)$2/$1 || exit 1;
100 endef
102 define INSTALL_FILE
103 $(QUIET_INST)install -v -m 644 $1 $(DESTDIR)$2/$1 || exit 1;
105 endef
107 SED_PC_CMD = 's|@version@|$(VERSION)|g; \
108 s|@prefix@|$(PREFIX)|g; \
109 s|@libdir@|$(LIBDIR)|g; \
110 s|@includedir@|$(INCLUDEDIR)|g'
114 # Allow users to override build settings without dirtying their trees
115 -include local.mk
118 all: $(PROGRAMS) sparse.pc
120 install: $(INST_PROGRAMS) $(LIBS) $(LIB_H) sparse.pc
121 $(Q)install -d $(DESTDIR)$(BINDIR)
122 $(Q)install -d $(DESTDIR)$(LIBDIR)
123 $(Q)install -d $(DESTDIR)$(MAN1DIR)
124 $(Q)install -d $(DESTDIR)$(INCLUDEDIR)/sparse
125 $(Q)install -d $(DESTDIR)$(PKGCONFIGDIR)
126 $(foreach f,$(INST_PROGRAMS),$(call INSTALL_EXEC,$f,$(BINDIR)))
127 $(foreach f,$(INST_MAN1),$(call INSTALL_FILE,$f,$(MAN1DIR)))
128 $(foreach f,$(LIBS),$(call INSTALL_FILE,$f,$(LIBDIR)))
129 $(foreach f,$(LIB_H),$(call INSTALL_FILE,$f,$(INCLUDEDIR)/sparse))
130 $(call INSTALL_FILE,sparse.pc,$(PKGCONFIGDIR))
132 sparse.pc: sparse.pc.in
133 $(QUIET_GEN)sed $(SED_PC_CMD) sparse.pc.in > sparse.pc
136 compile_EXTRA_DEPS = compile-i386.o
138 $(foreach p,$(PROGRAMS),$(eval $(p): $($(p)_EXTRA_DEPS) $(LIBS)))
139 $(PROGRAMS): % : %.o
140 $(QUIET_LINK)$(CC) $(LDFLAGS) -o $@ $^ $($@_EXTRA_OBJS)
142 $(LIB_FILE): $(LIB_OBJS)
143 $(QUIET_AR)$(AR) rcs $@ $(LIB_OBJS)
145 $(SLIB_FILE): $(LIB_OBJS)
146 $(QUIET_LINK)$(CC) $(LDFLAGS) -Wl,-soname,$@ -shared -o $@ $(LIB_OBJS)
148 DEP_FILES := $(wildcard .*.o.d)
149 $(if $(DEP_FILES),$(eval include $(DEP_FILES)))
151 c2xml.o: c2xml.c $(LIB_H)
152 $(QUIET_CC)$(CC) `pkg-config --cflags libxml-2.0` -o $@ -c $(CFLAGS) $<
154 compat-linux.o: compat/strtold.c compat/mmap-blob.c $(LIB_H)
155 compat-solaris.o: compat/mmap-blob.c $(LIB_H)
156 compat-mingw.o: $(LIB_H)
157 compat-cygwin.o: $(LIB_H)
159 %.o: %.c
160 $(QUIET_CC)$(CC) -o $@ -c $(CFLAGS) $<
162 clean: clean-check
163 rm -f *.[oa] .*.d *.so $(PROGRAMS) $(SLIB_FILE) pre-process.h sparse.pc
165 dist:
166 @if test "`git describe`" != "v$(VERSION)" ; then \
167 echo 'Update VERSION in the Makefile before running "make dist".' ; \
168 exit 1 ; \
170 git archive --format=tar --prefix=sparse-$(VERSION)/ HEAD^{tree} | gzip -9 > sparse-$(VERSION).tar.gz
172 check: all
173 $(Q)cd validation && ./test-suite
175 clean-check:
176 find validation/ \( -name "*.c.output.expected" \
177 -o -name "*.c.output.got" \
178 -o -name "*.c.output.diff" \
179 -o -name "*.c.error.expected" \
180 -o -name "*.c.error.got" \
181 -o -name "*.c.error.diff" \
182 \) -exec rm {} \;