Skip to content

Commit

Permalink
extmod: Make extmod.mk self-contained.
Browse files Browse the repository at this point in the history
This makes it so that all a port needs to do is set the relevant variables
and "include extmod.mk" and doesn't need to worry about adding anything to
OBJ, CFLAGS, SRC_QSTR, etc.

Make all extmod variables (src, flags, etc) private to extmod.mk.

Also move common/shared, extmod-related fragments (e.g. wiznet, cyw43,
bluetooth) into extmod.mk.

Now that SRC_MOD, CFLAGS_MOD, CXXFLAGS_MOD are unused by both extmod.mk
(and user-C-modules in a previous commit), remove all uses of them from
port makefiles.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
  • Loading branch information
jimmo authored and dpgeorge committed Oct 11, 2022
1 parent 87011f6 commit d6d8722
Show file tree
Hide file tree
Showing 21 changed files with 235 additions and 283 deletions.
38 changes: 23 additions & 15 deletions extmod/btstack/btstack.mk
Expand Up @@ -3,17 +3,19 @@
ifeq ($(MICROPY_BLUETOOTH_BTSTACK),1)

GIT_SUBMODULES += lib/btstack

MICROPY_BLUETOOTH_BTSTACK_USB ?= 0
MICROPY_BLUETOOTH_BTSTACK_H4 ?= 1

BTSTACK_EXTMOD_DIR = extmod/btstack

EXTMOD_SRC_C += extmod/btstack/modbluetooth_btstack.c
SRC_EXTMOD_C += $(BTSTACK_EXTMOD_DIR)/modbluetooth_btstack.c

INC += -I$(TOP)/$(BTSTACK_EXTMOD_DIR)

CFLAGS_MOD += -DMICROPY_BLUETOOTH_BTSTACK=1
CFLAGS_MOD += -DMICROPY_PY_BLUETOOTH_USE_SYNC_EVENTS=1
CFLAGS_MOD += -DMICROPY_PY_BLUETOOTH_ENABLE_PAIRING_BONDING=1
CFLAGS_EXTMOD += -DMICROPY_BLUETOOTH_BTSTACK=1
CFLAGS_EXTMOD += -DMICROPY_PY_BLUETOOTH_USE_SYNC_EVENTS=1
CFLAGS_EXTMOD += -DMICROPY_PY_BLUETOOTH_ENABLE_PAIRING_BONDING=1

BTSTACK_DIR = $(TOP)/lib/btstack

Expand All @@ -28,44 +30,50 @@ INC += -I$(BTSTACK_DIR)/3rd-party/bluedroid/encoder/include
INC += -I$(BTSTACK_DIR)/3rd-party/md5
INC += -I$(BTSTACK_DIR)/3rd-party/yxml

SRC_BTSTACK = \
SRC_BTSTACK_C = \
$(addprefix lib/btstack/src/, $(SRC_FILES)) \
$(addprefix lib/btstack/src/ble/, $(filter-out %_tlv.c, $(SRC_BLE_FILES))) \

ifeq ($(MICROPY_BLUETOOTH_BTSTACK_USB),1)
ifeq ($(MICROPY_BLUETOOTH_BTSTACK_H4),1)
$(error Cannot specifiy both MICROPY_BLUETOOTH_BTSTACK_USB and MICROPY_BLUETOOTH_BTSTACK_H4)
$(error Cannot enable both MICROPY_BLUETOOTH_BTSTACK_USB and MICROPY_BLUETOOTH_BTSTACK_H4)
endif
endif

ifneq ($(MICROPY_BLUETOOTH_BTSTACK_USB),1)
ifneq ($(MICROPY_BLUETOOTH_BTSTACK_H4),1)
$(error Must enable one of MICROPY_BLUETOOTH_BTSTACK_USB or MICROPY_BLUETOOTH_BTSTACK_H4)
endif
endif

ifeq ($(MICROPY_BLUETOOTH_BTSTACK_USB),1)
SRC_BTSTACK += \
SRC_BTSTACK_C += \
lib/btstack/platform/libusb/hci_transport_h2_libusb.c

CFLAGS_MOD += -DMICROPY_BLUETOOTH_BTSTACK_USB=1
CFLAGS_EXTMOD += -DMICROPY_BLUETOOTH_BTSTACK_USB=1

