From 73cdffb0c669fada2831bc7d46a7d12e49f3483d Mon Sep 17 00:00:00 2001 From: "Marcus M. Darden" <mmdarden@umich.edu> Date: Thu, 23 May 2019 10:41:53 -0400 Subject: [PATCH] Reimplement 'make all' % make all This now builds executable, executable_debug, and executable_profile. This will allow for easy implementation of the autograder building and testing student solutions. When a SIG occurs, the AG can then run valgrind with a debug build, to give improved feedback to students. Build objects (.o files) are now only created for release builds. Therefore, any .o file found in the directory will be compiled with -O3 and -DNDEBUG. The other two build targets (debug and profile) are compiled directly from source to executable. This should prevent any unfortunate hybrid builds. Some minor documentation and formatting updates were also made. --- Makefile | 32 +++++++++++++++++++------------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/Makefile b/Makefile index bb48e51..166c892 100644 --- a/Makefile +++ b/Makefile @@ -21,15 +21,14 @@ # TODO (begin) # ####################### # Change IDENTIFIER to match the project identifier given in the project spec. -IDENTIFIER = EEC50281EEC50281EEC50281EEC50281EEC50281 +IDENTIFIER = EEC50281EEC50281EEC50281EEC50281EEC50281 # Change EXECUTABLE to match the command name given in the project spec. EXECUTABLE = executable -DEBUG = $(EXECUTABLE)_debug -# The following line looks for a project's main() in a file named project*.cpp, +# The following line looks for a project's main() in files named project*.cpp, # executable.cpp (substituted from EXECUTABLE above), or main.cpp -PROJECTFILE = $(or $(wildcard project*.cpp), $(wildcard $(EXECUTABLE).cpp), main.cpp) +PROJECTFILE = $(or $(wildcard project*.cpp $(EXECUTABLE).cpp), main.cpp) # If main() is in another file delete line above, edit and uncomment below #PROJECTFILE = mymainfile.cpp ####################### @@ -76,15 +75,16 @@ CXXFLAGS = -std=c++1z -Wconversion -Wall -Werror -Wextra -pedantic release: CXXFLAGS += -O3 -DNDEBUG release: $(EXECUTABLE) -# make debug - will compile "all" with $(CXXFLAGS) and the -g flag +# make debug - will compile sources with $(CXXFLAGS) and the -g3 flag # also defines DEBUG, so "#ifdef DEBUG /*...*/ #endif" works -debug: EXECUTABLE := $(DEBUG) debug: CXXFLAGS += -g3 -DDEBUG -debug: clean $(EXECUTABLE) +debug: + $(CXX) $(CXXFLAGS) $(SOURCES) -o $(EXECUTABLE)_debug # make profile - will compile "all" with $(CXXFLAGS) and the -pg flag profile: CXXFLAGS += -pg -profile: clean $(EXECUTABLE) +profile: + $(CXX) $(CXXFLAGS) $(SOURCES) -o $(EXECUTABLE)_profile # make static - will perform static analysis in the matter currently used # on the autograder @@ -96,12 +96,18 @@ static: # include the project identifier; skip subdirectories; # also removes old submit tarballs, they are outdated identifier: - @if [ $$(grep --include=*.{h,hpp,c,cpp} --exclude=xcode_redirect.hpp --directories=skip -L $(IDENTIFIER) * | wc -l) -ne 0 ]; then echo -n "Missing project identifier in file(s): ";echo `grep --include=*.{h,hpp,c,cpp} --directories=skip -L $(IDENTIFIER) *`;rm -f $(PARTIAL_SUBMITFILE) $(FULL_SUBMITFILE); exit 1; fi + @if [ $$(grep --include=*.{h,hpp,c,cpp} --exclude=xcode_redirect.hpp --directories=skip -L $(IDENTIFIER) * | wc -l) -ne 0 ]; then \ + echo "Missing project identifier in file(s): \c"; \ + echo `grep --include=*.{h,hpp,c,cpp} --directories=skip -L $(IDENTIFIER) *`; \ + rm -f $(PARTIAL_SUBMITFILE) $(FULL_SUBMITFILE); \ + exit 1; \ + fi # Build both release and debug executables -all: clean +all: $(MAKE) -Rr release $(MAKE) debug + $(MAKE) profile $(EXECUTABLE): $(OBJECTS) ifeq ($(EXECUTABLE), executable) @@ -127,7 +133,7 @@ define make_tests endef $(foreach test, $(TESTS), $(eval $(call make_tests, $(test)))) -alltests: clean $(TESTS) +alltests: $(TESTS) # rule for creating objects %.o: %.cpp @@ -135,8 +141,8 @@ alltests: clean $(TESTS) # make clean - remove .o files, executables, tarball clean: - rm -f $(OBJECTS) $(EXECUTABLE) $(DEBUG) $(TESTS) \ - $(PARTIAL_SUBMITFILE) $(FULL_SUBMITFILE) $(PERF_FILE) + rm -f $(OBJECTS) $(EXECUTABLE) $(EXECUTABLE)_debug $(EXECUTABLE)_profile \ + $(TESTS) $(PARTIAL_SUBMITFILE) $(FULL_SUBMITFILE) $(PERF_FILE) rm -Rf *.dSYM # make partialsubmit.tar.gz - cleans, creates tarball -- GitLab