Back to Contents


Compiling Programs

Summary:

See also: Tools, Form Files, Message Files, Localized Strings.


Compiling Source Code

Source code modules (.4gl) must be compiled to p-code modules (.42m) with the fglcomp tool. Compiled p-code modules are portable; you can compile a module on a Windows platform and install it on a Unix production machine.

The following lines show a compilation in a Unix shell session:

$ cat xx.4gl
main
  display "hello"
end main

$ fglcomp xx.4gl

$ ls -s xx.42m
   4 xx.42m


Creating Libraries

Compiled .42m modules can be grouped in a library file using the .42x extension.

Program linking is done with the fglrun tool by using the -l option. You can also use the fgllink tool.

The following lines show a link procedure to create a library in a Unix shell session:

$ fglcomp fileutils.4gl
$ fglcomp userutils.4gl
$ fgllink -o libutils.42x fileutils.42m userutils.42m

When you create a library, all functions of the .42m modules used in the link command are registered in the .42x file.

Warning: The .42x library file does not contain the .42m files. When deploying your application, you must provide all p-code modules as well as .42f, .42r and .42x files.


Linking Programs

Genero programs are created by linking several .42m modules and/or .42x libraries together, to produce a file with the .42r extension.

Program linking is done with the fglrun tool by using the -l option. You can also use the fgllink tool.

Warning: The .42r program file does not contain the .42m files. When deploying your application, you must provide all p-code modules as well as .42f, .42r and .42x files.

The following lines show a link procedure to create a library in a Unix shell session:

$ fglcomp xx.4gl
$ fglcomp yy.4gl
$ fgllink -o xx.42r xx.42m yy.42m

By default, if you do not specify an absolute path for a file, the linker searches for .42m modules and .42x libraries in the current directory.

Additionally, you can specify a search path with the FGLLDPATH environment variable:

$ FGLLDPATH=/usr/dev/lib/maths:/usr/dev/lib/utils
$ export FGLLDPATH
$ ls /usr/dev/lib/maths
mathlib1.42x
mathlib2.42x
mathmodule11.42m
mathmodule12.42m
mathmodule22.42m
$ ls /usr/dev/lib/utils
fileutils.42m
userutils.42m
dbutils.42m
$ fgllink -o myprog.42r mymodule.42m mathlib1.42x fileutils.42m

Here the linker will find the specified files in the /usr/dev/lib/maths and /usr/dev/lib/utils directories defined in FGLLDPATH.

Warning: When linking a program, if none of the functions of a module are used by the program, the complete module is excluded from the link. This may cause undefined function errors at runtime, such as when a function is only used in a dynamic call (an initialization function, for example.) 

The following case illustrates this behavior:

$ cat x1.4gl
function fx1A()
end function
function fx2A()
end function

$ cat x2.4gl
function fx2A()
end function
function fx2B()
end function

$ cat prog.4gl
main
  call fx1A()
end main

$ fglcomp x1.4gl
$ fglcomp x2.4gl
$ fglcomp prog.4gl

$ fgllink -o lib.42x x1.42m x2.42m

$ fgllink -o prog.42r prog.42m lib.42x

Here, module x1.42m will be included, but module x2.42m will not be included in the program. At runtime, any dynamic call to fx2A() or fx2B() will fail.

The link process searches recursively for the functions used by the program. For example, if the MAIN block calls function FA in module MA, and FA calls FB in module MB, all functions from module MA and MB will be included in the .42r program definition.


Using Makefiles

Most UNIX platforms provide the make utility program to compile projects. The make program is an interpreter of Makefiles. These files contain directives to compile and link programs and/or generate other kind of files.

When developing on Microsoft Windows platforms, you may use the NMAKE utility provided with Visual C++, however this tool does not have the same behavior as the Unix make program. To have a compatible make on Windows, you can install a GNU make or third party Unix tools such as Cygwin.

For more details about the make utility, see the platform-specific documentation.

The follow example shows a typical Makefile for Genero applications:

#------------------------------------------------------
# Generic makefile rules to be included in Makefiles

.SUFFIXES: .42s .42f .42m .42r .str .per .4gl .msg .hlp

FGLFORM=fglform -M
FGLCOMP=fglcomp -M
FGLLINK=fglrun -l
FGLMKMSG=fglmkmsg
FGLMKSTR=fglmkstr
FGLLIB=$$FGLDIR/lib/libfgl4js.42x

all::

.msg.hlp:
	$(FGLMKMSG) $*.msg $*.hlp

.str.42s:
	$(FGLMKSTR) $*.str $*.42s

.per.42f:
	$(FGLFORM) $*.per

.4gl.42m:
	$(FGLCOMP) $*.4gl

clean::
	rm -f *.hlp *.42? *.out


#-----------------------------
# Makefile example

include Makeincl

FORMS=\
 customers.42f\
 orderlist.42f\
 itemlist.42f

MODULES=\
 customerInput.42m\
 zoomOrders.42m\
 zoomItems.42m

customer.42x: $(MODULES)
	$(FGLLINK) -o customer.42x $(MODULES)
all:: customer.42x $(FORMS)