From 07db82a590a26c49f5f638f43e5853789f4bca4e Mon Sep 17 00:00:00 2001 From: Berenguer Montserrat Date: Sat, 17 Aug 2019 09:54:47 +0200 Subject: [PATCH] Modified Makefile to create a shared library Modified Makefile to be able to create a shared library. This simplifies the use of that code (used in the example) in other projects. Now, the example provided links against this library as well. Because Raspberry Pi and Jetson differ in hardware, they use different libraries, specific for each platform. So, I have added a simple rule which tells the user to make for one or for the other, instead of making for both. I have added a gitignore that ignores de bin folder, which is not necessary to be under source control. The two binaries, epd (example) and the library are ignored as well. I have modified the Makefile accordingly to be able to create the bin folder. Finally, I have added a little print in the examples' main.c to tell the user to uncomment one of the tests, because by default, the example demo does nothing and do not inform the user. --- RaspberryPi&JetsonNano/c/Makefile | 99 +++++++++++++++--------- RaspberryPi&JetsonNano/c/examples/main.c | 3 +- 2 files changed, 64 insertions(+), 38 deletions(-) diff --git a/RaspberryPi&JetsonNano/c/Makefile b/RaspberryPi&JetsonNano/c/Makefile index 0d3bc83..882c2e9 100644 --- a/RaspberryPi&JetsonNano/c/Makefile +++ b/RaspberryPi&JetsonNano/c/Makefile @@ -4,66 +4,91 @@ 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_GUI}/*.c ${DIR_Examples}/*.c ${DIR_FONTS}/*.c ) -OBJ_O = $(patsubst %.c,${DIR_BIN}/%.o,$(notdir ${OBJ_C})) -RPI_DEV_C = $(wildcard $(DIR_BIN)/dev_hardware_SPI.o $(DIR_BIN)/RPI_sysfs_gpio.o $(DIR_BIN)/DEV_Config.o ) -JETSON_DEV_C = $(wildcard $(DIR_BIN)/sysfs_software_spi.o $(DIR_BIN)/sysfs_gpio.o $(DIR_BIN)/DEV_Config.o ) +SRC_EPD = $(wildcard ${DIR_EPD}/*.c) +SRC_FONTS = $(wildcard ${DIR_FONTS}/*.c) +SRC_GUI = $(wildcard ${DIR_GUI}/*.c) +SRC_Examples = $(wildcard ${DIR_Examples}/*.c) +SRC_EXAMPLE = ${SRC_Examples} +SRC_LIB = ${SRC_EPD} ${SRC_FONTS} ${SRC_GUI} + +OBJ_EXAMPLE = $(patsubst %.c,${DIR_BIN}/%.o,$(notdir ${SRC_EXAMPLE})) +OBJ_LIB = $(patsubst %.c,${DIR_BIN}/%.o,$(notdir ${SRC_LIB})) + +OBJ_DEV_RPI = $(wildcard $(DIR_BIN)/dev_hardware_SPI.o $(DIR_BIN)/RPI_sysfs_gpio.o $(DIR_BIN)/DEV_Config.o ) +OBJ_DEV_JETSON = $(wildcard $(DIR_BIN)/sysfs_software_spi.o $(DIR_BIN)/sysfs_gpio.o $(DIR_BIN)/DEV_Config.o ) DEBUG = -D DEBUG -# USELIB_RPI = USE_BCM2835_LIB -# USELIB_RPI = USE_WIRINGPI_LIB -USELIB_RPI = USE_DEV_LIB +# RASPBERRY PI LIBRARIES + +#USELIB_RPI = USE_DEV_LIB +USELIB_RPI = USE_BCM2835_LIB +#USELIB_RPI = USE_WIRINGPI_LIB + +LIB_RPI = -lm ifeq ($(USELIB_RPI), USE_BCM2835_LIB) - LIB_RPI = -lbcm2835 -lm + LIB_RPI += -lbcm2835 else ifeq ($(USELIB_RPI), USE_WIRINGPI_LIB) - LIB_RPI = -lwiringPi -lm -else ifeq ($(USELIB_RPI), USE_DEV_LIB) - LIB_RPI = -lm + LIB_RPI += -lwiringPi endif DEBUG_RPI = -D $(USELIB_RPI) -D RPI -USELIB_JETSONI = USE_DEV_LIB -# USELIB_JETSONI = USE_HARDWARE_LIB -ifeq ($(USELIB_JETSONI), USE_DEV_LIB) - LIB_JETSONI = -lm -else ifeq ($(USELIB_JETSONI), USE_HARDWARE_LIB) - LIB_JETSONI = -lm -endif -DEBUG_JETSONI = -D $(USELIB_JETSONI) -D JETSON + +# JETSON NANO LIBRARIES + +USELIB_JETSON = USE_DEV_LIB +#USELIB_JETSON = USE_HARDWARE_LIB + +LIB_JETSON = -lm +DEBUG_JETSON = -D $(USELIB_JETSON) -D JETSON + .PHONY : RPI JETSON clean -RPI:RPI_DEV RPI_epd -JETSON: JETSON_DEV JETSON_epd +all: select_one +RPI: make_bin_dir RPI_DEV RPI_lib RPI_example +JETSON: make_bin_dir JETSON_DEV JETSON_lib JETSON_example -TARGET = epd +TARGET_example = epd +TARGET_lib = libepd.so CC = gcc -MSG = -g -O0 -Wall -CFLAGS += $(MSG) +CFLAGS += -g -O0 -Wall -RPI_epd:${OBJ_O} +select_one: + $(info Use 'make RPI' or 'make JETSON') + +make_bin_dir: + mkdir -p ${DIR_BIN} + +RPI_lib: make_bin_dir ${OBJ_LIB} + $(CC) -shared -o ${TARGET_lib} ${OBJ_LIB} ${OBJ_DEV_RPI} ${LIB_RPI} + +JETSON_lib: make_bin_dir ${OBJ_LIB} + $(CC) -shared -o ${TARGET_lib} ${OBJ_LIB} ${OBJ_DEV_JETSON} ${LIB_JETSON} + +RPI_example: RPI_lib ${OBJ_EXAMPLE} echo $(@) - $(CC) $(CFLAGS) -D RPI $(OBJ_O) $(RPI_DEV_C) -o $(TARGET) $(LIB_RPI) $(DEBUG) + $(CC) $(CFLAGS) -D RPI $(OBJ_EXAMPLE) -o $(TARGET_example) $(LIB_RPI) $(DEBUG) -L$(DIR_LIB) -lepd -Wl,-rpath=$(DIR_LIB) -JETSON_epd:${OBJ_O} +JETSON_example: JETSON_lib ${OBJ_EXAMPLE} echo $(@) - $(CC) $(CFLAGS) $(OBJ_O) $(JETSON_DEV_C) -o $(TARGET) $(LIB_JETSONI) $(DEBUG) + $(CC) $(CFLAGS) -D JETSON $(OBJ_EXAMPLE) -o $(TARGET_example) $(LIB_JETSON) $(DEBUG) -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) $(DEBUG) + $(CC) $(CFLAGS) -c $< -o $@ -I $(DIR_Config) -I $(DIR_GUI) -I $(DIR_EPD) $(DEBUG) ${DIR_BIN}/%.o:$(DIR_EPD)/%.c - $(CC) $(CFLAGS) -c $< -o $@ -I $(DIR_Config) $(DEBUG) + $(CC) $(CFLAGS) -c $< -o $@ -I $(DIR_Config) $(DEBUG) ${DIR_BIN}/%.o:$(DIR_FONTS)/%.c - $(CC) $(CFLAGS) -c $< -o $@ $(DEBUG) + $(CC) $(CFLAGS) -c $< -o $@ $(DEBUG) ${DIR_BIN}/%.o:$(DIR_GUI)/%.c - $(CC) $(CFLAGS) -c $< -o $@ -I $(DIR_Config) $(DEBUG) + $(CC) $(CFLAGS) -c $< -o $@ -I $(DIR_Config) $(DEBUG) RPI_DEV: $(CC) $(CFLAGS) $(DEBUG_RPI) -c $(DIR_Config)/dev_hardware_SPI.c -o $(DIR_BIN)/dev_hardware_SPI.o $(LIB_RPI) $(DEBUG) @@ -71,11 +96,11 @@ RPI_DEV: $(CC) $(CFLAGS) $(DEBUG_RPI) -c $(DIR_Config)/DEV_Config.c -o $(DIR_BIN)/DEV_Config.o $(LIB_RPI) $(DEBUG) JETSON_DEV: - $(CC) $(CFLAGS) $(DEBUG_JETSONI) -c $(DIR_Config)/sysfs_software_spi.c -o $(DIR_BIN)/sysfs_software_spi.o $(LIB_JETSONI) $(DEBUG) - $(CC) $(CFLAGS) $(DEBUG_JETSONI) -c $(DIR_Config)/sysfs_gpio.c -o $(DIR_BIN)/sysfs_gpio.o $(LIB_JETSONI) $(DEBUG) - $(CC) $(CFLAGS) $(DEBUG_JETSONI) -c $(DIR_Config)/DEV_Config.c -o $(DIR_BIN)/DEV_Config.o $(LIB_JETSONI) $(DEBUG) + $(CC) $(CFLAGS) $(DEBUG_JETSON) -c $(DIR_Config)/sysfs_software_spi.c -o $(DIR_BIN)/sysfs_software_spi.o $(LIB_JETSON) $(DEBUG) + $(CC) $(CFLAGS) $(DEBUG_JETSON) -c $(DIR_Config)/sysfs_gpio.c -o $(DIR_BIN)/sysfs_gpio.o $(LIB_JETSON) $(DEBUG) + $(CC) $(CFLAGS) $(DEBUG_JETSON) -c $(DIR_Config)/DEV_Config.c -o $(DIR_BIN)/DEV_Config.o $(LIB_JETSON) $(DEBUG) clean : - rm $(DIR_BIN)/*.* - rm $(TARGET) + rm -rf $(DIR_BIN) + rm -f $(TARGET_example) $(TARGET_lib) diff --git a/RaspberryPi&JetsonNano/c/examples/main.c b/RaspberryPi&JetsonNano/c/examples/main.c index ac64be8..c9357ce 100644 --- a/RaspberryPi&JetsonNano/c/examples/main.c +++ b/RaspberryPi&JetsonNano/c/examples/main.c @@ -15,8 +15,9 @@ int main(void) { // Exception handling:ctrl + c signal(SIGINT, Handler); + printf("Uncomment the test you want to run in examples/main.c\n"); - // EPD_1in54_test(); + EPD_1in54_test(); // EPD_1in54_V2_test(); // EPD_1in54b_test(); // EPD_1in54c_test();