2023-09-27 14:25:12 +00:00
# Interface:
# make
# make build
# make format
# make run
# Compiler
2023-11-18 21:00:02 +00:00
CC = gcc # required for nested functions
2023-09-27 14:25:12 +00:00
# CC=tcc # <= faster compilation
# Main file
2023-11-18 21:00:02 +00:00
SRC = example.c ../../squiggle.c ../../extra.c
OUTPUT = ./example
2023-09-27 14:25:12 +00:00
## Dependencies
MATH = -lm
2023-11-18 21:00:02 +00:00
DEPENDENCIES = $( MATH)
# OPENMP=-fopenmp
2023-09-27 14:25:12 +00:00
## Flags
DEBUG = #'-g'
2023-11-18 21:00:02 +00:00
STANDARD = -std= c99 ## gnu99 allows for nested functions.
EXTENSIONS = #-fnested-functions
2023-09-27 14:25:12 +00:00
WARNINGS = -Wall
2023-11-18 21:00:02 +00:00
OPTIMIZED = -O3#-Ofast
CFLAGS = $( DEBUG) $( STANDARD) $( EXTENSIONS) $( WARNINGS) $( OPTIMIZED)
2023-09-27 14:25:12 +00:00
## Formatter
STYLE_BLUEPRINT = webkit
FORMATTER = clang-format -i -style= $( STYLE_BLUEPRINT)
## make build
build : $( SRC )
2023-11-18 21:00:02 +00:00
# gcc -std=gnu99 example.c -lm -o example
$( CC) $( CFLAGS) $( SRC) $( DEPENDENCIES) -o $( OUTPUT)
2023-09-27 14:25:12 +00:00
format : $( SRC )
$( FORMATTER) $( SRC)
run : $( SRC ) $( OUTPUT )
./$( OUTPUT) && echo
time-linux :
@echo "Requires /bin/time, found on GNU/Linux systems" && echo
@echo " Running 100x and taking avg time $( OUTPUT) "
2023-11-18 21:00:02 +00:00
@t= $$ ( /usr/bin/time -f "%e" -p bash -c 'for i in {1..100}; do $(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
2023-09-27 14:25:12 +00:00
## Profiling
profile-linux :
echo "Requires perf, which depends on the kernel version, and might be in linux-tools package or similar"
echo "Must be run as sudo"
$( CC) $( SRC) $( MATH) -o $( OUTPUT)
sudo perf record ./$( OUTPUT)
sudo perf report
rm perf.data