uthread/Makefile
2025-03-14 17:57:50 +01:00

75 lines
1.4 KiB
Makefile

build_dir?=build
src_dir?=src
tst_dir?=tst
install_dir?=install
bins?= \
01-main \
02-switch \
03-equity \
11-join \
12-join-main \
21-create-many \
22-create-many-recursive \
23-create-many-once \
31-switch-many \
32-switch-many-join \
33-switch-many-cascade \
51-fibonacci \
61-mutex \
62-mutex \
71-preemption \
81-deadlock
bins_target=$(addprefix ${build_dir}/,${bins})
install_bins_targets=$(addprefix ${install_dir}/bin/,${bins})
src_dirs=$(sort $(dir $(wildcard ${src_dir}/**/)))
includes=$(patsubst %,-I%,${src_dirs})
CFLAGS+=-g -O0 -std=c99 ${includes} -lpthread
LDFLAGS+=
srcs+=$(wildcard ${src_dir}/*.c ${src_dir}/**/*.c)
objs+=$(patsubst %.c,${build_dir}/%.o,${srcs})
.PHONY: all
all: build
.PHONY: install
install: build ${install_bins_targets}
.PHONY: ${install_bins_targets}
${install_bins_targets}: ${install_dir}/bin/%: ${build_dir}/%
@mkdir -p $(dir $@)
install $^ $@
.PHONY: graphs
graphs:
true
.PHONY: valgrind
valgrind: build
valgrind --leak-check=full --show-reachable=yes --track-origins=yes
.PHONY: build
build: ${bins_target}
.PHONY: check
check:
true
${bins_target}: ${build_dir}/%: ${objs} ${build_dir}/${tst_dir}/%.o
${CC} -o $@ $^ ${CFLAGS} ${LDFLAGS}
${build_dir}/%.o: %.c
@mkdir -p $(dir $@)
${CC} -o $@ -c $^ ${CFLAGS}
.PHONY: compile_flags.txt
compile_flags.txt:
(echo "${CFLAGS} ${LDFLAGS}" | sed 's/ /\n/g') > compile_flags.txt
.PHONY: clean
clean:
${RM} -rf build main