How to get **kicad*.exe** using **copydll.sh** of kicad-winbuilder

HI.guys。
I use kicad-winbuilder to compile kicad.
I use make_x64.bat to get a zip of kicad.pkg.xz*.
I want to get the kicad.exe* installation package, using the NSIS tool?
I don’t know much about how NSIS is used.
I found that copydll.sh can be used to make kicad.exe*.
But I don’t quite understand how it works. Can you give an example of making kicad.exe* with copydll.sh?
Cheers!

I want to speed up the compilation of kicad. Modify the contents of PKGBUILD in the *\msys64\MINGW-packages\mingw-w64-kicad-git* directory to something like the one shown below.

# Maintainer: Alexey Pavlov <alexpux@gmail.com>

_realname=kicad
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}-git"
pkgver=5.1.4_1
_upver=`echo ${pkgver} | sed -e 's/_.*//g'`
_basever=5.1.4
_rcver=`echo ${pkgver} | sed -e 's/.*_//g'`
pkgrel=1
pkgdesc="Software for the creation of electronic schematic diagrams and printed circuit board artwork (mingw-w64)"
arch=('any')
url="http://www.kicad.org"
license=("GPL2+")
provides=("${MINGW_PACKAGE_PREFIX}-${_realname}")
conflicts=("${MINGW_PACKAGE_PREFIX}-${_realname}")
depends=("${MINGW_PACKAGE_PREFIX}-boost"
     "${MINGW_PACKAGE_PREFIX}-cairo"
     "${MINGW_PACKAGE_PREFIX}-curl"
     "${MINGW_PACKAGE_PREFIX}-glew"
     "${MINGW_PACKAGE_PREFIX}-openssl"
     "${MINGW_PACKAGE_PREFIX}-wxPython"
     "${MINGW_PACKAGE_PREFIX}-wxWidgets"
     "${MINGW_PACKAGE_PREFIX}-libxslt"
     "${MINGW_PACKAGE_PREFIX}-oce"
     "${MINGW_PACKAGE_PREFIX}-ngspice"
     "${MINGW_PACKAGE_PREFIX}-fftw")
makedepends=("${MINGW_PACKAGE_PREFIX}-cmake"
         "${MINGW_PACKAGE_PREFIX}-doxygen"
         "${MINGW_PACKAGE_PREFIX}-gcc"
         "${MINGW_PACKAGE_PREFIX}-python2"
         "${MINGW_PACKAGE_PREFIX}-pkg-config"
         "${MINGW_PACKAGE_PREFIX}-swig"
         "${MINGW_PACKAGE_PREFIX}-glm"
         "git")
source=("${_realname}::git+https://git.launchpad.net/kicad#tag=${_upver}"
#source=("${_realname}::git+https://git.launchpad.net/kicad#branch=5.0"
    "${_realname}-i18n-${_upver}.tar.gz"::"https://github.com/KiCad/kicad-i18n/archive/${_upver}.tar.gz"
		)
md5sums=('SKIP'
     'f8f88696977bdb78e0ebc40761331626')
		 
prepare() {
  # Hack to get UTF8 support for paths with mingw
  # https://lists.launchpad.net/kicad-developers/msg28560.html
  rm -rf ${srcdir}/${_realname}/include/wx
  mkdir ${srcdir}/${_realname}/include/wx
  cp $(find ${MINGW_PREFIX} -path "*wx-3.0\\/wx\\/app.h") \
${srcdir}/${_realname}/include/wx
  cd ${srcdir}/${_realname}
  patch -p1 -i ${srcdir}/${_realname}/patches/wxwidgets-3.0.2_mingw_fix_unicode_entry.patch
}

