Skip to content

Commit 7785eb9

Browse files
committed
Workarounds for GNU Autotools (#50)
Introduce a "system-wide" profile loaded before ~/.profile, and populate it with variables to guide GNU Autoconf. In general, "configure" scripts should now work out-of-the-box. Libtool assumes the host environment is MSYS2 and will be confused by Windows-style command switches. The "/c" in "cmd /c" looks like a path, which MSYS2 incorrectly decodes to "c:/". Anticipating this, libtool encodes these calls as "cmd //c" which does not work outside MSYS2. A busybox-w32 patch makes it behave like MSYS2 in just this one case. This patch has been upstreamed and will be removed on the next upgrade.
1 parent 9ca8a28 commit 7785eb9

File tree

4 files changed

+46
-1
lines changed

4 files changed

+46
-1
lines changed

Dockerfile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ RUN sha256sum -c $PREFIX/src/SHA256SUMS \
6161
&& tar xzf cppcheck-$CPPCHECK_VERSION.tar.gz
6262
COPY src/w64devkit.c src/w64devkit.ico src/libmemory.c src/libchkstk.S \
6363
src/alias.c src/debugbreak.c src/pkg-config.c src/vc++filt.c \
64-
src/peports.c $PREFIX/src/
64+
src/peports.c src/profile $PREFIX/src/
6565

6666
ARG ARCH=x86_64-w64-mingw32
6767

@@ -504,6 +504,7 @@ RUN printf "id ICON \"$PREFIX/src/w64devkit.ico\"" >w64devkit.rc \
504504
&& $ARCH-gcc -DEXE=pkg-config.exe -DCMD=pkg-config \
505505
-Os -fno-asynchronous-unwind-tables -Wl,--gc-sections -s -nostdlib \
506506
-o $PREFIX/bin/$ARCH-pkg-config.exe $PREFIX/src/alias.c -lkernel32 \
507+
&& sed -i s/'\<ARCH\>'/$ARCH/g $PREFIX/src/profile \
507508
&& mkdir -p $PREFIX/$ARCH/lib/pkgconfig \
508509
&& cp /mingw-w64-v$MINGW_VERSION/COPYING.MinGW-w64-runtime/COPYING.MinGW-w64-runtime.txt \
509510
$PREFIX/ \

src/busybox-003-fix-libtool.patch

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
--- a/shell/ash.c
2+
+++ b/shell/ash.c
3+
@@ -9142,6 +9142,17 @@ tryexec(IF_FEATURE_SH_STANDALONE(int applet_no,) const char *cmd, char **argv, c
4+
#endif
5+
6+
#if ENABLE_PLATFORM_MINGW32
7+
+ /* Workaround for libtool bug, which assumes the host is an MSYS2
8+
+ * environment and requires special-case escaping for cmd.exe.
9+
+ * https://github.com/skeeto/w64devkit/issues/50
10+
+ */
11+
+ if (string_array_len(argv) >= 3 &&
12+
+ strcmp(argv[0], "cmd") == 0 &&
13+
+ strcmp(argv[1], "//c") == 0 &&
14+
+ strcmp(argv[2], "echo") == 0) {
15+
+ argv[1]++; /* drop extra slash */
16+
+ }
17+
+
18+
/* cmd was allocated on the stack with room for an extension */
19+
add_win32_extension((char *)cmd);
20+
execve(cmd, argv, envp);

src/busybox-004-system-profile.patch

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
--- a/shell/ash.c
2+
+++ b/shell/ash.c
3+
@@ -16282,7 +16282,14 @@ int ash_main(int argc UNUSED_PARAM, char **argv)
4+
5+
state = 1;
6+
#if ENABLE_PLATFORM_MINGW32
7+
- hp = xasprintf("%s/etc/profile", get_system_drive() ?: "");
8+
+ const char *syspath = bb_busybox_exec_path;
9+
+ int syspathlen = 0;
10+
+ for (int i = 0; syspath[i]; i++) {
11+
+ if (syspath[i] == '/') {
12+
+ syspathlen = i;
13+
+ }
14+
+ }
15+
+ hp = xasprintf("%.*s/../src/profile", syspathlen, syspath);
16+
read_profile(hp);
17+
free((void *)hp);
18+
#else

src/profile

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# GNU Autotools "configure" detects w64devkit as an MSYS2 environment, so
2+
# set some environment variables to disabuse it. Goes hand-in-hand with
3+
# the busybox-w32 ash patch for libtool.
4+
export PATH_SEPARATOR=';'
5+
export ac_executable_extensions=.exe
6+
export build_alias=ARCH

0 commit comments

Comments
 (0)