Skip to content

Instantly share code, notes, and snippets.

@irondoge
Last active October 14, 2016 23:29
Show Gist options
  • Select an option

  • Save irondoge/cfb995fcf484def20aa0c5167ca62137 to your computer and use it in GitHub Desktop.

Select an option

Save irondoge/cfb995fcf484def20aa0c5167ca62137 to your computer and use it in GitHub Desktop.
Makefile generic template for binary
#
# paths
#
SRCDIR := sources
LIBDIR := lib
INCDIRS := includes $(LIBDIR)/includes
#
# compilation options
#
CC := gcc
INCFLAGS := $(addprefix -I , $(INCDIRS))
CFLAGS := $(INCFLAGS) -std=c89 \
-W -Wall -Wextra -Wpointer-arith \
-Wundef -Wshadow -Wunreachable-code \
-Wfloat-equal -Wconversion \
-Wwrite-strings -Waggregate-return \
-Wcast-align -Wcast-qual
#
# link options
#
LINKER := $(CC)
LDFLAGS := -Wl,-rpath=$(LIBDIR) -L $(LIBDIR)
LDLIBS := -llib
#
# binary options
#
NAME := a.out
SRC := main.c \
test.c
SRC := $(addprefix $(SRCDIR)/, $(SRC))
OBJ := $(SRC:.c=.o)
#
# build rules
#
all: $(NAME)
$(NAME): $(OBJ)
$(LINKER) -o $@ $^ $(LDFLAGS) $(LDLIBS)
@printf "=== $@ BUILD COMPLETE ===\n\n"
#
# clean rules
#
RM := rm -fv
clean:; $(RM) $(OBJ)
fclean: clean
$(RM) $(NAME)
re: fclean all
#
# special rules
#
.PHONY: all clean fclean re
.SILENT: clean fclean
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment