summaryrefslogtreecommitdiff
path: root/libloragw/Makefile
diff options
context:
space:
mode:
Diffstat (limited to 'libloragw/Makefile')
-rw-r--r--libloragw/Makefile222
1 files changed, 164 insertions, 58 deletions
diff --git a/libloragw/Makefile b/libloragw/Makefile
index 2b91fa8..9d5660b 100644
--- a/libloragw/Makefile
+++ b/libloragw/Makefile
@@ -1,84 +1,190 @@
-# putting the configuration in a separate file
+### get external defined data
+
+LIBLORAGW_VERSION := `cat ../VERSION`
include library.cfg
-# constant symbols
-CROSS_COMPILE=
-CC=gcc
-CFLAGS=-O2 -Wall -Wextra -Iinc -I.
-C99FLAGS=-O2 -Wall -Wextra -std=c99 -Iinc -I.
+### constant symbols
-# configuration-dependant symbols
-ifeq ($(LGW_PHY),native)
-LDFLAGS=-lrt
-endif
-ifeq ($(LGW_PHY),ftdi)
-LDFLAGS=-lrt -lmpsse
-endif
+CROSS_COMPILE :=
+CC := $(CROSS_COMPILE)gcc
+AR := $(CROSS_COMPILE)ar
-# general build targets
+CFLAGS := -O2 -Wall -Wextra -std=c99 -Iinc -I.
-all: libloragw.a test_loragw_spi test_loragw_reg test_loragw_hal test_loragw_gps
+### library.cfg configuration file processing
-clean:
- rm -f *.a
- rm -f test_*
- rm -f obj/*.o
- rm -f .conf_ok
+ifeq ($(CFG_SPI),native)
+ CFG_SPI_MSG := Linux native SPI driver (/dev/spidev0.0)
+ CFG_SPI_OPT := CFG_SPI_NATIVE
+else ifeq ($(CFG_SPI),ftdi)
+ CFG_SPI_MSG := FTDI SPI-over-USB bridge using libmpsse/libftdi/libusb
+ CFG_SPI_OPT := CFG_SPI_FTDI
+else
+ $(error No SPI physical layer selected, check ../target.cfg file.)
+endif
+
+ifeq ($(CFG_CHIP),sx1301)
+ CFG_CHIP_MSG := Semtech SX1301 production chip
+ CFG_CHIP_OPT := CFG_CHIP_1301
+else ifeq ($(CFG_CHIP),fpga1301)
+ CFG_CHIP_MSG := FPGA containing the SX1301 IP
+ CFG_CHIP_OPT := CFG_CHIP_FPGA
+else
+ $(error No concentrator chip selected, check library.cfg file.)
+endif
-.conf_ok: library.cfg
- @echo "*** Checking Lora gateway HAL library config ***"
- @rm -f .conf_ok
-ifeq ($(LGW_PHY),native)
- @echo "Selected SPI interface type: Linux native driver"
+ifeq ($(CFG_RADIO),sx1257)
+ CFG_RADIO_MSG := Dual SX1257 transceivers, covering 860-1000 MHz
+ CFG_RADIO_OPT := CFG_RADIO_1257
+else ifeq ($(CFG_RADIO),sx1255)
+ CFG_RADIO_MSG := Dual SX1255 transceivers, covering 400-510 MHz
+ CFG_RADIO_OPT := CFG_RADIO_1255
else
-ifeq ($(LGW_PHY),ftdi)
- @echo "Selected SPI interface type: FTDI SPI-over-USB bridge"
+ $(error No radio chip selected, check library.cfg file.)
+endif
+
+ifeq ($(CFG_BAND),full)
+ CFG_BAND_MSG := Full range supported by the radio(s)
+ CFG_BAND_OPT := CFG_BAND_FULL
+else ifeq ($(CFG_BAND),eu868)
+ ifeq ($(CFG_RADIO),sx1257)
+ CFG_BAND_MSG := ETSI 868 (866) MHz band
+ CFG_BAND_OPT := CFG_BAND_868
+ else
+ $(error The selected radio(s) cannot work in the selected band.)
+ endif
+else ifeq ($(CFG_BAND),us915)
+ ifeq ($(CFG_RADIO),sx1257)
+ CFG_BAND_MSG := FCC 915 MHz band
+ CFG_BAND_OPT := CFG_BAND_915
+ else
+ $(error The selected radio(s) cannot work in the selected band.)
+ endif
+else ifeq ($(CFG_BAND),cn470)
+ ifeq ($(CFG_RADIO),sx1255)
+ CFG_BAND_MSG := China 470 MHz band
+ CFG_BAND_OPT := CFG_BAND_470
+ else
+ $(error The selected radio(s) cannot work in the selected band.)
+ endif
+else ifeq ($(CFG_BAND),eu433)
+ ifeq ($(CFG_RADIO),sx1255)
+ CFG_BAND_MSG := ETSI 433 MHz band
+ CFG_BAND_OPT := CFG_BAND_433
+ else
+ $(error The selected radio(s) cannot work in the selected band.)
+ endif
else
- $(error No SPI physical layer selected)
+ $(warning [Warning] No frequency band selected, full radio capability assumed.)
+ CFG_BAND_MSG := Full range supported by the radio(s)
+ CFG_BAND_OPT := CFG_BAND_FULL
endif
+
+ifeq ($(CFG_BRD),dev_nano_868)
+ CFG_BRD_MSG := FPGA-based nano-concentrator, with 868 MHz SAW filter
+ CFG_BRD_OPT := CFG_BRD_NANO868
+else ifeq ($(CFG_BRD),ref_1301_57nf)
+ CFG_BRD_MSG := SX1301 reference board with SX1257 radios, no filters
+ CFG_BRD_OPT := CFG_BRD_REF1301
+else
+ $(info [Info] No specific board selected.)
+ CFG_BRD_MSG := None
+ CFG_BRD_OPT := CFG_BRD_NONE
endif
- @echo "*** Config seems ok ***"
- @echo ""
- @touch .conf_ok
-# static library
+### linking options
-libloragw.a: obj/loragw_hal.o obj/loragw_gps.o obj/loragw_reg.o obj/loragw_spi.o obj/loragw_aux.o
- $(CROSS_COMPILE)ar rcs libloragw.a obj/loragw_hal.o obj/loragw_gps.o obj/loragw_reg.o obj/loragw_spi.o obj/loragw_aux.o
+ifeq ($(CFG_SPI),native)
+ LIBS := -lloragw -lrt
+else ifeq ($(CFG_SPI),ftdi)
+ LIBS := -lloragw -lrt -lmpsse
+endif
-# library module target
+### general build targets
-obj/loragw_aux.o: .conf_ok src/loragw_aux.c inc/loragw_aux.h
- $(CROSS_COMPILE)$(CC) -c $(CFLAGS) src/loragw_aux.c -o obj/loragw_aux.o $(FLAG_AUX)
+all: libloragw.a test_loragw_spi test_loragw_reg test_loragw_hal test_loragw_gps
-obj/loragw_spi.o: .conf_ok src/loragw_spi.native.c src/loragw_spi.ftdi.c inc/loragw_spi.h
-ifeq ($(LGW_PHY),native)
- $(CROSS_COMPILE)$(CC) -c $(C99FLAGS) src/loragw_spi.native.c -o obj/loragw_spi.o $(FLAG_SPI)
-endif
-ifeq ($(LGW_PHY),ftdi)
- $(CROSS_COMPILE)$(CC) -c $(C99FLAGS) src/loragw_spi.ftdi.c -o obj/loragw_spi.o $(FLAG_SPI)
+clean:
+ rm -f libloragw.a
+ rm -f test_loragw_*
+ rm -f obj/*.o
+ rm -f inc/config.h
+
+### transpose library.cfg into a C header file : config.h
+
+inc/config.h: ../VERSION library.cfg
+ @echo "*** Checking libloragw library configuration ***"
+ @rm -f $@
+ # File initialization
+ @echo "#ifndef _LORAGW_CONFIGURATION_H" >> $@
+ @echo "#define _LORAGW_CONFIGURATION_H" >> $@
+ # Release version
+ @echo "Release version : $(LIBLORAGW_VERSION)"
+ @echo " #define LIBLORAGW_VERSION "\"$(LIBLORAGW_VERSION)\""" >> $@
+ # SPI interface
+ @echo "SPI interface : $(CFG_SPI_MSG)"
+ @echo " #define $(CFG_SPI_OPT) 1" >> $@
+ # Concentrator chip
+ @echo "Concentrator chip : $(CFG_CHIP_MSG)"
+ @echo " #define $(CFG_CHIP_OPT) 1" >> $@
+ # Radio chip(s)
+ @echo "Radio chip(s) : $(CFG_RADIO_MSG)"
+ @echo " #define $(CFG_RADIO_OPT) 1" >> $@
+ # Frequency band
+ @echo "Frequency band : $(CFG_BAND_MSG)"
+ @echo " #define $(CFG_BAND_OPT) 1" >> $@
+ # Board misc. parameters
+ @echo "Board misc. param : $(CFG_BRD_MSG)"
+ @echo " #define $(CFG_BRD_OPT) 1" >> $@
+ # Debug options
+ @echo " #define DEBUG_AUX $(DEBUG_AUX)" >> $@
+ @echo " #define DEBUG_SPI $(DEBUG_SPI)" >> $@
+ @echo " #define DEBUG_REG $(DEBUG_REG)" >> $@
+ @echo " #define DEBUG_HAL $(DEBUG_HAL)" >> $@
+ @echo " #define DEBUG_GPS $(DEBUG_GPS)" >> $@
+ # end of file
+ @echo "#endif" >> $@
+ @echo "*** Configuration seems ok ***"
+
+### library module target
+
+obj/loragw_aux.o: src/loragw_aux.c inc/loragw_aux.h inc/config.h
+ $(CC) -c $(CFLAGS) $< -o $@
+
+ifeq ($(CFG_SPI),native)
+obj/loragw_spi.o: src/loragw_spi.native.c inc/loragw_spi.h inc/config.h
+ $(CC) -c $(CFLAGS) $< -o $@
+else ifeq ($(CFG_SPI),ftdi)
+obj/loragw_spi.o: src/loragw_spi.ftdi.c inc/loragw_spi.h inc/config.h
+ $(CC) -c $(CFLAGS) $< -o $@
endif
-obj/loragw_reg.o: .conf_ok src/loragw_reg.c inc/loragw_reg.h inc/loragw_spi.h
- $(CROSS_COMPILE)$(CC) -c $(C99FLAGS) src/loragw_reg.c -o obj/loragw_reg.o $(FLAG_REG)
+obj/loragw_reg.o: src/loragw_reg.c inc/loragw_reg.h inc/loragw_spi.h inc/config.h
+ $(CC) -c $(CFLAGS) $< -o $@
-obj/loragw_hal.o: .conf_ok src/loragw_hal.c inc/loragw_hal.h inc/loragw_reg.h inc/loragw_aux.h VERSION src/arb_fw.var src/agc_fw.var
- $(CROSS_COMPILE)$(CC) -c $(C99FLAGS) src/loragw_hal.c -o obj/loragw_hal.o -D LGW_PHY="\"$(LGW_PHY)\"" $(FLAG_HAL)
+obj/loragw_hal.o: src/loragw_hal.c inc/loragw_hal.h inc/loragw_reg.h inc/loragw_aux.h src/arb_fw.var src/agc_fw.var inc/config.h
+ $(CC) -c $(CFLAGS) $< -o $@
-obj/loragw_gps.o: .conf_ok src/loragw_gps.c inc/loragw_gps.h
- $(CROSS_COMPILE)$(CC) -c $(C99FLAGS) src/loragw_gps.c -o obj/loragw_gps.o $(FLAG_GPS)
+obj/loragw_gps.o: src/loragw_gps.c inc/loragw_gps.h inc/config.h
+ $(CC) -c $(CFLAGS) $< -o $@
+
+### static library
+
+libloragw.a: obj/loragw_hal.o obj/loragw_gps.o obj/loragw_reg.o obj/loragw_spi.o obj/loragw_aux.o
+ $(AR) rcs $@ $^
-# test programs
+### test programs
-test_loragw_spi: tst/test_loragw_spi.c obj/loragw_spi.o
- $(CROSS_COMPILE)$(CC) $(C99FLAGS) tst/test_loragw_spi.c obj/loragw_spi.o -o test_loragw_spi $(LDFLAGS)
+test_loragw_spi: tst/test_loragw_spi.c libloragw.a
+ $(CC) $(CFLAGS) -L. $< -o $@ $(LIBS)
-test_loragw_reg: tst/test_loragw_reg.c obj/loragw_reg.o obj/loragw_spi.o
- $(CROSS_COMPILE)$(CC) $(C99FLAGS) tst/test_loragw_reg.c obj/loragw_reg.o obj/loragw_spi.o -o test_loragw_reg $(LDFLAGS)
+test_loragw_reg: tst/test_loragw_reg.c libloragw.a
+ $(CC) $(CFLAGS) -L. $< -o $@ $(LIBS)
-test_loragw_hal: tst/test_loragw_hal.c obj/loragw_hal.o obj/loragw_reg.o obj/loragw_spi.o obj/loragw_aux.o
- $(CROSS_COMPILE)$(CC) $(C99FLAGS) tst/test_loragw_hal.c obj/loragw_hal.o obj/loragw_reg.o obj/loragw_spi.o obj/loragw_aux.o -o test_loragw_hal $(LDFLAGS)
+test_loragw_hal: tst/test_loragw_hal.c libloragw.a
+ $(CC) $(CFLAGS) -L. $< -o $@ $(LIBS)
-test_loragw_gps: tst/test_loragw_gps.c obj/loragw_gps.o obj/loragw_hal.o obj/loragw_reg.o obj/loragw_spi.o obj/loragw_aux.o
- $(CROSS_COMPILE)$(CC) $(C99FLAGS) tst/test_loragw_gps.c obj/loragw_gps.o obj/loragw_hal.o obj/loragw_reg.o obj/loragw_spi.o obj/loragw_aux.o -o test_loragw_gps $(LDFLAGS)
+test_loragw_gps: tst/test_loragw_gps.c libloragw.a
+ $(CC) $(CFLAGS) -L. $< -o $@ $(LIBS)
+### EOF \ No newline at end of file