build() {
  cd "${srcdir}"

  # Configure and build KiCad.
  [[ -d build-${MINGW_CHOST} ]] && rm -r build-${MINGW_CHOST}
  mkdir build-${MINGW_CHOST} && cd build-${MINGW_CHOST}

  # Get GCC version
  GCCVERSION=`gcc --version | grep ^gcc | sed 's/^.* //g'`

  # Add flag to silence deprecation warnings
  # Due to bug in gcc 5.1,5.2
  # https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65974
  EXTRA_FLAGS=""
  if [ $GCCVERSION = "5.1.0" ] || [ $GCCVERSION = "5.2.0" ]; then
EXTRA_FLAGS=" -DCMAKE_CXX_FLAGS=-Wno-deprecated-declarations"
  fi

  MSYS2_ARG_CONV_EXCL="-DCMAKE_INSTALL_PREFIX=" \
  ${MINGW_PREFIX}/bin/cmake \
-G"MSYS Makefiles" \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_VERBOSE_MAKEFILE:BOOL=ON \
-DCMAKE_RULE_MESSAGES:BOOL=OFF \
-DCMAKE_PREFIX_PATH=${MINGW_PREFIX} \
-DCMAKE_INSTALL_PREFIX=${MINGW_PREFIX} \
-DDEFAULT_INSTALL_PATH=${MINGW_PREFIX} \
-DOPENSSL_ROOT_DIR=${MINGW_PREFIX} \
-DKICAD_VERSION_EXTRA=${_rcver} \
-DKICAD_SCRIPTING=ON \
-DKICAD_SCRIPTING_MODULES=ON \
-DKICAD_SCRIPTING_WXPYTHON=ON \
-DKICAD_SCRIPTING_ACTION_MENU=ON \
-DKICAD_USE_OCE=ON \
-DKICAD_SPICE=ON \
-DPYTHON_EXECUTABLE=${MINGW_PREFIX}/bin/python2 \
-DwxWidgets_CONFIG_EXECUTABLE=${MINGW_PREFIX}/bin/wx-config \
${EXTRA_FLAGS} \
../${_realname}
  make

  cd "${srcdir}"

  # Configure the translation installation build.
  [[ -d build-i18n ]] && rm -r build-i18n
  mkdir build-i18n && cd build-i18n
  MSYS2_ARG_CONV_EXCL="-DCMAKE_INSTALL_PREFIX=" \
  ${MINGW_PREFIX}/bin/cmake \
-G "MSYS Makefiles" \
-DCMAKE_VERBOSE_MAKEFILE:BOOL=ON \
-DCMAKE_RULE_MESSAGES:BOOL=OFF \
-DCMAKE_INSTALL_PREFIX=${MINGW_PREFIX} \
../${_realname}-i18n-${_upver}

  cd "${srcdir}"

}

package() {
  # Install KiCad.
  cd "${srcdir}/build-${MINGW_CHOST}"
  make DESTDIR=${pkgdir} install

  # Install KiCad i18n.
  cd "${srcdir}/build-i18n"
  make DESTDIR=${pkgdir} install

}

There is an example of calling the copydlls.sh in the end of KiCad-Winbuilder.cmake.

MSYS /F/kicad-winbuilder
# ./make_x86_64.bat
-- HOME_DIR
-- KICAD_PACKAGE_SOURCE_DIR /MINGW-packages/mingw-w64-kicad-git/
-- MSYS2 user name is: $USERNAME=
-- Running cd "/MINGW-packages/mingw-w64-kicad-git" && export CARCH=x86_64 && TERM=vt220 makepkg-mingw -s --noconfirm
==> 正在创建软件包:mingw-w64-x86_64-kicad-git r12153.72c885797-1 (2019年08月16日  9:29:33)
==> 正在检查运行时依赖关系...
==> 正在检查编译时依赖关系
==> 获取源代码...
  -> 正在升级 kicad git 仓库...
正在获取 origin

Why is $USERNAME= null?

Maybe your windows username has unicode characters in it and that is not supported properly in msys2.
Another probable reason is that you are running make.bat from within msys2, it is supposed to be run in normal windows shell.

I created a new directory under the home directory that is the same as the windows user.

mkdir msys64/home/YI

make_x86_64.bat
-- HOME_DIR F:/kicad-winbuilder/msys64/home/YI
-- KICAD_PACKAGE_SOURCE_DIR F:/kicad-winbuilder/msys64/home/YI/MINGW-packages/mingw-w64-kicad-git/
-- MSYS2 user name is: $USERNAME=YI
-- Running cd "F:/kicad-winbuilder/msys64/home/YI/MINGW-packages/mingw-w64-kicad-git" && export CARCH=x86_64 && TERM=vt220 makepkg-mingw -s --noconfirm

Msys2 uses the user directory under Windows.
Not the user directory under /home used

==> Creating package "mingw-w64-x86_64-kicad-git"...
  -> Generating .PKGINFO file...
  -> Generating .BUILDINFO file...
  -> Generating .MTREE file...
  -> Compressing package...
==> Finished making: mingw-w64-x86_64-kicad-git 5.1.4_1-1 (Fri Aug 16 11:34:13 2019)
=> WARNING: You don't have installed mingw-w64 toolchain for architecture i686.
=> WARNING: To install it run: 'pacman -S mingw-w64-i686-toolchain'
-- Success 0: cd "F:/kicad-winbuilder/msys64/home/YI/MINGW-packages/mingw-w64-kicad-git" && export CARCH=x86_64 && TERM=vt220 makepkg-mingw -s --noconfirm
-- Running ~/copydlls.sh                          --arch=x86_64                          --pkgpath=$HOME/MINGW-packages/mingw-w64-kicad-git                          --nsispath=$HOME/nsis                          --makensis=F:/kicad-winbuilder/.support/nsis-3.03/Bin/makensis.exe
/usr/bin/bash: /c/Users/YI/copydlls.sh: No such file or directory
CMake Error at KiCad-Winbuilder.cmake:280 (message):
  Error running ~/copydlls.sh --arch=x86_64
  --pkgpath=$HOME/MINGW-packages/mingw-w64-kicad-git --nsispath=$HOME/nsis
  --makensis=F:/kicad-winbuilder/.support/nsis-3.03/Bin/makensis.exe

   Output in: F:/kicad-winbuilder/.logs/last_error
