Making Evaluator a MathPaper Auxiliary Executable

In the previous chapter, we created and tested Evaluator in a Unix shell. Now we want to add the Evaluator source files (grammar.y and rules.l ) to the MathPaper project and create a second target, so that the MathPaper project can create both the front end and the back end of the MathPaper application. We’ll name this second target “Evaluator”, and we’ll make the MathPaper target dependent on the Evaluator target, which will result in the Evaluator target’s being built before the MathPaper target is built. We’ll also set up the MathPaper target so that the Evaluator executable is automatically copied into the MathPaper application wrapper as an auxiliary executable.

What a lot of work! Until now, the MathPaper application itself has been the only target. Let’s get started on the modifications that we need.

  1. Open MathPaper.pbproj in Project Builder.

  2. Choose Project New Target, and a new sheet will drop down in PB’s main window.

  3. Scroll to the bottom of the new sheet and select Tool, as shown in Figure 11-1.

Selecting a new target for MathPaper

Figure 11-1. Selecting a new target for MathPaper

  1. Click the Next button and a second new sheet will drop down, prompting for the name of the new target.

  2. Enter “Evaluator” in the Target Name field in this second drop-down sheet, as shown in Figure 11-2. Select MathPaper as the project to which to add the new target.

Giving the new target a name and project

Figure 11-2. Giving the new target a name and project

  1. Click the Finish button to add the new Evaluator target to the MathPaper project.

After you complete these steps, the Evaluator target should appear next to a target icon in the Targets pane of the MathPaper.pbproj project window. The MathPaper project was already in this pane because it was our first build target.

At this point, the Evaluator target has no source files with which it can build its target. Thus, our next task is to add the Evaluator source files rules.l and grammar.y to the project.

  1. Choose Project Add Files to begin the process of adding Evaluator’s source files to the project. A new drop-down sheet appears with a filesystem browser.

  2. Select the yacc source file grammar.y file in the browser (it should be in your ~/Evaluator folder), as shown in Figure 11-3.

Finding the grammar.y yacc source file in the filesystem

Figure 11-3. Finding the grammar.y yacc source file in the filesystem

  1. Click the Open button to get a new sheet, as shown in Figure 11-4.

Adding grammar.y to the Evaluator target

Figure 11-4. Adding grammar.y to the Evaluator target

  1. Click the checkbox next to “Copy items into destination group’s folder”,[32] choose the Project Relative Reference Style, click the “Create Folder References for any added folders” radio button, click the Evaluator target, and finally click the Add button. Make sure that your settings are the same as those in Figure 11-4 before clicking Add.

  2. Choose Project Add Files again and add the lex rules file, rules.l, as you did with grammar.y. Make sure you choose the same settings as in Figure 11-4 for rules.l.

Warning

It is important that you add grammar.y before you load rules.l, because compiling the rules.l file requires an intermediate file produced when the grammar.y file is compiled. If you get the order wrong, you can manually change it by rearranging the order of the icons for these files within the Sources section of the Files & Build Phases tab of the Evaluator’s Targets pane. The icon for the grammary.y file should be above the icon for the rules.l file.

If you check your ~/MathPaper folder in the Finder, you’ll find that the grammar.y and rules.l files have been added to the folder. Next, we need to inform PB that the MathPaper target depends upon the Evaluator target.

  1. Click the vertical Targets tab in PB’s main window to open the Targets pane.

  2. Drag the Evaluator target and drop it on top of the MathPaper target. (Drop the Evaluator target when the disclosure triangle changes to your highlight color — it took us several tries to make it work.)

Your Targets pane should now look like the one on the left in Figure 11-5.

Targets pane — adding Evaluator to MathPaper target (left) and selecting Evaluator as active target (right)

Figure 11-5. Targets pane — adding Evaluator to MathPaper target (left) and selecting Evaluator as active target (right)

Now we need to tell PB that the tool created when the Evaluator target is built is an auxiliary executable for the MathPaper target:

  1. Make Evaluator the active (build) target by clicking the area to the left of the disclosure triangle next to its name. Your Targets pane should now look like the one on the right in Figure 11-5.

  2. Build and run Evaluator by clicking the build and run button.

  3. With Evaluator running in the Run pane in PB’s main window, verify that it works by typing some mathematical expressions. Recall our type conventions: what you type is in bold and the results are in regular type.

            302002/2001
        1.0005sin(2*pi) + cos(4*pi)
             1

    The output is shown in Figure 11-6.

    Evaluator running in PB’s main window

    Figure 11-6. Evaluator running in PB’s main window

  4. Click the stop button in PB’s main window to terminate the Evaluator programs running within the PB environment.

As a result of our building the Evaluator target, you should now have an Evaluator executable in your ~/MathPaper/build folder. It has a little Terminal-like icon next to it. The Evaluator executable will also be listed in the Products section of PB’s Groups & Files pane. We now need to tell PB that MathPaper needs this executable in order to run:

  1. Make MathPaper the active (build) target by clicking the area to the left of the MathPaper disclosure triangle. Your Targets pane should now look like the one on the left in Figure 11-5 again.

  2. Select the Files & Build Phases tab.

  3. Select the Frameworks & Libraries section.

  4. Choose the Project New Build Phase New Copy Files Build Phase command. A new section labeled “Copy Files” will appear.

  5. Select the Files tab to display the Groups & Files tree view.

  6. Scroll to the bottom to reveal the Products folder.

  7. Open the Products folder to reveal the icon labeled “Evaluator”.

  8. Drag the Evaluator icon from the Products folder to the Files field of the Copy Files section.

  9. Change the pop-up menu to read “Executables”. The window should now appear as ours does in Figure 11-7.

The Evaluator product is added to a newly created Copy Files section of the Files & Build Phases tab of the Targets pane

Figure 11-7. The Evaluator product is added to a newly created Copy Files section of the Files & Build Phases tab of the Targets pane

  1. Type Command-S to save the project file.

Before moving on, we’ll clean up our Groups & Files browser by putting all of the filenames in their correct groups.

  1. Drag the recently added Evaluator executable into the Resources group.

  2. Similarly, drag the grammar.y and rules.l source files into the Other Sources group. It’s easier to do this when the groups are open.

If you open the groups, your Groups & Files pane should look like the one in Figure 11-8. Evaluator should be listed both as a resource for the MathPaper project and as a product itself. (The order of files within a group doesn’t matter; in fact, the distribution of files into these groups is mostly a convenience for programmers.)

Groups & Files pane with Evaluator and its source files added

Figure 11-8. Groups & Files pane with Evaluator and its source files added



[32] By copying the files from the ~/Evaluator folder into the ~/MathPaper folder, we make sure that the MathPaper application has its own copy of these files. All of the source code on which the MathPaper application depends should be contained within the ~/MathPaper folder.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.136.18.218