From dfb14b5c4a48f8b1bb8d1c20f8d25a3b3bb1606c Mon Sep 17 00:00:00 2001 From: Cory Date: Sun, 24 Sep 2023 14:40:59 +0200 Subject: [PATCH] Create better Makefile --- src/Makefile | 30 +++++++++++++++++++++++------- 1 file changed, 23 insertions(+), 7 deletions(-) diff --git a/src/Makefile b/src/Makefile index 443b225..80cd25b 100644 --- a/src/Makefile +++ b/src/Makefile @@ -1,18 +1,34 @@ -INCLUDE=../include - CC=g++ -CCFLAGS=-larmadillo -llapack -std=c++11 +LIBSRCS=utils.cpp matrix.cpp jacobi.cpp +LIBOBJS=$(LIBSRCS:.cpp=.o) + +INCLUDE=../include + +CFLAGS=-larmadillo -llapack -std=c++11 + +DEBUG ?= 0 +ifeq ($(DEBUG), 1) + DBGFLAG=-DDBG +else + DBGFLAG= +endif -DEBUG=-DDBG .PHONY: clean -test_suite: test_suite.o matrix.o jacobi.o - $(CC) $^ -o $@ $(CCFLAGS) $(DEBUG) +all: test_suite main +# Rules for executables +main: main.o $(LIBOBJS) + $(CC) $^ -o $@ $(CFLAGS) $(DBGFLAG) -I$(INCLUDE) + +test_suite: test_suite.o $(LIBOBJS) + $(CC) $^ -o $@ $(CFLAGS) $(DBGFLAG) -I$(INCLUDE) + +# Rule for object files %.o: %.cpp - $(CC) -c $^ -o $@ -I $(INCLUDE) $(DEBUG) + $(CC) -c $^ -o $@ $(DBGFLAG) -I$(INCLUDE) clean: rm *.o