7 CFLAGS
= -O2
-finline-functions
-fno-strict-aliasing
-g
8 CFLAGS
+= -Wall
-Wwrite-strings
12 ALL_CFLAGS
= $(CFLAGS
) $(BASIC_CFLAGS
)
14 # For debugging, put this in local.mk:
16 # CFLAGS += -O0 -DDEBUG -g3 -gdwarf-2
19 HAVE_LIBXML
:=$(shell pkg-config
--exists libxml-2.0
2>/dev
/null
&& echo
'yes')
20 HAVE_GCC_DEP
:=$(shell touch .gcc-test.c
&& \
21 $(CC
) -c
-Wp
,-MD
,.gcc-test.d .gcc-test.c
2>/dev
/null
&& \
22 echo
'yes'; rm -f .gcc-test.d .gcc-test.o .gcc-test.c
)
23 HAVE_GTK2
:=$(shell pkg-config
--exists gtk
+-2.0 2>/dev
/null
&& echo
'yes')
25 GCC_BASE
= $(shell $(CC
) --print-file-name
=)
26 BASIC_CFLAGS
= -DGCC_BASE
=\"$(GCC_BASE
)\"
28 ifeq ($(HAVE_GCC_DEP
),yes
)
29 BASIC_CFLAGS
+= -Wp
,-MD
,$(@D
)/.
$(@F
).d
36 MANDIR
=$(PREFIX
)/share
/man
37 MAN1DIR
=$(MANDIR
)/man1
38 INCLUDEDIR
=$(PREFIX
)/include
39 PKGCONFIGDIR
=$(LIBDIR
)/pkgconfig
41 PROGRAMS
=test-lexing test-parsing obfuscate compile graph sparse \
42 test-linearize example test-unssa test-dissect ctags
43 INST_PROGRAMS
=sparse cgcc
44 INST_MAN1
=sparse
.1 cgcc
.1
46 ifeq ($(HAVE_LIBXML
),yes
)
49 c2xml_EXTRA_OBJS
= `pkg-config --libs libxml-2.0`
51 $(warning Your system does not have libxml
, disabling c2xml
)
54 ifeq ($(HAVE_GTK2
),yes
)
55 GTK2_CFLAGS
:= $(shell pkg-config
--cflags gtk
+-2.0)
56 GTK2_LIBS
:= $(shell pkg-config
--libs gtk
+-2.0)
57 PROGRAMS
+= test-inspect
58 INST_PROGRAMS
+= test-inspect
59 test-inspect_EXTRA_DEPS
:= ast-model.o ast-view.o ast-inspect.o
60 test-inspect.o
$(test-inspect_EXTRA_DEPS
): BASIC_CFLAGS
+= $(GTK2_CFLAGS
)
61 test-inspect_EXTRA_OBJS
:= $(GTK2_LIBS
)
63 $(warning Your system does not have libgtk2
, disabling test-inspect
)
66 LIB_H
= token.h parse.h lib.h symbol.h scope.h expression.h target.h \
67 linearize.h bitmap.h ident-list.h compat.h flow.h allocate.h \
68 storage.h ptrlist.h dissect.h
70 LIB_OBJS
= target.o parse.o tokenize.o pre-process.o symbol.o lib.o scope.o \
71 expression.o show-parse.o evaluate.o expand.o inline.o linearize.o \
72 sort.o allocate.o compat-
$(OS
).o ptrlist.o \
73 flow.o cse.o simplify.o memops.o liveness.o storage.o unssa.o dissect.o
76 SLIB_FILE
= libsparse.so
78 # If you add $(SLIB_FILE) to this, you also need to add -fpic to BASIC_CFLAGS above.
79 # Doing so incurs a noticeable performance hit, and Sparse does not have a
80 # stable shared library interface, so this does not occur by default. If you
81 # really want a shared library, you may want to build Sparse twice: once
82 # without -fpic to get all the Sparse tools, and again with -fpic to get the
91 QUIET_CC
= $(Q
:@
=@echo
' CC '$@
;)
92 QUIET_AR
= $(Q
:@
=@echo
' AR '$@
;)
93 QUIET_GEN
= $(Q
:@
=@echo
' GEN '$@
;)
94 QUIET_LINK
= $(Q
:@
=@echo
' LINK '$@
;)
95 # We rely on the -v switch of install to print 'file -> $install_dir/file'
96 QUIET_INST_SH
= $(Q
:@
=echo
-n
' INSTALL ';)
97 QUIET_INST
= $(Q
:@
=@echo
-n
' INSTALL ';)
100 $(QUIET_INST
)install -v
$1 $(DESTDIR
)$2/$1 || exit
1;
105 $(QUIET_INST
)install -v
-m
644 $1 $(DESTDIR
)$2/$1 || exit
1;
109 SED_PC_CMD
= 's|@version@|$(VERSION)|g; \
110 s|@prefix@|$(PREFIX)|g; \
111 s|@libdir@|$(LIBDIR)|g; \
112 s|@includedir@|$(INCLUDEDIR)|g'
116 # Allow users to override build settings without dirtying their trees
120 all: $(PROGRAMS
) sparse.
pc
122 all-installable
: $(INST_PROGRAMS
) $(LIBS
) $(LIB_H
) sparse.
pc
124 install: all-installable
125 $(Q
)install -d
$(DESTDIR
)$(BINDIR
)
126 $(Q
)install -d
$(DESTDIR
)$(LIBDIR
)
127 $(Q
)install -d
$(DESTDIR
)$(MAN1DIR
)
128 $(Q
)install -d
$(DESTDIR
)$(INCLUDEDIR
)/sparse
129 $(Q
)install -d
$(DESTDIR
)$(PKGCONFIGDIR
)
130 $(foreach f
,$(INST_PROGRAMS
),$(call INSTALL_EXEC
,$f,$(BINDIR
)))
131 $(foreach f
,$(INST_MAN1
),$(call INSTALL_FILE
,$f,$(MAN1DIR
)))
132 $(foreach f
,$(LIBS
),$(call INSTALL_FILE
,$f,$(LIBDIR
)))
133 $(foreach f
,$(LIB_H
),$(call INSTALL_FILE
,$f,$(INCLUDEDIR
)/sparse
))
134 $(call INSTALL_FILE
,sparse.
pc,$(PKGCONFIGDIR
))
136 sparse.
pc: sparse.
pc.in
137 $(QUIET_GEN
)sed
$(SED_PC_CMD
) sparse.
pc.in
> sparse.
pc
140 compile_EXTRA_DEPS
= compile-i386.o
142 $(foreach p
,$(PROGRAMS
),$(eval
$(p
): $($(p
)_EXTRA_DEPS
) $(LIBS
)))
144 $(QUIET_LINK
)$(CC
) $(LDFLAGS
) -o
$@
$^
$($@_EXTRA_OBJS
)
146 $(LIB_FILE
): $(LIB_OBJS
)
147 $(QUIET_AR
)$(AR
) rcs
$@
$(LIB_OBJS
)
149 $(SLIB_FILE
): $(LIB_OBJS
)
150 $(QUIET_LINK
)$(CC
) $(LDFLAGS
) -Wl
,-soname
,$@
-shared
-o
$@
$(LIB_OBJS
)
152 DEP_FILES
:= $(wildcard .
*.o.d
)
153 $(if
$(DEP_FILES
),$(eval
include $(DEP_FILES
)))
155 c2xml.o
: c2xml.c
$(LIB_H
)
156 $(QUIET_CC
)$(CC
) `pkg-config --cflags libxml-2.0` -o
$@
-c
$(ALL_CFLAGS
) $<
158 compat-linux.o
: compat
/strtold.c compat
/mmap-blob.c
$(LIB_H
)
159 compat-solaris.o
: compat
/mmap-blob.c
$(LIB_H
)
160 compat-mingw.o
: $(LIB_H
)
161 compat-cygwin.o
: $(LIB_H
)
164 $(QUIET_CC
)$(CC
) -o
$@
-c
$(ALL_CFLAGS
) $<
167 rm -f
*.
[oa
] .
*.d
*.so
$(PROGRAMS
) $(SLIB_FILE
) pre-process.h sparse.
pc
170 @if
test "`git describe`" != "v$(VERSION)" ; then \
171 echo
'Update VERSION in the Makefile before running "make dist".' ; \
174 git archive
--format
=tar --prefix=sparse-
$(VERSION
)/ HEAD^
{tree
} | gzip
-9 > sparse-
$(VERSION
).
tar.gz
177 $(Q
)cd validation
&& .
/test-suite
180 find validation
/ \
( -name
"*.c.output.expected" \
181 -o
-name
"*.c.output.got" \
182 -o
-name
"*.c.output.diff" \
183 -o
-name
"*.c.error.expected" \
184 -o
-name
"*.c.error.got" \
185 -o
-name
"*.c.error.diff" \