Skip to content

Commit 42b5d2d

Browse files
committed
Auto detect Windows sketchbook path using USERPROFILE not HOME and spelling
1 parent e413fee commit 42b5d2d

File tree

3 files changed

+27
-15
lines changed

3 files changed

+27
-15
lines changed

Arduino.mk

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -62,20 +62,23 @@
6262
# AVR_TOOLS_DIR = /usr
6363
#
6464
# On Windows declare this environmental variables using the windows
65-
# configuration options. Control Panel > System > Advanced system settings
66-
# Also take into account that when you set them you have to add '\' on
67-
# all spaces and special characters.
65+
# configuration options or Cygwin .bashrc. Control Panel > System > Advanced system settings
66+
# The paths must use Unix style forward slash and not have any spaces
67+
# or escape charactors. One must use a symbolic link if the path does
68+
# contain spaces.
69+
#
6870
# This are just examples, you have to adapt this variables accordingly to
6971
# your system. Note the difference between ARDMK_DIR, which can use /cygdrive/
70-
# and USER_LIB_PATH, which cannnot due to invoking with the build tools
72+
# and USER_LIB_PATH, which cannnot due to invoking with the build tools.
73+
# It is best practice to avoid cygdrive all together.
7174
#
7275
# ARDUINO_DIR = C:/Arduino
7376
# AVR_TOOLS_DIR = C:/Arduino/hardware/tools/avr
7477
# ARDMK_DIR = /cygdrive/c/Users/"YourUser"/Arduino-Makefile
7578
#
7679
# On Windows it is highly recommended that you create a symbolic link directory
7780
# for avoiding using the normal directories name of windows such as
78-
# c:\Program Files (x86)\Arduino
81+
# C:\Program Files (x86)\Arduino
7982
# For this use the command mklink on the console.
8083
#
8184
#
@@ -364,9 +367,15 @@ ifndef ARDUINO_SKETCHBOOK
364367
ifneq ($(ARDUINO_SKETCHBOOK),)
365368
$(call show_config_variable,ARDUINO_SKETCHBOOK,[AUTODETECTED],(from arduino preferences file))
366369
else
367-
ARDUINO_SKETCHBOOK := $(firstword \
368-
$(call dir_if_exists,$(HOME)/sketchbook) \
369-
$(call dir_if_exists,$(HOME)/Documents/Arduino) )
370+
ifeq ($(CURRENT_OS), WINDOWS)
371+
ARDUINO_SKETCHBOOK := $(firstword \
372+
$(call dir_if_exists,$(USERPROFILE)/sketchbook) \
373+
$(call dir_if_exists,$(USERPROFILE)/Documents/Arduino) )
374+
else
375+
ARDUINO_SKETCHBOOK := $(firstword \
376+
$(call dir_if_exists,$(HOME)/sketchbook) \
377+
$(call dir_if_exists,$(HOME)/Documents/Arduino) )
378+
endif
370379
$(call show_config_variable,ARDUINO_SKETCHBOOK,[DEFAULT])
371380
endif
372381
else

Common.mk

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,3 +79,9 @@ ifndef ARDUINO_DIR
7979
else
8080
$(call show_config_variable,ARDUINO_DIR,[USER])
8181
endif
82+
83+
ifeq ($(CURRENT_OS),WINDOWS)
84+
ifneq ($(shell echo $(ARDUINO_DIR) | egrep '\\|[[:space:]]|cygdrive'),)
85+
echo $(error On Windows, ARDUINO_DIR and other defines must use forward slash and not contain spaces, special characters or be cygdrive relative)
86+
endif
87+
endif

README.md

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -205,16 +205,13 @@ On Windows (using Cygwin), you might want to set:
205205
# Symbolic link to Arduino installation directory - see below
206206
ARDUINO_DIR = C:/Arduino
207207
ARDMK_DIR = path/to/mkfile
208-
ARDUINO_SKETCHBOOK = C:/Users/USERNAME/Documents/Arduino
209208
MONITOR_PORT = com3
210209
BOARD_TAG = mega2560
211210
```
212211

213212
**NOTE: Use forward slash not backslash and there should be no spaces or
214213
special characters in the Windows paths (due to Win/Unix crossover). The paths
215-
should not be *cygdrive* paths.** `ARDUINO_SKETCHBOOK` is defined to avoid
216-
automatic resolution, which resolve to *cygdrive* and is incompatable with the
217-
build tools.
214+
should not be *cygdrive* paths.**
218215

219216
On Windows (using MSYS and PuTTY), you might want to set the following extra parameters:
220217

@@ -262,7 +259,7 @@ Instead of:
262259
ARDUINO_DIR=C:/Program\ Files\ \(x86\)/Arduino
263260
```
264261

265-
### Usefull Variables
262+
### Useful Variables
266263

267264
The list of all variables that can be overridden is available at [arduino-mk-vars.md](arduino-mk-vars.md) file.
268265

@@ -271,8 +268,8 @@ The list of all variables that can be overridden is available at [arduino-mk-var
271268
- `ARDUINO_DIR` - Path to Arduino installation. Using Windows with Cygwin,
272269
this path must use Unix / and not Windows \\ (eg "C:/Arduino" not
273270
"C:\\Arduino).
274-
- `ARDMK_DIR` - Path where the `*.mk` are present. If you installed the package, then it is usually `/usr/share/arduino`. On Windows, this should be a path without spaces and no special characters, it can be a *cygdrive* path if nessessary and must use / not \\.
275-
- `AVR_TOOLS_DIR` - Path where the avr tools chain binaries are present. If you are going to use the binaries that came with Arduino installation, then you don't have to set it. Otherwise set it realtive and not absolute.
271+
- `ARDMK_DIR` - Path where the `*.mk` are present. If you installed the package, then it is usually `/usr/share/arduino`. On Windows, this should be a path without spaces and no special characters, it can be a *cygdrive* path if necessary and must use / not \\.
272+
- `AVR_TOOLS_DIR` - Path where the avr tools chain binaries are present. If you are going to use the binaries that came with Arduino installation, then you don't have to set it. Otherwise set it relative and not absolute.
276273

277274

278275

0 commit comments

Comments
 (0)