From daa29e49c6517e98a3d467b303ddec6c108352a7 Mon Sep 17 00:00:00 2001 From: Berenguer Montserrat Date: Sun, 28 Jul 2019 11:39:44 +0200 Subject: [PATCH] Modified Makefile to create a shared library Modified Makefile to create a easy to link shard library for e-Paper display driver for Raspberry Pi (C code). This way, it is more easy to link against this code when creating custom projects which use that e-paper screen. * Reorganized src variables * Created 2 new targets: make lib and make example (and make all) * make clean now does not file if files do not exist * make clean removes bin directory. There is a target which create it automatically --- Raspberry Pi/c/Makefile | 46 ++++++++++++++++++++++++++++++----------- 1 file changed, 34 insertions(+), 12 deletions(-) diff --git a/Raspberry Pi/c/Makefile b/Raspberry Pi/c/Makefile index f8a4e18..b74f646 100644 --- a/Raspberry Pi/c/Makefile +++ b/Raspberry Pi/c/Makefile @@ -1,14 +1,28 @@ +# Make sure to run make on the same directory where Makefile is located +# Make sure to execute the example "epd" as sudo and in the same directory where Makefile is located + DIR_Config = ./lib/Config DIR_EPD = ./lib/e-Paper DIR_FONTS = ./lib/Fonts DIR_GUI = ./lib/GUI DIR_Examples = ./examples DIR_BIN = ./bin +DIR_LIB = "$(shell pwd)" -OBJ_C = $(wildcard ${DIR_EPD}/*.c ${DIR_Config}/*.c ${DIR_GUI}/*.c ${DIR_Examples}/*.c ${DIR_FONTS}/*.c) -OBJ_O = $(patsubst %.c,${DIR_BIN}/%.o,$(notdir ${OBJ_C})) +SRC_EPD = $(wildcard ${DIR_EPD}/*.c) +SRC_Config = $(wildcard ${DIR_Config}/*.c) +SRC_GUI = $(wildcard ${DIR_GUI}/*.c) +SRC_Examples = $(wildcard ${DIR_Examples}/*.c) +SRC_FONTS = $(wildcard ${DIR_FONTS}/*.c) -TARGET = epd +SRC_LIB = $(SRC_EPD) $(SRC_Config) $(SRC_GUI) $(SRC_FONTS) +OBJ_LIB = $(patsubst %.c,${DIR_BIN}/%.o,$(notdir ${SRC_LIB})) + +SRC_EXAMPLE = $(SRC_Examples) +OBJ_EXAMPLE = $(patsubst %.c,${DIR_BIN}/%.o,$(notdir ${SRC_EXAMPLE})) + +TARGET_LIB = libepd.so +TARGET_EXAMPLE = epd USELIB = USE_BCM2835_LIB # USELIB = USE_WIRINGPI_LIB @@ -20,12 +34,20 @@ else ifeq ($(USELIB), USE_WIRINGPI_LIB) endif CC = gcc -MSG = -g -O0 -Wall +MSG = -g -O0 -Wall -fpic CFLAGS += $(MSG) $(DEBUG) -${TARGET}:${OBJ_O} - $(CC) $(CFLAGS) $(OBJ_O) -o $@ $(LIB) - +all: make_bin_dir lib example + +make_bin_dir: + mkdir -p $(DIR_BIN) + +lib: make_bin_dir $(OBJ_LIB) + $(CC) -shared -o $(TARGET_LIB) $(OBJ_LIB) $(LIB) + +example: make_bin_dir lib $(OBJ_EXAMPLE) + $(CC) $(CFLAGS) $(OBJ_EXAMPLE) -o $(TARGET_EXAMPLE) $(LIB) -L$(DIR_LIB) -lepd -Wl,-rpath=$(DIR_LIB) + ${DIR_BIN}/%.o:$(DIR_Examples)/%.c $(CC) $(CFLAGS) -c $< -o $@ -I $(DIR_Config) -I $(DIR_GUI) -I $(DIR_EPD) @@ -40,8 +62,8 @@ ${DIR_BIN}/%.o:$(DIR_FONTS)/%.c ${DIR_BIN}/%.o:$(DIR_GUI)/%.c $(CC) $(CFLAGS) -c $< -o $@ -I $(DIR_Config) - - -clean : - rm $(DIR_BIN)/*.* - rm $(TARGET) \ No newline at end of file + + +clean: + rm -rf $(DIR_BIN) + rm -f $(TARGET_EXAMPLE) $(TARGET_LIB)