CFLAGS += $(shell pkg-config libusb-1.0 --cflags)
LDFLAGS += $(shell pkg-config libusb-1.0 --libs)
CFLAGS_THIRDPARTY += $(shell pkg-config libusb-1.0 --cflags)
LDFLAGS_THIRDPARTY += $(shell pkg-config libusb-1.0 --libs)
endif

ifeq ($(MICROPY_BLUETOOTH_BTSTACK_H4),1)
SRC_BTSTACK += \
SRC_BTSTACK_C += \
lib/btstack/src/hci_transport_h4.c \
lib/btstack/chipset/zephyr/btstack_chipset_zephyr.c

EXTMOD_SRC_C += \
SRC_BTSTACK_C += \
extmod/btstack/btstack_hci_uart.c \

CFLAGS_MOD += -DMICROPY_BLUETOOTH_BTSTACK_H4=1
CFLAGS_EXTMOD += -DMICROPY_BLUETOOTH_BTSTACK_H4=1
endif

ifeq ($(MICROPY_BLUETOOTH_BTSTACK_ENABLE_CLASSIC),1)
include $(BTSTACK_DIR)/src/classic/Makefile.inc
SRC_BTSTACK += \
SRC_BTSTACK_C += \
$(addprefix lib/btstack/src/classic/, $(SRC_CLASSIC_FILES))
endif

LIB_SRC_C += $(SRC_BTSTACK)
SRC_THIRDPARTY_C += $(SRC_BTSTACK_C)

# Suppress some warnings.
BTSTACK_WARNING_CFLAGS = -Wno-old-style-definition -Wno-unused-variable -Wno-unused-parameter -Wno-implicit-fallthrough
Expand Down
208 changes: 138 additions & 70 deletions extmod/extmod.mk
@@ -1,67 +1,78 @@
# This makefile fragment adds the source code files for the core extmod modules
# and provides rules to build 3rd-party components for extmod modules.

PY_EXTMOD_O_BASENAME = \
extmod/moduasyncio.o \
extmod/moductypes.o \
extmod/modujson.o \
extmod/moduos.o \
extmod/modure.o \
extmod/moduzlib.o \
extmod/moduheapq.o \
extmod/modutimeq.o \
extmod/moduhashlib.o \
extmod/moducryptolib.o \
extmod/modubinascii.o \
extmod/virtpin.o \
extmod/machine_bitstream.o \
extmod/machine_mem.o \
extmod/machine_pinbase.o \
extmod/machine_signal.o \
extmod/machine_pulse.o \
extmod/machine_pwm.o \
extmod/machine_i2c.o \
extmod/machine_spi.o \
extmod/modbluetooth.o \
extmod/modlwip.o \
extmod/modussl_axtls.o \
extmod/modussl_mbedtls.o \
extmod/moduplatform.o\
extmod/modurandom.o \
extmod/moduselect.o \
extmod/moduwebsocket.o \
extmod/modwebrepl.o \
extmod/modframebuf.o \
extmod/vfs.o \
extmod/vfs_blockdev.o \
extmod/vfs_reader.o \
extmod/vfs_posix.o \
extmod/vfs_posix_file.o \
extmod/vfs_fat.o \
extmod/vfs_fat_diskio.o \
extmod/vfs_fat_file.o \
extmod/vfs_lfs.o \
extmod/utime_mphal.o \
extmod/uos_dupterm.o \
shared/libc/abort_.o \
shared/libc/printf.o \
SRC_EXTMOD_C += \
extmod/machine_bitstream.c \
extmod/machine_i2c.c \
extmod/machine_mem.c \
extmod/machine_pinbase.c \
extmod/machine_pulse.c \
extmod/machine_pwm.c \
extmod/machine_signal.c \
extmod/machine_spi.c \
extmod/modbluetooth.c \
extmod/modbtree.c \
extmod/modframebuf.c \
extmod/modlwip.c \
extmod/modnetwork.c \
extmod/modonewire.c \
extmod/moduasyncio.c \
extmod/modubinascii.c \
extmod/moducryptolib.c \
extmod/moductypes.c \
extmod/moduhashlib.c \
extmod/moduheapq.c \
extmod/modujson.c \
extmod/moduos.c \
extmod/moduplatform.c\
extmod/modurandom.c \
extmod/modure.c \
extmod/moduselect.c \
extmod/modusocket.c \
extmod/modussl_axtls.c \
extmod/modussl_mbedtls.c \
extmod/modutimeq.c \
extmod/moduwebsocket.c \
extmod/moduzlib.c \
extmod/modwebrepl.c \
extmod/network_cyw43.c \
extmod/network_ninaw10.c \
extmod/network_wiznet5k.c \
extmod/uos_dupterm.c \
extmod/utime_mphal.c \
extmod/vfs.c \
extmod/vfs_blockdev.c \
extmod/vfs_fat.c \
extmod/vfs_fat_diskio.c \
extmod/vfs_fat_file.c \
extmod/vfs_lfs.c \
extmod/vfs_posix.c \
extmod/vfs_posix_file.c \
extmod/vfs_reader.c \
extmod/virtpin.c \
shared/libc/abort_.c \
shared/libc/printf.c \