Call Stack (most recent call first):
  KiCad-Winbuilder.cmake:364 (execute_msys2_bash)

The compilation script specifies the directory to the **Windows user directory again.
It’s not in the home directory anymore.

ls msys64\home\YI\
MINGW-packages/  copydlls.sh*  nsis/

Run the make_x86_64.bat from cmd or powershell, not msys shell.

The cmder terminal used is the cmd environment

Maybe something is messed up in the msys environment. I don’t know why it would expand ‘~’ to windows home dir instead of it’s own. But you shouldn’t have to create it manually either so something is wrong from the start.

Just delete everything in the repo and start over
git reset --hard
git clean -xfd
.\make_x86_64.bat

You shouldn’t have to do anything else at all.

PS F:\kicad-winbuilder_off> .\make_x86_64.bat -- HOME_DIR -- KICAD_PACKAGE_SOURCE_DIR /MINGW-packages/mingw-w64-kicad-git/ -- MSYS2 user name is: $USERNAME= -- Running cd "/MINGW-packages/mingw-w64-kicad-git" && export CARCH=x86_64 && TERM=vt220 makepkg-mingw -s --noconfirm /usr/bin/bash: 第 0 行:cd: /MINGW-packages/mingw-w64-kicad-git: No such file or directory CMake Error at KiCad-Winbuilder.cmake:280 (message): Error running cd "/MINGW-packages/mingw-w64-kicad-git" && export CARCH=x86_64 && TERM=vt220 makepkg-mingw -s --noconfirm Output in: F:/kicad-winbuilder_off/.logs/last_error Call Stack (most recent call first): KiCad-Winbuilder.cmake:338 (execute_msys2_bash)

I’ll follow the steps you said.
Reuse the power shell for compilation.
There is no corresponding user directory under the home directory.

ls 目录: F:\kicad-winbuilder\msys64\home\YI\MINGW-packages\mingw-w64-kicad-git Mode LastWriteTime Length Name ---- ------------- ------ ---- d----- 2019/8/16 16:28 kicad d-r--- 2019/8/16 15:01 pkg d----- 2019/8/16 16:39 src -a---- 2019/8/15 9:45 494 glm_version_ok.patch -a---- 2019/8/16 14:59 117329 kicad-i18n -a---- 2019/8/15 11:58 4310971 kicad-i18n-5.1.4.tar.gz -a---- 2019/8/16 14:43 27618480 mingw-w64-i686-kicad-git-5.1.4_1-1-any.pkg.tar.xz -a---- 2019/8/16 13:42 26245304 mingw-w64-x86_64-kicad-git-5.1.4_1-1-any.pkg.tar.xz -a---- 2019/8/15 18:18 4018 PKGBUILD

It’s very hard to read the listings you paste because they don’t have newlines.

I’m not sure what is wrong with your setup or why there is no home directory in msys. If I were to guess it has something to do with your environment, maybe Chinese locale. Try launching msys shell separately and figure out there why home doesn’t exist.

I’ll try to find out the problem again, according to the information you provide.
At present, there are the following ways:

  1. Try to build a Windows virtual machine in English environment
  2. Solving the Compilation Problem of msys 2

If you can share what your end goal is maybe there is easier way.
Is your goal to have working windows development environment? Is it to be able to build installer executable?

Yeah, I am going to build a stable windows compilation environment, and I also want to learn the process of compiling and packaging. Easy to compile to the appropriate version of Windows.

If you want to really learn how it works you will have to read and understand cmake, PKGBUILD and copydlls.sh files.
On high level this is what happens when you launch that .bat file:

  • Invoke cmake to run Kicad-Winbuilder.cmake top level script. It’s essentially just a very convoluted shell script, not sure why devs decided to write it in cmake, probably because it would have been more painful to write in .bat file directly. This script then:
    • downloads and installs msys (think of it as a development toolchain), supporting utilities 7z and installer creation tool NSIS.
    • Updates msys environment and installs via pacman some prerequisites for compiling kicad
    • Invokes makepkg-mingw from withing msys shell to actually build kicad.
      • That involves downloading all libraries, docs, kicad repo, building everything using nested cmake call and installing it to some location within msys environment
    • At this point kicad is built but not usable because build process doesn’t collect dynamically linked deps. That is what’s copydlls.sh is for.
      • It copies all dlls, certs and some miscellaneous stuff
      • It copies python stuff like site-packages, pip and some of it’s own dlls.
      • It invokes NSIS to build an installer from the package.

