Revert "metadata: Make JACK_METADATA_* constant"
[jack2.git] / windows / README_MINGW
blob5ec8fe7596fcb3ac7378ce6c2891e78189c0c8a7
1 HOW TO COMPILE JACK USING WAF AND MINGW
2 =======================================
4 Rev. 1 - 2019-09-01 - First version
5 Rev. 2 - 2019-09-18 - Include contributions from @Schroedingers-Cat
6 Rev. 3 - 2019-12-14 - Include contributions from @Schroedingers-Cat
10 Introduction
11 ------------
13 This guide contains detailed instructions for building JACK on a modern MinGW
14 installation. It was conceived as the starting point for unifying the JACK build
15 process across all platforms.
17 As this is work in progress, there are still a couple of caveats:
19 - Asynchronous mode is unusable with low latencies
20 - JackRouter still builds using a Visual Studio project
21 - Lots of real world testing is needed
25 Creating the development environment
26 ------------------------------------
28 This guide uses MSYS2 as the toolchain, it can be found at https://www.msys2.org/
29 It comes as a handy installer called msys2-x86_64-{version}.exe. Once installed:
31 - Open "MSYS2 MinGW 64-bit terminal" from the MSYS2 start menu shortcuts
33 - Upgrade base MSYS2 packages
35 pacman -Suy
37 It is possible pacman ends with the following banner:
39 warning: terminate MSYS2 without returning to shell and check for updates again
40 warning: for example close your terminal window instead of calling exit
42 In such case close the MSYS2 window, re-open, and run pacman -Suy again.
44 - Install required packages
46 pacman -S mingw-w64-x86_64-toolchain patch autoconf make \
47 gettext-devel automake libtool pkgconfig p7zip unzip git python
49 - Replace the GCC compiler with a version configured for SJLJ exceptions, as
50 instructed by the original Windows build instructions (windows/README)
52 Prebuilt binaries can be found at
53 https://sourceforge.net/projects/mingw-w64/files/Toolchains%20targetting%20Win64/
55 Look for "x86_64-posix-sjlj" under "MinGW-W64 GCC-{version}", the file should be
56 called x86_64-{version}-release-posix-sjlj-rt_v6-rev0.7z
58 Or just download from a direct link (GCC 8.1.0):
60 wget https://downloads.sourceforge.net/project/mingw-w64/Toolchains%20targetting%20Win64/Personal%20Builds/mingw-builds/8.1.0/threads-posix/sjlj/x86_64-8.1.0-release-posix-sjlj-rt_v6-rev0.7z
62 Once downloaded:
64 p7zip -d x86_64-8.1.0-release-posix-sjlj-rt_v6-rev0.7z
66 That will decompress to a folder called mingw64 in the working directory.
67 Now replace the files from the previous mingw-w64-x86_64-toolchain package
68 installation:
70 mv /mingw64 /mingw64.bak   -> backup original
71 rm /mingw64                -> see explanation below
72 mv mingw64 /               -> sjlj toolchain
74 The first step results in a new file called mingw64 file being created in /. The
75 file is not visible to the Windows File Explorer when inspecting C:\msys64, so
76 it is probably an artifact and safe to delete it in the second step. Otherwise
77 the last mv step will fail with:
79 mv: cannot overwrite non-directory '/mingw64' with directory 'mingw64'
81 An alternate solution consists in closing the MSYS2 window and replicating the
82 above procedure using the File Explorer. The following assumes the toolchain 7z
83 file was decompressed to the home directory:
85 Rename C:\msys64\mingw64 to C:\msys64\mingw64.bak
86 Move C:\msys64\home\{username}\mingw64 to C:\msys64
88 Make sure gcc runs and it is the expected version:
90 $ gcc --version
91 gcc.exe (x86_64-posix-sjlj-rev0, Built by MinGW-W64 project) {version}
95 Preparing JACK dependencies
96 ---------------------------
98 There are prebuilt MinGW binaries for all the libraries that can be installed
99 using the pacman package manager, but since we are using a compiler that is not
100 the default version shipped by MinGW, it seems better idea to build from source
101 to avoid any linker and runtime issues. A good technical explanation and/or
102 evidence for this statement is currently missing from this guide.
104 Fortunately there are PKGBUILD files for doing so together with a nice guide at
105 https://github.com/msys2/MINGW-packages
107 git clone https://github.com/msys2/MINGW-packages.git
109 Before building libraries, adjust the includes path:
111 export C_INCLUDE_PATH=/mingw64/include
113 The basic procedure for building and installing libraries is:
115 cd MINGW-packages/mingw-w64-{libname}
116 MINGW_INSTALLS=mingw64 makepkg-mingw -sLf
117 pacman -U mingw-w64-{libname}-{suffix}.pkg.tar.xz
119 Repeat the procedure for each library listed below replacing {libname} with the
120 appropriate name and {suffix} with whatever the above process creates. Keep the
121 recommended build order, for example libsamplerate depends on libsndfile, and
122 libsystre depends on libtre-git. libsystre is a wrapper around libtre that
123 allows including <regex.h> later.
125 Some libraries like libsndfile and libsamplerate will ask for installing extra
126 dependencies, it is ok to do so.
128 For low latency audio it is recommended to build portaudio with ASIO support, so
129 the Steinberg ASIO SDK should be manually downloaded beforehand. It can be found
130 at https://www.steinberg.net/en/company/developers.html. The waf script will
131 later check if the SDK is present at /opt/asiosdk
133 wget https://www.steinberg.net/asiosdk -O /tmp/asiosdk.zip
134 unzip /tmp/asiosdk.zip -d /tmp
135 mkdir /opt   <- MinGW does not create /opt during installation
136 mv /tmp/asiosdk_{version}_{date} /opt/asiosdk
138 The description file in portaudio (MINGW-packages/mingw-w64-portaudio/PKGBUILD)
139 needs to be patched so configure is called with the necessary flags for ASIO:
141 --with-asiodir=/opt/asiosdk   <- new option     
142 --with-winapi=wmme,directx,wasapi,vdmks,asio   <- append 'asio' to existing
144 Both static and shared library versions of portaudio are built. To prevent
145 errors while building the shared version or recompiling static, also insert the
146 following lines in PKGBUILD after the first make call (around line 60) and after
147 second make (around line 70):
149 find /opt/asiosdk -name "*.lo" -type f -delete
150 find /opt/asiosdk -name "*.o" -type f -delete
152 Finally here is the list of libraries to build:
155 libsndfile
156 libsamplerate
157 libtre-git
158 libsystre
159 portaudio
163 Compiling JACK
164 --------------
166 - Clone repo
168 git clone https://github.com/jackaudio/jack2
170 - Build and install
172 cd jack2
173 ./waf configure --prefix=/opt/jack && ./waf -p install
175 The resulting files can be found at /c/opt/jack/bin, or C:\msys64\opt\jack\bin
179 Compiling JackRouter
180 --------------------
182 Visual Studio with MFC support is needed to build the included JackRouter VS
183 project. The project was tested to successfully generate a 64bit version of
184 JackRouter.dll using Visual Studio 2017 and 2019. MFC support can be added from
185 the VS installer, by selecting Workloads/Visual C++ build tools/Visual C++ MFC
186 for x86 and x64 (valid for VS 2017). Once ready, just open and build the project
188 windows/JackRouter/JackRouter_MinGW_deps.vcxproj
190 Differences from the original JackRouter.vcxproj:
192 - Depends on the asiosdk files from the previous MinGW JACK installation (i.e.,
193   it points to absolute paths starting with C:\msys64\opt)
194 - Links to the jack.dll.a created by the previous build, instead of libjack.lib
195   This means JackRouter.dll will currently depend on libjack-0.dll
196 - Force includes stdint.h and defines _STDINT_H to avoid int8_t, int32_t and
197   uint32_t basic types redefinition during compilation
201 Running and distributing
202 ------------------------
204 An automated installation process should copy files to two destinations. One for
205 the JACK server binary and standalone tools, and another for the client library.
206 The latter is needed by JACK enabled applications in order to be able to connect
207 to the server.
209 - Create a directory named C:\Program Files\Jack (can be anything else)
210 - Copy all files in C:\msys64\opt\jack\bin to C:\Program Files\Jack
211 - Copy the following DLLs from C:\msys64\mingw64\bin to C:\Program Files\Jack,
212 these are dependencies for the JACK server and tools:
214 libstdc++-6.dll
215 libdb-6.0.dll
216 libsndfile-1.dll
217 libsamplerate-0.dll
218 libportaudio-2.dll
219 libgcc_s_sjlj-1.dll
220 libwinpthread-1.dll
221 libtre-5.dll
222 libsystre-0.dll
224 - Copy and rename the following files from C:\msys64\opt\jack\bin to C:\Windows
225 to make libjack available to clients:
227 libjackserver-0.dll   -> libjackserver64.dll
228 libjack-0.dll         -> libjack64.dll
230 - Copy the following files from C:\msys64\mingw64\bin to C:\Windows, these are
231 dependencies for libjack. C:\Windows is the directory the current official JACK
232 1.9.11 binary installer targets, a better solution should be devised to avoid
233 cluttering the Windows directory:
235 libgcc_s_sjlj-1.dll
236 libwinpthread-1.dll
237 libtre-5.dll
238 libsystre-0.dll
240 - Copy JackRouter.dll from windows\JackRouter\Release64 to C:\Program Files\Jack
241 This allows non-JACK applications to connect to the server through a special
242 ASIO driver that routes audio to JACK instead of a physical audio device.
243 Also copy libjack-0.dll from C:\msys64\mingw64\bin to C:\Program Files\Jack
244 because JackRouter depends on libjack but will check for libjack-0.dll instead
245 of the system-wide libjack64.dll previously copied to C:\Windows. Once done,
246 JackRouter needs to be registered:
248 regsvr32 JackRouter.dll
250 Tested working clients:
251 Ardour
252 Bitwig Studio
253 QJackCtl
254 JackRouter
256 Example of starting the JACK server including MIDI support for a Focusrite USB
257 audio device using ASIO:
258 jackd -R -S -X winmme -d portaudio -p 32 -r 48000 -d "ASIO::Focusrite USB ASIO"
262 Development tools and links
263 ---------------------------
265 http://www.dependencywalker.com/
266 https://docs.microsoft.com/en-us/sysinternals/downloads/procmon
267 https://docs.microsoft.com/en-us/windows-hardware/drivers/debugger/gflags
268 https://blogs.msdn.microsoft.com/junfeng/2006/11/20/debugging-loadlibrary-failures/
269 https://stackoverflow.com/questions/15852677/static-and-dynamic-shared-linking-with-mingw
270 https://github.com/EddieRingle/portaudio/blob/master/src/hostapi/asio/ASIO-README.txt