52 lines
1.2 KiB
Makefile
52 lines
1.2 KiB
Makefile
TARGET = $(notdir $(CURDIR))
|
|
|
|
INSTALL = /usr/local/bin
|
|
|
|
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 -Wno-unused-parameter
|
|
|
|
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)/'))
|
|
|
|
build: $(TARGET)
|
|
@echo Done.
|
|
|
|
run: build
|
|
@./$(TARGET)
|
|
|
|
install: $(TARGET)
|
|
@test -d ~/bin && cp $(TARGET) ~/bin &>/dev/null \
|
|
|| echo "Directory ~/bin does not exist, installation failed"
|
|
|
|
uninstall:
|
|
-@rm ~/bin/psh
|
|
|
|
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: build run install clean
|