At this point you should look at install.nsi and it has it’s own scripting language but on high level it just zips everything that copydlls.sh and other scripts have put together into one installer executable.

So yeah, it’s not trivial and not well documented but nothing one can’t get a handle on in one evening of diligent code reading.

Going back to your problem with home directory in msys, the top level cmake file tries to detect it on lines 315-320.

file( GLOB HOME_DIR "${CMAKE_SOURCE_DIR}/${MSYS2}/home/*" )
set( KICAD_PACKAGE_SOURCE_DIR "${HOME_DIR}/MINGW-packages/mingw-w64-kicad-git/" )
message( STATUS "HOME_DIR ${HOME_DIR}" )
message( STATUS "KICAD_PACKAGE_SOURCE_DIR ${KICAD_PACKAGE_SOURCE_DIR}" )
get_filename_component( USERNAME "${HOME_DIR}" NAME )
message( STATUS "MSYS2 user name is: $USERNAME=${USERNAME}" )

That is the part that is failing because msys for some reason doesn’t create home directory for you.
If you google for msys2 home directory there are some interesting answers on stackoverflow and the like that mention configuring /etc/nsswitch.conf to point to windows home directory. You want the opposite of that, it should be cygwin home directory. I would dig in that direction, if you fix the home directory issue and make msys shell recognize it properly you should good to go.

2 Likes

Thank you very much. I will try to solve the problem in this direction.

  • Under “Environment Variables > User variables”, add HOME -> %USERPROFILE%

I found the problem. I deleted the HOME system environment variable and created home/YI automatically.

Copying skeleton files.
These files are for the users to personalise their msys2 experience.

They will never be overwritten nor automatically updated.

'./.bashrc' -> '/home/YI/.bashrc'
'./.bash_logout' -> '/home/YI/.bash_logout'
'./.bash_profile' -> '/home/YI/.bash_profile'
'./.inputrc' -> '/home/YI/.inputrc'
'./.profile' -> '/home/YI/.profile'
'./.vimrc' -> '/home/YI/.vimrc'

I think it’s a home system environment variable created automatically by msys2 or other software during installation.

==> 正在清理安装...
  -> 正在删除 libtool 文件...
  -> 正在清除不打算要的文件...
  -> 正在从二进制文件和库中清除不需要的系统符号...
  -> 正在压缩 man 及 info 文档...
==> 正在检查打包问题...
==> 警告: 软件包含有对 $srcdir 的引用
mingw32/bin/bitmap2component.exe
mingw32/bin/dxf2idf.exe
mingw32/bin/eeschema.exe
mingw32/bin/gerbview.exe
mingw32/bin/idf2vrml.exe
mingw32/bin/kicad-ogltest.exe
mingw32/bin/kicad.exe
mingw32/bin/kicad2step.exe
mingw32/bin/libkicad_3dsg.dll
mingw32/bin/pcbnew.exe
mingw32/bin/pcb_calculator.exe
mingw32/bin/plugins/3d/libs3d_plugin_idf.dll
mingw32/bin/plugins/3d/libs3d_plugin_vrml.dll
mingw32/bin/pl_editor.exe
mingw32/bin/_cvpcb.kiface
mingw32/bin/_eeschema.kiface
mingw32/bin/_gerbview.kiface
mingw32/bin/_pcbnew.kiface
mingw32/bin/_pcb_calculator.kiface
mingw32/bin/_pl_editor.kiface
mingw32/lib/python2.7/site-packages/_pcbnew.pyd
==> 正在创建软件包"mingw-w64-i686-kicad-git"...
  -> 正在生成 .PKGINFO 文件...
  -> 正在生成 .BUILDINFO 文件...
  -> 正在生成 .MTREE 文件...
  -> 正在压缩软件包...
==> 完成创建:mingw-w64-i686-kicad-git 5.1.4_1-1 (2019年08月18日  5:04:11)

Is it possible to get kicad *. XZ compressed package after executing make_x86_64. bat or not to generate kicad *. exe executable file, which is the problem of copydlls. sh?

I don’t understand the question.
.xz is generated by makepkg-mingw and is not used really. Installer exe is generated by nsis which is called by copydlls.sh in the end.
Are you asking how to speed up something? Which part, compiling or packaging the installer?