1 # Sample Makefile to build simple project.
3 # This Makefile expect all source files (.c) to be at the same level, in the
4 # current working directory.
6 # It will automatically generate dependencies, compile all files, and produce a
7 # binary using the provided name.
9 # Set BINARY_NAME to the name of the binary file to build.
10 # Set BUILD_TYPE to either debug or release
12 # Automatic dependencies code from:
13 # http://make.mad-scientist.net/papers/advanced-auto-dependency-generation/#tldr
14 BINARY_NAME
=pile_contigue
17 # ====================================
18 # DO NOT CHANGE STUFF BEYOND THIS LINE
19 # ====================================
26 WARN_FLAGS
= -Wall
-Wextra
29 ifeq ($(BUILD_TYPE
),debug
)
30 BUILDDIR
:= .build
/debug
35 BUILDDIR
:= .build
/release
41 CFLAGS
:= $(CFLAGS
) $(WARN_FLAGS
) $(STD_FLAG
) $(OPTI_FLAG
) $(DEBUG_FLAG
)
42 LDFLAGS
:= $(LDFLAGS
) $(STRIP_FLAG
)
44 OBJDIR
:= $(BUILDDIR
)/objs
45 $(shell mkdir
-p
$(OBJDIR
))
48 OBJS
=$(patsubst %.c
,$(OBJDIR
)/%.o
,$(SRCS
))
50 DEPDIR
:= $(BUILDDIR
)/deps
51 $(shell mkdir
-p
$(DEPDIR
))
52 DEPFLAGS
= -MT
$@
-MMD
-MP
-MF
$(DEPDIR
)/$*.Td
53 POSTCOMPILE
= mv
-f
$(DEPDIR
)/$*.Td
$(DEPDIR
)/$*.d
55 $(BINARY_NAME
): $(OBJS
)
57 @
$(LD
) $(CFLAGS
) $(LDFLAGS
) $^
$(LDLIBS
) -o
$@
59 $(OBJDIR
)/%.o
: %.c
$(DEPDIR
)/%.d
61 @
$(CC
) $(DEPFLAGS
) $(CFLAGS
) -c
$< -o
$@
66 .PRECIOUS
: $(DEPDIR
)/%.d
68 include $(wildcard $(patsubst %,$(DEPDIR
)/%.d
,$(basename $(SRCS
))))
75 disassemble
: $(BINARY_NAME
)
78 symbols
: $(BINARY_NAME
)
79 objdump
-t
$< |
sort | less