Skip to content

Instantly share code, notes, and snippets.

@Eun
Last active May 16, 2016 10:41
Show Gist options
  • Save Eun/a6bcc3c8da608133d6ea to your computer and use it in GitHub Desktop.
Save Eun/a6bcc3c8da608133d6ea to your computer and use it in GitHub Desktop.
Makefile
## MAKEFILE V 1.4 ##
BIN = a.out
CC = gcc
CPLUS = g++
LINK = g++
OBJC = $(shell find ./src -name "*.c" | sed 's/\.c/\.o/g' | sed 's/\.\/src\//\.\/obj\//g')
OBJCPP = $(shell find ./src -name "*.cpp" | sed 's/\.cpp/\.opp/g' | sed 's/\.\/src\//\.\/obj\//g')
OBJ = $(OBJC) $(OBJCPP)
CFLAGS = -Wall -I./inc/
CPPFLAGS = -Wall -I./inc/
LDFLAGS = -Wall
LIBS =
# ========================================================================= #
SILENT = 2>/dev/null || true
pathpat=(.*/[^/]*)+:[0-9]+
pathpatlink=(.*/[^/]*)+:
ccred=$(shell printf "\033[0;31m")
ccyellow=$(shell printf "\033[0;33m")
ccgray=$(shell printf "\033[1;30m")
ccbold=$(shell printf "\033[1m")
ccend=$(shell printf "\033[0m")
LANG=en_US.UTF-8
all: dirs $(BIN)
debug: CFLAGS += -g -DDEBUG
debug: CPPFLAGS += -g -DDEBUG
debug: all
dirs:
-@mkdir bin $(SILENT)
-@mkdir obj $(SILENT)
-@mkdir -p $(shell find ./src/ -type d | sed 's|./src/|./obj/|g')
@printf "\033[1m\033[4m1. COMPILING\033[0m\n"
$(BIN): $(OBJ)
@printf "\033[1m\033[4m2. LINKING\033[0m\n"
@$(LINK) $(LDFLAGS) $(OBJ) $(LIBS) -o ./bin/$@ 2>&1 | sed -E -e "/undefined[: ]/s%$(pathpatlink)%$(ccred)&$(ccend)%g" -e "s/obj\///" -e "s/.\///"
@printf "\033[1m\033[4m3. DONE\033[0m\n"
./obj/%.o: ./src/%.c
@printf "\033[1m>> $<\033[0m\n" | sed 's/src\///g'
@$(CC) $(CFLAGS) -o $@ -c $< 2>&1 | sed -E -e "/[Ee]rror[: ]/s%$(pathpat)%$(ccred)&$(ccend)%g" -e "/[Ww]arning[: ]/s%$(pathpat)%$(ccyellow)&$(ccend)%g" -e "/[Nn]ote[: ]/s%$(pathpat)%$(ccgray)&$(ccend)%g" -e "s/src\///"
./obj/%.opp: ./src/%.cpp
@printf "\033[1m>> $<\033[0m\n" | sed 's/src\///g'
@$(CPLUS) $(CPPFLAGS) -o $@ -c $< 2>&1 | sed -E -e "/[Ee]rror[: ]/s%$(pathpat)%$(ccred)&$(ccend)%g" -e "/[Ww]arning[: ]/s%$(pathpat)%$(ccyellow)&$(ccend)%g" -e "/[Nn]ote[: ]/s%$(pathpat)%$(ccgray)&$(ccend)%g" -e "s/src\///"
clean:
@printf "\033[1m\033[4mCLEANING\033[0m\n"
rm -rf bin
rm -rf obj
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment