Table of Contents Previous Next


2 ECPGPlus - Overview : 2.2 Constructing a Makefile

A makefile contains a set of instructions that tell the make utility how to transform a program written in C (that contains embedded SQL) into a C program. To try the examples in this guide, you will need:
the make utility
a makefile that contains instructions for ECPGPlus
The following code is an example of a makefile for the samples included in this guide. To use the sample code, save it in a file named makefile in the directory that contains the source code file.
The first two lines use the pg_config program to locate the necessary header files and library directories:
The pg_config program is shipped with Advanced Server.
make knows that it should use the CFLAGS variable when running the C compiler and LDFLAGS and LDLIBS when invoking the linker. ECPG programs must be linked against the ECPG run-time library (-lecpg) and the libpq library (-lpq)
The sample makefile instructs make how to translate a .pgc or a .pc file into a C program. Two lines in the makefile specify the mode in which the source file will be compiled. The first compile option is:
The first option tells make how to transform a file that ends in .pgc (presumably, an ECPG source file) into a file that ends in .c (a C program), using community ECPG (without the ECPGPlus enhancements). It invokes the ECPG pre-compiler with the -c flag (instructing the compiler to convert SQL code into C), using the value of the INCLUDES variable and the name of the .pgc file.
The second option tells make how to transform a file that ends in .pg (an ECPG source file) into a file that ends in .c (a C program), using the ECPGPlus extensions. It invokes the ECPG pre-compiler with the -c flag (instructing the compiler to convert SQL code into C), as well as the -C PROC flag (instructing the compiler to use ECPGPlus in Pro*C-compatibility mode), using the value of the INCLUDES variable and the name of the .pgc file.
When you run make, pass the name of the ECPG source code file you wish to compile. For example, to compile an ECPG source code file named customer_list.pgc, use the command:
The make utility consults the makefile (located in the current directory), discovers that the makefile contains a rule that will compile customer_list.pgc into a C program (customer_list.c), and then uses the rules built into make to compile customer_list.c into an executable program.

2 ECPGPlus - Overview : 2.2 Constructing a Makefile

Table of Contents Previous Next