| 1 |
########################################################################## |
| 2 |
# # |
| 3 |
# This file is part of Frama-C. # |
| 4 |
# # |
| 5 |
# Copyright (C) 2007-2022 # |
| 6 |
# CEA (Commissariat à l'énergie atomique et aux énergies # |
| 7 |
# alternatives) # |
| 8 |
# # |
| 9 |
# you can redistribute it and/or modify it under the terms of the GNU # |
| 10 |
# Lesser General Public License as published by the Free Software # |
| 11 |
# Foundation, version 2.1. # |
| 12 |
# # |
| 13 |
# It is distributed in the hope that it will be useful, # |
| 14 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of # |
| 15 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # |
| 16 |
# GNU Lesser General Public License for more details. # |
| 17 |
# # |
| 18 |
# See the GNU Lesser General Public License version 2.1 # |
| 19 |
# for more details (enclosed in the file licenses/LGPLv2.1). # |
| 20 |
# # |
| 21 |
########################################################################## |
| 22 |
|
| 23 |
# Makefile for Frama-C/Eva case studies. |
| 24 |
# This file is included by epilogue.mk, when using template.mk. |
| 25 |
# See the Frama-C User Manual for more details. |
| 26 |
# |
| 27 |
# This Makefile uses the following variables. |
| 28 |
# |
| 29 |
# FRAMAC frama-c binary |
| 30 |
# FRAMAC_GUI frama-c gui binary |
| 31 |
# CPPFLAGS preprocessing flags |
| 32 |
# MACHDEP machdep |
| 33 |
# FCFLAGS general flags to use with frama-c |
| 34 |
# FCGUIFLAGS flags to use with frama-c-gui |
| 35 |
# EVAFLAGS flags to use with the Eva plugin |
| 36 |
# EVABUILTINS Eva builtins to be set (via -eva-builtin) |
| 37 |
# EVAUSESPECS Eva functions to be overridden by specs (-eva-use-spec) |
| 38 |
# WPFLAGS flags to use with the WP plugin |
| 39 |
# |
| 40 |
# FLAMEGRAPH If set (to any value), running an analysis will produce an |
| 41 |
# SVG + HTML flamegraph at the end. |
| 42 |
# |
| 43 |
# There are several ways to define or change these variables. |
| 44 |
# |
| 45 |
# With an environment variable: |
| 46 |
# export FRAMAC=~/bin/frama-c |
| 47 |
# make |
| 48 |
# |
| 49 |
# With command line arguments: |
| 50 |
# make FRAMAC=~/bin/frama-c |
| 51 |
# |
| 52 |
# In your Makefile, when you want to change a parameter for all analyses: |
| 53 |
# FCFLAGS += -verbose 2 |
| 54 |
# |
| 55 |
# In your Makefile, for a single target : |
| 56 |
# target.eva: FCFLAGS += -main my_main |
| 57 |
# |
| 58 |
# For each analysis target, you must give the list of sources to be analyzed |
| 59 |
# by adding them as prerequisites of target.parse, as in: |
| 60 |
# |
| 61 |
# target.parse: file1.c file2.c file3.c... |
| 62 |
# |
| 63 |
|
| 64 |
# Test if Makefile is > 4.0 |
| 65 |
ifneq (4.0,$(firstword $(sort $(MAKE_VERSION) 4.0))) |
| 66 |
$(error This Makefile requires Make >= 4.0 - available at http://ftp.gnu.org/gnu/make/) |
| 67 |
endif |
| 68 |
|
| 69 |
# Test if sed has the '--unbuffered' option (GNU sed has, but neither macOS' |
| 70 |
# nor Busybox' have it, in which case we ignore it) |
| 71 |
SED_UNBUFFERED:=sed$(shell sed --unbuffered //p /dev/null 2>/dev/null && echo " --unbuffered" || true) |
| 72 |
|
| 73 |
# If there is a GNU time in the PATH, which contains the desired options |
| 74 |
# (-f and -o), use them; otherwise, use any time (be it a shell builtin |
| 75 |
# or a command). 'env' allows bypassing shell builtins (if they exist), |
| 76 |
# since they usually don't have the required options. |
| 77 |
ifeq (OK,$(shell env time -f 'test' -o '/dev/null' echo OK || echo KO)) |
| 78 |
define time_with_output |
| 79 |
env time -f 'user_time=%U\nmemory=%M' -o "$(1)" |
| 80 |
endef |
| 81 |
else |
| 82 |
define time_with_output |
| 83 |
time |
| 84 |
endef |
| 85 |
endif |
| 86 |
|
| 87 |
# --- Utilities --- |
| 88 |
|
| 89 |
define display_command = |
| 90 |
@{ |
| 91 |
echo ''; |
| 92 |
[ -t 1 ] && tput setaf 4; |
| 93 |
echo "Command: $(strip $(1))"; |
| 94 |
[ -t 1 ] && tput sgr0; |
| 95 |
echo ''; |
| 96 |
} |
| 97 |
endef |
| 98 |
|
| 99 |
empty := |
| 100 |
space := $(empty) $(empty) |
| 101 |
comma := , |
| 102 |
|
| 103 |
fc_list = $(subst $(space),$(comma),$(strip $1)) |
| 104 |
|
| 105 |
|
| 106 |
# --- Default configuration --- |
| 107 |
|
| 108 |
FRAMAC ?= frama-c |
| 109 |
FRAMAC_SCRIPT = $(FRAMAC)-script |
| 110 |
FRAMAC_GUI ?= frama-c-gui |
| 111 |
EVAFLAGS ?= \ |
| 112 |
-eva-no-print -eva-no-show-progress -eva-msg-key=-initial-state \ |
| 113 |
-eva-print-callstacks -eva-warn-key alarm=inactive \ |
| 114 |
-no-deps-print -no-calldeps-print \ |
| 115 |
-eva-warn-key garbled-mix \ |
| 116 |
-calldeps -from-verbose 0 \ |
| 117 |
$(if $(EVABUILTINS), -eva-builtin=$(call fc_list,$(EVABUILTINS)),) \ |
| 118 |
$(if $(EVAUSESPECS), -eva-use-spec $(call fc_list,$(EVAUSESPECS)),) |
| 119 |
WPFLAGS ?= |
| 120 |
FCFLAGS ?= |
| 121 |
FCGUIFLAGS ?= |
| 122 |
|
| 123 |
export LIBOVERLAY_SCROLLBAR=0 |
| 124 |
|
| 125 |
|
| 126 |
# --- Cleaning --- |
| 127 |
|
| 128 |
.PHONY: clean |
| 129 |
clean:: |
| 130 |
$(RM) -r *.parse *.eva |
| 131 |
|
| 132 |
clean-backups: |
| 133 |
find . -regextype posix-extended \ |
| 134 |
-regex '^.*_[0-9]{4}-[0-9]{2}-[0-9]{2}_[0-9]{2}-[0-9]{2}-[0-9]{2}\.eva(\.(log|stats|alarms|warnings|metrics))?' \ |
| 135 |
-delete |
| 136 |
|
| 137 |
|
| 138 |
# --- Generic rules --- |
| 139 |
|
| 140 |
HR_TIMESTAMP := $(shell date +"%H:%M:%S %d/%m/%Y")# Human readable |
| 141 |
DIR := $(dir $(lastword $(MAKEFILE_LIST))) |
| 142 |
SHELL := $(shell which bash) |
| 143 |
.SHELLFLAGS := -eu -o pipefail -c |
| 144 |
|
| 145 |
.ONESHELL: |
| 146 |
.SECONDEXPANSION: |
| 147 |
.FORCE: |
| 148 |
.SUFFIXES: # Disable make builtins |
| 149 |
|
| 150 |
%.parse/command %.eva/command %.wp/command: |
| 151 |
@# |
| 152 |
|
| 153 |
%.parse: SOURCES = $(filter-out %/command,$^) |
| 154 |
%.parse: PARSE = $(FRAMAC) $(FCFLAGS) $(if $(value MACHDEP),-machdep $(MACHDEP),) -cpp-extra-args="$(CPPFLAGS)" $(SOURCES) |
| 155 |
%.parse: $$(if $$^,,.IMPOSSIBLE) $$(shell $(DIR)cmd-dep.sh $$@/command $$(PARSE)) |
| 156 |
@$(call display_command,$(PARSE)) |
| 157 |
mkdir -p $@ |
| 158 |
mv -f $@/{command,running} |
| 159 |
{ |
| 160 |
$(call time_with_output,$@/stats.txt) \ |
| 161 |
$(PARSE) \ |
| 162 |
-kernel-log w:$@/warnings.log \ |
| 163 |
-variadic-log w:$@/warnings.log \ |
| 164 |
-metrics -metrics-log a:$@/metrics.log \ |
| 165 |
-save $@/framac.sav \ |
| 166 |
-print -ocode $@/framac.ast -then -no-print \ |
| 167 |
|| ($(RM) $@/stats.txt && false) # Prevents having error code reporting in stats.txt |
| 168 |
} 2>&1 | |
| 169 |
$(SED_UNBUFFERED) '/\[metrics\]/,999999d' | |
| 170 |
tee $@/parse.log |
| 171 |
{ |
| 172 |
printf 'timestamp=%q\n' "$(HR_TIMESTAMP)"; |
| 173 |
printf 'warnings=%s\n' "`cat $@/warnings.log | grep ':\[kernel\]' | wc -l`"; |
| 174 |
printf 'cmd_args=%q\n' "$(subst ",\",$(wordlist 2,999,$(PARSE)))" |
| 175 |
} >> $@/stats.txt |
| 176 |
mv $@/{running,command} |
| 177 |
touch $@ # Update timestamp and prevent remake if nothing changes |
| 178 |
|
| 179 |
%.eva: EVA = $(FRAMAC) $(FCFLAGS) -eva $(EVAFLAGS) |
| 180 |
%.eva: PARSE_RESULT = $(word 1,$(subst ., ,$*)).parse |
| 181 |
%.eva: $$(PARSE_RESULT) $$(shell $(DIR)cmd-dep.sh $$@/command $$(EVA)) $(if $(BENCHMARK),.FORCE,) |
| 182 |
@$(call display_command,$(EVA)) |
| 183 |
mkdir -p $@ |
| 184 |
mv -f $@/{command,running} |
| 185 |
{ |
| 186 |
$(call time_with_output,$@/stats.txt) \ |
| 187 |
$(EVA) \ |
| 188 |
-load $(PARSE_RESULT)/framac.sav -save $@/framac.sav \ |
| 189 |
-eva-flamegraph $@/flamegraph.txt \ |
| 190 |
-kernel-log w:$@/warnings.log \ |
| 191 |
-from-log w:$@/warnings.log \ |
| 192 |
-inout-log w:$@/warnings.log \ |
| 193 |
-scope-log w:$@/warnings.log \ |
| 194 |
-eva-log w:$@/warnings.log \ |
| 195 |
-then \ |
| 196 |
-report-csv $@/alarms.csv -report-no-proven \ |
| 197 |
-report-log w:$@/warnings.log \ |
| 198 |
-metrics-eva-cover \ |
| 199 |
-metrics-log a:$@/metrics.log \ |
| 200 |
-nonterm -nonterm-log a:$@/nonterm.log \ |
| 201 |
|| ($(RM) $@/stats.txt && false) # Prevents having error code reporting in stats.txt |
| 202 |
} 2>&1 | |
| 203 |
$(SED_UNBUFFERED) '/\[eva\] Values at end of function/,999999d' | |
| 204 |
tee $@/eva.log |
| 205 |
$(DIR)parse-coverage.sh $@/eva.log $@/stats.txt |
| 206 |
{ |
| 207 |
printf 'timestamp=%q\n' "$(HR_TIMESTAMP)"; |
| 208 |
printf 'warnings=%s\n' "`cat $@/warnings.log | grep ':\[\(eva\|kernel\|from\)\]' | wc -l`"; |
| 209 |
printf 'alarms=%s\n' "`expr $$(cat $@/alarms.csv | wc -l) - 1`"; |
| 210 |
printf 'cmd_args=%q\n' "$(subst ",\",$(wordlist 2,999,$(EVA)))"; |
| 211 |
printf 'benchmark_tag=%s' "$(BENCHMARK)" |
| 212 |
} >> $@/stats.txt |
| 213 |
if [ ! -z $${FLAMEGRAPH+x} ]; then |
| 214 |
NOGUI=1 $(FRAMAC_SCRIPT) flamegraph $@/flamegraph.txt $@/ |
| 215 |
fi |
| 216 |
mv $@/{running,command} |
| 217 |
touch $@ # Update timestamp and prevents remake if nothing changes |
| 218 |
|
| 219 |
%.wp: WP = $(FRAMAC) $(FCFLAGS) -wp $(WPFLAGS) |
| 220 |
%.wp: PARSE_RESULT = $(word 1,$(subst ., ,$*)).parse |
| 221 |
%.wp: $$(PARSE_RESULT) $$(shell $(DIR)cmd-dep.sh $$@/command $$(WP)) $(if $(BENCHMARK),.FORCE,) |
| 222 |
@$(call display_command,$(WP)) |
| 223 |
mkdir -p $@ |
| 224 |
mv -f $@/{command,running} |
| 225 |
{ |
| 226 |
$(call time_with_output,$@/stats.txt) \ |
| 227 |
$(WP) \ |
| 228 |
-load $(PARSE_RESULT)/framac.sav -save $@/framac.sav \ |
| 229 |
-kernel-log w:$@/warnings.log \ |
| 230 |
-wp-log w:$@/warnings.log \ |
| 231 |
-then \ |
| 232 |
-report-csv $@/alarms.csv -report-no-proven \ |
| 233 |
-report-log w:$@/warnings.log \ |
| 234 |
|| ($(RM) $@/stats.txt && false) # Prevents having error code reporting in stats.txt |
| 235 |
} 2>&1 | |
| 236 |
tee $@/wp.log |
| 237 |
{ |
| 238 |
printf 'timestamp=%q\n' "$(HR_TIMESTAMP)"; |
| 239 |
printf 'warnings=%s\n' "`cat $@/warnings.log | grep ':\[\(wp\|kernel\)\]' | wc -l`"; |
| 240 |
printf 'alarms=%s\n' "`expr $$(cat $@/alarms.csv | wc -l) - 1`"; |
| 241 |
printf 'cmd_args=%q\n' "$(subst ",\",$(wordlist 2,999,$(WP)))"; |
| 242 |
printf 'benchmark_tag=%s' "$(BENCHMARK)" |
| 243 |
} >> $@/stats.txt |
| 244 |
mv $@/{running,command} |
| 245 |
touch $@ # Update timestamp and prevent remake if nothing changes |
| 246 |
|
| 247 |
%.gui: % |
| 248 |
$(FRAMAC_GUI) $(FCGUIFLAGS) -load $^/framac.sav & |
| 249 |
|
| 250 |
# Produce and open an SVG + HTML from raw flamegraph data produced by Eva |
| 251 |
%/flamegraph: %/flamegraph.html |
| 252 |
@ |
| 253 |
case "$$OSTYPE" in |
| 254 |
cygwin*) cmd /c start "$^";; |
| 255 |
linux*) xdg-open "$^";; |
| 256 |
darwin*) open "$^";; |
| 257 |
esac |
| 258 |
|
| 259 |
%/flamegraph.html %/flamegraph.svg: %/flamegraph.txt |
| 260 |
NOGUI=1 $(FRAMAC_SCRIPT) flamegraph $^ $(dir $^) |
| 261 |
|
| 262 |
.PRECIOUS: %/flamegraph.html |
| 263 |
|
| 264 |
# clean is generally not the default goal, but if there is no default |
| 265 |
# rule when including this file, it would be. |
| 266 |
|
| 267 |
ifeq ($(.DEFAULT_GOAL),clean) |
| 268 |
.DEFAULT_GOAL := |
| 269 |
endif |