Skip to content

Commit

Permalink
Some environment improvements.
Browse files Browse the repository at this point in the history
* New script /etc/msystem providing information associated with the
  current MSYSTEM. This is sourced by /etc/profile but can be used by
  non-login scripts for getting information such as the current
  compiler architecture or mount point.

* New script /usr/bin/shell for switching between shells without
  restarting MSYS2. This can be used in interactive sessions but also
  from shell scripts for switching the MSYSTEM without restarting bash
  or spawning a subshell.

* Allow /etc/profile to be sourced multiple times without continuously
  appending stuff to PATH or losing track of the original Windows TEMP.
  Also implemented for /etc/profile.d/perlbin.sh, so perl path is not
  repeatedly appended.
  • Loading branch information
renatosilva committed May 24, 2016
1 parent 98f8df2 commit b827a67
Show file tree
Hide file tree
Showing 6 changed files with 108 additions and 18 deletions.
11 changes: 8 additions & 3 deletions filesystem/PKGBUILD
@@ -1,4 +1,5 @@
# Maintainer: Alexey Pavlov <alexpux@gmail.com>
# Contributor: Renato Silva <br.renatosilva@gmail.com>

pkgname=filesystem
pkgver=2016.05
Expand Down Expand Up @@ -26,13 +27,15 @@ source=('bash.bash_logout'
'start_shell.cmd'
'mingw32_shell.bat'
'mingw64_shell.bat'
'msystem'
'msys2_shell.bat'
'msys2.ico'
'nsswitch.conf'
'profile'
'profile.lang.sh'
'profile.tzset.sh'
'regen-info.sh'
'shell'
'shells'
'start'
'01-devices.post'
Expand All @@ -55,13 +58,15 @@ sha256sums=('6d651f6b0b2d173961a3fa21acd9d44c783ed9cd73a031687698c8b9ed1f6dee'
'e38c92ded3ba1cb5bedec40dc3691a4558d88bb632e07b614df7bb10fcd34cad'
'73bf20b5d11a5d2e8754bd62bb8a7cbb4fd31dfe781169723b1842aa62c323ab'
'71f3031066ca0824e4b494127f74a41920b15f8b6d3f573c43da080050c0e1ca'
'3afdc0d689da510c32a04da2a021241c6fda85fdf1f1f558da5f1d778a2037f7'
'cc4088d418a2dbb1ec754a0e89b80b8521b04011c08b8f5c9a563f1bdd745c8f'
'7d6994d7caf52a459b562cfb0da1d758a4b7bca478d1df00de3a96686e59008e'
'91f1f918cf13deab0124082086e990786113b0e710dbda4678d8fc14905ad94d'
'400c159975f38e1578e8452cf825310fd7aee3c65c4b36714c024928e9c711af'
'5b3109cb32639aff640d5629e9c1a898e540b8b8d38ac26aa34014df6b002b63'
'0a3a3b131ace34f11f428118dfe81b34da148e29b6bea3b027d79bebd47141a7'
'020d0619a6af9a4d6e1068cb77f2789bcf470380426214e90177f5596d651835'
'756df34c5b28478a81331785de0f56438bb652cf5f29029a9db2d83281361340'
'9f7e0f3f640e8acd0ec3a92231bb7d983b2b4741ccc16cac649d32c4e8a652f8'
'f63241cc56aa7b7ec6962d19991d211b4e1641b78ba5226835118ab493830a8b'
'e96c1f54ffff792e738aa032815c82c30821b0683806e5ed0ba2a759db2fd494'
'95105051d31ecbe4ace262a4496ec1055bdd14d61b7d475a771b56fe15f8ccd9'
Expand Down Expand Up @@ -90,7 +95,7 @@ package() {
# setup /etc
#
install -d etc/{fstab.d,skel,profile.d,post-install}
for f in bash.bashrc bash.bash_logout fstab shells profile nsswitch.conf; do
for f in bash.bashrc bash.bash_logout fstab shells profile nsswitch.conf msystem; do
install -m644 ${srcdir}/${f} etc/
done

Expand Down Expand Up @@ -131,7 +136,7 @@ package() {
install -d -m755 usr/share/man/man${d}
done
# various shell scripts
for f in cmd start dep-search regen-info.sh; do
for f in cmd start dep-search regen-info.sh shell; do
install -m755 ${srcdir}/${f} usr/bin
done

Expand Down
46 changes: 46 additions & 0 deletions filesystem/msystem
@@ -0,0 +1,46 @@
# MSYSTEM Environment Information
# Copyright (C) 2016 Renato Silva
# Licensed under public domain

# Once sourced, this script provides common information associated with the
# current MSYSTEM. For example, the compiler architecture and host type.

# The MSYSTEM_ prefix is used for avoiding too generic names. For example,
# makepkg is sensitive to the value of CARCH, so MSYSTEM_CARCH is defined
# instead. The MINGW_ prefix does not influence makepkg-mingw variables and
# is not used for the MSYS shell.

unset MSYSTEM_PREFIX
unset MSYSTEM_CARCH
unset MSYSTEM_CHOST

unset MINGW_CHOST
unset MINGW_PREFIX
unset MINGW_PACKAGE_PREFIX

case "${MSYSTEM}" in
MINGW32)
MSYSTEM_PREFIX='/mingw32'
MSYSTEM_CARCH='i686'
MSYSTEM_CHOST='i686-w64-mingw32'
MINGW_CHOST="${MSYSTEM_CHOST}"
MINGW_PREFIX="${MSYSTEM_PREFIX}"
MINGW_PACKAGE_PREFIX="mingw-w64-${MSYSTEM_CARCH}"
export MSYSTEM_PREFIX MSYSTEM_CARCH MSYSTEM_CHOST MINGW_CHOST MINGW_PREFIX MINGW_PACKAGE_PREFIX
;;
MINGW64)
MSYSTEM_PREFIX='/mingw64'
MSYSTEM_CARCH='x86_64'
MSYSTEM_CHOST='x86_64-w64-mingw32'
MINGW_CHOST="${MSYSTEM_CHOST}"
MINGW_PREFIX="${MSYSTEM_PREFIX}"
MINGW_PACKAGE_PREFIX="mingw-w64-${MSYSTEM_CARCH}"
export MSYSTEM_PREFIX MSYSTEM_CARCH MSYSTEM_CHOST MINGW_CHOST MINGW_PREFIX MINGW_PACKAGE_PREFIX
;;
MSYS)
MSYSTEM_PREFIX='/usr'
MSYSTEM_CARCH="${HOSTTYPE}"
MSYSTEM_CHOST="${MACHTYPE}"
export MSYSTEM_PREFIX MSYSTEM_CARCH MSYSTEM_CHOST
;;
esac
22 changes: 15 additions & 7 deletions filesystem/profile
Expand Up @@ -35,7 +35,7 @@ case "${MSYS2_PATH_TYPE:-minimal}" in
inherit)
# Inherit previous path. Note that this will make all of the Windows path
# available in current shell, with possible interference in project builds.
ORIGINAL_PATH="${PATH}"
ORIGINAL_PATH="${ORIGINAL_PATH:-${PATH}}"
;;
*)
# Do not inherit any path configuration but configure a default Windows path
Expand All @@ -44,19 +44,20 @@ case "${MSYS2_PATH_TYPE:-minimal}" in
ORIGINAL_PATH="${WIN_ROOT}/System32:${WIN_ROOT}:${WIN_ROOT}/System32/Wbem:${WIN_ROOT}/System32/WindowsPowerShell/v1.0/"
esac

