Skip to content

Commit f3c0857

Browse files
committed
More robust handling of Emscripten availability and Cygwin in Makefile
1 parent db168e1 commit f3c0857

File tree

1 file changed

+41
-23
lines changed

1 file changed

+41
-23
lines changed

Makefile

Lines changed: 41 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,19 @@ H8300_LD ?= $(H8300_TOOLPREFIX)ld
5858
H8300_AS ?= $(H8300_TOOLPREFIX)as
5959
H8300_OBJDUMP ?= $(H8300_TOOLPREFIX)objdump
6060

61-
H8300_FOUND := $(shell $(H8300_AS) --version >/dev/null 2>&1 && echo found)
62-
ifneq ($(H8300_FOUND), found)
63-
$(warning h8300-hitachi-coff toolchain not found, using pre-built files)
61+
H8300_FOUND := $(shell $(H8300_AS) --version > /dev/null 2>&1 && echo found)
62+
ifneq ($(H8300_FOUND),found)
63+
$(warning h8300-hitachi-coff binutils toolchain not found, using pre-built files)
64+
endif
65+
66+
#
67+
# Toolchain for Emscripten
68+
#
69+
EMSCRIPTEN_MAKE ?= emmake
70+
# NOTE: "emmake --version" does not work as a test and returns a non-zero error code
71+
EMSCRIPTEN_FOUND := $(shell which $(EMSCRIPTEN_MAKE) > /dev/null 2>&1 && echo found)
72+
ifneq ($(EMSCRIPTEN_FOUND),found)
73+
$(warning Emscripten "$(EMSCRIPTEN_MAKE)" toolchain not found, skipping Emscripten build)
6474
endif
6575

6676
# installation defaults
@@ -119,6 +129,9 @@ GEN_DIR ?= $(BUILD_DIR)/$(GEN_SUBDIR_NAME)
119129
USBOBJ ?= RCX_USBTowerPipe_none
120130
TCPOBJ ?= RCX_TcpPipe_none
121131

132+
DEFAULT_USB_NAME ?= "/dev/usb/legousbtower0"
133+
DEFAULT_DEVICE_NAME ?= "usb"
134+
122135
#
123136
# Platform specific settings
124137
#
@@ -144,61 +157,62 @@ ifneq (,$(strip $(findstring $(TARGETTYPE), JS-WebAssembly)))
144157
# - Target JavaScript instead of WASM: -s WASM=0
145158
CFLAGS_EXEC += --shell-file ./emscripten/webnqc_shell.html -s EXPORT_NAME=createWebNqc -s EXPORTED_RUNTIME_METHODS='["callMain","FS"]' \
146159
-s INVOKE_RUN=false -s MODULARIZE=1 -s ENVIRONMENT=web -s SINGLE_FILE
147-
else
148-
ifneq (,$(strip $(findstring $(OSTYPE), Darwin)))
160+
else ifneq (,$(strip $(findstring $(OSTYPE), Darwin)))
149161
# Mac OS X
150162
LIBS += -framework IOKit -framework CoreFoundation
151163
USBOBJ = RCX_USBTowerPipe_osx
152164
CXX = c++
153165
CFLAGS += -O3 -std=c++11 -Wno-deprecated-register
154-
else
155-
ifneq (,$(strip $(findstring $(OSTYPE), Linux)))
166+
else ifneq (,$(strip $(findstring $(OSTYPE), Linux)))
156167
# Linux
157168
USBOBJ = RCX_USBTowerPipe_linux
158169
TCPOBJ = RCX_TcpPipe_linux
159170
DEFAULT_SERIAL_NAME ?= "/dev/ttyS0"
160171
# Timeout value is 200 in kernel driver module legousbtower.c
161172
LEGO_TOWER_SET_READ_TIMEOUT ?= 200
162173
CFLAGS += -DLEGO_TOWER_SET_READ_TIMEOUT='$(LEGO_TOWER_SET_READ_TIMEOUT)' -Wno-deprecated
163-
else
164-
ifneq (,$(findstring $(OSTYPE), SunOS))
174+
else ifneq (,$(strip $(findstring $(OSTYPE), CYGWIN)))
175+
# Cygwin
176+
# USBOBJ = RCX_USBTowerPipe_linux
177+
TCPOBJ = RCX_TcpPipe_linux
178+
DEFAULT_DEVICE_NAME ?= "tcp"
179+
DEFAULT_SERIAL_NAME ?= "/dev/ttyS0"
180+
# Timeout value is 200 in kernel driver module legousbtower.c
181+
LEGO_TOWER_SET_READ_TIMEOUT ?= 200
182+
CFLAGS += -DLEGO_TOWER_SET_READ_TIMEOUT='$(LEGO_TOWER_SET_READ_TIMEOUT)' -Wno-deprecated
183+
else ifneq (,$(findstring $(OSTYPE), SunOS))
165184
# Solaris
166185
CFLAGS += -DSOLARIS
167-
else
168-
ifneq (,$(strip $(findstring $(OSTYPE), FreeBSD)))
186+
else ifneq (,$(strip $(findstring $(OSTYPE), FreeBSD)))
169187
# FreeBSD
170188
USBOBJ = RCX_USBTowerPipe_fbsd
171189
DEFAULT_SERIAL_NAME?= "/dev/cuad0"
172190
CFLAGS += -Wno-deprecated
173-
else
174-
ifneq (,$(strip $(findstring $(OSTYPE), OpenBSD)))
191+
else ifneq (,$(strip $(findstring $(OSTYPE), OpenBSD)))
175192
# OpenBSD i386
176193
DEFAULT_SERIAL_NAME ?= "/dev/cua00"
177194
CFLAGS += -O2 -std=gnu++98 -pipe
178195
else
179196
# default Unix build without USB support
180197
CFLAGS += -O2
181198
endif
182-
endif
183-
endif
184-
endif
185-
endif
186-
endif
187199

