lmi-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[lmi-commits] [lmi] master da520c6 3/3: Support WSL as an alternative to


From: Greg Chicares
Subject: [lmi-commits] [lmi] master da520c6 3/3: Support WSL as an alternative to Cygwin
Date: Sun, 26 May 2019 12:02:48 -0400 (EDT)

branch: master
commit da520c69bdc397fd665cec8697e8b53517bb45a7
Author: Gregory W. Chicares <address@hidden>
Commit: Gregory W. Chicares <address@hidden>

    Support WSL as an alternative to Cygwin
---
 INSTALL               |  53 ++++++++++++++++++++++--
 configuration.make    |   7 +++-
 install_msw.sh        |  51 ++++++++++++++++++++++-
 install_wsl.ps1       |  88 ++++++++++++++++++++++++++++++++++++++++
 msw_wsl.make          | 110 ++++++++++++++++++++++++++++++++++++++++++++++++++
 test_coding_rules.cpp |   5 ++-
 6 files changed, 305 insertions(+), 9 deletions(-)

diff --git a/INSTALL b/INSTALL
index 98c39c3..0594599 100644
--- a/INSTALL
+++ b/INSTALL
@@ -19,11 +19,13 @@
 // email: <address@hidden>
 // snail: Chicares, 186 Belle Woods Drive, Glastonbury CT 06033, USA
 
-[Just go here:
+Just go here:
   https://lists.nongnu.org/archive/html/lmi/2008-05/msg00001.html
-if you're not running ms windows.]
+if you're not running ms windows. Otherwise, follow the steps below:
+ - either (A1) or (A2) to install Cygwin or WSL, respectively; then
+ - (B) to build and run lmi.
 
-(1) Install Cygwin
+(A1) Install Cygwin
 
 Open a "Command Prompt" window, and enable pasting into it:
 
@@ -55,7 +57,46 @@ After a few minutes, you should see something like this at 
the end:
 
 Close the "Command prompt" window.
 
-(2) Install lmi
+(A2) Install WSL
+
+Open a "Windows PowerShell" window as Administrator:
+
+  Start | Programs | Windows PowerShell | Windows PowerShell
+
+Copy and paste the following lines into the "Windows PowerShell" window:
+
+  New-Item -ItemType Directory -Force -Path C:\cache_for_lmi
+  Set-Location -Path C:\cache_for_lmi
+  Invoke-WebRequest -Uri 
https://git.savannah.gnu.org/cgit/lmi.git/plain/install_wsl.ps1 -OutFile 
install_wsl.ps1 -UseBasicParsing
+  Set-ExecutionPolicy Unrestricted
+  Enable-WindowsOptionalFeature -Online -FeatureName 
Microsoft-Windows-Subsystem-Linux
+
+Agree to restart your computer.
+
+Note: Only the last two commands need administrator privileges. So if the 
execution
+policy already was set and Microsoft-Windows-Subsystem-Linux feature was 
enabled
+earlier, you don't need to execute them and restart the computer (and 
administrator
+privileges are not required either).
+
+Open a "Windows PowerShell" window (administrator privileges are not required)
+and execute the installation script:
+
+  C:\cache_for_lmi\install_wsl.ps1
+
+Select preferred OS or simply press Enter to install Ubuntu 18.04.
+After a few minutes, you should see something like this at the end:
+
+  "WSL installation seems to have succeeded"
+
+Then return back to the Restricted policy after installing
+(restart "Windows PowerShell" window as Administrator to execute
+this command):
+
+  Set-ExecutionPolicy Restricted
+
+Close the "Windows PowerShell" window.
+
+(B) Install lmi
 
 [Experienced users: Make sure 'C:\cache_for_lmi\' contains any files you
 need to download manually due to corporate firewall weirdness.]
@@ -64,6 +105,10 @@ Start a Cygwin shell:
 
   Start | Programs | Cygwin | Cygwin Terminal
 
+or a WSL shell:
+
+  Start | All Programs | Apps | <Installed OS name>
+
 Copy the following, and paste it (Shift-Insert) into the shell:
 
   mkdir -p /tmp
