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
19 # ====================================
20 # DO NOT CHANGE STUFF BEYOND THIS LINE
21 # ====================================
28 WARN_FLAGS
= -Wall
-Wextra
31 ifeq ($(BUILD_TYPE
),debug
)
32 BUILDDIR
:= .build
/debug
38 BUILDDIR
:= .build
/release
45 CFLAGS
:= -DDEBUG
=$(DEBUG
) $(CFLAGS
) $(WARN_FLAGS
) $(STD_FLAG
) $(OPTI_FLAG
) $(DEBUG_FLAG
)
46 LDFLAGS
:= $(LDFLAGS
) $(STRIP_FLAG
)
48 OBJDIR
:= $(BUILDDIR
)/objs
49 $(shell mkdir
-p
$(OBJDIR
))
52 OBJS
=$(patsubst %.c
,$(OBJDIR
)/%.o
,$(SRCS
))
54 DEPDIR
:= $(BUILDDIR
)/deps
55 $(shell mkdir
-p
$(DEPDIR
))
56 DEPFLAGS
= -MT
$@
-MMD
-MP
-MF
$(DEPDIR
)/$*.Td
57 POSTCOMPILE
= mv
-f
$(DEPDIR
)/$*.Td
$(DEPDIR
)/$*.d
59 $(BINARY_NAME
): $(OBJS
)
61 @
$(LD
) $(CFLAGS
) $(LDFLAGS
) $^
$(LDLIBS
) -o
$@
63 $(OBJDIR
)/%.o
: %.c
$(DEPDIR
)/%.d
65 @
$(CC
) $(DEPFLAGS
) $(CFLAGS
) -c
$< -o
$@
70 .PRECIOUS
: $(DEPDIR
)/%.d
72 include $(wildcard $(patsubst %,$(DEPDIR
)/%.d
,$(basename $(SRCS
))))
79 disassemble
: $(BINARY_NAME
)
82 symbols
: $(BINARY_NAME
)
83 objdump
-t
$< |
sort | less