From 183bea62db7ffc44f412a8cfb8cbc8e1511638ab Mon Sep 17 00:00:00 2001 From: Artur Tamborski Date: Sat, 1 Dec 2018 18:09:44 +0100 Subject: [PATCH] Add my trusty makefile --- makefile | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 makefile diff --git a/makefile b/makefile new file mode 100644 index 0000000..0340e78 --- /dev/null +++ b/makefile @@ -0,0 +1,42 @@ +TARGET = $(notdir $(CURDIR)) + +SRCEXT = .c +INCEXT = .h +OBJEXT = .o + +SRCDIR = src +INCDIR = . +OBJDIR = bin + +CC = gcc +LD = gcc + +LDFLAGS = -lm -lpthread +CCFLAGS = -std=gnu99 -g -ggdb -Og -Wall -Wextra -pedantic + +SRCTREE = $(shell find $(SRCDIR) -type d) +INCS = $(shell find $(INCDIR) -type f -name '*$(INCEXT)') +SRCS = $(shell find $(SRCDIR) -type f -name '*$(SRCEXT)') +OBJTREE = $(foreach D,$(SRCTREE),$(shell echo $(D) | sed 's/$(SRCDIR)/$(OBJDIR)/')) +OBJSTMP = $(foreach F,$(SRCS),$(shell echo $(F) | sed -e 's/$(SRCDIR)/$(OBJDIR)/')) +OBJS = $(foreach O,$(OBJSTMP),$(shell echo $(O) | sed -e 's/\$(SRCEXT)/\$(OBJEXT)/')) + +all: $(TARGET) + @echo Done. + +run: $(TARGET) + @./$(TARGET) + +clean: + @rm -r $(TARGET) $(OBJS) $(OBJDIR) 2>/dev/null || true + +$(TARGET): $(OBJS) | $(OBJDIR) + @$(LD) $(LDFLAGS) -L$(OBJDIR) -o $@ $^ + +$(OBJS): $(OBJDIR)/%$(OBJEXT) : $(SRCDIR)/%$(SRCEXT) | $(OBJDIR) + @$(CC) $(CCFLAGS) -I$(INCDIR) -c -o $@ $? + +$(OBJDIR): + @mkdir -p $(OBJDIR) $(OBJTREE) + +.PHONY: all run clean