diff --git a/.gitignore b/.gitignore index 6c2cec1..edce810 100644 --- a/.gitignore +++ b/.gitignore @@ -3,6 +3,7 @@ /install /tags /.vscode +/.lastpthread /compile_flags.txt # Local History for Visual Studio Code diff --git a/Makefile b/Makefile index cd5530b..033f235 100644 --- a/Makefile +++ b/Makefile @@ -26,14 +26,28 @@ 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 + +CFLAGS+=-g -O0 -std=c99 ${includes} LDFLAGS+= +ifdef _USE_PTHREAD +LDFLAGS+=-lpthread +endif + +# Tests if the last compilation was with pthread +ifeq ("$(wildcard .lastpthread)","") + all_targets:=build + pthread_targets:=clean build +else + pthread_targets:=build + all_targets:=clean build +endif srcs+=$(wildcard ${src_dir}/*.c ${src_dir}/**/*.c) objs+=$(patsubst %.c,${build_dir}/%.o,${srcs}) .PHONY: all -all: build +all: ${all_targets} + ${RM} .lastpthread # Set that the last build was without pthread .PHONY: install install: build ${install_bins_targets} @@ -55,7 +69,8 @@ build: ${bins_target} .PHONY: pthreads pthreads: - true + $(MAKE) _USE_PTHREAD=. ${pthread_targets} + touch .lastpthread .PHONY: check check: @@ -74,4 +89,4 @@ compile_flags.txt: .PHONY: clean clean: - ${RM} -rf build main + ${RM} -r build