MINGW_MOUNT_POINT=
unset MINGW_MOUNT_POINT
if [ -n "$MSYSTEM" ]
then
source /etc/msystem
case "$MSYSTEM" in
MINGW32)
MINGW_MOUNT_POINT=/mingw32
MINGW_MOUNT_POINT="${MINGW_PREFIX}"
PATH="${MINGW_MOUNT_POINT}/bin:${MSYS2_PATH}${ORIGINAL_PATH:+:${ORIGINAL_PATH}}"
PKG_CONFIG_PATH="${MINGW_MOUNT_POINT}/lib/pkgconfig:${MINGW_MOUNT_POINT}/share/pkgconfig"
ACLOCAL_PATH="${MINGW_MOUNT_POINT}/share/aclocal:/usr/share/aclocal"
MANPATH="${MINGW_MOUNT_POINT}/share/man:${MANPATH}"
;;
MINGW64)
MINGW_MOUNT_POINT=/mingw64
MINGW_MOUNT_POINT="${MINGW_PREFIX}"
PATH="${MINGW_MOUNT_POINT}/bin:${MSYS2_PATH}${ORIGINAL_PATH:+:${ORIGINAL_PATH}}"
PKG_CONFIG_PATH="${MINGW_MOUNT_POINT}/lib/pkgconfig:${MINGW_MOUNT_POINT}/share/pkgconfig"
ACLOCAL_PATH="${MINGW_MOUNT_POINT}/share/aclocal:/usr/share/aclocal"
Expand All @@ -82,8 +83,15 @@ SYSCONFDIR="${SYSCONFDIR:=/etc}"
# them set to the default Windows temporary directory or unset
# can have unexpected consequences for msys2 apps, so we define
# our own to match GNU/Linux behaviour.
ORIGINAL_TMP=$TMP
ORIGINAL_TEMP=$TEMP
#
# Note: this uppercase/lowercase workaround does not seem to work.
# In fact, it has been removed from Cygwin some years ago. See:
#
# * https://cygwin.com/git/gitweb.cgi?p=cygwin-apps/base-files.git;a=commitdiff;h=3e54b07
# * https://cygwin.com/git/gitweb.cgi?p=cygwin-apps/base-files.git;a=commitdiff;h=7f09aef
#
ORIGINAL_TMP="${ORIGINAL_TMP:-${TMP}}"
ORIGINAL_TEMP="${ORIGINAL_TEMP:-${TEMP}}"
unset TMP TEMP
tmp=$(cygpath -w "$ORIGINAL_TMP" 2> /dev/null)
temp=$(cygpath -w "$ORIGINAL_TEMP" 2> /dev/null)
Expand Down Expand Up @@ -151,7 +159,7 @@ then
export ACLOCAL_PATH
fi

