-
Notifications
You must be signed in to change notification settings - Fork 1
/
Makefile
38 lines (30 loc) · 1.01 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
BIN = gsconf
LIBS = -lssh2 -lreadline -lpq
CFLAGS = -pipe -Werror -Wall -Wextra -Wno-unused -Wno-unused-parameter -g -I `pg_config --includedir`
LDFLAGS =
SRC = $(wildcard *.c)
OBJ = $(patsubst %.c,.tmp/%.o,$(SRC))
DEP = $(patsubst %.c,.tmp/%.d,$(SRC))
TMPDIR = .tmp
.PHONY: all clean
all: $(TMPDIR) $(BIN)
clean:
@printf " \033[38;5;154mCLEAN\033[0m\n"
@rm -f $(BIN) $(TMPDIR)/*.d $(TMPDIR)/*.o
# rule for creating final binary
$(BIN): $(OBJ)
@printf " \033[38;5;69mLD\033[0m $@\n"
@$(CC) $(LDFLAGS) $(OBJ) $(LIBS) -o $(BIN)
# rule for creating object files
$(OBJ) : $(TMPDIR)/%.o : %.c
@printf " \033[38;5;33mCC\033[0m $(<:.c=.o)\n"
@$(CC) $(CFLAGS) -std=gnu99 -MMD -MF $(TMPDIR)/$(<:.c=.d) -MT $@ -o $@ -c $<
@cp -f $(TMPDIR)/$*.d $(TMPDIR)/$*.d.tmp
@sed -e 's/.*://' -e 's/\\$$//' < $(TMPDIR)/$*.d.tmp | fmt -1 | sed -e 's/^ *//' -e 's/$$/:/' >> $(TMPDIR)/$*.d
@rm -f $(TMPDIR)/$*.d.tmp
$(TMPDIR):
@mkdir $(TMPDIR)
# include dependency files
ifneq ($(MAKECMDGOALS),clean)
-include $(DEP)
endif