2023-11-19 14:32:29 +00:00
# Interface:
# make all
# make format-all
# make run-all
# make one DIR=01_one_sample
# make format-one DIR=01_one_sample
# make run-one DIR=01_one_sample
# make time-linux-one DIR=01_one_sample
# make profile-one DIR=01_one_sample
# Compiler
CC = gcc
# CC=tcc # <= faster compilation
# Main file
SRC = example.c
OUTPUT = example
## Dependencies
SQUIGGLE = ../../squiggle.c
MATH = -lm
DEPS = $( SQUIGGLE) $( MATH)
## Flags
2023-12-09 18:59:53 +00:00
# DEBUG=-fsanitize=address,undefined -fanalyzer
2023-12-09 18:49:20 +00:00
# DEBUG=-g
2023-12-09 18:59:53 +00:00
# DEBUG=
2023-12-09 18:49:20 +00:00
WARN = -Wall -Wextra -Wdouble-promotion -Wconversion
2023-11-19 14:32:29 +00:00
STANDARD = -std= c99
OPTIMIZED = -O3 #-Ofast
## Formatter
STYLE_BLUEPRINT = webkit
FORMATTER = clang-format -i -style= $( STYLE_BLUEPRINT)
## make all
all :
2023-12-09 17:59:41 +00:00
$( CC) $( OPTIMIZED) $( DEBUG) $( WARN) 00_example_template/$( SRC) $( DEPS) -o 00_example_template/$( OUTPUT)
$( CC) $( OPTIMIZED) $( DEBUG) $( WARN) 01_one_sample/$( SRC) $( DEPS) -o 01_one_sample/$( OUTPUT)
$( CC) $( OPTIMIZED) $( DEBUG) $( WARN) 02_time_to_botec/$( SRC) $( DEPS) -o 02_time_to_botec/$( OUTPUT)
$( CC) $( OPTIMIZED) $( DEBUG) $( WARN) 03_gcc_nested_function/$( SRC) $( DEPS) -o 03_gcc_nested_function/$( OUTPUT)
2023-12-09 17:31:32 +00:00
$( CC) $( OPTIMIZED) $( DEBUG) $( WARN) 04_gamma_beta/$( SRC) $( DEPS) -o 04_gamma_beta/$( OUTPUT)
$( CC) $( OPTIMIZED) $( DEBUG) $( WARN) 05_hundred_lognormals/$( SRC) $( DEPS) -o 05_hundred_lognormals/$( OUTPUT)
2023-11-19 14:32:29 +00:00
format-all :
$( FORMATTER) 00_example_template/$( SRC)
$( FORMATTER) 01_one_sample/$( SRC)
$( FORMATTER) 02_time_to_botec/$( SRC)
$( FORMATTER) 03_gcc_nested_function/$( SRC)
$( FORMATTER) 04_gamma_beta/$( SRC)
$( FORMATTER) 05_hundred_lognormals/$( SRC)
run-all :
00_example_template/$( OUTPUT)
01_one_sample/$( OUTPUT)
02_time_to_botec/$( OUTPUT)
03_gcc_nested_function/$( OUTPUT)
04_gamma_beta/$( OUTPUT)
05_hundred_lognormals/$( OUTPUT)
## make one DIR=01_one_sample
one : $( DIR ) /$( SRC )
2023-12-09 17:31:32 +00:00
$( CC) $( OPTIMIZED) $( DEBUG) $( WARN) $( DIR) /$( SRC) $( DEPS) -o $( DIR) /$( OUTPUT)
2023-11-19 14:32:29 +00:00
## make format-one DIR=01_one_sample
format-one : $( DIR ) /$( SRC )
$( FORMATTER) $( DIR) /$( SRC)
## make run-one DIR=01_one_sample
run-one : $( DIR ) /$( OUTPUT )
$( DIR) /$( OUTPUT) && echo
## make time-linux-one DIR=01_one_sample
time-linux-one : $( DIR ) /$( OUTPUT )
@echo "Requires /bin/time, found on GNU/Linux systems" && echo
@echo " Running 100x and taking avg time $( DIR) / $( OUTPUT) "
@t= $$ ( /usr/bin/time -f "%e" -p bash -c 'for i in {1..100}; do $(DIR)/$(OUTPUT); done' 2>& 1 >/dev/null | grep real | awk '{print $$2}' ) ; echo " scale=2; 1000 * $$ t / 100 " | bc | sed "s|^|Time using 1 thread: |" | sed 's|$$|ms|' && echo
## e.g., make profile-linux-one DIR=01_one_sample
profile-linux-one :
echo "Requires perf, which depends on the kernel version, and might be in linux-tools package or similar"
echo "Must be run as sudo"
2023-12-09 17:31:32 +00:00
$( CC) $( OPTIMIZED) $( DEBUG) $( WARN) $( DIR) /$( SRC) $( DEPS) -o $( DIR) /$( OUTPUT)
2023-11-19 14:32:29 +00:00
# $(CC) $(SRC) $(DEPS) -o $(OUTPUT)
sudo perf record $( DIR) /$( OUTPUT)
sudo perf report
rm perf.data