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
36 SMATCHDATADIR
=$(PREFIX
)/share
/smatch
/
38 SMATCH_FILES
=smatch_flow.o smatch_conditions.o smatch_slist.o smatch_states.o \
39 smatch_helper.o smatch_type.o smatch_hooks.o smatch_function_hooks.o \
40 smatch_modification_hooks.o smatch_extra.o \
41 smatch_ranges.o smatch_implied.o smatch_ignore.o \
42 smatch_tracker.o smatch_files.o smatch_expression_stacks.o smatch_oom.o \
44 SMATCH_CHECKS
=$(shell ls check_
*.c | sed
-e
's/\.c/.o/')
45 SMATCH_DATA
=smatch_data
/kernel.allocation_funcs smatch_data
/kernel.balanced_funcs \
46 smatch_data
/kernel.frees_argument smatch_data
/kernel.puts_argument \
47 smatch_data
/kernel.dev_queue_xmit smatch_data
/kernel.returns_err_ptr \
48 smatch_data
/kernel.dma_funcs smatch_data
/kernel.returns_held_funcs
50 PROGRAMS
=test-lexing test-parsing obfuscate compile graph sparse \
51 test-linearize example test-unssa test-dissect ctags
52 INST_PROGRAMS
=sparse cgcc smatch
54 INST_MAN1
=sparse
.1 cgcc
.1
56 ifeq ($(HAVE_LIBXML
),yes
)
59 c2xml_EXTRA_OBJS
= `pkg-config --libs libxml-2.0`
62 LIB_H
= token.h parse.h lib.h symbol.h scope.h expression.h target.h \
63 linearize.h bitmap.h ident-list.h compat.h flow.h allocate.h \
64 storage.h ptrlist.h dissect.h
66 LIB_OBJS
= target.o parse.o tokenize.o pre-process.o symbol.o lib.o scope.o \
67 expression.o show-parse.o evaluate.o expand.o inline.o linearize.o \
68 sort.o allocate.o compat-
$(OS
).o ptrlist.o \
69 flow.o cse.o simplify.o memops.o liveness.o storage.o unssa.o dissect.o
72 SLIB_FILE
= libsparse.so
74 # If you add $(SLIB_FILE) to this, you also need to add -fpic to CFLAGS above.
75 # Doing so incurs a noticeable performance hit, and Sparse does not have a
76 # stable shared library interface, so this does not occur by default. If you
77 # really want a shared library, you may want to build Sparse twice: once
78 # without -fpic to get all the Sparse tools, and again with -fpic to get the
87 QUIET_CC
= $(Q
:@
=@echo
' CC '$@
;)
88 QUIET_AR
= $(Q
:@
=@echo
' AR '$@
;)
89 QUIET_GEN
= $(Q
:@
=@echo
' GEN '$@
;)
90 QUIET_LINK
= $(Q
:@
=@echo
' LINK '$@
;)
91 # We rely on the -v switch of install to print 'file -> $install_dir/file'
92 QUIET_INST_SH
= $(Q
:@
=echo
-n
' INSTALL ';)
93 QUIET_INST
= $(Q
:@
=@echo
-n
' INSTALL ';)
96 $(QUIET_INST
)install -v
$1 $(DESTDIR
)$2/$1 || exit
1;
101 $(QUIET_INST
)install -v
-m
644 $1 $(DESTDIR
)$2/$1 || exit
1;
105 SED_PC_CMD
= 's|@version@|$(VERSION)|g; \
106 s|@prefix@|$(PREFIX)|g; \
107 s|@libdir@|$(LIBDIR)|g; \
108 s|@includedir@|$(INCLUDEDIR)|g'
112 # Allow users to override build settings without dirtying their trees
116 all: $(PROGRAMS
) sparse.
pc smatch
118 install: $(INST_PROGRAMS
) $(LIBS
) $(LIB_H
) sparse.
pc
119 $(Q
)install -d
$(DESTDIR
)$(BINDIR
)
120 $(Q
)install -d
$(DESTDIR
)$(LIBDIR
)
121 $(Q
)install -d
$(DESTDIR
)$(MAN1DIR
)
122 $(Q
)install -d
$(DESTDIR
)$(INCLUDEDIR
)/sparse
123 $(Q
)install -d
$(DESTDIR
)$(PKGCONFIGDIR
)
124 $(Q
)install -d
$(DESTDIR
)$(SMATCHDATADIR
)/smatch_data
/
125 $(foreach f
,$(INST_PROGRAMS
),$(call INSTALL_EXEC
,$f,$(BINDIR
)))
126 $(foreach f
,$(INST_MAN1
),$(call INSTALL_FILE
,$f,$(MAN1DIR
)))
127 $(foreach f
,$(LIBS
),$(call INSTALL_FILE
,$f,$(LIBDIR
)))
128 $(foreach f
,$(LIB_H
),$(call INSTALL_FILE
,$f,$(INCLUDEDIR
)/sparse
))
129 $(call INSTALL_FILE
,sparse.
pc,$(PKGCONFIGDIR
))
130 $(foreach f
,$(SMATCH_DATA
),$(call INSTALL_FILE
,$f,$(SMATCHDATADIR
)))
132 sparse.
pc: sparse.
pc.in
133 $(QUIET_GEN
)sed
$(SED_PC_CMD
) sparse.
pc.in
> sparse.
pc
136 compile_EXTRA_DEPS
= compile-i386.o
138 $(foreach p
,$(PROGRAMS
),$(eval
$(p
): $($(p
)_EXTRA_DEPS
) $(LIBS
)))
140 $(QUIET_LINK
)$(CC
) $(LDFLAGS
) -o
$@
$^
$($@_EXTRA_OBJS
)
142 smatch
: smatch.o
$(SMATCH_FILES
) $(SMATCH_CHECKS
) $(LIBS
)
143 $(CC
) $(LDFLAGS
) -o
$@
$< $(SMATCH_FILES
) $(SMATCH_CHECKS
) $(LIBS
)
145 $(LIB_FILE
): $(LIB_OBJS
)
146 $(QUIET_AR
)$(AR
) rcs
$@
$(LIB_OBJS
)
148 $(SLIB_FILE
): $(LIB_OBJS
)
149 $(QUIET_LINK
)$(CC
) $(LDFLAGS
) -Wl
,-soname
,$@
-shared
-o
$@
$(LIB_OBJS
)
151 smatch_flow.o
: $(LIB_H
) smatch.h smatch_expression_stacks.h smatch_extra.h
152 smatch_conditions.o
: $(LIB_H
) smatch.h smatch_slist.h
153 smatch_extra.o
: $(LIB_H
) smatch.h smatch_extra.h
154 smatch_ranges.o
: $(LIB_H
) smatch.h smatch_extra.h
155 smatch_implied.o
: $(LIB_H
) smatch.h smatch_slist.h smatch_extra.h
156 smatch_ignore.o
: $(LIB_H
) smatch.h
157 smatch_tracker.o
: $(LIB_H
) smatch.h
158 smatch_files.o
: $(LIB_H
) smatch.h
159 smatch_hooks.o
: $(LIB_H
) smatch.h
160 smatch_function_hooks.o
: $(LIB_H
) smatch.h smatch_slist.h smatch_extra.h
161 smatch_modification_hooks.o
: $(LIB_H
) smatch.h
162 smatch_helper.o
: $(LIB_H
) smatch.h
163 smatch_type.o
: $(LIB_H
) smatch.h
164 smatch_slist.o
: $(LIB_H
) smatch.h smatch_slist.h
165 smatch_states.o
: $(LIB_H
) smatch.h smatch_slist.h smatch_extra.h
166 smatch_expression_stacks.o
: $(LIB_H
) smatch.h
167 smatch_oom.c
: $(LIB_H
) smatch.h
168 smatch_redefine.c
: $(LIB_H
) smatch.h
169 smatch.o
: smatch.c
$(LIB_H
) smatch.h check_list.h
170 $(CC
) -c smatch.c
-DSMATCHDATADIR
='"$(SMATCHDATADIR)"'
171 $(SMATCH_CHECKS
): smatch.h smatch_slist.h smatch_extra.h
172 test-unssa.o
: $(LIB_H
)
174 compile.o
: $(LIB_H
) compile.h
175 compile-i386.o
: $(LIB_H
) compile.h
178 obfuscate.o
: $(LIB_H
)
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
$(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
$(CFLAGS
) $<
198 rm -f
*.
[oa
] .
*.d
*.so cwchash
/*.o cwchash
/.
*.d cwchash
/tester \
199 $(PROGRAMS
) $(SLIB_FILE
) pre-process.h sparse.
pc
202 @if
test "`git describe`" != "v$(VERSION)" ; then \
203 echo
'Update VERSION in the Makefile before running "make dist".' ; \
206 git archive
--format
=tar --prefix=sparse-
$(VERSION
)/ HEAD^
{tree
} | gzip
-9 > sparse-
$(VERSION
).
tar.gz
209 $(Q
)cd validation
&& .
/test-suite
212 find validation
/ \
( -name
"*.c.output.expected" \
213 -o
-name
"*.c.output.got" \
214 -o
-name
"*.c.output.diff" \
215 -o
-name
"*.c.error.expected" \
216 -o
-name
"*.c.error.got" \
217 -o
-name
"*.c.error.diff" \