export PATH MANPATH INFOPATH PKG_CONFIG_PATH USER TMP TEMP PRINTER HOSTNAME PS1 SHELL tmp temp
export PATH MANPATH INFOPATH PKG_CONFIG_PATH USER TMP TEMP PRINTER HOSTNAME PS1 SHELL tmp temp ORIGINAL_TMP ORIGINAL_TEMP ORIGINAL_PATH
unset PATH_SEPARATOR

if [ "$MAYBE_FIRST_START" = "true" ]; then
Expand Down
27 changes: 27 additions & 0 deletions filesystem/shell
@@ -0,0 +1,27 @@
#!/bin/bash

if [[ "${BASH_SOURCE}" = "${0}" || ! "${1}" =~ ^(mingw(32|64)|msys)$ ]]; then tee <<done
MSYS2 Shell Switcher 2016.5.1
Copyright (C) 2016 Renato Silva
Licensed under public domain
This script switches between shells without restarting MSYS2. This is done
by setting the MSYSTEM variable and sourcing /etc/profile, as well as
~/.bashrc, for interactive shells.
Usage: source $(basename "${0}") mingw32|mingw64|msys
done
if [[ "${BASH_SOURCE}" = "${0}" ]]
then exit 1
else return 1
fi
fi

_current_directory="$(pwd)"
export MSYSTEM="${1^^}"
source /etc/profile
[[ "${-}" = *i* ]] && source ~/.bashrc
cd "${_current_directory}"
unset _current_directory
4 changes: 2 additions & 2 deletions perl/PKGBUILD
Expand Up @@ -2,7 +2,7 @@

pkgname=perl
pkgver=5.22.1
pkgrel=1
pkgrel=2
pkgdesc="A highly capable, feature-rich programming language"
arch=(i686 x86_64)
license=('GPL' 'PerlArtistic')
Expand Down Expand Up @@ -139,7 +139,7 @@ provides=('perl-Archive-Tar=2.04'
# Add your own provides here
provides=(${provides[@]})
sha256sums=('e98e4075a3167fa40524abe447c30bcca10c60e02a54ee1361eff278947a1221'
'7b7808ea08749d84f1990b1b060c7d007581704a0af8dee428df400606423aab'
'a02db738d30fa3a9fd77c7e57667315c5276337e055e92e1d3e59c05f0490aca'
'8a8331eea71b067ab63602e751617478f299f5946b9d02a93bbe491d50c5cf41'
'a4ec2fd5cd7f3447b881798f99fdc522148f2b8135aa9f0f5b17efd57d79d358'
'10ebe5519bfe174345cd2cb8b9fa5d46dd64870e6b4fd2d82a11905023e4cc9e'
Expand Down
16 changes: 10 additions & 6 deletions perl/perlbin.sh
Expand Up @@ -3,15 +3,19 @@
# Added /usr/bin/*_perl dirs for scripts
# Remove /usr/lib/perl5/*_perl/bin in next release

[ -d /usr/bin/site_perl ] && PATH=$PATH:/usr/bin/site_perl
[ -d /usr/lib/perl5/site_perl/bin ] && PATH=$PATH:/usr/lib/perl5/site_perl/bin
if test -z "${PERL_PATH}"; then

[ -d /usr/bin/vendor_perl ] && PATH=$PATH:/usr/bin/vendor_perl
[ -d /usr/lib/perl5/vendor_perl/bin ] && PATH=$PATH:/usr/lib/perl5/vendor_perl/bin
[ -d /usr/bin/site_perl ] && PERL_PATH="${PERL_PATH:+${PERL_PATH}:}/usr/bin/site_perl"
[ -d /usr/lib/perl5/site_perl/bin ] && PERL_PATH="${PERL_PATH:+${PERL_PATH}:}/usr/lib/perl5/site_perl/bin"

[ -d /usr/bin/core_perl ] && PATH=$PATH:/usr/bin/core_perl
[ -d /usr/bin/vendor_perl ] && PERL_PATH="${PERL_PATH:+${PERL_PATH}:}/usr/bin/vendor_perl"
[ -d /usr/lib/perl5/vendor_perl/bin ] && PERL_PATH="${PERL_PATH:+${PERL_PATH}:}/usr/lib/perl5/vendor_perl/bin"

export PATH
[ -d /usr/bin/core_perl ] && PERL_PATH="${PERL_PATH:+${PERL_PATH}:}/usr/bin/core_perl"

fi

export PERL_PATH PATH="${PATH}:${PERL_PATH}"

This comment has been minimized.

Copy link
@dscho

dscho Feb 16, 2017

Contributor

This is incorrect. PERL_PATH is long established as a variable used by scripts to refer to the Perl interpreter. Exporting this causes harm and is improper.

This comment has been minimized.

Copy link
@Alexpux

Alexpux Feb 16, 2017

Member

You are right. Will rename it.


# If you have modules in non-standard directories you can add them here.
#export PERLLIB=dir1:dir2
Expand Down

0 comments on commit b827a67

Please sign in to comment.