Refine .gitignore some more.
[Algorithmic_C.git] / TP3 / Makefile
CommitLineData
a7c59b01
JB
1# Sample Makefile to build simple project.
2#
3# This Makefile expect all source files (.c) to be at the same level, in the
4# current working directory.
5#
6# It will automatically generate dependencies, compile all files, and produce a
7# binary using the provided name.
8#
9# Set BINARY_NAME to the name of the binary file to build.
10# Set BUILD_TYPE to either debug or release
11#
12# Automatic dependencies code from:
13# http://make.mad-scientist.net/papers/advanced-auto-dependency-generation/#tldr
14BINARY_NAME=tp3
15BUILD_TYPE=debug
16
17# ====================================
18# DO NOT CHANGE STUFF BEYOND THIS LINE
19# ====================================
20
21all: $(BINARY_NAME)
22
23CC=gcc
24LD=gcc
25
26WARN_FLAGS = -Wall -Wextra
27STD_FLAG = -std=c99
28
29ifeq ($(BUILD_TYPE),debug)
30BUILDDIR := .build/debug
31DEBUG_FLAG = -g
32STRIP_FLAG =
33OPTI_FLAG = -O0
34else
35BUILDDIR := .build/release
36DEBUG_FLAG =
37STRIP_FLAG = -s
5e90a798 38OPTI_FLAG = -O3
a7c59b01
JB
39endif
40
41CFLAGS := $(CFLAGS) $(WARN_FLAGS) $(STD_FLAG) $(OPTI_FLAG) $(DEBUG_FLAG)
42LDFLAGS := $(LDFLAGS) $(STRIP_FLAG)
43
44OBJDIR := $(BUILDDIR)/objs
45$(shell mkdir -p $(OBJDIR))
46
47SRCS=$(wildcard *.c)
48OBJS=$(patsubst %.c,$(OBJDIR)/%.o,$(SRCS))
49
50DEPDIR := $(BUILDDIR)/deps
51$(shell mkdir -p $(DEPDIR))
52DEPFLAGS = -MT $@ -MMD -MP -MF $(DEPDIR)/$*.Td
53POSTCOMPILE = mv -f $(DEPDIR)/$*.Td $(DEPDIR)/$*.d
54
55$(BINARY_NAME): $(OBJS)
56 @echo "[LD ] $@"
57 @$(LD) $(CFLAGS) $(LDFLAGS) $^ $(LDLIBS) -o $@
58
59$(OBJDIR)/%.o: %.c $(DEPDIR)/%.d
60 @echo "[C ] $*"
61 @$(CC) $(DEPFLAGS) $(CFLAGS) -c $< -o $@
62 @$(POSTCOMPILE)
63
64$(DEPDIR)/%.d: ;
65
66.PRECIOUS: $(DEPDIR)/%.d
67
68include $(wildcard $(patsubst %,$(DEPDIR)/%.d,$(basename $(SRCS))))
69
70clean:
71 @echo "[CLN]"
72 -@rm -r $(BUILDDIR)
73 -@rm $(BINARY_NAME)
74
75disassemble: $(BINARY_NAME)
76 objdump -d $< | less
77
78symbols: $(BINARY_NAME)
79 objdump -t $< | sort | less