sparse 0.4.3 finial
[smatch.git] / Makefile
blob74905df0b411116529a630558a931ce180a09d40
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 endif
50 ifeq ($(HAVE_GTK2),yes)
51 GTK2_CFLAGS := $(shell pkg-config --cflags gtk+-2.0)
52 GTK2_LIBS := $(shell pkg-config --libs gtk+-2.0)
53 PROGRAMS += test-inspect
54 INST_PROGRAMS += test-inspect
55 test-inspect_EXTRA_DEPS := ast-model.o ast-view.o ast-inspect.o
56 test-inspect.o $(test-inspect_EXTRA_DEPS): CFLAGS += $(GTK2_CFLAGS)
57 test-inspect_EXTRA_OBJS := $(GTK2_LIBS)
58 endif
60 LIB_H= token.h parse.h lib.h symbol.h scope.h expression.h target.h \
61 linearize.h bitmap.h ident-list.h compat.h flow.h allocate.h \
62 storage.h ptrlist.h dissect.h
64 LIB_OBJS= target.o parse.o tokenize.o pre-process.o symbol.o lib.o scope.o \
65 expression.o show-parse.o evaluate.o expand.o inline.o linearize.o \
66 sort.o allocate.o compat-$(OS).o ptrlist.o \
67 flow.o cse.o simplify.o memops.o liveness.o storage.o unssa.o dissect.o
69 LIB_FILE= libsparse.a
70 SLIB_FILE= libsparse.so
72 # If you add $(SLIB_FILE) to this, you also need to add -fpic to CFLAGS above.
73 # Doing so incurs a noticeable performance hit, and Sparse does not have a
74 # stable shared library interface, so this does not occur by default. If you
75 # really want a shared library, you may want to build Sparse twice: once
76 # without -fpic to get all the Sparse tools, and again with -fpic to get the
77 # shared library.
78 LIBS=$(LIB_FILE)
81 # Pretty print
83 V = @
84 Q = $(V:1=)
85 QUIET_CC = $(Q:@=@echo ' CC '$@;)
86 QUIET_AR = $(Q:@=@echo ' AR '$@;)
87 QUIET_GEN = $(Q:@=@echo ' GEN '$@;)
88 QUIET_LINK = $(Q:@=@echo ' LINK '$@;)
89 # We rely on the -v switch of install to print 'file -> $install_dir/file'
90 QUIET_INST_SH = $(Q:@=echo -n ' INSTALL ';)
91 QUIET_INST = $(Q:@=@echo -n ' INSTALL ';)
93 define INSTALL_EXEC
94 $(QUIET_INST)install -v $1 $(DESTDIR)$2/$1 || exit 1;
96 endef
98 define INSTALL_FILE
99 $(QUIET_INST)install -v -m 644 $1 $(DESTDIR)$2/$1 || exit 1;
101 endef
103 SED_PC_CMD = 's|@version@|$(VERSION)|g; \
104 s|@prefix@|$(PREFIX)|g; \
105 s|@libdir@|$(LIBDIR)|g; \
106 s|@includedir@|$(INCLUDEDIR)|g'
110 # Allow users to override build settings without dirtying their trees
111 -include local.mk
114 all: $(PROGRAMS) sparse.pc
116 install: $(INST_PROGRAMS) $(LIBS) $(LIB_H) sparse.pc
117 $(Q)install -d $(DESTDIR)$(BINDIR)
118 $(Q)install -d $(DESTDIR)$(LIBDIR)
119 $(Q)install -d $(DESTDIR)$(MAN1DIR)
120 $(Q)install -d $(DESTDIR)$(INCLUDEDIR)/sparse
121 $(Q)install -d $(DESTDIR)$(PKGCONFIGDIR)
122 $(foreach f,$(INST_PROGRAMS),$(call INSTALL_EXEC,$f,$(BINDIR)))
123 $(foreach f,$(INST_MAN1),$(call INSTALL_FILE,$f,$(MAN1DIR)))
124 $(foreach f,$(LIBS),$(call INSTALL_FILE,$f,$(LIBDIR)))
125 $(foreach f,$(LIB_H),$(call INSTALL_FILE,$f,$(INCLUDEDIR)/sparse))
126 $(call INSTALL_FILE,sparse.pc,$(PKGCONFIGDIR))
128 sparse.pc: sparse.pc.in
129 $(QUIET_GEN)sed $(SED_PC_CMD) sparse.pc.in > sparse.pc
132 compile_EXTRA_DEPS = compile-i386.o
134 $(foreach p,$(PROGRAMS),$(eval $(p): $($(p)_EXTRA_DEPS) $(LIBS)))
135 $(PROGRAMS): % : %.o
136 $(QUIET_LINK)$(CC) $(LDFLAGS) -o $@ $^ $($@_EXTRA_OBJS)
138 $(LIB_FILE): $(LIB_OBJS)
139 $(QUIET_AR)$(AR) rcs $@ $(LIB_OBJS)
141 $(SLIB_FILE): $(LIB_OBJS)
142 $(QUIET_LINK)$(CC) $(LDFLAGS) -Wl,-soname,$@ -shared -o $@ $(LIB_OBJS)
144 DEP_FILES := $(wildcard .*.o.d)
145 $(if $(DEP_FILES),$(eval include $(DEP_FILES)))
147 c2xml.o: c2xml.c $(LIB_H)
148 $(QUIET_CC)$(CC) `pkg-config --cflags libxml-2.0` -o $@ -c $(CFLAGS) $<
150 compat-linux.o: compat/strtold.c compat/mmap-blob.c $(LIB_H)
151 compat-solaris.o: compat/mmap-blob.c $(LIB_H)
152 compat-mingw.o: $(LIB_H)
153 compat-cygwin.o: $(LIB_H)
155 %.o: %.c
156 $(QUIET_CC)$(CC) -o $@ -c $(CFLAGS) $<
158 clean: clean-check
159 rm -f *.[oa] .*.d *.so $(PROGRAMS) $(SLIB_FILE) pre-process.h sparse.pc
161 dist:
162 @if test "`git describe`" != "v$(VERSION)" ; then \
163 echo 'Update VERSION in the Makefile before running "make dist".' ; \
164 exit 1 ; \
166 git archive --format=tar --prefix=sparse-$(VERSION)/ HEAD^{tree} | gzip -9 > sparse-$(VERSION).tar.gz
168 check: all
169 $(Q)cd validation && ./test-suite
171 clean-check:
172 find validation/ \( -name "*.c.output.expected" \
173 -o -name "*.c.output.got" \
174 -o -name "*.c.output.diff" \
175 -o -name "*.c.error.expected" \
176 -o -name "*.c.error.got" \
177 -o -name "*.c.error.diff" \
178 \) -exec rm {} \;