about summary refs log tree commit diff stats
path: root/build/c/makefile
blob: 6128f06c53d77d7734789f0ad2bba9ea4fc99464 (plain) (blame)
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
PREFIX    := /usr/local
BINPREFIX := $(DESTDIR)$(PREFIX)/bin
MANPREFIX := $(DESTDIR)$(PREFIX)/share/man/man1

BIN_NAME := %INIT_APPLICATION_NAME
# This version is set automatically on `cog bump --auto`;
BIN_VERSION := "v%INIT_APPLICATION_VERSION"  # GUIDING VERSION STRING

# The trailing slash is important
BUILD_DIR := ./target/
BIN_PATH := $(BUILD_DIR)$(BIN_NAME)


SRC := $(wildcard src/*.c)
OBJ := $(addprefix $(BUILD_DIR),$(notdir $(SRC:.c=.o)))
DEP := $(addprefix $(BUILD_DIR),$(notdir $(SRC:.c=.d)))

LIBS :=

ALL_CFLAGS  := -O3 -MMD -Wall -Wextra -Wno-unused-parameter $(CFLAGS) $(CPPFLAGS)
ALL_LDFLAGS := $(addprefix -l,$(LIBS)) -L $(LD_LIBRARY_PATH) $(LDFLAGS)

default: all

all: $(BIN_NAME)

$(BIN_NAME): $(OBJ)
	$(CC) $^ -o $(addprefix $(BUILD_DIR),$(notdir $(BIN_NAME))) $(ALL_CFLAGS) $(ALL_LDFLAGS)

$(OBJ): $(SRC)
	@mkdir --parents $(BUILD_DIR)
	$(CC) -c -o $@  $(addprefix ./src/,$(patsubst %.o,%.c,$(notdir $@))) $(ALL_CFLAGS)

manual:
	mkdir --parents $(BUILD_DIR)docs
	pandoc "./docs/$(BIN_NAME).1.md" -s -t man > $(BUILD_DIR)docs/$(BIN_NAME).1

.PHONY : clean options install memory_leak_test
options:
	@echo "PREFIX    = $(PREFIX)"
	@echo "BINPREFIX = $(BINPREFIX)"
	@echo "MANPREFIX = $(MANPREFIX)"
	@echo ""
	@echo "BIN_NAME = $(BIN_NAME)"
	@echo "BUILD_DIR = $(BUILD_DIR)"
	@echo "BIN_PATH = $(BIN_PATH)"
	@echo ""
	@echo "SRC = $(SRC)"
	@echo "OBJ = $(OBJ)"
	@echo "DEP = $(DEP)"
	@echo ""
	@echo "LIBS = $(LIBS)"
	@echo ""
	@echo "ALL_CFLAGS  = $(ALL_CFLAGS)"
	@echo "ALL_LDFLAGS = $(ALL_LDFLAGS)"
	@echo ""

clean :
	rm --recursive $(BUILD_DIR)

install: $(BIN_NAME) manual
	install -D $(BUILD_DIR)docs/$(BIN_NAME).1  $(MANPREFIX)/$(BIN_NAME);
	install -D $(BUILD_DIR)$(BIN_NAME)  $(BINPREFIX)/$(BIN_NAME);

memory_leak_test:
	sh ./scripts/valgrind_test.sh $(BIN_NAME)