adaddf03082e863ecebc91f9e794d753d489bf24
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
15 LIBOBJS
=clist.o
# object to put in the library
20 # ====================================
21 # DO NOT CHANGE STUFF BEYOND THIS LINE
22 # ====================================
24 all: $(BINARY_NAME
) $(BINARY_NAME
).dynamic
$(BINARY_NAME
).staticlocal
30 WARN_FLAGS
= -Wall
-Wextra
33 ifeq ($(BUILD_TYPE
),debug
)
34 BUILDDIR
:= .build
/debug
39 BUILDDIR
:= .build
/release
45 #FIXME: Add a way to better control the library build
46 CFLAGS
:= -fPIC
$(CFLAGS
) $(WARN_FLAGS
) $(STD_FLAG
) $(OPTI_FLAG
) $(DEBUG_FLAG
)
47 LDFLAGS
:= $(LDFLAGS
) $(STRIP_FLAG
)
48 LIBLDFLAGS
:= -shared
$(LDFLAGS
)
50 OBJDIR
:= $(BUILDDIR
)/objs
51 $(shell mkdir
-p
$(OBJDIR
))
54 OBJS
=$(patsubst %.c
,$(OBJDIR
)/%.o
,$(SRCS
))
55 OBJSLIB
=$(addprefix $(OBJDIR
)/,$(LIBOBJS
))
57 DEPDIR
:= $(BUILDDIR
)/deps
58 $(shell mkdir
-p
$(DEPDIR
))
59 DEPFLAGS
= -MT
$@
-MMD
-MP
-MF
$(DEPDIR
)/$*.Td
60 POSTCOMPILE
= mv
-f
$(DEPDIR
)/$*.Td
$(DEPDIR
)/$*.d
62 $(LIBRARY_NAME
).a
: $(OBJSLIB
)
66 $(LIBRARY_NAME
).so
: $(OBJSLIB
)
68 @
$(LD
) $(CFLAGS
) $(LIBLDFLAGS
) $^
$(LDLIBS
) -o
$@
70 $(BINARY_NAME
): $(OBJS
)
72 @
$(LD
) $(CFLAGS
) $(LDFLAGS
) $^
$(LDLIBS
) -o
$@
75 $(BINARY_NAME
).staticlocal
: $(OBJDIR
)/$(BINARY_NAME
).o
$(LIBRARY_NAME
).a
77 @
$(LD
) $(CFLAGS
) $(LDFLAGS
) $^
$(LOCALLDLIBS
) $(LDLIBS
) -o
$@
79 $(BINARY_NAME
).dynamic
: $(OBJDIR
)/$(BINARY_NAME
).o
$(LIBRARY_NAME
).so
81 @
$(LD
) $(CFLAGS
) $(LDFLAGS
) $^
$(LOCALLDLIBS
) $(LDLIBS
) -o
$@
83 $(OBJDIR
)/%.o
: %.c
$(DEPDIR
)/%.d
85 @
$(CC
) $(DEPFLAGS
) $(CFLAGS
) -c
$< -o
$@
90 .PRECIOUS
: $(DEPDIR
)/%.d
92 include $(wildcard $(patsubst %,$(DEPDIR
)/%.d
,$(basename $(SRCS
))))
98 -@
rm $(BINARY_NAME
).staticlocal
99 -@
rm $(BINARY_NAME
).dynamic
100 -@
rm $(LIBRARY_NAME
).so
101 -@
rm $(LIBRARY_NAME
).a
103 disassemble
: $(BINARY_NAME
)
106 symbols
: $(BINARY_NAME
)
107 objdump
-t
$< |
sort | less