Sparse 0.4.2
[smatch.git] / Makefile
blob571673e7cd6f090f5dcb6e99ac9190bfe5a66fe3
1 VERSION=0.4.2
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)
23 CFLAGS += -DGCC_BASE=\"$(shell $(CC) --print-file-name=)\"
25 ifeq ($(HAVE_GCC_DEP),yes)
26 CFLAGS += -Wp,-MD,$(@D)/.$(@F).d
27 endif
29 DESTDIR=
30 PREFIX=$(HOME)
31 BINDIR=$(PREFIX)/bin
32 LIBDIR=$(PREFIX)/lib
33 MANDIR=$(PREFIX)/share/man
34 MAN1DIR=$(MANDIR)/man1
35 INCLUDEDIR=$(PREFIX)/include
36 PKGCONFIGDIR=$(LIBDIR)/pkgconfig
38 PROGRAMS=test-lexing test-parsing obfuscate compile graph sparse \
39 test-linearize example test-unssa test-dissect ctags
40 INST_PROGRAMS=sparse cgcc
41 INST_MAN1=sparse.1 cgcc.1
43 ifeq ($(HAVE_LIBXML),yes)
44 PROGRAMS+=c2xml
45 INST_PROGRAMS+=c2xml
46 c2xml_EXTRA_OBJS = `pkg-config --libs libxml-2.0`
47 endif
49 LIB_H= token.h parse.h lib.h symbol.h scope.h expression.h target.h \
50 linearize.h bitmap.h ident-list.h compat.h flow.h allocate.h \
51 storage.h ptrlist.h dissect.h
53 LIB_OBJS= target.o parse.o tokenize.o pre-process.o symbol.o lib.o scope.o \
54 expression.o show-parse.o evaluate.o expand.o inline.o linearize.o \
55 sort.o allocate.o compat-$(OS).o ptrlist.o \
56 flow.o cse.o simplify.o memops.o liveness.o storage.o unssa.o dissect.o
58 LIB_FILE= libsparse.a
59 SLIB_FILE= libsparse.so
61 # If you add $(SLIB_FILE) to this, you also need to add -fpic to CFLAGS above.
62 # Doing so incurs a noticeable performance hit, and Sparse does not have a
63 # stable shared library interface, so this does not occur by default. If you
64 # really want a shared library, you may want to build Sparse twice: once
65 # without -fpic to get all the Sparse tools, and again with -fpic to get the
66 # shared library.
67 LIBS=$(LIB_FILE)
70 # Pretty print
72 V = @
73 Q = $(V:1=)
74 QUIET_CC = $(Q:@=@echo ' CC '$@;)
75 QUIET_AR = $(Q:@=@echo ' AR '$@;)
76 QUIET_GEN = $(Q:@=@echo ' GEN '$@;)
77 QUIET_LINK = $(Q:@=@echo ' LINK '$@;)
78 # We rely on the -v switch of install to print 'file -> $install_dir/file'
79 QUIET_INST_SH = $(Q:@=echo -n ' INSTALL ';)
80 QUIET_INST = $(Q:@=@echo -n ' INSTALL ';)
82 define INSTALL_CMD
83 $(Q)$(QUIET_INST_SH)install -v $1 $(DESTDIR)$2/$1 || exit 1;
85 endef
87 SED_PC_CMD = 's|@version@|$(VERSION)|g; \
88 s|@prefix@|$(PREFIX)|g; \
89 s|@libdir@|$(LIBDIR)|g; \
90 s|@includedir@|$(INCLUDEDIR)|g'
94 # Allow users to override build settings without dirtying their trees
95 -include local.mk
98 all: $(PROGRAMS) sparse.pc
100 install: $(INST_PROGRAMS) $(LIBS) $(LIB_H) sparse.pc
101 $(Q)install -d $(DESTDIR)$(BINDIR)
102 $(Q)install -d $(DESTDIR)$(LIBDIR)
103 $(Q)install -d $(DESTDIR)$(MAN1DIR)
104 $(Q)install -d $(DESTDIR)$(INCLUDEDIR)/sparse
105 $(Q)install -d $(DESTDIR)$(PKGCONFIGDIR)
106 $(foreach f,$(INST_PROGRAMS),$(call INSTALL_CMD,$f,$(BINDIR)))
107 $(foreach f,$(INST_MAN1),$(call INSTALL_CMD,$f,$(MAN1DIR)))
108 $(foreach f,$(LIBS),$(call INSTALL_CMD,$f,$(LIBDIR)))
109 $(foreach f,$(LIB_H),$(call INSTALL_CMD,$f,$(INCLUDEDIR)/sparse))
110 $(call INSTALL_CMD,sparse.pc,$(PKGCONFIGDIR))
112 sparse.pc: sparse.pc.in
113 $(QUIET_GEN)sed $(SED_PC_CMD) sparse.pc.in > sparse.pc
116 compile_EXTRA_DEPS = compile-i386.o
118 PROG_LINK_CMD = $(QUIET_LINK)$(CC) $(LDFLAGS) -o $@ $^ $($@_EXTRA_OBJS)
120 define BUILD_PROGRAM
121 $(prog): $(prog).o $$($(prog)_EXTRA_DEPS) $$(LIBS)
122 $$(PROG_LINK_CMD)
123 endef
125 $(foreach prog,$(PROGRAMS),$(eval $(BUILD_PROGRAM)))
127 $(LIB_FILE): $(LIB_OBJS)
128 $(QUIET_AR)$(AR) rcs $@ $(LIB_OBJS)
130 $(SLIB_FILE): $(LIB_OBJS)
131 $(QUIET_LINK)$(CC) $(LDFLAGS) -Wl,-soname,$@ -shared -o $@ $(LIB_OBJS)
133 DEP_FILES := $(wildcard .*.o.d)
134 $(if $(DEP_FILES),$(eval include $(DEP_FILES)))
136 c2xml.o: c2xml.c $(LIB_H)
137 $(QUIET_CC)$(CC) `pkg-config --cflags libxml-2.0` -o $@ -c $(CFLAGS) $<
139 compat-linux.o: compat/strtold.c compat/mmap-blob.c $(LIB_H)
140 compat-solaris.o: compat/mmap-blob.c $(LIB_H)
141 compat-mingw.o: $(LIB_H)
142 compat-cygwin.o: $(LIB_H)
144 .c.o:
145 $(QUIET_CC)$(CC) -o $@ -c $(CFLAGS) $<
147 clean: clean-check
148 rm -f *.[oa] .*.d *.so $(PROGRAMS) $(SLIB_FILE) pre-process.h sparse.pc
150 dist:
151 @if test "`git describe`" != "v$(VERSION)" ; then \
152 echo 'Update VERSION in the Makefile before running "make dist".' ; \
153 exit 1 ; \
155 git archive --format=tar --prefix=sparse-$(VERSION)/ HEAD^{tree} | gzip -9 > sparse-$(VERSION).tar.gz
157 check: all
158 $(Q)cd validation && ./test-suite
160 clean-check:
161 find validation/ \( -name "*.c.output.expected" \
162 -o -name "*.c.output.got" \
163 -o -name "*.c.output.diff" \
164 -o -name "*.c.error.expected" \
165 -o -name "*.c.error.got" \
166 -o -name "*.c.error.diff" \
167 \) -exec rm {} \;