xref: /illumos-gate/usr/src/tools/smatch/Makefile (revision 99ea293e719ac006d413e4fde6ac0d5cd4dd6c59)
1#
2# This file and its contents are supplied under the terms of the
3# Common Development and Distribution License ("CDDL"), version 1.0.
4# You may only use this file in accordance with the terms of version
5# 1.0 of the CDDL.
6#
7# A full copy of the text of the CDDL should have accompanied this
8# source.  A copy of the CDDL is also available via the Internet at
9# http://www.illumos.org/license/CDDL.
10#
11# Copyright 2020 Joyent, Inc.
12#
13
14#
15# The src/ sub-directory is un-modified copy of
16# https://github.com/illumos/smatch/tree/$SPARSE_VERSION
17#
18# This Makefile installs just enough for us to be able to run smatch
19# locally.
20#
21
22PROG = smatch
23SPARSE_VERSION = 0.6.1-rc1-il-5
24
25include ../Makefile.tools
26
27# We have to build smatch before we can use cw
28i386_CC = $(GNUC_ROOT)/bin/gcc
29sparc_CC = $(GNUC_ROOT)/bin/gcc
30# sparc doesn't recognise -msave-args
31i386_SMATCHFLAGS = -msave-args
32sparc_SMATCHFLAGS =
33
34# When we use builtins, then ld's -zguidance will complain that libm is
35# unused on x86 because the compiler will replace ceil(3M) with its own copy.
36# However, on SPARC, it doesn't. So for now we disable builtins to make it
37# consistent.
38CFLAGS = -O -m64 -std=gnu99 -nodefaultlibs -D__sun $($(MACH)_SMATCHFLAGS)
39CFLAGS += -fno-builtin
40CFLAGS += -Wall -Wno-unknown-pragmas -Wno-psabi
41
42SMATCHDATADIR = $(ROOTONBLDSHARE)/smatch
43
44CFLAGS += -DSMATCHDATADIR='"$(SMATCHDATADIR)"'
45CFLAGS += -DGCC_BASE='"/no/such/dir"'
46CFLAGS += -DMULTIARCH_TRIPLET=NULL
47
48LDCHECKS = $(ZASSERTDEFLIB) $(ZGUIDANCE) $(ZFATALWARNINGS)
49LDLIBS += $(ZLAZYLOAD) $(ZDIRECT) -lsqlite3 -lcrypto -lgcc -lm -lc
50LDFLAGS = $(MAPFILE.NES:%=-Wl,-M%)
51LDFLAGS += -L$(NATIVE_ADJUNCT)/lib -R$(NATIVE_ADJUNCT)/lib
52
53NATIVE_LIBS += libsqlite3.so libcrypto.so libm.so libc.so
54LDFLAGS += $(NATIVE_LIBS:%=$(ZASSERTDEFLIB)=%)
55
56CPPFLAGS += -nostdinc
57CPPFLAGS += -Isrc/
58CPPFLAGS += -I$(NATIVE_ADJUNCT)/include
59
60# no install.bin
61INS.file = $(RM) $@; $(CP) $< $(@D); $(CHMOD) $(FILEMODE) $@
62INS.dir = mkdir -p $@; $(CHMOD) $(DIRMODE) $@
63
64# fine for us
65OS=linux
66
67LIB_OBJS =
68LIB_OBJS += allocate.o
69LIB_OBJS += builtin.o
70LIB_OBJS += char.o
71LIB_OBJS += compat-$(OS).o
72LIB_OBJS += cse.o
73LIB_OBJS += dissect.o
74LIB_OBJS += dominate.o
75LIB_OBJS += evaluate.o
76LIB_OBJS += expand.o
77LIB_OBJS += expression.o
78LIB_OBJS += flow.o
79LIB_OBJS += flowgraph.o
80LIB_OBJS += inline.o
81LIB_OBJS += ir.o
82LIB_OBJS += lib.o
83LIB_OBJS += linearize.o
84LIB_OBJS += liveness.o
85LIB_OBJS += memops.o
86LIB_OBJS += opcode.o
87LIB_OBJS += optimize.o
88LIB_OBJS += parse.o
89LIB_OBJS += pre-process.o
90LIB_OBJS += ptrlist.o
91LIB_OBJS += ptrmap.o
92LIB_OBJS += scope.o
93LIB_OBJS += show-parse.o
94LIB_OBJS += simplify.o
95LIB_OBJS += sort.o
96LIB_OBJS += ssa.o
97LIB_OBJS += sset.o
98LIB_OBJS += stats.o
99LIB_OBJS += storage.o
100LIB_OBJS += symbol.o
101LIB_OBJS += target.o
102LIB_OBJS += tokenize.o
103LIB_OBJS += unssa.o
104LIB_OBJS += utils.o
105LIB_OBJS += macro_table.o
106LIB_OBJS += token_store.o
107LIB_OBJS += hashtable.o
108
109SMATCH_OBJS =
110SMATCH_OBJS += avl.o
111SMATCH_OBJS += smatch_about_fn_ptr_arg.o
112SMATCH_OBJS += smatch_address.o
113SMATCH_OBJS += smatch_annotate.o
114SMATCH_OBJS += smatch_array_values.o
115SMATCH_OBJS += smatch_assigned_expr.o
116SMATCH_OBJS += smatch_bits.o
117SMATCH_OBJS += smatch_buf_comparison.o
118SMATCH_OBJS += smatch_buf_size.o
119SMATCH_OBJS += smatch_capped.o
120SMATCH_OBJS += smatch_common_functions.o
121SMATCH_OBJS += smatch_comparison.o
122SMATCH_OBJS += smatch_conditions.o
123SMATCH_OBJS += smatch_constraints.o
124SMATCH_OBJS += smatch_constraints_required.o
125SMATCH_OBJS += smatch_container_of.o
126SMATCH_OBJS += smatch_data_source.o
127SMATCH_OBJS += smatch_db.o
128SMATCH_OBJS += smatch_equiv.o
129SMATCH_OBJS += smatch_estate.o
130SMATCH_OBJS += smatch_expressions.o
131SMATCH_OBJS += smatch_expression_stacks.o
132SMATCH_OBJS += smatch_extra.o
133SMATCH_OBJS += smatch_files.o
134SMATCH_OBJS += smatch_flow.o
135SMATCH_OBJS += smatch_fresh_alloc.o
136SMATCH_OBJS += smatch_fn_arg_link.o
137SMATCH_OBJS += smatch_function_hooks.o
138SMATCH_OBJS += smatch_function_info.o
139SMATCH_OBJS += smatch_function_ptrs.o
140SMATCH_OBJS += smatch_helper.o
141SMATCH_OBJS += smatch_hooks.o
142SMATCH_OBJS += smatch_ignore.o
143SMATCH_OBJS += smatch_imaginary_absolute.o
144SMATCH_OBJS += smatch_implied.o
145SMATCH_OBJS += smatch_impossible.o
146SMATCH_OBJS += smatch_integer_overflow.o
147SMATCH_OBJS += smatch_kernel_user_data.o
148SMATCH_OBJS += smatch_links.o
149SMATCH_OBJS += smatch_math.o
150SMATCH_OBJS += smatch_mem_tracker.o
151SMATCH_OBJS += smatch_modification_hooks.o
152SMATCH_OBJS += smatch_mtag_data.o
153SMATCH_OBJS += smatch_mtag_map.o
154SMATCH_OBJS += smatch_mtag.o
155SMATCH_OBJS += smatch_nul_terminator.o
156SMATCH_OBJS += smatch_param_cleared.o
157SMATCH_OBJS += smatch_param_compare_limit.o
158SMATCH_OBJS += smatch_parameter_names.o
159SMATCH_OBJS += smatch_param_filter.o
160SMATCH_OBJS += smatch_param_limit.o
161SMATCH_OBJS += smatch_param_set.o
162SMATCH_OBJS += smatch_param_to_mtag_data.o
163SMATCH_OBJS += smatch_param_used.o
164SMATCH_OBJS += smatch_parse_call_math.o
165SMATCH_OBJS += smatch_passes_array_size.o
166SMATCH_OBJS += smatch_project.o
167SMATCH_OBJS += smatch_ranges.o
168SMATCH_OBJS += smatch_real_absolute.o
169SMATCH_OBJS += smatch_recurse.o
170SMATCH_OBJS += smatch_returns.o
171SMATCH_OBJS += smatch_return_to_param.o
172SMATCH_OBJS += smatch_scope.o
173SMATCH_OBJS += smatch_slist.o
174SMATCH_OBJS += smatch_start_states.o
175SMATCH_OBJS += smatch_statement_count.o
176SMATCH_OBJS += smatch_states.o
177SMATCH_OBJS += smatch_stored_conditions.o
178SMATCH_OBJS += smatch_string_list.o
179SMATCH_OBJS += smatch_strings.o
180SMATCH_OBJS += smatch_strlen.o
181SMATCH_OBJS += smatch_struct_assignment.o
182SMATCH_OBJS += smatch_sval.o
183SMATCH_OBJS += smatch_tracker.o
184SMATCH_OBJS += smatch_type_links.o
185SMATCH_OBJS += smatch_type.o
186SMATCH_OBJS += smatch_type_val.o
187SMATCH_OBJS += smatch_unknown_value.o
188SMATCH_OBJS += smatch_untracked_param.o
189SMATCH_OBJS += smatch_var_sym.o
190SMATCH_OBJS += smatch_parsed_conditions.o
191
192SMATCH_CHECK_OBJS:sh=ls src/check_*.c | sed -e 's+\.c+.o+;s+src/++;'
193
194OBJS = smatch.o $(LIB_OBJS) $(SMATCH_OBJS) $(SMATCH_CHECK_OBJS)
195
196SMATCH_DATA = \
197	illumos_kernel.skipped_functions \
198	illumos_user.skipped_functions
199
200SMATCH_DB_DATA =
201SMATCH_DB_DATA += call_implies.schema
202SMATCH_DB_DATA += function_ptr.schema
203SMATCH_DB_DATA += mtag_map.schema
204SMATCH_DB_DATA += caller_info.schema
205SMATCH_DB_DATA += function_type.schema
206SMATCH_DB_DATA += param_map.schema
207SMATCH_DB_DATA += common_caller_info.schema
208SMATCH_DB_DATA += function_type_info.schema
209SMATCH_DB_DATA += parameter_name.schema
210SMATCH_DB_DATA += constraints.schema
211SMATCH_DB_DATA += function_type_size.schema
212SMATCH_DB_DATA += return_implies.schema
213SMATCH_DB_DATA += constraints_required.schema
214SMATCH_DB_DATA += function_type_value.schema
215SMATCH_DB_DATA += return_states.schema
216SMATCH_DB_DATA += data_info.schema
217SMATCH_DB_DATA += local_values.schema
218SMATCH_DB_DATA += sink_info.schema
219SMATCH_DB_DATA += db.schema
220SMATCH_DB_DATA += mtag_about.schema
221SMATCH_DB_DATA += type_info.schema
222SMATCH_DB_DATA += fn_data_link.schema
223SMATCH_DB_DATA += mtag_alias.schema
224SMATCH_DB_DATA += type_size.schema
225SMATCH_DB_DATA += fn_ptr_data_link.schema
226SMATCH_DB_DATA += mtag_data.schema
227SMATCH_DB_DATA += mtag_info.schema
228SMATCH_DB_DATA += type_value.schema
229
230ROOTONBLDDATAFILES = $(SMATCH_DATA:%=$(SMATCHDATADIR)/smatch_data/%)
231ROOTONBLDDATAFILES += $(SMATCH_DB_DATA:%=$(SMATCHDATADIR)/smatch_data/db/%)
232
233BUILT_HEADERS = src/version.h src/check_list_local.h
234
235.KEEP_STATE:
236
237.PARALLEL: $(OBJS)
238
239all: $(PROG)
240
241install: all .WAIT $(ROOTONBLDMACHPROG) $(ROOTONBLDDATAFILES)
242
243clean:
244	rm -f $(OBJS) $(BUILT_HEADERS)
245
246$(ROOTONBLDDATAFILES): $(SMATCHDATADIR)/smatch_data/db
247
248$(SMATCHDATADIR)/smatch_data/%: src/smatch_data/%
249	$(INS.file)
250
251$(SMATCHDATADIR)/smatch_data/db:
252	$(INS.dir)
253
254$(SMATCHDATADIR)/smatch_data:
255	$(INS.dir)
256
257$(PROG): $(OBJS)
258	$(LINK.c) $(OBJS) -o $@ $(LDLIBS)
259	$(POST_PROCESS)
260
261%.o: src/%.c $(BUILT_HEADERS)
262	$(COMPILE.c) -o $@ $<
263
264%.o: src/cwchash/%.c
265	$(COMPILE.c) -o $@ $<
266
267src/check_list_local.h:
268	touch src/check_list_local.h
269
270src/version.h:
271	echo '#define SPARSE_VERSION "$(SPARSE_VERSION)"' > src/version.h
272
273include ../Makefile.targ
274