Take the rest of specifiers to parse.c
[smatch.git] / Makefile
blob15daba5643c5c64a1436b6a3ce0c905ec5663b5e
1 VERSION=0.4.1
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, uncomment the next one
15 #CFLAGS += -O0 -DDEBUG -g3 -gdwarf-2
17 HAVE_LIBXML=$(shell pkg-config --exists libxml-2.0 && echo 'yes')
18 HAVE_GCC_DEP=$(shell touch .gcc-test.c && \
19 $(CC) -c -Wp,-MD,.gcc-test.d .gcc-test.c 2>/dev/null && \
20 echo 'yes'; rm -f .gcc-test.d .gcc-test.o .gcc-test.c)
22 CFLAGS += -DGCC_BASE=\"$(shell $(CC) --print-file-name=)\"
24 ifeq ($(HAVE_GCC_DEP),yes)
25 CFLAGS += -Wp,-MD,$(@D)/.$(@F).d
26 endif
28 DESTDIR=
29 PREFIX=$(HOME)
30 BINDIR=$(PREFIX)/bin
31 LIBDIR=$(PREFIX)/lib
32 MANDIR=$(PREFIX)/share/man
33 MAN1DIR=$(MANDIR)/man1
34 INCLUDEDIR=$(PREFIX)/include
35 PKGCONFIGDIR=$(LIBDIR)/pkgconfig
37 PROGRAMS=test-lexing test-parsing obfuscate compile graph sparse \
38 test-linearize example test-unssa test-dissect ctags
39 INST_PROGRAMS=sparse cgcc
40 INST_MAN1=sparse.1 cgcc.1
42 ifeq ($(HAVE_LIBXML),yes)
43 PROGRAMS+=c2xml
44 INST_PROGRAMS+=c2xml
45 c2xml_EXTRA_OBJS = `pkg-config --libs libxml-2.0`
46 endif
48 LIB_H= token.h parse.h lib.h symbol.h scope.h expression.h target.h \
49 linearize.h bitmap.h ident-list.h compat.h flow.h allocate.h \
50 storage.h ptrlist.h dissect.h
52 LIB_OBJS= target.o parse.o tokenize.o pre-process.o symbol.o lib.o scope.o \
53 expression.o show-parse.o evaluate.o expand.o inline.o linearize.o \
54 sort.o allocate.o compat-$(OS).o ptrlist.o \
55 flow.o cse.o simplify.o memops.o liveness.o storage.o unssa.o dissect.o
57 LIB_FILE= libsparse.a
58 SLIB_FILE= libsparse.so
60 # If you add $(SLIB_FILE) to this, you also need to add -fpic to CFLAGS above.
61 # Doing so incurs a noticeable performance hit, and Sparse does not have a
62 # stable shared library interface, so this does not occur by default. If you
63 # really want a shared library, you may want to build Sparse twice: once
64 # without -fpic to get all the Sparse tools, and again with -fpic to get the
65 # shared library.
66 LIBS=$(LIB_FILE)
69 # Pretty print
71 V = @
72 Q = $(V:1=)
73 QUIET_CC = $(Q:@=@echo ' CC '$@;)
74 QUIET_AR = $(Q:@=@echo ' AR '$@;)
75 QUIET_GEN = $(Q:@=@echo ' GEN '$@;)
76 QUIET_LINK = $(Q:@=@echo ' LINK '$@;)
77 # We rely on the -v switch of install to print 'file -> $install_dir/file'
78 QUIET_INST_SH = $(Q:@=echo -n ' INSTALL ';)
79 QUIET_INST = $(Q:@=@echo -n ' INSTALL ';)
81 define INSTALL_CMD
82 $(Q)$(QUIET_INST_SH)install -v $1 $(DESTDIR)$2/$1 || exit 1;
84 endef
86 SED_PC_CMD = 's|@version@|$(VERSION)|g; \
87 s|@prefix@|$(PREFIX)|g; \
88 s|@libdir@|$(LIBDIR)|g; \
89 s|@includedir@|$(INCLUDEDIR)|g'
92 all: $(PROGRAMS) sparse.pc
94 install: $(INST_PROGRAMS) $(LIBS) $(LIB_H) sparse.pc
95 $(Q)install -d $(DESTDIR)$(BINDIR)
96 $(Q)install -d $(DESTDIR)$(LIBDIR)
97 $(Q)install -d $(DESTDIR)$(MAN1DIR)
98 $(Q)install -d $(DESTDIR)$(INCLUDEDIR)/sparse
99 $(Q)install -d $(DESTDIR)$(PKGCONFIGDIR)
100 $(foreach f,$(INST_PROGRAMS),$(call INSTALL_CMD,$f,$(BINDIR)))
101 $(foreach f,$(INST_MAN1),$(call INSTALL_CMD,$f,$(MAN1DIR)))
102 $(foreach f,$(LIBS),$(call INSTALL_CMD,$f,$(LIBDIR)))
103 $(foreach f,$(LIB_H),$(call INSTALL_CMD,$f,$(INCLUDEDIR)/sparse))
104 $(call INSTALL_CMD,sparse.pc,$(PKGCONFIGDIR))
106 sparse.pc: sparse.pc.in
107 $(QUIET_GEN)sed $(SED_PC_CMD) sparse.pc.in > sparse.pc
110 compile_EXTRA_DEPS = compile-i386.o
112 PROG_LINK_CMD = $(QUIET_LINK)$(CC) $(LDFLAGS) -o $@ $^ $($@_EXTRA_OBJS)
114 define BUILD_PROGRAM
115 $(prog): $(prog).o $$($(prog)_EXTRA_DEPS) $$(LIBS)
116 $$(PROG_LINK_CMD)
117 endef
119 $(foreach prog,$(PROGRAMS),$(eval $(BUILD_PROGRAM)))
121 $(LIB_FILE): $(LIB_OBJS)
122 $(QUIET_AR)$(AR) rcs $@ $(LIB_OBJS)
124 $(SLIB_FILE): $(LIB_OBJS)
125 $(QUIET_LINK)$(CC) $(LDFLAGS) -Wl,-soname,$@ -shared -o $@ $(LIB_OBJS)
127 DEP_FILES := $(wildcard .*.o.d)
128 $(if $(DEP_FILES),$(eval include $(DEP_FILES)))
130 c2xml.o: c2xml.c $(LIB_H)
131 $(QUIET_CC)$(CC) `pkg-config --cflags libxml-2.0` -o $@ -c $(CFLAGS) $<
133 compat-linux.o: compat/strtold.c compat/mmap-blob.c $(LIB_H)
134 compat-solaris.o: compat/mmap-blob.c $(LIB_H)
135 compat-mingw.o: $(LIB_H)
136 compat-cygwin.o: $(LIB_H)
138 .c.o:
139 $(QUIET_CC)$(CC) -o $@ -c $(CFLAGS) $<
141 clean: clean-check
142 rm -f *.[oa] .*.d *.so $(PROGRAMS) $(SLIB_FILE) pre-process.h sparse.pc
144 dist:
145 @if test "`git describe`" != "$(VERSION)" ; then \
146 echo 'Update VERSION in the Makefile before running "make dist".' ; \
147 exit 1 ; \
149 git archive --format=tar --prefix=sparse-$(VERSION)/ HEAD^{tree} | gzip -9 > sparse-$(VERSION).tar.gz
151 check: all
152 $(Q)cd validation && ./test-suite
154 clean-check:
155 find validation/ \( -name "*.c.output.expected" \
156 -o -name "*.c.output.got" \
157 -o -name "*.c.output.diff" \
158 -o -name "*.c.error.expected" \
159 -o -name "*.c.error.got" \
160 -o -name "*.c.error.diff" \
161 \) -exec rm {} \;