From 08c5f9712ad52546f2fa8a7ffd57d06ff2d9d5da Mon Sep 17 00:00:00 2001 From: Arkaprabha Chakraborty Date: Mon, 22 Jan 2024 07:11:49 +0530 Subject: [PATCH] Update Makefile for build improvements and testing Commit details: - Set optimization level to O3 and include pedantic warnings in CXXFLAGS. - Introduce separate build and source directories for better project organization. - Add a target to run tests with the ENABLE_TESTS macro. - Improve the 'all' target to create the build directory before building the executable. - Introduce a 'rebuild' target for cleaning and rebuilding the project. Changes made in Makefile: - Update CXXFLAGS with -O3 and -pedantic. - Introduce BUILD_DIR and SRC_DIR variables for better organization. - Modifie SOURCE to point to the source file within the source directory. - Update EXECUTABLE to exclude the file extension. - Update 'all' target to create the build directory. - Add 'test' target to run tests with the ENABLE_TESTS macro. - Add 'rebuild' target for cleaning and rebuilding the project. --- Makefile | 36 ++++++++++++++++++++++++------------ 1 file changed, 24 insertions(+), 12 deletions(-) diff --git a/Makefile b/Makefile index 642bce1..31eeb9f 100644 --- a/Makefile +++ b/Makefile @@ -1,18 +1,30 @@ CXX = clang++ -CXXFLAGS = -std=c++17 -Wall -Wextra -SOURCE = main.cxx -EXECUTABLE = ast.out +CXXFLAGS = -O3 -std=c++17 -Wall -Wextra -pedantic +BUILD_DIR = build +SRC_DIR = src +SOURCE = ast.cxx +EXECUTABLE = ast -# Build target -all: $(EXECUTABLE) +all: $(BUILD_DIR) $(BUILD_DIR)/$(EXECUTABLE) -# Rule to build the executable -$(EXECUTABLE): $(SOURCE) - @$(CXX) $(CXXFLAGS) -o $@ $< +$(BUILD_DIR): + mkdir -p $@ -run: $(EXECUTABLE) - @./$(EXECUTABLE) +$(BUILD_DIR)/$(EXECUTABLE): $(SRC_DIR)/$(SOURCE) $(BUILD_DIR) + $(CXX) $(CXXFLAGS) -o $@ $< -# Clean up generated files +.PHONY: run +run: $(BUILD_DIR)/$(EXECUTABLE) + ./$< + +.PHONY: test +test: CXXFLAGS += -DENABLE_TESTS +test: $(BUILD_DIR)/$(EXECUTABLE) + ./$< --run-test + +.PHONY: clean clean: - @rm -f $(EXECUTABLE) + rm -rf $(BUILD_DIR) + +.PHONY: rebuild +rebuild: clean all