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.
This commit is contained in:
Berenguer Montserrat 2019-08-17 09:54:47 +02:00
commit 07db82a590
2 changed files with 64 additions and 38 deletions

View file

@ -4,66 +4,91 @@ DIR_FONTS = ./lib/Fonts
DIR_GUI = ./lib/GUI DIR_GUI = ./lib/GUI
DIR_Examples = ./examples DIR_Examples = ./examples
DIR_BIN = ./bin DIR_BIN = ./bin
DIR_LIB = "$(shell pwd)"
OBJ_C = $(wildcard ${DIR_EPD}/*.c ${DIR_GUI}/*.c ${DIR_Examples}/*.c ${DIR_FONTS}/*.c ) SRC_EPD = $(wildcard ${DIR_EPD}/*.c)
OBJ_O = $(patsubst %.c,${DIR_BIN}/%.o,$(notdir ${OBJ_C})) SRC_FONTS = $(wildcard ${DIR_FONTS}/*.c)
RPI_DEV_C = $(wildcard $(DIR_BIN)/dev_hardware_SPI.o $(DIR_BIN)/RPI_sysfs_gpio.o $(DIR_BIN)/DEV_Config.o ) SRC_GUI = $(wildcard ${DIR_GUI}/*.c)
JETSON_DEV_C = $(wildcard $(DIR_BIN)/sysfs_software_spi.o $(DIR_BIN)/sysfs_gpio.o $(DIR_BIN)/DEV_Config.o ) 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 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) ifeq ($(USELIB_RPI), USE_BCM2835_LIB)
LIB_RPI = -lbcm2835 -lm LIB_RPI += -lbcm2835
else ifeq ($(USELIB_RPI), USE_WIRINGPI_LIB) else ifeq ($(USELIB_RPI), USE_WIRINGPI_LIB)
LIB_RPI = -lwiringPi -lm LIB_RPI += -lwiringPi
else ifeq ($(USELIB_RPI), USE_DEV_LIB)
LIB_RPI = -lm
endif endif
DEBUG_RPI = -D $(USELIB_RPI) -D RPI DEBUG_RPI = -D $(USELIB_RPI) -D RPI
USELIB_JETSONI = USE_DEV_LIB
# USELIB_JETSONI = USE_HARDWARE_LIB # JETSON NANO LIBRARIES
ifeq ($(USELIB_JETSONI), USE_DEV_LIB)
LIB_JETSONI = -lm USELIB_JETSON = USE_DEV_LIB
else ifeq ($(USELIB_JETSONI), USE_HARDWARE_LIB) #USELIB_JETSON = USE_HARDWARE_LIB
LIB_JETSONI = -lm
endif LIB_JETSON = -lm
DEBUG_JETSONI = -D $(USELIB_JETSONI) -D JETSON DEBUG_JETSON = -D $(USELIB_JETSON) -D JETSON
.PHONY : RPI JETSON clean .PHONY : RPI JETSON clean
RPI:RPI_DEV RPI_epd all: select_one
JETSON: JETSON_DEV JETSON_epd 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 CC = gcc
MSG = -g -O0 -Wall CFLAGS += -g -O0 -Wall
CFLAGS += $(MSG)
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 $(@) 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 $(@) 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 ${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 ${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 ${DIR_BIN}/%.o:$(DIR_FONTS)/%.c
$(CC) $(CFLAGS) -c $< -o $@ $(DEBUG) $(CC) $(CFLAGS) -c $< -o $@ $(DEBUG)
${DIR_BIN}/%.o:$(DIR_GUI)/%.c ${DIR_BIN}/%.o:$(DIR_GUI)/%.c
$(CC) $(CFLAGS) -c $< -o $@ -I $(DIR_Config) $(DEBUG) $(CC) $(CFLAGS) -c $< -o $@ -I $(DIR_Config) $(DEBUG)
RPI_DEV: RPI_DEV:
$(CC) $(CFLAGS) $(DEBUG_RPI) -c $(DIR_Config)/dev_hardware_SPI.c -o $(DIR_BIN)/dev_hardware_SPI.o $(LIB_RPI) $(DEBUG) $(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) $(CC) $(CFLAGS) $(DEBUG_RPI) -c $(DIR_Config)/DEV_Config.c -o $(DIR_BIN)/DEV_Config.o $(LIB_RPI) $(DEBUG)
JETSON_DEV: 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_JETSON) -c $(DIR_Config)/sysfs_software_spi.c -o $(DIR_BIN)/sysfs_software_spi.o $(LIB_JETSON) $(DEBUG)
$(CC) $(CFLAGS) $(DEBUG_JETSONI) -c $(DIR_Config)/sysfs_gpio.c -o $(DIR_BIN)/sysfs_gpio.o $(LIB_JETSONI) $(DEBUG) $(CC) $(CFLAGS) $(DEBUG_JETSON) -c $(DIR_Config)/sysfs_gpio.c -o $(DIR_BIN)/sysfs_gpio.o $(LIB_JETSON) $(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)/DEV_Config.c -o $(DIR_BIN)/DEV_Config.o $(LIB_JETSON) $(DEBUG)
clean : clean :
rm $(DIR_BIN)/*.* rm -rf $(DIR_BIN)
rm $(TARGET) rm -f $(TARGET_example) $(TARGET_lib)

View file

@ -15,8 +15,9 @@ int main(void)
{ {
// Exception handling:ctrl + c // Exception handling:ctrl + c
signal(SIGINT, Handler); 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_1in54_V2_test();
// EPD_1in54b_test(); // EPD_1in54b_test();
// EPD_1in54c_test(); // EPD_1in54c_test();