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
21 ALL_CFLAGS
= $(CFLAGS
) $(BASIC_CFLAGS
)
23 # For debugging, put this in local.mk:
25 # CFLAGS += -O0 -DDEBUG -g3 -gdwarf-2
28 HAVE_LIBXML
:=$(shell pkg-config
--exists libxml-2.0
2>/dev
/null
&& echo
'yes')
29 HAVE_GCC_DEP
:=$(shell touch .gcc-test.c
&& \
30 $(CC
) -c
-Wp
,-MD
,.gcc-test.d .gcc-test.c
2>/dev
/null
&& \
31 echo
'yes'; rm -f .gcc-test.d .gcc-test.o .gcc-test.c
)
32 HAVE_GTK2
:=$(shell pkg-config
--exists gtk
+-2.0 2>/dev
/null
&& echo
'yes')
33 HAVE_LLVM
:=$(shell llvm-config
--version
>/dev
/null
2>&1 && echo
'yes')
34 HAVE_LLVM_VERSION
:=$(shell llvm-config
--version | grep
"^[3-9].*" >/dev
/null
2>&1 && echo yes
)
35 LLVM_VERSION
=$(shell llvm-config
--version
)
37 GCC_BASE
= $(shell $(CC
) --print-file-name
=)
38 BASIC_CFLAGS
= -DGCC_BASE
=\"$(GCC_BASE
)\"
40 ifeq ($(HAVE_GCC_DEP
),yes
)
41 BASIC_CFLAGS
+= -Wp
,-MD
,$(@D
)/.
$(@F
).d
48 MANDIR
=$(PREFIX
)/share
/man
49 MAN1DIR
=$(MANDIR
)/man1
50 INCLUDEDIR
=$(PREFIX
)/include
51 PKGCONFIGDIR
=$(LIBDIR
)/pkgconfig
53 PROGRAMS
=test-lexing test-parsing obfuscate compile graph sparse \
54 test-linearize example test-unssa test-dissect ctags
55 INST_PROGRAMS
=sparse cgcc
56 INST_MAN1
=sparse
.1 cgcc
.1
58 ifeq ($(HAVE_LIBXML
),yes
)
61 c2xml_EXTRA_OBJS
= `pkg-config --libs libxml-2.0`
63 $(warning Your system does not have libxml
, disabling c2xml
)
66 ifeq ($(HAVE_GTK2
),yes
)
67 GTK2_CFLAGS
:= $(shell pkg-config
--cflags gtk
+-2.0)
68 GTK2_LIBS
:= $(shell pkg-config
--libs gtk
+-2.0)
69 PROGRAMS
+= test-inspect
70 INST_PROGRAMS
+= test-inspect
71 test-inspect_EXTRA_DEPS
:= ast-model.o ast-view.o ast-inspect.o
72 test-inspect.o
$(test-inspect_EXTRA_DEPS
): BASIC_CFLAGS
+= $(GTK2_CFLAGS
)
73 test-inspect_EXTRA_OBJS
:= $(GTK2_LIBS
)
75 $(warning Your system does not have libgtk2
, disabling test-inspect
)
78 ifneq ($(HAVE_LLVM
),yes
)
79 $(warning Your system does not have llvm
, disabling sparse-llvm
)
81 ifneq ($(HAVE_LLVM_VERSION
),yes
)
82 $(warning LLVM
3.0 or later required. Your system has version
$(LLVM_VERSION
) installed.
)
85 LLVM_PROGS
:= sparse-llvm
86 $(LLVM_PROGS
): LD
:= g
++
87 LLVM_LDFLAGS
:= $(shell llvm-config
--ldflags)
88 LLVM_CFLAGS
:= $(shell llvm-config
--cflags | sed
-e
"s/-DNDEBUG//g")
89 LLVM_LIBS
:= $(shell llvm-config
--libs
)
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
)
97 LIB_H
= token.h parse.h lib.h symbol.h scope.h expression.h target.h \
98 linearize.h bitmap.h ident-list.h compat.h flow.h allocate.h \
99 storage.h ptrlist.h dissect.h
101 LIB_OBJS
= target.o parse.o tokenize.o pre-process.o symbol.o lib.o scope.o \
102 expression.o show-parse.o evaluate.o expand.o inline.o linearize.o \
103 char.o
sort.o allocate.o compat-
$(OS
).o ptrlist.o \
104 flow.o cse.o simplify.o memops.o liveness.o storage.o unssa.o dissect.o
106 LIB_FILE
= libsparse.a
107 SLIB_FILE
= libsparse.so
109 # If you add $(SLIB_FILE) to this, you also need to add -fpic to BASIC_CFLAGS above.
110 # Doing so incurs a noticeable performance hit, and Sparse does not have a
111 # stable shared library interface, so this does not occur by default. If you
112 # really want a shared library, you may want to build Sparse twice: once
113 # without -fpic to get all the Sparse tools, and again with -fpic to get the
122 QUIET_CC
= $(Q
:@
=@echo
' CC '$@
;)
123 QUIET_AR
= $(Q
:@
=@echo
' AR '$@
;)
124 QUIET_GEN
= $(Q
:@
=@echo
' GEN '$@
;)
125 QUIET_LINK
= $(Q
:@
=@echo
' LINK '$@
;)
126 # We rely on the -v switch of install to print 'file -> $install_dir/file'
127 QUIET_INST_SH
= $(Q
:@
=echo
-n
' INSTALL ';)
128 QUIET_INST
= $(Q
:@
=@echo
-n
' INSTALL ';)
131 $(QUIET_INST
)install -v
$1 $(DESTDIR
)$2/$1 || exit
1;
136 $(QUIET_INST
)install -v
-m
644 $1 $(DESTDIR
)$2/$1 || exit
1;
140 SED_PC_CMD
= 's|@version@|$(VERSION)|g; \
141 s|@prefix@|$(PREFIX)|g; \
142 s|@libdir@|$(LIBDIR)|g; \
143 s|@includedir@|$(INCLUDEDIR)|g'
147 # Allow users to override build settings without dirtying their trees
151 all: $(PROGRAMS
) sparse.
pc
153 all-installable
: $(INST_PROGRAMS
) $(LIBS
) $(LIB_H
) sparse.
pc
155 install: all-installable
156 $(Q
)install -d
$(DESTDIR
)$(BINDIR
)
157 $(Q
)install -d
$(DESTDIR
)$(LIBDIR
)
158 $(Q
)install -d
$(DESTDIR
)$(MAN1DIR
)
159 $(Q
)install -d
$(DESTDIR
)$(INCLUDEDIR
)/sparse
160 $(Q
)install -d
$(DESTDIR
)$(PKGCONFIGDIR
)
161 $(foreach f
,$(INST_PROGRAMS
),$(call INSTALL_EXEC
,$f,$(BINDIR
)))
162 $(foreach f
,$(INST_MAN1
),$(call INSTALL_FILE
,$f,$(MAN1DIR
)))
163 $(foreach f
,$(LIBS
),$(call INSTALL_FILE
,$f,$(LIBDIR
)))
164 $(foreach f
,$(LIB_H
),$(call INSTALL_FILE
,$f,$(INCLUDEDIR
)/sparse
))
165 $(call INSTALL_FILE
,sparse.
pc,$(PKGCONFIGDIR
))
167 sparse.
pc: sparse.
pc.in
168 $(QUIET_GEN
)sed
$(SED_PC_CMD
) sparse.
pc.in
> sparse.
pc
171 compile_EXTRA_DEPS
= compile-i386.o
173 $(foreach p
,$(PROGRAMS
),$(eval
$(p
): $($(p
)_EXTRA_DEPS
) $(LIBS
)))
175 $(QUIET_LINK
)$(LD
) $(LDFLAGS
) -o
$@
$^
$($@_EXTRA_OBJS
)
177 $(LIB_FILE
): $(LIB_OBJS
)
178 $(QUIET_AR
)$(AR
) rcs
$@
$(LIB_OBJS
)
180 $(SLIB_FILE
): $(LIB_OBJS
)
181 $(QUIET_LINK
)$(CC
) $(LDFLAGS
) -Wl
,-soname
,$@
-shared
-o
$@
$(LIB_OBJS
)
183 DEP_FILES
:= $(wildcard .
*.o.d
)
184 $(if
$(DEP_FILES
),$(eval
include $(DEP_FILES
)))
186 c2xml.o
: c2xml.c
$(LIB_H
)
187 $(QUIET_CC
)$(CC
) `pkg-config --cflags libxml-2.0` -o
$@
-c
$(ALL_CFLAGS
) $<
189 compat-linux.o
: compat
/strtold.c compat
/mmap-blob.c
$(LIB_H
)
190 compat-solaris.o
: compat
/mmap-blob.c
$(LIB_H
)
191 compat-mingw.o
: $(LIB_H
)
192 compat-cygwin.o
: $(LIB_H
)
195 $(QUIET_CC
)$(CC
) -o
$@
-c
$(ALL_CFLAGS
) $<
198 rm -f
*.
[oa
] .
*.d
*.so
$(PROGRAMS
) $(SLIB_FILE
) pre-process.h sparse.
pc
201 @if
test "$(SPARSE_VERSION)" != "v$(VERSION)" ; then \
202 echo
'Update VERSION in the Makefile before running "make dist".' ; \
205 git archive
--format
=tar --prefix=sparse-
$(VERSION
)/ HEAD^
{tree
} | gzip
-9 > sparse-
$(VERSION
).
tar.gz
208 $(Q
)cd validation
&& .
/test-suite
211 find validation
/ \
( -name
"*.c.output.expected" \
212 -o
-name
"*.c.output.got" \
213 -o
-name
"*.c.output.diff" \
214 -o
-name
"*.c.error.expected" \
215 -o
-name
"*.c.error.got" \
216 -o
-name
"*.c.error.diff" \