diff --git a/configuration.make b/configuration.make
index 7dcd910..2613871 100644
--- a/configuration.make
+++ b/configuration.make
@@ -30,7 +30,12 @@ ifeq (msys,$(findstring msys,$(lmi_build_type)))
 else ifeq (cygwin,$(findstring cygwin,$(lmi_build_type)))
   platform_makefile := msw_cygwin.make
 else
-  ifeq (mingw32,$(findstring mingw32,$(LMI_TRIPLET)))
+# 'config.guess' might indicate something like "x86_64-pc-wsl"
+# someday, but until then:
+  kernel_release := $(shell uname -r)
+  ifeq (Microsoft,$(findstring Microsoft,$(kernel_release)))
+    platform_makefile := msw_wsl.make
+  else ifeq (mingw32,$(findstring mingw32,$(LMI_TRIPLET)))
     platform_makefile := msw_generic.make
   else
     platform_makefile := posix_fhs.make
diff --git a/install_msw.sh b/install_msw.sh
index 98e2a96..4f4777f 100755
--- a/install_msw.sh
+++ b/install_msw.sh
@@ -64,6 +64,14 @@ case "$lmi_build_type" in
         ;;
 esac
 
+# 'config.guess' might indicate something like "x86_64-pc-wsl"
+# someday, but until then:
+case "$(uname -r)" in
+    (*Microsoft*)
+        platform=WSL
+        ;;
+esac
+
 if [ "Cygwin" = "$platform" ]
 then
     mount
@@ -128,6 +136,45 @@ then
     git config --global core.fileMode false
 fi
 
+if [ "WSL" = "$platform" ]
+then
+    # Install/update packages.
+    packages_list='autoconf automake bsdtar dos2unix doxygen
+      gdb git libtool make patch pkg-config rsync unzip wget
+      zip zsh g++-mingw-w64-i686'
+
+    # Disable shellcheck warning about the need to double quote $packages_list:
+    # it can't be done here and we really want word splitting to happen here.
+    # shellcheck disable=SC2086
+    missing_packages_count=$(dpkg-query -W -f="\${Status}\n" $packages_list 
2>&1 | \
+      grep -v -c 'install ok installed')
+
+    if [ "$missing_packages_count" -gt 0 ]
+    then
+        sudo apt update
+        # shellcheck disable=SC2086
+        sudo apt install -y $packages_list
+    fi
+
+    # Mount /opt/lmi and /cache_for_lmi directories.
+    # Unfortunately sudo must be used because we don't have permissions to
+    # write to /opt and / directories.
+    mkdir --parents /mnt/c/opt/lmi/src/lmi
+    restore_lmi_mount=$(mount | grep '/opt/lmi')
+    if [ -z "$restore_lmi_mount" ]
+    then
+        [ ! -d /opt/lmi ] && sudo mkdir /opt/lmi
+        sudo mount --bind /mnt/c/opt/lmi /opt/lmi
+    fi
+    mkdir --parents /mnt/c/cache_for_lmi
+    restore_cache_mount=$(mount | grep '/cache_for_lmi')
+    if [ -z "$restore_cache_mount" ]
+    then
+        [ ! -d /cache_for_lmi ] && sudo mkdir /cache_for_lmi
+        sudo mount --bind /mnt/c/cache_for_lmi /cache_for_lmi
+    fi
+fi
+
 java -version
 
 if [ "/opt/lmi/src/lmi" = "$PWD" ]
@@ -205,7 +252,7 @@ do
     # designed to be independent of lmi's runtime path.
     export PATH="$minimal_path"
 
-    # For Cygwin, install and use this msw-native compiler.
+    # For Cygwin or WSL, install and use this msw-native compiler.
     # Install it for other build types, too, even if only for
     # validating the installation procedure.
     mingw_dir=/opt/lmi/${LMI_COMPILER}_${LMI_TRIPLET}/gcc_msw
@@ -300,7 +347,7 @@ EOF
 # therefore, symlink the directories lmi uses as described in
 # 'README.schroot'.
 
-if [ "Cygwin" != "$platform" ]
+if [ "Cygwin" != "$platform" ] && [ "WSL" != "$platform" ]
 then
     sed -i /opt/lmi/data/configurable_settings.xml -e's/C://g'
 fi
