Skip to content

Instantly share code, notes, and snippets.

@irondoge
Last active October 14, 2016 23:29
Show Gist options
  • Save irondoge/8c4c8ce8a1fe0c50b196cae6904618d3 to your computer and use it in GitHub Desktop.
Save irondoge/8c4c8ce8a1fe0c50b196cae6904618d3 to your computer and use it in GitHub Desktop.
Makefile generic template for shared object
#
# paths
#
SRCDIR := sources
INCDIR := includes
#
# compilation options
#
CC := gcc
CFLAGS := -I $(INCDIR) -fpic -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 := -shared
LDLIBS := -lm
#
# shared object options
#
NAME := liblib.so
SRC := init.c \
utils.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) $(NAME)
re: clean all
#
# special rules
#
.PHONY: all clean re
.SILENT: clean
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment