Last active
October 14, 2016 23:29
-
-
Save irondoge/cfb995fcf484def20aa0c5167ca62137 to your computer and use it in GitHub Desktop.
Makefile generic template for binary
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # | |
| # 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