Scripting:Build Environment: Difference between revisions

Building pieces of another world.
Jump to navigation Jump to search
gravatar The Watcher [userbureaucratsysopPHRhYmxlIGNsYXNzPSJ0d3BvcHVwIj48dHI+PHRkIGNsYXNzPSJ0d3BvcHVwLWVudHJ5dGl0bGUiPkdyb3Vwczo8L3RkPjx0ZD51c2VyPGJyIC8+YnVyZWF1Y3JhdDxiciAvPnN5c29wPGJyIC8+PC90ZD48L3RyPjwvdGFibGU+] (talk | contribs)
No edit summary
gravatar The Watcher [userbureaucratsysopPHRhYmxlIGNsYXNzPSJ0d3BvcHVwIj48dHI+PHRkIGNsYXNzPSJ0d3BvcHVwLWVudHJ5dGl0bGUiPkdyb3Vwczo8L3RkPjx0ZD51c2VyPGJyIC8+YnVyZWF1Y3JhdDxiciAvPnN5c29wPGJyIC8+PC90ZD48L3RyPjwvdGFibGU+] (talk | contribs)
No edit summary
Line 104: Line 104:
You should now have three or four directories inside your t2scripts directory: lg, scriptlib, twscript, and possibly publicscripts. Now to compile them...
You should now have three or four directories inside your t2scripts directory: lg, scriptlib, twscript, and possibly publicscripts. Now to compile them...


== compiling the libraries ==
== Compiling the libraries ==
Before you can actually create any scripts, you need to have compiled the support libraries your scripts will need to use in order to communicate with the Dark engine. This step should be pretty straightforward at this point. Henceforth, for simplicity, I am going to assume that all the projects you cloned in the previous section are inside the <code>C:\t2scripts</code> directory as discussed there - if you cloned them elsewhere, you must update the paths accordingly.
Before you can actually create any scripts, you need to have compiled the support libraries your scripts will need to use in order to communicate with the Dark engine. This step should be pretty straightforward at this point. Henceforth, for simplicity, I am going to assume that all the projects you cloned in the previous section are inside the <code>C:\t2scripts</code> directory as discussed there - if you cloned them elsewhere, you must update the paths accordingly.



Revision as of 23:03, 10 September 2014

If you are interested in using this package as the base from which you can develop your own scripts, or just want to bugfix and recompile twscript, you will need to do rather more work than a normal Dromed user. You will need to have at least the following installed:

  1. a working compiler setup (and editor to code in)
  2. git (the distributed version control system) to fetch the library code.
  3. the supporting libraries
  4. the twscript code.

what follows is a walkthrough of how to get the above set up, and how to get to the point where you can actually compile scripts.

Setting up the compiler

