Created
August 26, 2017 08:58
-
-
Save lithiumhead/e7d47a967a22c3c22851af53ee1992d4 to your computer and use it in GitHub Desktop.
Hello World - C Shared Library
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
############ Configure the following four variable and set your sources and names | |
LIB_TARGET_NAME = hello | |
LIB_SRCS = libhello.c | |
EXE_TARGET_NAME = main.exe | |
EXE_SRCS = main.c | |
############ The following variables are auto generated | |
CC = gcc | |
RM = rm -f | |
CURR_DIRR = $(shell pwd) | |
LIB_CFLAGS = -c -fPIC -Wall -Werror | |
LIB_LDFLAGS = -Wall -shared | |
LIB_TARGET_SO = $(addprefix lib,$(addsuffix .so,$(LIB_TARGET_NAME))) | |
LIB_OBJS = $(LIB_SRCS:.c=.o) | |
EXE_CFLAGS = -c -Wall -Werror | |
EXE_LDFLAGS = -Wall -L$(CURR_DIRR) -l$(LIB_TARGET_NAME) | |
EXE_OBJS = $(EXE_SRCS:.c=.o) | |
############ Build Recipes | |
.PHONY: all | |
all: ${LIB_TARGET_SO} ${EXE_TARGET_NAME} | |
$(LIB_TARGET_SO): $(LIB_OBJS) | |
$(CC) ${LIB_LDFLAGS} -o $@ $^ | |
$(LIB_OBJS): $(LIB_SRCS) | |
$(CC) $(LIB_CFLAGS) -o $@ $^ | |
$(EXE_TARGET_NAME): $(EXE_OBJS) | |
$(CC) -o $@ $^ ${EXE_LDFLAGS} | |
$(EXE_OBJS): $(EXE_SRCS) | |
$(CC) $(EXE_CFLAGS) -o $@ $^ | |
############ Clean Recipes | |
.PHONY: clean | |
clean: | |
-${RM} ${LIB_TARGET_SO} ${LIB_OBJS} | |
-${RM} ${EXE_TARGET_NAME} ${EXE_OBJS} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment