2018-12-01 18:09:44 +01:00
|
|
|
TARGET = $(notdir $(CURDIR))
|
|
|
|
|
2019-01-02 00:55:12 +01:00
|
|
|
INSTALL = /usr/local/bin
|
|
|
|
|
|
|
|
SRCEXT = .c
|
2018-12-01 18:09:44 +01:00
|
|
|
INCEXT = .h
|
|
|
|
OBJEXT = .o
|
|
|
|
|
|
|
|
SRCDIR = src
|
|
|
|
INCDIR = .
|
|
|
|
OBJDIR = bin
|
|
|
|
|
|
|
|
CC = gcc
|
2019-01-02 00:55:12 +01:00
|
|
|
LD = gcc
|
2018-12-01 18:09:44 +01:00
|
|
|
|
|
|
|
LDFLAGS = -lm -lpthread
|
2018-12-17 01:59:10 +01:00
|
|
|
CCFLAGS = -std=gnu99 -g -ggdb -Og -Wall -Wextra -pedantic -Wno-unused-parameter
|
2018-12-01 18:09:44 +01:00
|
|
|
|
2019-01-02 00:55:12 +01:00
|
|
|
SRCTREE = $(shell find $(SRCDIR) -type d)
|
|
|
|
INCS = $(shell find $(INCDIR) -type f -name '*$(INCEXT)')
|
|
|
|
SRCS = $(shell find $(SRCDIR) -type f -name '*$(SRCEXT)')
|
2018-12-01 18:09:44 +01:00
|
|
|
OBJTREE = $(foreach D,$(SRCTREE),$(shell echo $(D) | sed 's/$(SRCDIR)/$(OBJDIR)/'))
|
2019-01-02 00:55:12 +01:00
|
|
|
OBJSTMP = $(foreach F,$(SRCS),$(shell echo $(F) | sed -e 's/$(SRCDIR)/$(OBJDIR)/'))
|
|
|
|
OBJS = $(foreach O,$(OBJSTMP),$(shell echo $(O) | sed -e 's/\$(SRCEXT)/\$(OBJEXT)/'))
|
2018-12-01 18:09:44 +01:00
|
|
|
|
2019-01-02 00:55:12 +01:00
|
|
|
build: $(TARGET)
|
2018-12-01 18:09:44 +01:00
|
|
|
@echo Done.
|
|
|
|
|
2019-01-02 00:55:12 +01:00
|
|
|
run: build
|
2018-12-01 18:09:44 +01:00
|
|
|
@./$(TARGET)
|
|
|
|
|
2019-01-02 01:23:41 +01:00
|
|
|
install: $(TARGET)
|
2019-01-02 01:28:08 +01:00
|
|
|
@test -d ~/bin && cp $(TARGET) ~/bin &>/dev/null \
|
|
|
|
|| echo "Directory ~/bin does not exist, installation failed"
|
|
|
|
|
|
|
|
uninstall:
|
|
|
|
-@rm ~/bin/psh
|
2019-01-02 00:55:12 +01:00
|
|
|
|
2018-12-01 18:09:44 +01:00
|
|
|
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)
|
|
|
|
|
2019-01-02 00:55:12 +01:00
|
|
|
.PHONY: build run install clean
|