Previous Next Contents Index Doc Set Home


Makefile Generation

15



15.1 Introduction

This section describes WorkShop Visual's Makefile generation facilities. WorkShop Visual can create two types of Makefile: simple or with templates. The simple Makefile only contains the build rules for the local .xd file and so is only useful for applications that are contained in a single file. A Makefile with templates can be updated to add files without overwriting your previous work. Unlike most generated files, Makefiles with templates can be edited and regenerated without losing your work.

This section gives step-by-step instructions for creating a Makefile with templates and then updating the Makefile when a second design file is added to the application.


15.2 Creating the Initial Makefile

The first step is to create a design, generate the C code for it and then generate an initial Makefile.

1. Create a new directory myapp. Make this your current directory and start WorkShop Visual.

2. Build the widget hierarchy shown in Figure 15-1:

Figure  15-1 Main Program Widget Hierarchy

3. Give the PushButton an Activate callback, button_pressed.

4. Use the Shell resource panel to designate the Shell widget as an Application Shell.

Before you generate a Makefile, you must generate the code files that you want to include in it. Generating the code files sets the names for these files in the design file. Until you do this, the Makefile generation feature doesn't know the names of these files and can't add them to the Makefile.

5. Display the Generate dialog and make sure that "C" is the selected language.

The Generate dialog will be primed with filenames based on the save file name or "untitled" if the design has not been saved.

6. Type: myapp.c into the "Code" field and set the "Generate" toggle.

7. Type: myapp.c into the "Main Program" field and set the "Generate" toggle.

If the "code" and "Main Program" filenames are the same, the code file is generated with a main procedure.

8. In the Code Options dialog, set the "Include Header File" toggle.

9. Type: app_stubs.c into the "Stubs" field and set the "Generate" toggle.

10. In the Generate Options dialog, set the "Links" option menu to "None".

Now you can generate a Makefile that compiles and links myapp.c and app_stubs.c:

11. Type: Makefile into the "Makefile" field and set the "Generate" toggle.

12. In the Makefile Options dialog set both "New Makefile" and "Makefile Template" toggles on, as shown in Figure 15-2.

Figure  15-2 Initial Makefile Generation.

13. In the Generate dialog press the "Generate" button.

The generated Makefile contains the required make rules and template lines for further amendment. Ignoring the template lines, the generated Makefile contains the following rules:

XD_C_PROGRAMS=\
		myapp
XD_C_PROGRAM_OBJECTS=\
		myapp.o
XD_C_PROGRAM_SOURCES=\
		myapp.c
XD_C_STUB_OBJECTS=\
		app_stubs.o
XD_C_STUB_SOURCES=\
		app_stubs.c
myapp: myapp.o $(XD_C_OBJECTS) $(XD_C_STUB_OBJECTS)
	$(CC) $(CFLAGS) $(CPPFLAGS) $(LDFLAGS) -o myapp myapp.o 
$(XD_C_OBJECTS) $(XD_C_STUB_OBJECTS) $(MOTIFLIBS) $(LDLIBS)
myapp.o: myapp.c
	$(CC) $(CFLAGS) $(CPPFLAGS) -c myapp.c
app_stubs.o: app_stubs.c
	$(CC) $(CFLAGS) $(CPPFLAGS) -c app_stubs.c

14. Save the current design to myapp.xd.


15.3 Updating the Initial Makefile

Once you have generated the initial Makefile, you can update it to reflect additional work. To demonstrate this, use the following instructions to build a popup dialog in another file, generate code for it and then update the Makefile to reflect the new modules.

1. Select "New" from the File menu to start a new design.

2. Build the hierarchy shown in Figure 15-3.

Figure  15-3 Secondary Popup Dialog.

3. Name the Shell and MessageBox error_shell and error_box respectively.

4. Give the MessageBox a Cancel callback, cancel_error.

5. Display the Generate dialog and make sure that "C" is the selected language.

6. Type: error.h into the "Externs" field and set the "Generate" toggle.

7. Type: error.c into the "Code" field and set the "Generate" toggle.

8. In the Code Options dialog, set the "Include Header File" toggle and type: error.h into the corresponding field.

9. Type: error_stubs.c into the "Stubs" field and set the "Generate" toggle.

10. Make sure that the "Generate" toggle next to "Main Program" is not set.

11. In the Generate Options dialog, select "None" from the "Links" option menu.

12. Type: Makefile into the "Makefile" field and set the "Generate" toggle.

13. In the Makefile Options dialog turn off the "New Makefile" toggle, leaving the "Makefile Template" toggle set, as shown in Figure 15-4.

Figure  15-4 Updating Makefile.

14. Press the "Generate" button in the Generate dialog.

The generated Makefile is updated with the new modules.

XD_C_PROGRAMS=\
myapp
XD_C_PROGRAM_OBJECTS=\
myapp.o
XD_C_PROGRAM_SOURCES=\
myapp.c
XD_C_OBJECTS=\
error.o
XD_C_SOURCES=\
error.c
XD_C_STUB_OBJECTS=\
error_stubs.o\
app_stubs.o
XD_C_STUB_SOURCES=\
error_stubs.c\
app_stubs.c
myapp: myapp.o $(XD_C_OBJECTS) $(XD_C_STUB_OBJECTS)
$(CC) $(CFLAGS) $(CPPFLAGS) $(LDFLAGS) -o myapp\
myapp.o $(XD_C_OBJECTS)\
$(XD_C_STUB_OBJECTS) $(MOTIFLIBS)\
$(LDLIBS)
myapp.o: myapp.c
$(CC) $(CFLAGS) $(CPPFLAGS) -c myapp.c
error.o: error.c
$(CC) $(CFLAGS) $(CPPFLAGS) -c error.c
app_stubs.o: app_stubs.c
$(CC) $(CFLAGS) $(CPPFLAGS) -c app_stubs.c
error_stubs.o: error_stubs.c
$(CC) $(CFLAGS) $(CPPFLAGS) -c error_stubs.c

