squiggle.c/examples/04_sample_from_cdf_simple/makefile

59 lines
1.5 KiB
Makefile
Raw Normal View History

2023-07-15 21:26:48 +00:00
# Interface:
# make
# make build
# make format
# make run
# Compiler
CC=gcc # required for nested functions
# CC=tcc # <= faster compilation
# Main file
SRC=example.c ../../squiggle.c ../../squiggle_more.c
2023-07-16 19:28:03 +00:00
OUTPUT=./example
2023-07-15 21:26:48 +00:00
## Dependencies
OPENMP=-fopenmp
2023-07-15 21:26:48 +00:00
MATH=-lm
DEPENDENCIES=$(MATH) $(OPENMP)
2023-07-15 21:26:48 +00:00
# OPENMP=-fopenmp
## Flags
DEBUG= #'-g'
STANDARD=-std=c99 ## gnu99 allows for nested functions.
2023-07-15 21:26:48 +00:00
EXTENSIONS= #-fnested-functions
WARNINGS=-Wall
OPTIMIZED=-O3#-Ofast
CFLAGS=$(DEBUG) $(STANDARD) $(EXTENSIONS) $(WARNINGS) $(OPTIMIZED)
## Formatter
STYLE_BLUEPRINT=webkit
FORMATTER=clang-format -i -style=$(STYLE_BLUEPRINT)
## make build
build: $(SRC)
2023-07-16 19:28:03 +00:00
# gcc -std=gnu99 example.c -lm -o example
2023-07-15 21:26:48 +00:00
$(CC) $(CFLAGS) $(SRC) $(DEPENDENCIES) -o $(OUTPUT)
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)"
@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
## 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)
2023-07-15 21:26:48 +00:00
sudo perf report
rm perf.data