• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1VERSION=0.6.3
2
3########################################################################
4# The following variables can be overwritten from the command line
5OS = linux
6
7
8CC = gcc
9CXX = g++
10LD = $(CC)
11AR = ar
12
13CFLAGS ?= -O2 -g
14
15DESTDIR ?=
16PREFIX ?= $(HOME)
17BINDIR ?= $(PREFIX)/bin
18MANDIR ?= $(PREFIX)/share/man
19
20PKG_CONFIG ?= pkg-config
21
22CHECKER_FLAGS ?= -Wno-vla
23
24# Allow users to override build settings without dirtying their trees
25# For debugging, put this in local.mk:
26#
27#     CFLAGS += -O0 -DDEBUG -g3 -gdwarf-2
28#
29SPARSE_LOCAL_CONFIG ?= local.mk
30-include ${SPARSE_LOCAL_CONFIG}
31########################################################################
32
33
34LIB_OBJS :=
35LIB_OBJS += allocate.o
36LIB_OBJS += builtin.o
37LIB_OBJS += char.o
38LIB_OBJS += compat-$(OS).o
39LIB_OBJS += cse.o
40LIB_OBJS += dissect.o
41LIB_OBJS += dominate.o
42LIB_OBJS += evaluate.o
43LIB_OBJS += expand.o
44LIB_OBJS += expression.o
45LIB_OBJS += flow.o
46LIB_OBJS += flowgraph.o
47LIB_OBJS += inline.o
48LIB_OBJS += ir.o
49LIB_OBJS += lib.o
50LIB_OBJS += linearize.o
51LIB_OBJS += liveness.o
52LIB_OBJS += memops.o
53LIB_OBJS += opcode.o
54LIB_OBJS += optimize.o
55LIB_OBJS += options.o
56LIB_OBJS += parse.o
57LIB_OBJS += predefine.o
58LIB_OBJS += pre-process.o
59LIB_OBJS += ptrlist.o
60LIB_OBJS += ptrmap.o
61LIB_OBJS += scope.o
62LIB_OBJS += show-parse.o
63LIB_OBJS += simplify.o
64LIB_OBJS += sort.o
65LIB_OBJS += ssa.o
66LIB_OBJS += stats.o
67LIB_OBJS += storage.o
68LIB_OBJS += symbol.o
69LIB_OBJS += target.o
70LIB_OBJS += target-alpha.o
71LIB_OBJS += target-arm.o
72LIB_OBJS += target-arm64.o
73LIB_OBJS += target-bfin.o
74LIB_OBJS += target-default.o
75LIB_OBJS += target-h8300.o
76LIB_OBJS += target-m68k.o
77LIB_OBJS += target-microblaze.o
78LIB_OBJS += target-mips.o
79LIB_OBJS += target-nds32.o
80LIB_OBJS += target-nios2.o
81LIB_OBJS += target-openrisc.o
82LIB_OBJS += target-ppc.o
83LIB_OBJS += target-riscv.o
84LIB_OBJS += target-s390.o
85LIB_OBJS += target-sh.o
86LIB_OBJS += target-sparc.o
87LIB_OBJS += target-x86.o
88LIB_OBJS += target-xtensa.o
89LIB_OBJS += tokenize.o
90LIB_OBJS += unssa.o
91LIB_OBJS += utils.o
92LIB_OBJS += version.o
93
94PROGRAMS :=
95PROGRAMS += compile
96PROGRAMS += ctags
97PROGRAMS += example
98PROGRAMS += graph
99PROGRAMS += obfuscate
100PROGRAMS += sparse
101PROGRAMS += test-dissect
102PROGRAMS += test-lexing
103PROGRAMS += test-linearize
104PROGRAMS += test-parsing
105PROGRAMS += test-show-type
106PROGRAMS += test-unssa
107
108INST_PROGRAMS=sparse cgcc
109INST_MAN1=sparse.1 cgcc.1
110
111
112all:
113
114########################################################################
115# common flags/options/...
116
117cflags = -fno-strict-aliasing
118cflags += -Wall -Wwrite-strings
119
120GCC_BASE := $(shell $(CC) --print-file-name=)
121cflags += -DGCC_BASE=\"$(GCC_BASE)\"
122
123MULTIARCH_TRIPLET := $(shell $(CC) -print-multiarch 2>/dev/null)
124cflags += -DMULTIARCH_TRIPLET=\"$(MULTIARCH_TRIPLET)\"
125
126
127bindir := $(DESTDIR)$(BINDIR)
128man1dir := $(DESTDIR)$(MANDIR)/man1
129
130########################################################################
131# target specificities
132
133compile: compile-i386.o
134EXTRA_OBJS += compile-i386.o
135
136# Can we use GCC's generated dependencies?
137HAVE_GCC_DEP:=$(shell touch .gcc-test.c && 				\
138		$(CC) -c -Wp,-MP,-MMD,.gcc-test.d .gcc-test.c 2>/dev/null && \
139		echo 'yes'; rm -f .gcc-test.d .gcc-test.o .gcc-test.c)
140ifeq ($(HAVE_GCC_DEP),yes)
141cflags += -Wp,-MP,-MMD,$(@D)/.$(@F).d
142endif
143
144# Can we use libxml (needed for c2xml)?
145HAVE_LIBXML:=$(shell $(PKG_CONFIG) --exists libxml-2.0 2>/dev/null && echo 'yes')
146ifeq ($(HAVE_LIBXML),yes)
147PROGRAMS+=c2xml
148INST_PROGRAMS+=c2xml
149c2xml-ldlibs := $(shell $(PKG_CONFIG) --libs libxml-2.0)
150c2xml-cflags := $(shell $(PKG_CONFIG) --cflags libxml-2.0)
151else
152$(warning Your system does not have libxml, disabling c2xml)
153endif
154
155HAVE_SQLITE := $(shell $(PKG_CONFIG) --exists sqlite3 2>/dev/null && echo 'yes')
156ifeq ($(HAVE_SQLITE),yes)
157SQLITE_VERSION:=$(shell $(PKG_CONFIG) --modversion sqlite3)
158SQLITE_VNUMBER:=$(shell printf '%d%02d%02d' $(subst ., ,$(SQLITE_VERSION)))
159ifeq ($(shell expr "$(SQLITE_VNUMBER)" '>=' 32400),1)
160PROGRAMS += semind
161INST_PROGRAMS += semind
162INST_MAN1 += semind.1
163semind-ldlibs := $(shell $(PKG_CONFIG) --libs sqlite3)
164semind-cflags := $(shell $(PKG_CONFIG) --cflags sqlite3)
165semind-cflags += -std=gnu99
166else
167$(warning Your SQLite3 version ($(SQLITE_VERSION)) is too old, 3.24.0 or later is required.)
168endif
169else
170$(warning Your system does not have sqlite3, disabling semind)
171endif
172
173# Can we use gtk (needed for test-inspect)
174GTK_VERSION:=3.0
175HAVE_GTK:=$(shell $(PKG_CONFIG) --exists gtk+-$(GTK_VERSION) 2>/dev/null && echo 'yes')
176ifneq ($(HAVE_GTK),yes)
177GTK_VERSION:=2.0
178HAVE_GTK:=$(shell $(PKG_CONFIG) --exists gtk+-$(GTK_VERSION) 2>/dev/null && echo 'yes')
179endif
180ifeq ($(HAVE_GTK),yes)
181GTK_CFLAGS := $(shell $(PKG_CONFIG) --cflags gtk+-$(GTK_VERSION))
182ast-view-cflags := $(GTK_CFLAGS)
183ast-model-cflags := $(GTK_CFLAGS)
184ast-inspect-cflags := $(GTK_CFLAGS)
185test-inspect-cflags := $(GTK_CFLAGS)
186test-inspect-ldlibs := $(shell $(PKG_CONFIG) --libs gtk+-$(GTK_VERSION))
187test-inspect: ast-model.o ast-view.o ast-inspect.o
188EXTRA_OBJS += ast-model.o ast-view.o ast-inspect.o
189PROGRAMS += test-inspect
190INST_PROGRAMS += test-inspect
191else
192$(warning Your system does not have gtk3/gtk2, disabling test-inspect)
193endif
194
195# Can we use LLVM (needed for ... sparse-llvm)?
196LLVM_CONFIG:=llvm-config
197HAVE_LLVM:=$(shell $(LLVM_CONFIG) --version >/dev/null 2>&1 && echo 'yes')
198ifeq ($(HAVE_LLVM),yes)
199arch := $(shell uname -m)
200ifeq (${MULTIARCH_TRIPLET},x86_64-linux-gnux32)
201arch := x32
202endif
203ifneq ($(filter ${arch},i386 i486 i586 i686 x86_64 amd64),)
204LLVM_VERSION:=$(shell $(LLVM_CONFIG) --version)
205LLVM_VERSION_MAJOR:=$(firstword $(subst ., ,$(LLVM_VERSION)))
206ifeq ($(shell expr "$(LLVM_VERSION_MAJOR)" '>=' 3),1)
207LLVM_PROGS := sparse-llvm
208$(LLVM_PROGS): LD := $(CXX)
209LLVM_LDFLAGS := $(shell $(LLVM_CONFIG) --ldflags)
210LLVM_CFLAGS := $(shell $(LLVM_CONFIG) --cppflags)
211LLVM_LIBS := $(shell $(LLVM_CONFIG) --libs)
212LLVM_LIBS += $(shell $(LLVM_CONFIG) --system-libs 2>/dev/null)
213LLVM_LIBS += $(shell $(LLVM_CONFIG) --cxxflags | grep -F -q -e '-stdlib=libc++' && echo -lc++)
214PROGRAMS += $(LLVM_PROGS)
215INST_PROGRAMS += sparse-llvm sparsec
216sparse-llvm-cflags := $(LLVM_CFLAGS)
217sparse-llvm-ldflags := $(LLVM_LDFLAGS)
218sparse-llvm-ldlibs := $(LLVM_LIBS)
219else
220$(warning LLVM 3.0 or later required. Your system has version $(LLVM_VERSION) installed.)
221endif
222else
223$(warning sparse-llvm disabled on ${arch})
224endif
225else
226$(warning Your system does not have llvm, disabling sparse-llvm)
227endif
228
229ifeq ($(HAVE_BOOLECTOR),yes)
230PROGRAMS += scheck
231scheck-cflags  := -I${BOOLECTORDIR}/include/boolector
232scheck-ldflags := -L${BOOLECTORDIR}/lib
233scheck-ldlibs  := -lboolector -llgl -lbtor2parser
234endif
235
236########################################################################
237LIBS := libsparse.a
238OBJS := $(LIB_OBJS) $(EXTRA_OBJS) $(PROGRAMS:%=%.o)
239
240# Pretty print
241V := @
242Q := $(V:1=)
243
244########################################################################
245all: $(PROGRAMS)
246
247ldflags += $($(@)-ldflags) $(LDFLAGS)
248ldlibs  += $($(@)-ldlibs)  $(LDLIBS)
249$(PROGRAMS): % : %.o $(LIBS)
250	@echo "  LD      $@"
251	$(Q)$(LD) $(ldflags) $^ $(ldlibs) -o $@
252
253libsparse.a: $(LIB_OBJS)
254	@echo "  AR      $@"
255	$(Q)$(AR) rcs $@ $^
256
257
258cflags   += $($(*)-cflags) $(CPPFLAGS) $(CFLAGS)
259%.o: %.c
260	@echo "  CC      $@"
261	$(Q)$(CC) $(cflags) -c -o $@ $<
262
263%.sc: %.c sparse
264	@echo "  CHECK   $<"
265	$(Q)CHECK=./sparse ./cgcc -no-compile $(CHECKER_FLAGS) $(cflags) -c $<
266
267selfcheck: $(OBJS:.o=.sc)
268
269SPARSE_VERSION:=$(shell git describe --dirty 2>/dev/null || echo '$(VERSION)')
270version.o: version.h
271version.h: FORCE
272	@echo '#define SPARSE_VERSION "$(SPARSE_VERSION)"' > version.h.tmp
273	@if cmp -s version.h version.h.tmp; then \
274		rm version.h.tmp; \
275	else \
276		echo "  GEN     $@"; \
277		mv version.h.tmp version.h; \
278	fi
279
280
281check: all
282	$(Q)cd validation && ./test-suite
283validation/%: $(PROGRAMS) FORCE
284	$(Q)validation/test-suite $*
285
286
287clean: clean-check
288	@rm -f *.[oa] .*.d $(PROGRAMS) version.h
289clean-check:
290	@echo "  CLEAN"
291	@find validation/ \( -name "*.c.output.*" \
292			  -o -name "*.c.error.*" \
293			  -o -name "*.o" \
294	                  \) -exec rm {} \;
295
296
297install: install-bin install-man
298install-bin: $(INST_PROGRAMS:%=$(bindir)/%)
299install-man: $(INST_MAN1:%=$(man1dir)/%)
300
301$(bindir)/%: %
302	@echo "  INSTALL $@"
303	$(Q)install -D        $< $@ || exit 1;
304$(man1dir)/%: %
305	@echo "  INSTALL $@"
306	$(Q)install -D -m 644 $< $@ || exit 1;
307
308.PHONY: FORCE
309
310# GCC's dependencies
311-include $(OBJS:%.o=.%.o.d)
312