Last active
October 14, 2016 23:29
-
-
Save irondoge/8c4c8ce8a1fe0c50b196cae6904618d3 to your computer and use it in GitHub Desktop.
Makefile generic template for shared object
This file contains 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 | |
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