diff --git a/install_wsl.ps1 b/install_wsl.ps1
new file mode 100644
index 0000000..ff32b80
--- /dev/null
+++ b/install_wsl.ps1
@@ -0,0 +1,88 @@
+# WSL installation.
+#
+# Copyright (C) 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019 
Gregory W. Chicares.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License version 2 as
+# published by the Free Software Foundation.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software Foundation,
+# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
+#
+# http://savannah.nongnu.org/projects/lmi
+# email: <address@hidden>
+# snail: Chicares, 186 Belle Woods Drive, Glastonbury CT 06033, USA
+
+# If you have UnauthorizedAccess error, run this command in PowerShell:
+# Set-ExecutionPolicy Unrestricted
+#
+# Return back to the Restricted policy after installing:
+# Set-ExecutionPolicy Restricted
+#
+# More info: https:/go.microsoft.com/fwlink/?LinkID=135170
+
+$wsl_registry = 'HKCU:\Software\Microsoft\Windows\CurrentVersion\Lxss'
+if ((Test-Path -Path $wsl_registry) -And `
+    (Get-ChildItem $wsl_registry).Length -gt 0) {
+    Write-Output 'WSL OS already installed:'
+    Write-Output (Get-ChildItem $wsl_registry | ForEach-Object 
{Get-ItemProperty $_.PSPath}).DistributionName
+    return
+}
+
+# Select a Debian-compatible OS: our build scripts use apt.
+$os_list = @(
+    @{
+        name = 'Ubuntu 18.04'
+        filename = 'Ubuntu_18_04.appx'
+        uri = 'https://aka.ms/wsl-ubuntu-1804'
+    }
+    @{
+        name = 'Ubuntu 16.04'
+        filename = 'Ubuntu_16_04.appx'
+        uri = 'https://aka.ms/wsl-ubuntu-1604'
+    }
+    @{
+        name = 'Debian GNU/Linux'
+        filename = 'Debian_GNU_Linux.appx'
+        uri = 'https://aka.ms/wsl-debian-gnulinux'
+    }
+)
+
+$options = @()
+for ($i=1; $i -le $os_list.Length; $i++) {
+    $os_name = $os_list[$i-1].name
+    $d = [System.Management.Automation.Host.ChoiceDescription]::new("&$i. 
$os_name")
+    $options += $d
+}
+
+$title = 'Please select the OS to install'
+$description = "Note: Non-Debian-based OS won't work, as we use apt."
+
+$opt = $host.UI.PromptForChoice($title, $description, $options, 0)
+$os = $os_list[$opt]
+Write-Output ('"' + $os.name + '" was chosen.')
+
+# Create the download directory.
+$dir = 'C:\cache_for_lmi\downloads\'
+If (!(Test-Path -Path $dir)) {
+    New-Item -ItemType Directory -Force -Path $dir
+}
+
+# Download the OS distribution.
+$path = 'C:\cache_for_lmi\downloads\' + $os.filename
+If (!(Test-Path -Path $path)) {
+    Write-Output ('Downloading "' + $os.name + '"...')
+    Invoke-WebRequest -Uri $os.uri -OutFile $path -UseBasicParsing
+}
+
+# Install the OS.
+Write-Output ('Installing "' + $os.name + '"...')
+Add-AppxPackage -Path $path
+
+Write-Output 'WSL installation seems to have succeeded'
diff --git a/msw_wsl.make b/msw_wsl.make
new file mode 100644
index 0000000..ff5c79f
--- /dev/null
+++ b/msw_wsl.make
@@ -0,0 +1,110 @@
+# Platform specifics: msw (WSL) with MinGW-w64 toolchain.
+#
+# Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 
2015, 2016, 2017, 2018, 2019 Gregory W. Chicares.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License version 2 as
+# published by the Free Software Foundation.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software Foundation,
+# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
+#
+# http://savannah.nongnu.org/projects/lmi
+# email: <address@hidden>
+# snail: Chicares, 186 Belle Woods Drive, Glastonbury CT 06033, USA
+
+################################################################################
+
+# Sanity checks.
+
+ifeq (,$(wildcard /opt/lmi/*))
+  $(warning Installation may be invalid: /opt/lmi/ missing or empty. )
+endif
+
+################################################################################
+
+system_root := /
+
+################################################################################
+
+# Compiler, linker, and so on.
+
+# Full path to gcc binaries, slash-terminated if nonempty. Setting it
+# to an empty string finds gcc on $PATH instead.
+
+gcc_bin_dir :=
+
+host_hyphen := $(LMI_TRIPLET)-
+
+AR      := $(gcc_bin_dir)$(host_hyphen)ar
+CC      := $(gcc_bin_dir)$(host_hyphen)gcc
+CPP     := $(gcc_bin_dir)$(host_hyphen)cpp
+CXX     := $(gcc_bin_dir)$(host_hyphen)g++
+LD      := $(gcc_bin_dir)$(host_hyphen)g++
+RC      := $(gcc_bin_dir)$(host_hyphen)windres
+
+# Identify run-time libraries for redistribution. See:
+#   https://lists.nongnu.org/archive/html/lmi/2017-05/msg00046.html
+# Perhaps gcc's '-print-sysroot' would be more suitable, but that
+# option returns an empty string with debian cross compilers.
+#
+# It might seem more robust to write something like
+#   compiler_sysroot := $(shell readlink -fn 
/usr/lib/gcc/$(LMI_TRIPLET)/*-win32)
+# but that would actually weaken makefile portability, and there
+# is no guarantee that this directory will be named similarly in
+# future debian releases, much less on other OSs.
+
+compiler_sysroot := $(dir $(shell $(CXX) -print-libgcc-file-name))
+
+compiler_runtime_files := \
+  $(wildcard $(compiler_sysroot)/libgcc*.dll) \
+  $(wildcard $(compiler_sysroot)/libstdc++*.dll) \
+
+################################################################################
+
+# Standard utilities.
+
+# Required in /bin (if anywhere) by FHS-2.2 .
+
+CP      := cp
+DATE    := date
+ECHO    := echo
+GZIP    := gzip
+LS      := ls
+MKDIR   := mkdir
+MV      := mv
+RM      := rm
+SED     := sed
+TAR     := tar
+
+# FHS-2.2 would presumably put these in /usr/bin . However, debian
+# puts 'bzip2' and 'grep' in /bin .
+
+BZIP2   := bzip2
+DIFF    := diff
+GREP    := grep
+MD5SUM  := md5sum
+PATCH   := patch
+SORT    := sort
+TOUCH   := touch
+TR      := tr
+WC      := wc
+WGET    := wget
+
+# Programs for which FHS doesn't specify a location.
+
+# Instead of requiring installation of the build system's own libxml2:
+    XMLLINT := $(localbindir)/xmllint.exe
+
+################################################################################
+
+# Configuration shared by all msw subplatforms.
+
+include $(srcdir)/msw_common.make
+$(srcdir)/msw_common.make:: ;
diff --git a/test_coding_rules.cpp b/test_coding_rules.cpp
index 41a07cd..7e2d050 100644
--- a/test_coding_rules.cpp
+++ b/test_coding_rules.cpp
@@ -180,6 +180,7 @@ file::file(std::string const& file_path)
         : ".ac"         == extension() ? e_script
         : ".bat"        == extension() ? e_script
         : ".m4"         == extension() ? e_script
+        : ".ps1"        == extension() ? e_script
         : ".rc"         == extension() ? e_script
         : ".sed"        == extension() ? e_script
         : ".sh"         == extension() ? e_script
@@ -1053,8 +1054,8 @@ void enforce_taboos(file const& f)
     // Certain proprietary libraries.
     taboo(f, R"(\bowl\b)", boost::regex::icase);
     taboo(f, "vtss", boost::regex::icase);
-    // Suspiciously specific to msw.
-    taboo(f, "Microsoft");
+    // Suspiciously specific to msw (although the string "Microsoft"
+    // is okay for identifying a GNU/Linux re-distribution).
     taboo(f, "Visual [A-Z]");
     taboo(f, R"(\bWIN\b)");
     taboo(f, R"(\bExcel\b)");



reply via email to

[Prev in Thread] Current Thread [Next in Thread]