15.3.1 Building the Application

WorkShop Visual has generated the code files for two dialogs, two stub files and a Makefile. All that remains is to fill in the two stubs and build the application.

1. Edit app_stubs.c and make the following changes.

At the end of the generated list of includes, add the following line:

#include <error.h>
Add functionality to the button_pressed callback stub. This callback pops up the error dialog when the button is pressed:

void
button_pressed (Widget w, XtPointer client_data, XtPointer 
call_data )
{
	if ( error_shell == NULL )
		create_error_shell (XtParent (XtParent (w) ) );
	XtManageChild ( error_box );
}

2. Edit error_stubs.c and make the following changes.

Add functionality to the cancel_error callback. This function pops down the error dialog when the user presses the "Cancel" button.

void
cancel_error (Widget w, XtPointer client_data, XtPointer 
call_data )
{
	XtUnmanageChild ( error_box );
}

3. Save the current design to error.xd.

4. Read the file myapp.xd into the current design.

5. Generate X resources into the file myapp.res.

6. To access these resources do the following:

7. If you are using a C shell enter on the command line:

		setenv XENVIRONMENT myapp.res

8. Or, if you are using a Bourne shell or ksh, enter on the command line:

		XENVIRONMENT=myapp.res export XENVIRONMENT

9. Set VISUROOT to the path of the WorkShop Visual installation directory.

This must be done as the Makefile includes files and libraries relative to the WorkShop Visual installation directory.

10. Build the application. On the command line, type: make

11. To run the application, type: myapp


15.4 Editing the Generated Makefile

You can edit and regenerate the Makefile without losing information. You can make the most commonly needed changes by editing the Makefile flags at the beginning of the file. For example, to make the compiler search the ../hdrs directory for header files, append the entry:

-I../hdrs
to the end of the CFLAGS line in the Makefile.

The change to CFLAGS is retained when you regenerate the Makefile with the "New makefile" toggle off. It is only lost if you generate a new Makefile.

15.4.1 Editing Template Lines

A large part of the generated Makefile consists of template lines. Template lines are comments that control the generation of information into the Makefile. Template lines have a #WorkShop Visual: prefix. For example, the following template lines tell WorkShop Visual how to generate the Makefile lines that produce a C object file from a C source file (XDG_C_SOURCE):

#WorkShop Visual:XDG_C_OBJECT: XDG_C_SOURCE
#WorkShop Visual:    $(CC) $(CFLAGS) $(CPPFLAGS) -c XDG_C_SOURCE
Each time you update the Makefile to add a file to your application, WorkShop Visual generates a template instance for each relevant template. These instances contain the actual build commands for your application.

Template instances are marked with a "DO NOT EDIT" comment at the beginning and at the end. A typical instance of the template shown above looks like:

#DO NOT EDIT >>>
error.o: error.c
        $(CC) $(CFLAGS) $(CPPFLAGS) -c error.c
#<<< DO NOT EDIT
Template instances should not be edited because your edits may be lost the next time you generate the Makefile. Instead, to change the build commands, edit the corresponding template lines. After you edit a template line, delete any instances of that template line that already exist in the Makefile. The instances are found just after the template line.

For example, to build all C files for debugging, you would:

1. Change the template line:

#WorkShop Visual: $(CC) $(CFLAGS) $(CPPFLAGS) -c XDG_C_SOURCE

to

#WorkShop Visual: $(CC) $(CFLAGS) $(CPPFLAGS) -g -c XDG_C_SOURCE

2. Remove the instances following the template line.

3. Regenerate the Makefile, with the "New" toggle off, for each design in the application.

This procedure generates new instances using the modified template.

15.4.2 Template Configuration

The original templates are specified by the file pointed to by the following resources:

visu.motifMakeTemplateFile: $VISUROOT/make_templates/motif
visu.mmfcMakeTemplateFile: $VISUROOT/make_templates/mfc
There are two resources so that you can have different templates customized to pick up the appropriate class libraries. The value for the resource can contain environment variables which will be expanded by /bin/sh.

If WorkShop Visual cannot find the file specified, it will fall back to the template specified in the WorkShop Visual resource file, using the makefileTemplate application resource. To make a change to the template apply globally to all new Makefiles, edit the resource file. For details, see the Configuration chapter.

WorkShop Visual refers to the template only when you generate a new Makefile. To change templates in an existing Makefile, edit the file by hand as described in the previous section, or delete the file and start over.

15.4.3 Dependency Information

WorkShop Visual does not generate dependency information into the Makefile. The default template includes a "depend" target that can be invoked using:

make depend
This operation invokes the makedepend utility, which scans the existing makefile and appends a standard dependency list. Use man makedepend for more information.


15.5 Using your own Makefiles

The $VISUROOT/make_templates directory contains the template(s) used to generate makefiles. The include directories and libraries you will need to include in your makefile are listed in the files in this directory. Those not required by your system are commented out. A typical example is shown below:

solaris 2.x
#XINCLUDES=-I/opt/SUNWmotif/include -I/usr/dt/include 
#XLIBS=-L/opt/SUNWmotif/lib -L/usr/dt/lib -L/usr/openwin/lib
...
XINCLUDES and XLIBS specify the extensions to the included directory and library path respectively.

The motif template is used for makefiles generated in non-Windows mode and the mfc template is used for generating makefiles for Motif XP in Windows mode.


Previous Next Contents Index Doc Set Home