3 # Generating file version.h if current version has changed
4 SPARSE_VERSION
:=$(shell git describe
2>/dev
/null || echo
'$(VERSION)')
5 VERSION_H
:= $(shell cat version.h
2>/dev
/null
)
6 ifneq ($(lastword
$(VERSION_H
)),"$(SPARSE_VERSION)")
7 $(info $(shell echo
' GEN 'version.h
))
8 $(shell echo
'#define SPARSE_VERSION "$(SPARSE_VERSION)"' > version.h
)
15 CFLAGS
= -O2
-finline-functions
-fno-strict-aliasing
-g
16 CFLAGS
+= -Wall
-Wwrite-strings
20 PKG_CONFIG
= pkg-config
22 ALL_CFLAGS
= $(CFLAGS
) $(BASIC_CFLAGS
)
24 # For debugging, put this in local.mk:
26 # CFLAGS += -O0 -DDEBUG -g3 -gdwarf-2
29 HAVE_LIBXML
:=$(shell $(PKG_CONFIG
) --exists libxml-2.0
2>/dev
/null
&& echo
'yes')
30 HAVE_GCC_DEP
:=$(shell touch .gcc-test.c
&& \
31 $(CC
) -c
-Wp
,-MD
,.gcc-test.d .gcc-test.c
2>/dev
/null
&& \
32 echo
'yes'; rm -f .gcc-test.d .gcc-test.o .gcc-test.c
)
33 HAVE_GTK2
:=$(shell $(PKG_CONFIG
) --exists gtk
+-2.0 2>/dev
/null
&& echo
'yes')
34 LLVM_CONFIG
:=llvm-config
35 HAVE_LLVM
:=$(shell $(LLVM_CONFIG
) --version
>/dev
/null
2>&1 && echo
'yes')
37 GCC_BASE
= $(shell $(CC
) --print-file-name
=)
38 BASIC_CFLAGS
= -DGCC_BASE
=\"$(GCC_BASE
)\"
40 MULTIARCH_TRIPLET
= $(shell $(CC
) -print-multiarch
2>/dev
/null
)
41 BASIC_CFLAGS
+= -DMULTIARCH_TRIPLET
=\"$(MULTIARCH_TRIPLET
)\"
43 ifeq ($(HAVE_GCC_DEP
),yes
)
44 BASIC_CFLAGS
+= -Wp
,-MD
,$(@D
)/.
$(@F
).d
51 MANDIR
=$(PREFIX
)/share
/man
52 MAN1DIR
=$(MANDIR
)/man1
53 INCLUDEDIR
=$(PREFIX
)/include
54 PKGCONFIGDIR
=$(LIBDIR
)/pkgconfig
56 PROGRAMS
=test-lexing test-parsing obfuscate compile graph sparse \
57 test-linearize example test-unssa test-dissect ctags
58 INST_PROGRAMS
=sparse cgcc
59 INST_MAN1
=sparse
.1 cgcc
.1
61 ifeq ($(HAVE_LIBXML
),yes
)
64 c2xml_EXTRA_OBJS
= `$(PKG_CONFIG) --libs libxml-2.0`
66 $(warning Your system does not have libxml
, disabling c2xml
)
69 ifeq ($(HAVE_GTK2
),yes
)
70 GTK2_CFLAGS
:= $(shell $(PKG_CONFIG
) --cflags gtk
+-2.0)
71 GTK2_LIBS
:= $(shell $(PKG_CONFIG
) --libs gtk
+-2.0)
72 PROGRAMS
+= test-inspect
73 INST_PROGRAMS
+= test-inspect
74 test-inspect_EXTRA_DEPS
:= ast-model.o ast-view.o ast-inspect.o
75 test-inspect.o
$(test-inspect_EXTRA_DEPS
): BASIC_CFLAGS
+= $(GTK2_CFLAGS
)
76 test-inspect_EXTRA_OBJS
:= $(GTK2_LIBS
)
78 $(warning Your system does not have libgtk2
, disabling test-inspect
)
81 ifeq ($(HAVE_LLVM
),yes
)
82 LLVM_VERSION
:=$(shell $(LLVM_CONFIG
) --version
)
83 ifeq ($(shell expr
"$(LLVM_VERSION)" : '[3-9]\.'),2)
84 LLVM_PROGS
:= sparse-llvm
85 $(LLVM_PROGS
): LD
:= g
++
86 LLVM_LDFLAGS
:= $(shell $(LLVM_CONFIG
) --ldflags)
87 LLVM_CFLAGS
:= $(shell $(LLVM_CONFIG
) --cflags | sed
-e
"s/-DNDEBUG//g" | sed
-e
"s/-pedantic//g")
88 LLVM_LIBS
:= $(shell $(LLVM_CONFIG
) --libs
)
89 LLVM_LIBS
+= $(shell $(LLVM_CONFIG
) --system-libs
2>/dev
/null
)
90 PROGRAMS
+= $(LLVM_PROGS
)
91 INST_PROGRAMS
+= sparse-llvm sparsec
92 sparse-llvm.o
: BASIC_CFLAGS
+= $(LLVM_CFLAGS
)
93 sparse-llvm_EXTRA_OBJS
:= $(LLVM_LIBS
) $(LLVM_LDFLAGS
)
95 $(warning LLVM
3.0 or later required. Your system has version
$(LLVM_VERSION
) installed.
)
98 $(warning Your system does not have llvm
, disabling sparse-llvm
)
101 LIB_H
= token.h parse.h lib.h symbol.h scope.h expression.h target.h \
102 linearize.h bitmap.h ident-list.h compat.h flow.h allocate.h \
103 storage.h ptrlist.h dissect.h
105 LIB_OBJS
= target.o parse.o tokenize.o pre-process.o symbol.o lib.o scope.o \
106 expression.o show-parse.o evaluate.o expand.o inline.o linearize.o \
107 char.o
sort.o allocate.o compat-
$(OS
).o ptrlist.o \
109 flow.o cse.o simplify.o memops.o liveness.o storage.o unssa.o dissect.o
111 LIB_FILE
= libsparse.a
112 SLIB_FILE
= libsparse.so
114 # If you add $(SLIB_FILE) to this, you also need to add -fpic to BASIC_CFLAGS above.
115 # Doing so incurs a noticeable performance hit, and Sparse does not have a
116 # stable shared library interface, so this does not occur by default. If you
117 # really want a shared library, you may want to build Sparse twice: once
118 # without -fpic to get all the Sparse tools, and again with -fpic to get the
127 QUIET_CC
= $(Q
:@
=@echo
' CC '$@
;)
128 QUIET_AR
= $(Q
:@
=@echo
' AR '$@
;)
129 QUIET_GEN
= $(Q
:@
=@echo
' GEN '$@
;)
130 QUIET_LINK
= $(Q
:@
=@echo
' LINK '$@
;)
131 # We rely on the -v switch of install to print 'file -> $install_dir/file'
132 QUIET_INST_SH
= $(Q
:@
=echo
-n
' INSTALL ';)
133 QUIET_INST
= $(Q
:@
=@echo
-n
' INSTALL ';)
136 $(QUIET_INST
)install -v
$1 $(DESTDIR
)$2/$1 || exit
1;
141 $(QUIET_INST
)install -v
-m
644 $1 $(DESTDIR
)$2/$1 || exit
1;
145 SED_PC_CMD
= 's|@version@|$(VERSION)|g; \
146 s|@prefix@|$(PREFIX)|g; \
147 s|@libdir@|$(LIBDIR)|g; \
148 s|@includedir@|$(INCLUDEDIR)|g'
152 # Allow users to override build settings without dirtying their trees
156 all: $(PROGRAMS
) sparse.
pc
158 all-installable
: $(INST_PROGRAMS
) $(LIBS
) $(LIB_H
) sparse.
pc
160 install: all-installable
161 $(Q
)install -d
$(DESTDIR
)$(BINDIR
)
162 $(Q
)install -d
$(DESTDIR
)$(LIBDIR
)
163 $(Q
)install -d
$(DESTDIR
)$(MAN1DIR
)
164 $(Q
)install -d
$(DESTDIR
)$(INCLUDEDIR
)/sparse
165 $(Q
)install -d
$(DESTDIR
)$(PKGCONFIGDIR
)
166 $(foreach f
,$(INST_PROGRAMS
),$(call INSTALL_EXEC
,$f,$(BINDIR
)))
167 $(foreach f
,$(INST_MAN1
),$(call INSTALL_FILE
,$f,$(MAN1DIR
)))
168 $(foreach f
,$(LIBS
),$(call INSTALL_FILE
,$f,$(LIBDIR
)))
169 $(foreach f
,$(LIB_H
),$(call INSTALL_FILE
,$f,$(INCLUDEDIR
)/sparse
))
170 $(call INSTALL_FILE
,sparse.
pc,$(PKGCONFIGDIR
))
172 sparse.
pc: sparse.
pc.in
173 $(QUIET_GEN
)sed
$(SED_PC_CMD
) sparse.
pc.in
> sparse.
pc
176 compile_EXTRA_DEPS
= compile-i386.o
178 $(foreach p
,$(PROGRAMS
),$(eval
$(p
): $($(p
)_EXTRA_DEPS
) $(LIBS
)))
180 $(QUIET_LINK
)$(LD
) $(LDFLAGS
) -o
$@
$^
$($@_EXTRA_OBJS
)
182 $(LIB_FILE
): $(LIB_OBJS
)
183 $(QUIET_AR
)$(AR
) rcs
$@
$(LIB_OBJS
)
185 $(SLIB_FILE
): $(LIB_OBJS
)
186 $(QUIET_LINK
)$(CC
) $(LDFLAGS
) -Wl
,-soname
,$@
-shared
-o
$@
$(LIB_OBJS
)
188 DEP_FILES
:= $(wildcard .
*.o.d
)
189 $(if
$(DEP_FILES
),$(eval
include $(DEP_FILES
)))
191 c2xml.o
: c2xml.c
$(LIB_H
)
192 $(QUIET_CC
)$(CC
) `$(PKG_CONFIG) --cflags libxml-2.0` -o
$@
-c
$(ALL_CFLAGS
) $<
194 compat-linux.o
: compat
/strtold.c compat
/mmap-blob.c
$(LIB_H
)
195 compat-solaris.o
: compat
/mmap-blob.c
$(LIB_H
)
196 compat-mingw.o
: $(LIB_H
)
197 compat-cygwin.o
: $(LIB_H
)
200 $(QUIET_CC
)$(CC
) -o
$@
-c
$(ALL_CFLAGS
) $<
203 rm -f
*.
[oa
] .
*.d
*.so
$(PROGRAMS
) $(SLIB_FILE
) pre-process.h sparse.
pc
206 @if
test "$(SPARSE_VERSION)" != "v$(VERSION)" ; then \
207 echo
'Update VERSION in the Makefile before running "make dist".' ; \
210 git archive
--format
=tar --prefix=sparse-
$(VERSION
)/ HEAD^
{tree
} | gzip
-9 > sparse-
$(VERSION
).
tar.gz
213 $(Q
)cd validation
&& .
/test-suite
216 find validation
/ \
( -name
"*.c.output.expected" \
217 -o
-name
"*.c.output.got" \
218 -o
-name
"*.c.output.diff" \
219 -o
-name
"*.c.error.expected" \
220 -o
-name
"*.c.error.got" \
221 -o
-name
"*.c.error.diff" \