Last active
February 3, 2021 00:41
-
-
Save evanrelf/26602e62db14ab7f681d644dd49b3413 to your computer and use it in GitHub Desktop.
Generic Makefile for C++ assignments at Saddleback College
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# USER SETTINGS | |
production = false | |
dir = .make-work | |
CXX = @clang++ | |
CXXFLAGS = -std=c++17 -Wall | |
ifeq ($(PRODUCTION),true) | |
CXXFLAGS += -Werror -O3 | |
else | |
CXXFLAGS += -g -O0 | |
endif | |
CXXFLAGS += -MMD -MP -I. | |
# AUTO SETTINGS (do not touch) | |
name = $(notdir $(shell pwd)) | |
src = $(wildcard *.cpp) | |
obj = $(src:%.cpp=$(dir)/%.o) | |
dep = $(obj:.o=.d) | |
# FILE TARGETS | |
build: $(name).out | |
$(name).out: $(obj) | |
$(CXX) $(CXXFLAGS) $^ -o $@ | |
$(dir)/%.o: %.cpp | $(dir) | |
$(CXX) $(CXXFLAGS) -c $< -o $@ | |
$(dir): | |
@mkdir -p $@ | |
-include $(dep) | |
# COMMANDS | |
run: $(name).out | |
@date > output.log | |
@echo "\033[0;34m--- PROGRAM:\033[0m" | |
@./$(name).out | tee -a output.log | |
valgrind: $(name).out | |
@date | tee output.log > valgrind.log | |
@echo "\033[0;34m--- PROGRAM:\033[0m" | |
@valgrind --show-leak-kinds=all ./$(name).out 2>> valgrind.log | tee -a output.log | |
@echo "\033[0;34m--- VALGRIND:\033[0m" | |
@cat valgrind.log | |
record: | |
@echo "\033[0;34m--- BEGIN RECORDING\033[0m" | |
@script -r $(name).scr.temp; \ | |
echo "\033[0;34m--- END RECORDING\033[0m"; \ | |
mv $(name).scr.temp $(name).scr | |
play: | |
@echo "\033[0;34m--- BEGIN PLAYBACK\033[0m" | |
@script -p $(name).scr | |
@echo "\033[0;34m--- END PLAYBACK\033[0m" | |
bundle: | |
@echo "\033[0;34m--- CREATING ARCHIVE...\033[0m" | |
tar -hczf $(name).tar.gz *.cpp *.hpp *.txt *.log *.scr Makefile | |
@tar -tvf $(name).tar.gz | |
@open -R $(name).tar.gz | |
clean: | |
rm -rf *.out $(dir) *.log *.scr *.tar.gz *.dSYM .DS_Store | |
.PHONY: build run valgrind record play bundle clean |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment