# References: # BUILD_DIR and per-.cpp file https://spin.atomicobject.com/2016/08/26/makefile-c-projects/ # https://bgstack15.ddns.net/blog/posts/2019/11/04/sample-makefile/ 2022-09-28-4 15:34 awkbin :=$(shell which awk) cpbin :=$(shell which cp) echobin :=$(shell which echo) findbin :=$(shell which find) grepbin :=$(shell which grep) installbin :=$(shell which install) rmbin :=$(shell which rm) sedbin :=$(shell which sed) sortbin :=$(shell which sort) truebin :=$(shell which true) CXX = g++ CC = gcc # to get full debug symbols, add to both FLAGS: -g # to make all warnings act as errors: -Wall -Weffc++ -Wextra -Wsign-conversion -Werror CXXFLAGS = -g -std=c++17 -Wall -Weffc++ -Wextra -Wsign-conversion -Werror CCFLAGS = -g -Wno-deprecated-declarations \ `pkg-config --cflags x11` \ `pkg-config --cflags gtk+-3.0` # to remove all debug symbols: -s # to add full debug symbols: -g LDFLAGS = -g \ `pkg-config --libs x11` \ `pkg-config --libs gtk+-3.0` src = $(wildcard *.c) obj = $(src:.c=.o) BUILD_DIR ?= . OUTEXE = status all: $(OUTEXE) $(obj): $(BUILD_DIR)/%.o: %.c $(CC) -c $(CCFLAGS) -o $@ $< # link $(OUTEXE): $(obj) $(CC) -o $@ $^ $(LDFLAGS) .PHONY: clean cleanall list list: @$(MAKE) -pRrq -f $(lastword $(MAKEFILE_LIST)) : 2>/dev/null | ${awkbin} -v RS= -F: '/^# File/,/^# Finished Make data base/ {if ($$1 !~ "^[#.]") {print $$1}}' | ${sortbin} | ${grepbin} -E -v -e '^[^[:alnum:]]' -e '^$@$$' -e '\.(cp*|o)' clean: rm -f $(obj) cleanall: rm -f $(obj) $(OUTEXE)