188200
CXX:=$(TOOLPREFIX)$(CXX)
189201

190202
#
191203
# If the serial port is explicitly set, use it.
192204
#
193205
ifneq ($(strip $(DEFAULT_SERIAL_NAME)),)
194-
CFLAGS += -DDEFAULT_SERIAL_NAME='$(DEFAULT_SERIAL_NAME)'
206+
CFLAGS += -DDEFAULT_SERIAL_NAME='$(DEFAULT_SERIAL_NAME)'
195207
endif
196208

197-
DEFAULT_USB_NAME ?= "/dev/usb/legousbtower0"
198-
CFLAGS += -DDEFAULT_USB_NAME='$(DEFAULT_USB_NAME)'
209+
ifneq ($(strip $(DEFAULT_USB_NAME)),)
210+
CFLAGS += -DDEFAULT_USB_NAME='$(DEFAULT_USB_NAME)'
211+
endif
199212

200-
DEFAULT_DEVICE_NAME ?= "usb"
213+
ifneq ($(strip $(DEFAULT_DEVICE_NAME)),)
201214
CFLAGS += -DDEFAULT_DEVICE_NAME='$(DEFAULT_DEVICE_NAME)'
215+
endif
202216

203217
#
204218
# Debug builds for most Clang/GCC environments.
@@ -251,7 +265,11 @@ $(EXEC_DIR)/nqc$(EXEC_EXT): compiler/parse.cpp $(OBJ)
251265
# Emscripten build for WebAssembly
252266
#
253267
emscripten-emmake:
254-
if which emmake > /dev/null 2>&1 ; then emmake make exec TARGETTYPE=JS-WebAssembly ; else echo -e "WARNING: \"emmake\" not found; skipping Emscripten build"; fi
268+
ifeq ($(EMSCRIPTEN_FOUND), found)
269+
$(EMSCRIPTEN_MAKE) make exec TARGETTYPE=JS-WebAssembly
270+
else
271+
@echo -e "WARNING: \"$(EMSCRIPTEN_MAKE)\" not found; skipping Emscripten build"
272+
endif
255273

256274
#
257275
# general rule for compiling

0 commit comments

Comments
 (0)