6 CFLAGS
= -O2
-finline-functions
-fno-strict-aliasing
-g
7 CFLAGS
+= -Wall
-Wwrite-strings
12 # For debugging, put this in local.mk:
14 # CFLAGS += -O0 -DDEBUG -g3 -gdwarf-2
17 HAVE_LIBXML
=$(shell pkg-config
--exists libxml-2.0
2>/dev
/null
&& echo
'yes')
18 HAVE_GCC_DEP
=$(shell touch .gcc-test.c
&& \
19 $(CC
) -c
-Wp
,-MD
,.gcc-test.d .gcc-test.c
2>/dev
/null
&& \
20 echo
'yes'; rm -f .gcc-test.d .gcc-test.o .gcc-test.c
)
22 CFLAGS
+= -DGCC_BASE
=\"$(shell $(CC
) --print-file-name
=)\"
24 ifeq ($(HAVE_GCC_DEP
),yes
)
25 CFLAGS
+= -Wp
,-MD
,$(@D
)/.
$(@F
).d
32 MANDIR
=$(PREFIX
)/share
/man
33 MAN1DIR
=$(MANDIR
)/man1
34 INCLUDEDIR
=$(PREFIX
)/include
35 PKGCONFIGDIR
=$(LIBDIR
)/pkgconfig
37 SMATCH_FILES
=smatch_flow.o smatch_conditions.o smatch_slist.o smatch_states.o \
38 smatch_helper.o smatch_type.o smatch_hooks.o smatch_function_hooks.o \
39 smatch_modification_hooks.o smatch_extra.o \
40 smatch_ranges.o smatch_implied.o smatch_ignore.o \
41 smatch_tracker.o smatch_files.o smatch_expression_stacks.o smatch_oom.o \
43 SMATCH_CHECKS
=$(shell ls check_
*.c | sed
-e
's/\.c/.o/')
46 PROGRAMS
=test-lexing test-parsing obfuscate compile graph sparse \
47 test-linearize example test-unssa test-dissect ctags
48 INST_PROGRAMS
=sparse cgcc smatch
50 INST_MAN1
=sparse
.1 cgcc
.1
52 ifeq ($(HAVE_LIBXML
),yes
)
55 c2xml_EXTRA_OBJS
= `pkg-config --libs libxml-2.0`
58 LIB_H
= token.h parse.h lib.h symbol.h scope.h expression.h target.h \
59 linearize.h bitmap.h ident-list.h compat.h flow.h allocate.h \
60 storage.h ptrlist.h dissect.h
62 LIB_OBJS
= target.o parse.o tokenize.o pre-process.o symbol.o lib.o scope.o \
63 expression.o show-parse.o evaluate.o expand.o inline.o linearize.o \
64 sort.o allocate.o compat-
$(OS
).o ptrlist.o \
65 flow.o cse.o simplify.o memops.o liveness.o storage.o unssa.o dissect.o
68 SLIB_FILE
= libsparse.so
70 # If you add $(SLIB_FILE) to this, you also need to add -fpic to CFLAGS above.
71 # Doing so incurs a noticeable performance hit, and Sparse does not have a
72 # stable shared library interface, so this does not occur by default. If you
73 # really want a shared library, you may want to build Sparse twice: once
74 # without -fpic to get all the Sparse tools, and again with -fpic to get the
83 QUIET_CC
= $(Q
:@
=@echo
' CC '$@
;)
84 QUIET_AR
= $(Q
:@
=@echo
' AR '$@
;)
85 QUIET_GEN
= $(Q
:@
=@echo
' GEN '$@
;)
86 QUIET_LINK
= $(Q
:@
=@echo
' LINK '$@
;)
87 # We rely on the -v switch of install to print 'file -> $install_dir/file'
88 QUIET_INST_SH
= $(Q
:@
=echo
-n
' INSTALL ';)
89 QUIET_INST
= $(Q
:@
=@echo
-n
' INSTALL ';)
92 $(QUIET_INST
)install -v
$1 $(DESTDIR
)$2/$1 || exit
1;
97 $(QUIET_INST
)install -v
-m
644 $1 $(DESTDIR
)$2/$1 || exit
1;
101 SED_PC_CMD
= 's|@version@|$(VERSION)|g; \
102 s|@prefix@|$(PREFIX)|g; \
103 s|@libdir@|$(LIBDIR)|g; \
104 s|@includedir@|$(INCLUDEDIR)|g'
108 # Allow users to override build settings without dirtying their trees
112 all: $(PROGRAMS
) sparse.
pc smatch
114 install: $(INST_PROGRAMS
) $(LIBS
) $(LIB_H
) sparse.
pc
115 $(Q
)install -d
$(DESTDIR
)$(BINDIR
)
116 $(Q
)install -d
$(DESTDIR
)$(LIBDIR
)
117 $(Q
)install -d
$(DESTDIR
)$(MAN1DIR
)
118 $(Q
)install -d
$(DESTDIR
)$(INCLUDEDIR
)/sparse
119 $(Q
)install -d
$(DESTDIR
)$(PKGCONFIGDIR
)
120 $(foreach f
,$(INST_PROGRAMS
),$(call INSTALL_EXEC
,$f,$(BINDIR
)))
121 $(foreach f
,$(INST_MAN1
),$(call INSTALL_FILE
,$f,$(MAN1DIR
)))
122 $(foreach f
,$(LIBS
),$(call INSTALL_FILE
,$f,$(LIBDIR
)))
123 $(foreach f
,$(LIB_H
),$(call INSTALL_FILE
,$f,$(INCLUDEDIR
)/sparse
))
124 $(call INSTALL_FILE
,sparse.
pc,$(PKGCONFIGDIR
))
126 sparse.
pc: sparse.
pc.in
127 $(QUIET_GEN
)sed
$(SED_PC_CMD
) sparse.
pc.in
> sparse.
pc
130 compile_EXTRA_DEPS
= compile-i386.o
132 $(foreach p
,$(PROGRAMS
),$(eval
$(p
): $($(p
)_EXTRA_DEPS
) $(LIBS
)))
134 $(QUIET_LINK
)$(CC
) $(LDFLAGS
) -o
$@
$^
$($@_EXTRA_OBJS
)
136 smatch
: smatch.o
$(SMATCH_FILES
) $(SMATCH_CHECKS
) $(LIBS
)
137 $(CC
) $(LDFLAGS
) -o
$@
$< $(SMATCH_FILES
) $(SMATCH_CHECKS
) $(LIBS
)
139 $(LIB_FILE
): $(LIB_OBJS
)
140 $(QUIET_AR
)$(AR
) rcs
$@
$(LIB_OBJS
)
142 $(SLIB_FILE
): $(LIB_OBJS
)
143 $(QUIET_LINK
)$(CC
) $(LDFLAGS
) -Wl
,-soname
,$@
-shared
-o
$@
$(LIB_OBJS
)
145 smatch_flow.o
: $(LIB_H
) smatch.h smatch_expression_stacks.h smatch_extra.h
146 smatch_conditions.o
: $(LIB_H
) smatch.h smatch_slist.h
147 smatch_extra.o
: $(LIB_H
) smatch.h smatch_extra.h
148 smatch_ranges.o
: $(LIB_H
) smatch.h smatch_extra.h
149 smatch_implied.o
: $(LIB_H
) smatch.h smatch_slist.h smatch_extra.h
150 smatch_ignore.o
: $(LIB_H
) smatch.h
151 smatch_tracker.o
: $(LIB_H
) smatch.h
152 smatch_files.o
: $(LIB_H
) smatch.h
153 smatch_hooks.o
: $(LIB_H
) smatch.h
154 smatch_function_hooks.o
: $(LIB_H
) smatch.h smatch_slist.h smatch_extra.h
155 smatch_modification_hooks.o
: $(LIB_H
) smatch.h
156 smatch_containers.o
: $(LIB_H
) smatch.h
157 smatch_helper.o
: $(LIB_H
) smatch.h
158 smatch_type.o
: $(LIB_H
) smatch.h
159 smatch_slist.o
: $(LIB_H
) smatch.h smatch_slist.h
160 smatch_states.o
: $(LIB_H
) smatch.h smatch_slist.h smatch_extra.h
161 smatch_expression_stacks.o
: $(LIB_H
) smatch.h
162 smatch_oom.c
: $(LIB_H
) smatch.h
163 smatch_redefine.c
: $(LIB_H
) smatch.h
164 smatch.o
: $(LIB_H
) smatch.h
165 $(SMATCH_CHECKS
): smatch.h smatch_slist.h smatch_extra.h
166 test-unssa.o
: $(LIB_H
)
168 compile.o
: $(LIB_H
) compile.h
169 compile-i386.o
: $(LIB_H
) compile.h
172 obfuscate.o
: $(LIB_H
)
177 DEP_FILES
:= $(wildcard .
*.o.d
)
178 $(if
$(DEP_FILES
),$(eval
include $(DEP_FILES
)))
180 c2xml.o
: c2xml.c
$(LIB_H
)
181 $(QUIET_CC
)$(CC
) `pkg-config --cflags libxml-2.0` -o
$@
-c
$(CFLAGS
) $<
183 compat-linux.o
: compat
/strtold.c compat
/mmap-blob.c
$(LIB_H
)
184 compat-solaris.o
: compat
/mmap-blob.c
$(LIB_H
)
185 compat-mingw.o
: $(LIB_H
)
186 compat-cygwin.o
: $(LIB_H
)
189 $(QUIET_CC
)$(CC
) -o
$@
-c
$(CFLAGS
) $<
192 rm -f
*.
[oa
] .
*.d
*.so
$(PROGRAMS
) $(SLIB_FILE
) pre-process.h sparse.
pc
195 @if
test "`git describe`" != "v$(VERSION)" ; then \
196 echo
'Update VERSION in the Makefile before running "make dist".' ; \
199 git archive
--format
=tar --prefix=sparse-
$(VERSION
)/ HEAD^
{tree
} | gzip
-9 > sparse-
$(VERSION
).
tar.gz
202 $(Q
)cd validation
&& .
/test-suite
205 find validation
/ \
( -name
"*.c.output.expected" \
206 -o
-name
"*.c.output.got" \
207 -o
-name
"*.c.output.diff" \
208 -o
-name
"*.c.error.expected" \
209 -o
-name
"*.c.error.got" \
210 -o
-name
"*.c.error.diff" \