xref: /Universal-ctags/docs/windows.rst (revision 5bac8ac2b8a1bc8326c7e3ac1689e02cd0b76c4b)
1f439b71bSVitor AntunesBuilding/hacking/using on MS-Windows
2878d8de4SMasatake YAMATO-----------------------------------------------------------------------------
3f439b71bSVitor Antunes
4f439b71bSVitor Antunes:Maintainer: Frank Fesevur <ffes@users.sourceforge.net>
5f439b71bSVitor Antunes
6f439b71bSVitor Antunes----
7f439b71bSVitor Antunes
8dccba5efSHiroo HAYASHIThis part of the documentation is written by Frank Fesevur, co-maintainer of Universal Ctags and the maintainer of the Windows port of this project. It is still very much a work in progress. Things still need to be written down, tested or even investigated. When building for Windows you should be aware that there are many compilers and build environments available. This is a summary of available options and things that have been tested so far.
9f439b71bSVitor Antunes
10f439b71bSVitor Antunes
11f439b71bSVitor AntunesCompilers
12878d8de4SMasatake YAMATO~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
13f439b71bSVitor Antunes
14ff522909SDoug KearnsThere are many compilers for Windows. Compilers not mentioned here may work but are not tested.
15f439b71bSVitor Antunes
16f439b71bSVitor Antunes
17f439b71bSVitor AntunesMicrosoft Visual Studio
18878d8de4SMasatake YAMATO.............................................................................
192b8661bbSK.Takatahttps://www.visualstudio.com/
20f439b71bSVitor Antunes
21ff522909SDoug KearnsObviously there is Microsoft Visual Studio 2013. Many professional developers targeting Windows use Visual Studio. Visual Studio comes in a couple of different editions. Their Express and Community editions are free to use, but a Microsoft-account is required to download the .iso and when you want to continue using it after a 30-days trial period. Other editions of Visual Studio must be purchased.
22f439b71bSVitor Antunes
23f439b71bSVitor AntunesInstalling Visual Studio will give you the IDE, the command line compilers and the MS-version of make named nmake.
24f439b71bSVitor Antunes
25ff522909SDoug KearnsNote that ctags cannot be built with Visual Studio older than 2013 anymore. There is C99 (or C11) coding used that generates syntax errors with VS2012 and older. This could affect compilers from other vendors as well.
26f439b71bSVitor Antunes
27f439b71bSVitor Antunes
28f439b71bSVitor AntunesGCC
29878d8de4SMasatake YAMATO.............................................................................
30f439b71bSVitor Antunes
31*5bac8ac2SK.TakataYou can use `MinGW-w64 <https://www.mingw-w64.org/>`_ to build ctags. There are several ways to install MinGW-w64 in Windows.
32f439b71bSVitor Antunes
33*5bac8ac2SK.Takata- MSYS2 https://www.msys2.org/
34*5bac8ac2SK.Takata- MinGW-w64 - for 32 and 64 bit Windows https://sourceforge.net/projects/mingw-w64/
35*5bac8ac2SK.Takata- TDM-GCC https://jmeubank.github.io/tdm-gcc/
36f439b71bSVitor Antunes
37*5bac8ac2SK.TakataIf you want to build a full-featured version, use MSYS2 (with Autotools). Otherwise, you can also use the other two distributions.
38*5bac8ac2SK.Takata
39*5bac8ac2SK.Takata**History**
40*5bac8ac2SK.Takata
41*5bac8ac2SK.TakataMinGW started it all, but development stalled for a while and no x64 was available. Then the MinGW-w64 fork emerged. It started as a 64-bit compiler, but soon they included both a 32-bit and a 64-bit compiler. But the name remained, a bit confusing. MinGW-w64 appears to be the most used flavor of MinGW at this moment. Many well known programs that originate from GNU/Linux use MinGW-w64 to compile their Windows port.
42f439b71bSVitor Antunes
43f439b71bSVitor AntunesBuilding ctags from the command line
44878d8de4SMasatake YAMATO~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
45f439b71bSVitor Antunes
46f439b71bSVitor AntunesMicrosoft Visual Studio
47878d8de4SMasatake YAMATO.............................................................................
48f439b71bSVitor Antunes
49ff522909SDoug KearnsMost users of Visual Studio will use the IDE and not the command line to compile a project. But by default a shortcut to the command prompt that sets the proper path is installed in the Start Menu. When this command prompt is used ``nmake -f mk_mvc.mak`` will compile ctags. You can also go into the ``win32`` subdirectory and run ``msbuild ctags_vs2013.sln`` for the default build. Use ``msbuild ctags_vs2013.sln /p:Configuration=Release`` to specifically build a release build. MSBuild is what the IDE uses internally and therefore will produce the same files as the IDE.
50f439b71bSVitor Antunes
511f151e60SK.TakataIf you want to build an iconv enabled version, you must specify ``WITH_ICONV=yes`` and ``ICONV_DIR`` like below::
521f151e60SK.Takata
531f151e60SK.Takata        nmake -f mk_mvc.mak WITH_ICONV=yes ICONV_DIR=path/to/iconvlib
541f151e60SK.Takata
551f151e60SK.TakataIf you want to build a debug version using ``mk_mvc.mak``, you must specify ``DEBUG=1`` like below::
561f151e60SK.Takata
571f151e60SK.Takata        nmake -f mk_mvc.mak DEBUG=1
581f151e60SK.Takata
59aeb75fc8SK.TakataIf you want to create PDB files for debugging even for a release version, you must specify ``PDB=1`` like below::
60aeb75fc8SK.Takata
61aeb75fc8SK.Takata        nmake -f mk_mvc.mak PDB=1
62aeb75fc8SK.Takata
63f439b71bSVitor AntunesGCC
64878d8de4SMasatake YAMATO.............................................................................
65f439b71bSVitor Antunes
66f439b71bSVitor Antunes**General**
67f439b71bSVitor Antunes
68f439b71bSVitor AntunesAll the GCC's come with installers or with zipped archives. Install or extract them in a directory without spaces.
6920ea5985SFrank Fesevur
70f439b71bSVitor AntunesGNU Make builds for Win32 are available as well, and sometimes are included with the compilers. Make sure it is in your path, for instance by copying the make.exe in the bin directory of your compiler.
7120ea5985SFrank Fesevur
72ff522909SDoug KearnsNative win32 versions of the GNU/Linux commands cp, rm and mv can be useful. rm is almost always used in by the ``clean`` target of a makefile.
73f439b71bSVitor Antunes
74f439b71bSVitor Antunes
75f439b71bSVitor Antunes**CMD**
76f439b71bSVitor Antunes
778251dcb9SFrank FesevurAny Windows includes a command prompt. Not the most advanced, but it is enough to do the build tasks. Make sure the path is set properly and ``make -f mk_mingw.mak`` should do the trick.
78f439b71bSVitor Antunes
791f151e60SK.TakataIf you want to build an iconv enabled version, you must specify ``WITH_ICONV=yes`` like below::
801f151e60SK.Takata
811f151e60SK.Takata        make -f mk_mingw.mak WITH_ICONV=yes
821f151e60SK.Takata
831f151e60SK.TakataIf you want to build a debug version, you must specify ``DEBUG=1`` like below::
841f151e60SK.Takata
851f151e60SK.Takata        make -f mk_mingw.mak DEBUG=1
861f151e60SK.Takata
87*5bac8ac2SK.Takata**MSYS2**
88f439b71bSVitor Antunes
89*5bac8ac2SK.TakataFrom mingw.org: MSYS is a collection of GNU utilities such as bash, make, gawk and grep to allow building of applications and programs which depend on traditional UNIX tools to be present. It is intended to supplement MinGW and the deficiencies of the cmd shell.
90f439b71bSVitor Antunes
911f151e60SK.TakataMSYS2 is a more maintained version of MSYS, but specially geared towards MinGW-w64. You can also use Autotools to build ctags.
92c8994a54SK.TakataIf you use Autotools you can enable parsers which require jansson, libxml2 or libyaml, and can also do the Units testing with ``make units``.
93*5bac8ac2SK.TakataIf you don't need such features, you can still build ctags without using Autotools: ``make -f mk_mingw.mak``.
94c8994a54SK.Takata
95c8994a54SK.TakataThe following packages are needed to build a full-featured version:
96c8994a54SK.Takata
97c8994a54SK.Takata- base-devel (make, autoconf)
98c8994a54SK.Takata- mingw-w64-{i686,x86_64}-toolchain (mingw-w64-{i686,x86_64}-gcc, mingw-w64-{i686,x86_64}-pkg-config)
99c8994a54SK.Takata- mingw-w64-{i686,x86_64}-jansson
100c8994a54SK.Takata- mingw-w64-{i686,x86_64}-libxml2
101c8994a54SK.Takata- mingw-w64-{i686,x86_64}-libyaml
102c8994a54SK.Takata- mingw-w64-{i686,x86_64}-xz
103c8994a54SK.Takata
104c8994a54SK.TakataIf you want to build a single static-linked binary, you can use the following command:
105c8994a54SK.Takata
106c8994a54SK.Takata.. code-block:: bash
107c8994a54SK.Takata
108c8994a54SK.Takata        ./autogen.sh
109fb0fd536SK.Takata        ./configure --disable-external-sort --enable-static
110c8994a54SK.Takata        make
111c8994a54SK.Takata
112c8994a54SK.Takata``--disable-external-sort`` is a recommended option for Windows builds.
113f439b71bSVitor Antunes
114f439b71bSVitor Antunes**Cygwin**
115f439b71bSVitor Antunes
116ff522909SDoug KearnsCygwin provides ports of many GNU/Linux tools and a POSIX API layer. This is the most complete way to get the GNU/Linux terminal feel under Windows. Cygwin has a setup that helps you install all the tools you need. One drawback of Cygwin is that it has poor performance.
117f439b71bSVitor Antunes
118f439b71bSVitor AntunesIt is easy to build a Cygwin version of ctags using the normal GNU/Linux build steps. This ctags.exe will depend on cygwin1.dll and should only be used within the Cygwin ecosystem.
119f439b71bSVitor Antunes
120215f3507SK.TakataThe following packages are needed to build a full-featured version:
121215f3507SK.Takata
122215f3507SK.Takata- libiconv-devel
123215f3507SK.Takata- libjansson-devel
124215f3507SK.Takata- libxml2-devel
125215f3507SK.Takata- libyaml-devel
126215f3507SK.Takata
1278251dcb9SFrank FesevurCygwin has packages with a recent version of MinGW-w64 as well. This way it is easy to cross-compile a native Windows application with ``make -f mk_mingw.mak  CC=i686-w64-mingw32-gcc``.
128f439b71bSVitor Antunes
1298251dcb9SFrank FesevurYou can also build a native Windows version using Autotools.
13020ea5985SFrank Fesevur
13120ea5985SFrank Fesevur.. code-block:: bash
13220ea5985SFrank Fesevur
1339d5b773cSMasatake YAMATO	./autogen.sh
1348251dcb9SFrank Fesevur	./configure --host=i686-w64-mingw32 --disable-external-sort
1358251dcb9SFrank Fesevur	make
1368251dcb9SFrank Fesevur
137c8994a54SK.TakataIf you use Autotools you can also do the Units testing with ``make units``.
1388251dcb9SFrank Fesevur
139ff522909SDoug KearnsSome anti-virus software slows down the build and test process significantly, especially when ``./configure`` is running and during the Units tests. In that case it could help to temporarily disable them. But be aware of the risks when you disable your anti-virus software.
140f439b71bSVitor Antunes
141f439b71bSVitor Antunes**Cross-compile from GNU/Linux**
142f439b71bSVitor Antunes
1438251dcb9SFrank FesevurAll major distributions have both MinGW and MinGW-w64 packages. Cross-compiling works the same way as with Cygwin. You cannot do the Windows based Units tests on GNU/Linux.
144f439b71bSVitor Antunes
145f439b71bSVitor Antunes
146f439b71bSVitor AntunesBuilding ctags with IDEs
147878d8de4SMasatake YAMATO~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
148f439b71bSVitor Antunes
1498251dcb9SFrank FesevurI have no idea how things work for most GNU/Linux developers, but most Windows developers are used to IDEs. Not many use a command prompt and running the debugger from the command line is not a thing a Windows developers would normally do. Many IDEs exist for Windows, I use the two below.
150f439b71bSVitor Antunes
151f439b71bSVitor AntunesMicrosoft Visual Studio
152878d8de4SMasatake YAMATO.............................................................................
153f439b71bSVitor Antunes
154ff522909SDoug KearnsAs already mentioned Microsoft Visual Studio 2013 has the free Express and Community editions. For ctags the Windows Desktop Express Edition is enough to get the job done. The IDE has a proper debugger. Project files for VS2013 can be found in the win32 directory.
155f439b71bSVitor Antunes
156aeb75fc8SK.TakataPlease know that when files are added to the sources.mak, these files need to be added to the .vcxproj and .vcxproj.filters files as well. The XML of these files should not be a problem.
157f439b71bSVitor Antunes
158f439b71bSVitor AntunesCode::Blocks
159878d8de4SMasatake YAMATO.............................................................................
160f439b71bSVitor Antuneshttp://www.codeblocks.org/
161f439b71bSVitor Antunes
162f439b71bSVitor AntunesCode::Blocks is a decent GPL-licensed IDE that has good gcc and gdb integration. The TDM-GCC that can be installed together with Code::Blocks works fine and I can provide a project file. This is an easy way to have a free - free as in beer as well as in speech - solution and to have the debugger within the GUI as well.
163f439b71bSVitor Antunes
164f439b71bSVitor Antunes
165f439b71bSVitor AntunesOther differences between Microsoft Windows and GNU/Linux
166878d8de4SMasatake YAMATO~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
167f439b71bSVitor Antunes
168f439b71bSVitor AntunesThere other things where building ctags on Microsoft Windows differs from building on GNU/Linux.
169f439b71bSVitor Antunes
170f439b71bSVitor Antunes- Filenames on Windows file systems are case-preserving, but not case-sensitive.
171bac486a0SK.Takata- Windows file systems use backslashes ``"\"`` as path separators, but paths with forward slashes ``"/"`` are no problem for a Windows program to recognize, even when a full path (include drive letter) is used.
172f439b71bSVitor Antunes- The default line-ending on Windows is CRLF. A tags file generated by the Windows build of ctags will contain CRLF.
1738251dcb9SFrank Fesevur- The tools used to build ctags do understand Unix-line endings without problems. There is no need to convert the line-ending of existing files in the repository.
174e3d8762fSK.Takata- Due to the differences between the GNU/Linux and Windows C runtime library there are some things that need to be added to ctags to make the program as powerful as it is on GNU/Linux. At this moment regex and fnmatch are borrowed from glibc. mkstemp() is taken from MinGW-w64's runtime library. scandir() is taken from `Pacemaker <https://github.com/ClusterLabs/pacemaker/blob/master/replace/scandir.c>`_.
175387b5431SK.Takata- Units testing needs a decent ``bash`` shell, some unix-like tools (e.g. ``diff``, ``sed``) and Python 3.5 or later. It is only tested using Cygwin or MSYS2.
176