From b4d4683f8dfa45daf481e6e980a4cd1d0efda62b Mon Sep 17 00:00:00 2001 From: Seth Hamilton Date: Sat, 9 Aug 2025 20:38:03 -0500 Subject: [PATCH] makefile seems to be in a decent state. auto-generates compile_commands.json --- .gitignore | 1 + makefile | 64 ++++++++++++++++++++++++++++++++++++++++++------- src/genetic.cpp | 2 +- 3 files changed, 58 insertions(+), 9 deletions(-) diff --git a/.gitignore b/.gitignore index 32f3587..5a6225b 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ **PTHREADS-BUILT** **obj** **bin** +.cache** diff --git a/makefile b/makefile index 9c2d332..8d622e1 100644 --- a/makefile +++ b/makefile @@ -1,13 +1,61 @@ -src_files = $(find src -iname "*.cpp") -obj_files = $(src_files:%.cpp=%.o) +src_files = $(shell find src -iname "*.cpp") +obj_files = $(src_files:src/%.cpp=obj/%.o) + + +ifeq ($(OS),Windows_NT) + CCFLAGS += -D WIN32 -Iext/PTHREADS-BUILT/include + PTHREADLIB = ext/PTHREADS-BUILT/lib/pthreadVCE3.lib + ifeq ($(PROCESSOR_ARCHITEW6432),AMD64) + CCFLAGS += -D AMD64 + else + ifeq ($(PROCESSOR_ARCHITECTURE),AMD64) + CCFLAGS += -D AMD64 + endif + ifeq ($(PROCESSOR_ARCHITECTURE),x86) + CCFLAGS += -D IA32 + endif + endif +else + UNAME_S := $(shell uname -s) + ifeq ($(UNAME_S),Linux) + CCFLAGS += -D LINUX + endif + ifeq ($(UNAME_S),Darwin) + CCFLAGS += -D OSX + endif + UNAME_P := $(shell uname -p) + ifeq ($(UNAME_P),x86_64) + CCFLAGS += -D AMD64 + endif + ifneq ($(filter %86,$(UNAME_P)),) + CCFLAGS += -D IA32 + endif + ifneq ($(filter arm%,$(UNAME_P)),) + CCFLAGS += -D ARM + endif +endif + +debug: OPTIMIZATION_FLAG = -g +release: OPTIMIZATION_FLAG = -O3 + +release: all export_comp_db + +debug: all export_comp_db all: $(obj_files) - echo $(obj_files) - echo $(src_files) - g++ -o main $^ + @ mkdir -p bin + g++ -I inc/ $^ $(PTHREADLIB) -o bin/main $(OPTIMIZATION_FLAG) $(CCFLAGS) -%.o: %.cpp - g++ -o $@ $< +obj/%.o: src/%.cpp + @ mkdir -p obj + g++ -I inc/ -c $< -o $@ $(OPTIMIZATION_FLAG) $(CCFLAGS) + +export_comp_db: + echo [ > compile_commands.json + make debug -B --dry-run > temp + awk '/g\+\+.*\.cpp/ { f="compile_commands.json"; printf "\t\{\n\t\t\"directory\": \"%s\",\n\t\t\"command\": \"%s\",\n\t\t\"file\": \"%s\"\n\t\},\n", ENVIRON["PWD"], $$0, $$5 >> f }' temp + echo ] >> compile_commands.json + rm temp clean: - rm -f *.o *.exe + rm -f obj/*.o bin/*.exe diff --git a/src/genetic.cpp b/src/genetic.cpp index f0b1ff4..f90eca6 100644 --- a/src/genetic.cpp +++ b/src/genetic.cpp @@ -1,7 +1,7 @@ #include "genetic.h" +#include "pthread.h" #include #include -#include namespace genetic {