@echo Nothing to be done.
install::
- install ecpglib.h $(HEADERDIR)
- install ecpgtype.h $(HEADERDIR)
- install sqlca.h $(HEADERDIR)
+ install ecpglib.h $(DESTDIR)$(HEADERDIR)
+ install ecpgtype.h $(DESTDIR)$(HEADERDIR)
+ install sqlca.h $(DESTDIR)$(HEADERDIR)
uninstall::
- rm -f $(HEADERDIR)/ecpglib.h
- rm -f $(HEADERDIR)/ecpgtype.h
- rm -f $(HEADERDIR)/sqlca.h
+ rm -f $(DESTDIR)$(HEADERDIR)/ecpglib.h
+ rm -f $(DESTDIR)$(HEADERDIR)/ecpgtype.h
+ rm -f $(DESTDIR)$(HEADERDIR)/sqlca.h
PQ_INCLUDE=-I$(SRCDIR)/include -I$(SRCDIR)/interfaces/libpq
-all: lib
+SO_MAJOR_VERSION=0
+SO_MINOR_VERSION=5
-lib: libecpg.a
+PORTNAME=@PORTNAME@
+
+# Shared library stuff
+shlib :=
+install-shlib-dep :=
+ifeq ($(PORTNAME), linux)
+ ifdef LINUX_ELF
+ install-shlib-dep := install-shlib
+ shlib := libecpg.so.$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION)
+ LDFLAGS_SL = -shared
+ CFLAGS += $(CFLAGS_SL)
+ endif
+endif
+ifeq ($(PORTNAME), bsd)
+ install-shlib-dep := install-shlib
+ shlib := libecpg.so.$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION)
+ LDFLAGS_SL = -x -Bshareable -Bforcearchive
+ CFLAGS += $(CFLAGS_SL)
+endif
+ifeq ($(PORTNAME), i386_solaris)
+ install-shlib-dep := install-shlib
+ shlib := libecpg.so.$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION)
+ LDFLAGS_SL = -G -z text
+ CFLAGS += $(CFLAGS_SL)
+endif
+ifeq ($(PORTNAME), univel)
+ install-shlib-dep := install-shlib
+ shlib := libecpg.so.1
+ LDFLAGS_SL = -G -z text
+ CFLAGS += $(CFLAGS_SL)
+endif
+
+all: libecpg.a $(shlib)
+
+$(shlib): ecpglib.o typename.o
+ $(LD) $(LDFLAGS_SL) -o $@ ecpglib.o typename.o
+ ln -sf $@ libecpg.so
clean:
- rm -f *.o *.a core a.out *~
+ rm -f *.o *.a core a.out *~ $(shlib) libecpg.so
install: libecpg.a
- install -m 644 libecpg.a $(LIBDIR)
+ install -m 644 libecpg.a $(DESTDIR)$(LIBDIR)
+ install -m 644 $(shlib) $(DESTDIR)$(LIBDIR)
+ ln -sf $(shlib) $(DESTDIR)$(LIBDIR)/libecpg.so
uninstall::
- rm -f $(LIBDIR)/libecpg.a
+ rm -f $(DESTDIR)$(LIBDIR)/libecpg.a $(DESTDIR)$(LIBDIR)/$(shlib)
# Rules that do something
libecpg.a : libecpg.a(ecpglib.o) libecpg.a(typename.o)
SRCDIR= ../../..
include $(SRCDIR)/Makefile.global
+MAJOR_VERSION=0
+MINOR_VERSION=5
+PATCHLEVEL=1
+
CC=@CC@
LEX=@LEX@
LEXLIB=@LEXLIB@
YACC=@YACC@
YFLAGS=@YFLAGS@
-CFLAGS=-I../include -O2 -g -Wall
+CFLAGS=-I../include -O2 -g -Wall -DMAJOR_VERSION=$(MAJOR_VERSION) -DMINOR_VERSION=$(MINOR_VERSION) -DPATCHLEVEL=$(PATCHLEVEL)
all:: ecpg
rm -f *.o core a.out ecpg preproc.tab.h y.tab.c *~
install: all
- install -c -m 755 ecpg $(BINDIR)
+ install -c -m 755 ecpg $(DESTDIR)$(BINDIR)
uninstall:
- rm -f $(BINDIR)/ecpg
+ rm -f $(DESTDIR)$(BINDIR)/ecpg
# Rule that really do something.
-ecpg: y.tab.o pgc.o type.o ecpg.o
- $(CC) -g -O2 -Wall -o ecpg y.tab.o pgc.o type.o ecpg.o -L../lib -lecpg $(LEXLIB)
+ecpg: y.tab.o pgc.o type.o ecpg.o ../lib/typename.o
+ $(CC) -g -O2 -Wall -o ecpg y.tab.o pgc.o type.o ecpg.o ../lib/typename.o $(LEXLIB)
y.tab.h y.tab.c: preproc.y
$(YACC) $(YFLAGS) $<
#include <stdlib.h>
#include <strings.h>
-extern void lex_init(void);
-extern FILE *yyin, *yyout;
-extern char * input_filename;
-extern int yyparse(void);
+#include "extern.h"
static void
usage(char *progname)
{
- fprintf(stderr, "Usage: %s: [ -o outout file name] file1 [file2] ...\n", progname);
+ fprintf(stderr, "ecpg - the postgresql preprocessor, version: %d.%d.%d\n", MAJOR_VERSION, MINOR_VERSION, PATCHLEVEL);
+ fprintf(stderr, "Usage: %s: [-v] [-d] [ -o outout file name] file1 [file2] ...\n", progname);
}
int
main(int argc, char *const argv[])
{
- char c,
- out_option = 0;
+ char c, out_option = 0;
int fnr;
- while ((c = getopt(argc, argv, "o:")) != EOF)
+ while ((c = getopt(argc, argv, "vdo:")) != EOF)
{
switch (c)
{
else
out_option = 1;
break;
+ case 'd':
+ debugging = 1;
+ break;
+ case 'v':
default:
usage(argv[0]);
}
}
- /* after the options there must not be anything but filenames */
- for (fnr = optind; fnr < argc; fnr++)
+ if (optind >= argc) /* no files specified */
+ usage(argv[0]);
+ else
{
- char *filename,
- *ptr2ext;
-
- filename = malloc(strlen(argv[fnr]) + 2);
- if (filename == NULL)
+ /* after the options there must not be anything but filenames */
+ for (fnr = optind; fnr < argc; fnr++)
{
- perror("malloc");
- continue;
- }
+ char *filename, *ptr2ext;
- strcpy(filename, argv[fnr]);
+ filename = malloc(strlen(argv[fnr]) + 2);
+ if (filename == NULL)
+ {
+ perror("malloc");
+ continue;
+ }
- ptr2ext = strrchr(filename, '.');
- /* no extension or extension not equal .pgc */
- if (ptr2ext == NULL || strcmp(ptr2ext, ".pgc") != 0)
- {
- ptr2ext = filename + strlen(filename);
- ptr2ext[0] = '.';
- }
+ strcpy(filename, argv[fnr]);
- /* make extension = .c */
- ptr2ext[1] = 'c';
- ptr2ext[2] = '\0';
+ ptr2ext = strrchr(filename, '.');
+ /* no extension or extension not equal .pgc */
+ if (ptr2ext == NULL || strcmp(ptr2ext, ".pgc") != 0)
+ {
+ ptr2ext = filename + strlen(filename);
+ ptr2ext[0] = '.';
+ }
- if (out_option == 0) /* calculate the output name */
- {
- yyout = fopen(filename, "w");
- if (yyout == NULL)
+ /* make extension = .c */
+ ptr2ext[1] = 'c';
+ ptr2ext[2] = '\0';
+
+ if (out_option == 0) /* calculate the output name */
{
- perror(filename);
- free(filename);
- continue;
+ yyout = fopen(filename, "w");
+ if (yyout == NULL)
+ {
+ perror(filename);
+ free(filename);
+ continue;
+ }
}
- }
- yyin = fopen(input_filename = argv[fnr], "r");
- if (yyin == NULL)
- {
- perror(argv[fnr]);
- }
- else
- {
- /* initialize lex */
- lex_init();
+ yyin = fopen(input_filename = argv[fnr], "r");
+ if (yyin == NULL)
+ perror(argv[fnr]);
+ else
+ {
+ /* initialize lex */
+ lex_init();
- /* we need two includes everytime */
- fprintf(yyout, "/* These two include files are added by the preprocessor */\n#include <ecpgtype.h>\n#include <ecpglib.h>\n");
+ /* we need two includes */
+ fprintf(yyout, "/* Processed by ecpg (%d.%d.%d) */\n/*These two include files are added by the preprocessor */\n#include <ecpgtype.h>\n#include <ecpglib.h>\n", MAJOR_VERSION, MINOR_VERSION, PATCHLEVEL);
- /* and parse the source */
- yyparse();
+ /* and parse the source */
+ yyparse();
- fclose(yyin);
- if (out_option == 0)
- fclose(yyout);
- }
+ fclose(yyin);
+ if (out_option == 0)
+ fclose(yyout);
+ }
- free(filename);
+ free(filename);
+ }
}
return (0);
}
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
+
#include "type.h"
+#include "extern.h"
-void yyerror(char *);
-extern FILE * yyout;
-extern char * yytext;
-extern int yylineno;
-extern int yyleng;
+static void yyerror(char *);
/*
* Variables containing simple states.
{
char * errorstring = (char *) malloc(strlen(name) + 100);
- sprintf(errorstring, "The variabel :%s is not declared.", name);
+ sprintf(errorstring, "The variable :%s is not declared.", name);
yyerror(errorstring);
}
/*
- * Here is the variables that need to be handled on every request.
+ * Here are the variables that need to be handled on every request.
* These are of two kinds: input and output.
* I will make two lists for them.
*/
| S_ANYTHING;
%%
-void yyerror(char * error)
+static void yyerror(char * error)
{
fprintf(stderr, "%s\n", error);
exit(1);
all: test2 perftest
test2: test2.c
- gcc -g -I ../include -I ../../../libpq -o test2 test2.c ../lib/libecpg.a ../../../libpq/libpq.a -lcrypt
+ gcc -g -I ../include -I ../../libpq -o test2 test2.c -L../lib -lecpg -L../../libpq -lpq -lcrypt
test2.c: test2.pgc
- ../preproc/ecpg test2.pgc
+ ecpg test2.pgc
perftest: perftest.c
- gcc -g -I ../include -I ../../../libpq -o perftest perftest.c ../lib/libecpg.a ../../../libpq/libpq.a -lcrypt
+ gcc -g -I ../include -I ../../libpq -o perftest perftest.c -L../lib -lecpg -L../../libpq -lpq -lcrypt
perftest.c: perftest.pgc
- ../preproc/ecpg perftest.pgc
+ ecpg perftest.pgc
clean:
- /bin/rm test2 test2.c perftest perftest.c
+ /bin/rm test2 test2.c perftest perftest.c log
+#include <stdio.h>
+
exec sql include sqlca;
#define SQLCODE sqlca.sqlcode
+extern void ECPGdebug(int n, FILE *dbgs);
+
void
db_error (char *msg)
{
main ()
{
exec sql begin declare section;
- varchar text[8];
- int count;
- double control;
+ varchar name[8];
+ long born;
exec sql end declare section;
+ FILE *dbgs;
+
+ if ((dbgs = fopen("log", "w")) != NULL)
+ ECPGdebug(1, dbgs);
exec sql connect 'mm';
if (SQLCODE)
db_error ("connect");
exec sql declare cur cursor for
- select text, control, count from test;
+ select name, born from meskes;
if (SQLCODE) db_error ("declare");
exec sql open cur;
db_error ("open");
while (1) {
- exec sql fetch in cur into :text, :control, :count;
+ exec sql fetch in cur into :name, :born;
if (SQLCODE)
break;
- printf ("%8.8s %d %f\n", text.arr, count, control);
+ printf ("%8.8s was born %d\n", name.arr, born);
}
if (SQLCODE < 0)
exec sql commit;
if (SQLCODE) db_error ("commit");
+ if (dbgs != NULL)
+ fclose(dbgs);
+
return (0);
}