More fixlets.
[Projet_Recherche_Operationnelle.git] / implémentation / Makefile
CommitLineData
f12bd30b
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=sqp
15#BUILD_TYPE=debug
16BUILD_TYPE=release
17
18# ====================================
19# DO NOT CHANGE STUFF BEYOND THIS LINE
20# ====================================
21
22all: $(BINARY_NAME)
23
24CC=gcc
25LD=gcc
26
27WARN_FLAGS = -Wall -Wextra
28STD_FLAG = -std=c11
29
30ifeq ($(BUILD_TYPE),debug)
31BUILDDIR := .build/debug
32DEBUG_FLAG = -g
33DEBUG = 1
34STRIP_FLAG =
35OPTI_FLAG = -O0
36else
37BUILDDIR := .build/release
38DEBUG_FLAG =
39DEBUG = 0
40STRIP_FLAG = -s
41OPTI_FLAG = -O3
42endif
43
44CFLAGS := -DDEBUG=$(DEBUG) $(CFLAGS) $(WARN_FLAGS) $(STD_FLAG) $(OPTI_FLAG) $(DEBUG_FLAG)
45LDFLAGS := $(LDFLAGS) $(STRIP_FLAG)
46
47OBJDIR := $(BUILDDIR)/objs
48$(shell mkdir -p $(OBJDIR))
49
50SRCS=$(wildcard *.c)
51OBJS=$(patsubst %.c,$(OBJDIR)/%.o,$(SRCS))
52
53DEPDIR := $(BUILDDIR)/deps
54$(shell mkdir -p $(DEPDIR))
55DEPFLAGS = -MT $@ -MMD -MP -MF $(DEPDIR)/$*.Td
56POSTCOMPILE = mv -f $(DEPDIR)/$*.Td $(DEPDIR)/$*.d
57
58$(BINARY_NAME): $(OBJS)
59 @echo "[LD ] $@"
60 @$(LD) $(CFLAGS) $(LDFLAGS) $^ $(LDLIBS) -o $@
61
62$(OBJDIR)/%.o: %.c $(DEPDIR)/%.d
63 @echo "[C ] $*"
64 @$(CC) $(DEPFLAGS) $(CFLAGS) -c $< -o $@
65 @$(POSTCOMPILE)
66
67$(DEPDIR)/%.d: ;
68
69.PRECIOUS: $(DEPDIR)/%.d
70
71include $(wildcard $(patsubst %,$(DEPDIR)/%.d,$(basename $(SRCS))))
72
73clean:
74 @echo "[CLN]"
75 -@rm -r $(BUILDDIR)
76 -@rm $(BINARY_NAME)
77
78disassemble: $(BINARY_NAME)
79 objdump -d $< | less
80
81symbols: $(BINARY_NAME)
82 objdump -t $< | sort | less