-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
73 lines (60 loc) · 1.79 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
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
67
68
69
70
71
72
73
# Copyright (c) 2019 André Filipe Caldas Laranjeira
# MIT License
# Message Logger module - Project Makefile.
# Executable name:
EXE = msg-logger-sample
# Project paths:
DOCDIR = doc
DOCHTMLDIR = html
DOCLATEXDIR = latex
IDIR = include
ODIR = src/obj
SDIR = src
# Project files:
_DEPS = message_logger.h
_OBJ = message_logger.o sample.o
_SRC = message_logger.c sample.c
# Joining file names with their respective paths:
DEPS = $(patsubst %,$(IDIR)/%,$(_DEPS))
OBJ = $(patsubst %,$(ODIR)/%,$(_OBJ))
SRC = $(patsubst %,$(SDIR)/%,$(_SRC))
# Compiler name, source file extension and compilation data (flags and libs):
CC = gcc
EXT = .c
CFLAGS = -Wall -g -I $(IDIR)
LIBS = -lm -lpthread
# Object files compilation rule:
$(ODIR)/%.o: $(SDIR)/%$(EXT) $(DEPS)
@if [ ! -d $(ODIR) ]; then mkdir $(ODIR); fi
$(CC) -c -o $@ $< $(CFLAGS)
# Project executable compilation rule:
$(EXE): $(OBJ)
$(CC) -o $@ $^ $(CFLAGS) $(LIBS)
# List of aditional makefile commands:
.PHONY: clean
.PHONY: doc
# Command to clean generated files:
clean:
@rm -f $(ODIR)/*.o *~ core
@rm -rf $(DOCDIR)
@if [ -f $(EXE) ]; then \
rm -i $(EXE); \
fi
# Command to generate the documentation:
doc:
@doxygen ./Doxyfile > /dev/null
@echo ""
@echo "Open documentation now?"
@echo "h - Open HTML format"
@echo "l - Open Latex format (pdflatex required to generate documentation)"
@echo "n - No (DEFAULT)"
@read -p "Choice (h/l/n): " DOC_CHOICE_RAW; \
DOC_CHOICE=$$(echo $$DOC_CHOICE_RAW | tr '[:upper:]' '[:lower:]'); \
if [[ $$DOC_CHOICE == "h" ]]; then \
xdg-open $(DOCDIR)/$(DOCHTMLDIR)/index.html > /dev/null 2>&1; \
elif [[ $$DOC_CHOICE == "l" ]]; then \
echo ""; \
echo "Generating latex documentation..."; \
$(MAKE) -C $(DOCDIR)/$(DOCLATEXDIR) > /dev/null; \
xdg-open $(DOCDIR)/$(DOCLATEXDIR)/refman.pdf > /dev/null 2>&1; \
fi