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