PY_EXTMOD_O = $(addprefix $(BUILD)/, $(PY_EXTMOD_O_BASENAME))
SRC_THIRDPARTY_C += \

PY_O += $(PY_EXTMOD_O)
SRC_QSTR += $(PY_EXTMOD_O_BASENAME:.o=.c)
PY_O += $(addprefix $(BUILD)/, $(SRC_EXTMOD_C:.c=.o))
PY_O += $(addprefix $(BUILD)/, $(SRC_THIRDPARTY_C:.c=.o))
SRC_QSTR += $(SRC_EXTMOD_C)

CFLAGS += $(CFLAGS_EXTMOD) $(CFLAGS_THIRDPARTY)
LDFLAGS += $(LDFLAGS_EXTMOD) $(LDFLAGS_THIRDPARTY)

################################################################################
# VFS FAT FS

OOFATFS_DIR = lib/oofatfs

# this sets the config file for FatFs
CFLAGS_MOD += -DFFCONF_H=\"$(OOFATFS_DIR)/ffconf.h\"
CFLAGS_THIRDPARTY += -DFFCONF_H=\"$(OOFATFS_DIR)/ffconf.h\"

ifeq ($(MICROPY_VFS_FAT),1)
CFLAGS_MOD += -DMICROPY_VFS_FAT=1
SRC_MOD += $(addprefix $(OOFATFS_DIR)/,\
CFLAGS_EXTMOD += -DMICROPY_VFS_FAT=1
SRC_THIRDPARTY_C += $(addprefix $(OOFATFS_DIR)/,\
ff.c \
ffunicode.c \
)
Expand All @@ -73,18 +84,18 @@ endif
LITTLEFS_DIR = lib/littlefs

ifeq ($(MICROPY_VFS_LFS1),1)
CFLAGS_MOD += -DMICROPY_VFS_LFS1=1
CFLAGS_MOD += -DLFS1_NO_MALLOC -DLFS1_NO_DEBUG -DLFS1_NO_WARN -DLFS1_NO_ERROR -DLFS1_NO_ASSERT
SRC_MOD += $(addprefix $(LITTLEFS_DIR)/,\
CFLAGS_EXTMOD += -DMICROPY_VFS_LFS1=1
CFLAGS_THIRDPARTY += -DLFS1_NO_MALLOC -DLFS1_NO_DEBUG -DLFS1_NO_WARN -DLFS1_NO_ERROR -DLFS1_NO_ASSERT
SRC_THIRDPARTY_C += $(addprefix $(LITTLEFS_DIR)/,\
lfs1.c \
lfs1_util.c \
)
endif

ifeq ($(MICROPY_VFS_LFS2),1)
CFLAGS_MOD += -DMICROPY_VFS_LFS2=1
CFLAGS_MOD += -DLFS2_NO_MALLOC -DLFS2_NO_DEBUG -DLFS2_NO_WARN -DLFS2_NO_ERROR -DLFS2_NO_ASSERT
SRC_MOD += $(addprefix $(LITTLEFS_DIR)/,\
CFLAGS_EXTMOD += -DMICROPY_VFS_LFS2=1
CFLAGS_THIRDPARTY += -DLFS2_NO_MALLOC -DLFS2_NO_DEBUG -DLFS2_NO_WARN -DLFS2_NO_ERROR -DLFS2_NO_ASSERT
SRC_THIRDPARTY_C += $(addprefix $(LITTLEFS_DIR)/,\
lfs2.c \
lfs2_util.c \
)
Expand All @@ -96,13 +107,13 @@ endif
# ussl

ifeq ($(MICROPY_PY_USSL),1)
CFLAGS_MOD += -DMICROPY_PY_USSL=1
CFLAGS_EXTMOD += -DMICROPY_PY_USSL=1
ifeq ($(MICROPY_SSL_AXTLS),1)
CFLAGS_MOD += -DMICROPY_SSL_AXTLS=1 -I$(TOP)/lib/axtls/ssl -I$(TOP)/lib/axtls/crypto -I$(TOP)/extmod/axtls-include
AXTLS_DIR = lib/axtls
GIT_SUBMODULES += $(AXTLS_DIR)
CFLAGS_EXTMOD += -DMICROPY_SSL_AXTLS=1 -I$(TOP)/lib/axtls/ssl -I$(TOP)/lib/axtls/crypto -I$(TOP)/extmod/axtls-include
$(BUILD)/$(AXTLS_DIR)/%.o: CFLAGS += -Wno-all -Wno-unused-parameter -Wno-uninitialized -Wno-sign-compare -Wno-old-style-definition -Dmp_stream_errno=errno $(AXTLS_DEFS_EXTRA)
SRC_MOD += $(addprefix $(AXTLS_DIR)/,\
SRC_THIRDPARTY_C += $(addprefix $(AXTLS_DIR)/,\
ssl/asn1.c \
ssl/loader.c \
ssl/tls1.c \
Expand All @@ -120,8 +131,9 @@ SRC_MOD += $(addprefix $(AXTLS_DIR)/,\
else ifeq ($(MICROPY_SSL_MBEDTLS),1)
MBEDTLS_DIR = lib/mbedtls
GIT_SUBMODULES += $(MBEDTLS_DIR)
SRC_MOD += lib/mbedtls_errors/mp_mbedtls_errors.c
SRC_MOD += $(addprefix $(MBEDTLS_DIR)/library/,\
CFLAGS_EXTMOD += -DMICROPY_SSL_MBEDTLS=1 -I$(TOP)/$(MBEDTLS_DIR)/include
SRC_THIRDPARTY_C += lib/mbedtls_errors/mp_mbedtls_errors.c
SRC_THIRDPARTY_C += $(addprefix $(MBEDTLS_DIR)/library/,\
aes.c \
aesni.c \
arc4.c \
Expand Down Expand Up @@ -204,10 +216,10 @@ GIT_SUBMODULES += lib/lwip
# A port should add an include path where lwipopts.h can be found (eg extmod/lwip-include)
LWIP_DIR = lib/lwip/src
INC += -I$(TOP)/$(LWIP_DIR)/include
CFLAGS_MOD += -DMICROPY_PY_LWIP=1
$(BUILD)/$(LWIP_DIR)/core/ipv4/dhcp.o: CFLAGS_MOD += -Wno-address
SRC_MOD += shared/netutils/netutils.c
SRC_MOD += $(addprefix $(LWIP_DIR)/,\
CFLAGS_EXTMOD += -DMICROPY_PY_LWIP=1
$(BUILD)/$(LWIP_DIR)/core/ipv4/dhcp.o: CFLAGS += -Wno-address
SRC_THIRDPARTY_C += shared/netutils/netutils.c
SRC_THIRDPARTY_C += $(addprefix $(LWIP_DIR)/,\
apps/mdns/mdns.c \
core/def.c \
core/dns.c \
Expand Down Expand Up @@ -246,8 +258,8 @@ SRC_MOD += $(addprefix $(LWIP_DIR)/,\
netif/ethernet.c \
)
ifeq ($(MICROPY_PY_LWIP_SLIP),1)
CFLAGS_MOD += -DMICROPY_PY_LWIP_SLIP=1
SRC_MOD += $(LWIP_DIR)/netif/slipif.c
CFLAGS_EXTMOD += -DMICROPY_PY_LWIP_SLIP=1
SRC_THIRDPARTY_C += $(LWIP_DIR)/netif/slipif.c
endif
endif

Expand All @@ -258,8 +270,7 @@ ifeq ($(MICROPY_PY_BTREE),1)
BTREE_DIR = lib/berkeley-db-1.xx
BTREE_DEFS = -D__DBINTERFACE_PRIVATE=1 -Dmpool_error=printf -Dabort=abort_ "-Dvirt_fd_t=void*" $(BTREE_DEFS_EXTRA)
INC += -I$(TOP)/$(BTREE_DIR)/PORT/include
SRC_MOD += extmod/modbtree.c
SRC_MOD += $(addprefix $(BTREE_DIR)/,\
SRC_THIRDPARTY_C += $(addprefix $(BTREE_DIR)/,\
btree/bt_close.c \
btree/bt_conv.c \
btree/bt_debug.c \
Expand All @@ -275,10 +286,67 @@ SRC_MOD += $(addprefix $(BTREE_DIR)/,\
btree/bt_utils.c \
mpool/mpool.c \
)
CFLAGS_MOD += -DMICROPY_PY_BTREE=1
CFLAGS_EXTMOD += -DMICROPY_PY_BTREE=1
# we need to suppress certain warnings to get berkeley-db to compile cleanly
# and we have separate BTREE_DEFS so the definitions don't interfere with other source code
$(BUILD)/$(BTREE_DIR)/%.o: CFLAGS += -Wno-old-style-definition -Wno-sign-compare -Wno-unused-parameter $(BTREE_DEFS)
$(BUILD)/extmod/modbtree.o: CFLAGS += $(BTREE_DEFS)
endif

################################################################################
# networking

ifeq ($(MICROPY_PY_NETWORK_CYW43),1)
CFLAGS_EXTMOD += -DMICROPY_PY_NETWORK_CYW43=1
DRIVERS_SRC_C += drivers/cyw43/cyw43_ctrl.c drivers/cyw43/cyw43_lwip.c
LIBS += $(TOP)/drivers/cyw43/libcyw43.a
endif

ifneq ($(MICROPY_PY_NETWORK_WIZNET5K),)
ifneq ($(MICROPY_PY_NETWORK_WIZNET5K),0)
WIZNET5K_DIR=lib/wiznet5k
GIT_SUBMODULES += lib/wiznet5k
INC += -I$(TOP)/$(WIZNET5K_DIR) -I$(TOP)/$(WIZNET5K_DIR)/Ethernet
CFLAGS += -DMICROPY_PY_NETWORK_WIZNET5K=$(MICROPY_PY_NETWORK_WIZNET5K) -D_WIZCHIP_=$(MICROPY_PY_NETWORK_WIZNET5K)
CFLAGS_THIRDPARTY += -DWIZCHIP_PREFIXED_EXPORTS=1
ifeq ($(MICROPY_PY_LWIP),1)
# When using MACRAW mode (with lwIP), maximum buffer space must be used for the raw socket
CFLAGS_THIRDPARTY += -DWIZCHIP_USE_MAX_BUFFER
endif
SRC_THIRDPARTY_C += $(addprefix $(WIZNET5K_DIR)/,\
Ethernet/W$(MICROPY_PY_NETWORK_WIZNET5K)/w$(MICROPY_PY_NETWORK_WIZNET5K).c \
Ethernet/wizchip_conf.c \
Ethernet/socket.c \
Internet/DNS/dns.c \
Internet/DHCP/dhcp.c \
)
endif
endif

################################################################################
# bluetooth

ifeq ($(MICROPY_PY_BLUETOOTH),1)
CFLAGS_EXTMOD += -DMICROPY_PY_BLUETOOTH=1

ifeq ($(MICROPY_BLUETOOTH_NIMBLE),1)
ifeq ($(MICROPY_BLUETOOTH_BTSTACK),1)
$(error Cannot enable both NimBLE and BTstack at the same time)
endif
endif

ifneq ($(MICROPY_BLUETOOTH_NIMBLE),1)
ifneq ($(MICROPY_BLUETOOTH_BTSTACK),1)
$(error Must enable one of MICROPY_BLUETOOTH_NIMBLE or MICROPY_BLUETOOTH_BTSTACK)
endif
endif

ifeq ($(MICROPY_BLUETOOTH_NIMBLE),1)
include $(TOP)/extmod/nimble/nimble.mk
endif

ifeq ($(MICROPY_BLUETOOTH_BTSTACK),1)
include $(TOP)/extmod/btstack/btstack.mk
endif

endif
5 changes: 3 additions & 2 deletions extmod/network_wiznet5k.c
Expand Up @@ -33,15 +33,16 @@
#include "py/stream.h"
#include "py/mperrno.h"
#include "py/mphal.h"

#if MICROPY_PY_NETWORK_WIZNET5K

#include "shared/netutils/netutils.h"
#include "extmod/modnetwork.h"
#include "extmod/machine_spi.h"
#include "extmod/virtpin.h"
#include "modmachine.h"
#include "drivers/bus/spi.h"

#if MICROPY_PY_NETWORK_WIZNET5K

#include "lib/wiznet5k/Ethernet/wizchip_conf.h"

// The WIZNET5K module supports two usage modes:
Expand Down

0 comments on commit d6d8722

Please sign in to comment.