Before you can do any compiling, you need a compiler. This is actually not as straightforward as you might think: as even if you already have a compiler available, there's a good chance it may not actually work with this code, or it may produce an .osm that Thief can't actually load (or it may work fine, in which case, great! But don't blame me if you end up up to your armpits in soul-devouring, tentacled horrors from beyond time and space when trying it). Hence, you are strongly advised to follow these steps, even if you already have a working compiler setup, unless you're feeling adventurous:

  1. Download the TDM-GCC compiler suite for Windows from the project site. You want to click on the "TDM32 bundle" button (currently 3.8.1), this will take you to a sourceforge download page to download a tdm-gcc-<version>.exe file.
  2. Run the tdm-gcc-<version>.exe installer:
    1. Click "Create"
    2. Select "MinGW/TDM (32-bit), click "Next"
    3. On the "New Installation: Installation Directory" step, unless you have some particular reason to change the install directory, just click "Next"
    4. Unless you have some preferred sourceforge mirror, click "Next" again.
    5. Review the selected components, you shouldn't need to change any, so click "Install".
    6. Go look at lolcats or something for a bit.
  3. From the Start Menu, select TDM-GCC-32 -> MinGW Command Prompt
  4. When the command prompt appears, type the following: `gcc -v`. If all goes well, you should see several lines of information output, ending in gcc version X.X.X (tdm-2), eg:

Scripting tdmgcc.png

This is enough to get you a working compiler, but the toolset included is very limited, I generally suggest installing MSYS as well.

Setting up MSYS

MSYS includes a number of additional tools to make using the compiler a little less painful, to install it:

  1. Download the latest version of the mingw-get-setup.exe installer from sourceforge
  2. Run mingw-get-setup.exe as Administrator
  3. Click 'Install'
  4. Change the "Installation directory" to the directory you installed TDM-GCC to (usually C:\TDM-GCC-32 with the default settings). If you do not do this, the MSYS tools won't locate your compiler correctly without additional work.
  5. Click 'Continue' (you should be able to leave all the options on defaults)
  6. Wait while stuff is downloaded
  7. Eventually the downloads will complete, then click 'Continue'
  8. The "MinGW Installation Manager" should now open
  9. Click on the checkbox next to "msys-base' and select "Mark for installation"
  10. Click on "All Packages" in the left list of the "MinGW Installation Manager"
  11. Locate "msys-mintty" in the list on the right. It should be about four fifths of the way down the list.[1]
  12. Click on the checkbox next to "msys-mintty' and select "Mark for installation"
  13. From the "Installation" menu, select "apply changes"
  14. Click "Apply"
  15. Wait while packages are downloaded and installed, then click "close"
  16. Close the package manager.

It is possible to skip steps 10 to 12, but the default command prompt for msys uses the ghastly and dreadful default Windows command line tool. mintty is far more usable and fully-featured.

For some reason best - if not only - known to the MinGW maintainers, the MinGW Installation Manager does not appear to create useful start menu shortcuts. This means that, unless you want to faff around each time you open the terminal, you need to create an appropriate shortcut:

  1. Using Windows Explorer, locate your msys directory. If you have followed the steps above and left the install paths as the defaults, this should be C:\TDM-GCC-32\msys\1.0. The directory should contain a file msys.bat.
  2. Select the msys.bat file, right click, and select "Create shortcut" from the popup menu.
  3. Select the shortcut and rename it to "Mintty"
  4. Open the shortcut properties.
  5. In the "Target:" field, add -mintty to the end, so it reads C:\TDM-GCC-32\msys\1.0\msys.bat -mintty
  6. In the "Start in:" field, add \bin to the end, so it reads C:\TDM-GCC-32\msys\1.0\bin
  7. If you want, change the icon to use the msys icon
  8. Apply the changes, and okay the properties window to close it.
  9. Drag the shortcut into the Windows start menu
  10. Run the Mintty shortcut from the start menu, after a brief delay a terminal prompt should open
  11. run make the terminal should respond with make: *** No targets specified and no makefile found. Stop.
  12. run gcc -v you should get the same output as before.

At this point, you should have a working compiler, and a decent set of tools installed.

Setting up an editor

I'm not going to tell you to use one editor or another here - editor choice has been the subject of Holy Wars for decades, and almost everyone has their favorite. If you don't have a decent programmer's editor installed, you can go far worse than to start off with Notepad++: it's fast, light, does syntax highlighting and block folding. TDM-GCC plays nice with the Code::Blocks IDE, so you might want to look at that. I tend to use Emacs, but I'm also reliably informed that I'm insane, so you may or may not want to attempt that.

Note that, if you use an IDE like Code::Blocks, do not expect to be able to use the IDE's build process to compile the scripts: you are going to need to use make, and wrangle makefiles, to get them to build unless you want to do a lot of finagling.

Setting up git

To actually get the code, you need to install git. If you already have git (or github's native tool) installed, you can skip this section.

  1. Download the latest installer from http://git-scm.com/downloads
  2. Run the installer, clicking "Next" through it until you come to the "Adjusting your PATH environment" page. Select the "Run Git from the Windows Command Prompt" option, and click "Next"
  3. Leave the "Choosing the SSH executable" option on "Use OpenSSH". Do not select "Use (Tortoise)Plink", even if you have it installed and working. Enabling that option can, and usually will, cause problems.
  4. Keep clicking "Next" until it starts installing.
  5. Twiddle your thumbs for a while.
  6. Once the install has finished, run Git -> Git Bash from the Start Menu.
  7. If all goes well, the Git Bash window should open, and you can use git --version to confirm that git is working.

Before continuing, you may want to become familiar with the basics of using Git. A good place to start is the online Pro Git Book.

Getting the code

Now you should be in the position where you can actually start to fetch code to work on. All the code is on github, so you need to clone copies of it with git (you may wish to fork the twscript project before doing so, if you want to push your changes back to github, but that's up to you).

  • Create a directory somewhere on your system, something like C:\t2scripts. It doesn't matter what you call it, provided that you can remember it, and it does not contain spaces. Spaces in filenames are a Bad Thing when working with mingw/msys and friends, and they're another way to summon those soul-devouring, tentacled horrors from beyond time and space, so avoid them: CamelCase or underscore_names are your friend.
  • From the start menu, select Git -> Git Bash
  • Change into the directory you created in the first step, using unix-like syntax, eg: cd /c/t2scripts
  • Enter the following commands to clone Telliamed's script support libraries:
       git clone https://github.com/whoopdedo/lg.git
       git clone https://github.com/whoopdedo/scriptlib.git
  • And this one to clone twscript (if you have forked it, clone your fork instead!):
       git clone https://github.com/TheWatcher/twscript.git
  • You'll probably also want to grab Telliamed's Public Scripts package itself, so that you can use the various script implementations it contains as a reference. You can either look at it on the web at github, or clone a local copy:
       git clone https://github.com/whoopdedo/publicscripts.git

You should now have three or four directories inside your t2scripts directory: lg, scriptlib, twscript, and possibly publicscripts. Now to compile them...

Compiling the libraries

Before you can actually create any scripts, you need to have compiled the support libraries your scripts will need to use in order to communicate with the Dark engine. This step should be pretty straightforward at this point. Henceforth, for simplicity, I am going to assume that all the projects you cloned in the previous section are inside the C:\t2scripts directory as discussed there - if you cloned them elsewhere, you must update the paths accordingly.

Before you compile the libraries, I recommend a few changes to them:

Open C:\t2scripts\lg\Makefile in your text editor, go to line 24, and change

       CXXFLAGS = -W -Wall -Wno-unused-parameter -masm=intel $(INCLUDEDIRS)

to be

       CXXFLAGS = -std=gnu++0x -W -Wall -Wno-unused-parameter -masm=intel $(INCLUDEDIRS)

Open C:\t2scripts\scriptlib\Makefile in your text editor, go to line 45, and change

       CXXFLAGS = -W -Wall -masm=intel
  to read
       CXXFLAGS = -std=gnu++0x -W -Wall -masm=intel

Next open C:\t2scripts\lg\lg\scrmsgs.h and locate the following around line 39:

       sScrMsgBase() { };

Immediately after it place the following:

       virtual ~sScrMsgBase() { };

(This will remove a probably harmless warning message)

Now you can start compiling:

  1. Start Mintty from the start menu
  2. Change into the lg directory, eg: cd /c/t2scripts/lg
  3. Run make (mingw32-make may work as well, but I just use make)
  4. Change into the scriptlib directory, eg: cd /c/t2scripts/scriptlib
  5. Run make

Test compiling TWScript

At this point, all the libraries required to compile scripts should be in place and compiled, so it is time to actually give it a go. Before you start working on any scripts of your own, you should make sure your environment is sane by compiling the TWScript package:

  1. If a Mintty window isn't current open, start one.
  2. Change into the twscript directory: cd /c/t2scripts/twscript
  3. Run make

If all is well, this should complete with no errors.

  1. Note: do not enable any other packages for installation unless you know what you're doing. Especially do not enable any of the compiler packages.

Authors

  • gravatar The Watcher [userbureaucratsysopPHRhYmxlIGNsYXNzPSJ0d3BvcHVwIj48dHI+PHRkIGNsYXNzPSJ0d3BvcHVwLWVudHJ5dGl0bGUiPkdyb3Vwczo8L3RkPjx0ZD51c2VyPGJyIC8+YnVyZWF1Y3JhdDxiciAvPnN5c29wPGJyIC8+PC90ZD48L3RyPjwvdGFibGU+]