From 0efa4581270013263742e5323d2acb03ef870761 Mon Sep 17 00:00:00 2001 From: michael Date: Fri, 18 May 2012 12:19:09 +0000 Subject: [PATCH] * Add PostGres Event notification component from Ludo Brands (22060) git-svn-id: trunk@21324 - --- .gitattributes | 2 + packages/fcl-db/examples/pqeventstest.pp | 114 ++++ packages/fcl-db/fpmake.pp | 10 + packages/fcl-db/src/sqldb/postgres/Makefile | 568 ++++++++---------- .../fcl-db/src/sqldb/postgres/Makefile.fpc | 2 +- packages/fcl-db/src/sqldb/postgres/fpmake.inc | 2 + .../src/sqldb/postgres/pqeventmonitor.pp | 251 ++++++++ 7 files changed, 636 insertions(+), 313 deletions(-) create mode 100644 packages/fcl-db/examples/pqeventstest.pp create mode 100644 packages/fcl-db/src/sqldb/postgres/pqeventmonitor.pp diff --git a/.gitattributes b/.gitattributes index 93e3a805c8..3a7e8b1b93 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1880,6 +1880,7 @@ packages/fcl-db/Makefile.fpc svneol=native#text/plain packages/fcl-db/Makefile.fpc.fpcmake svneol=native#text/plain packages/fcl-db/examples/fbadmindemo.pp svneol=native#text/plain packages/fcl-db/examples/fbeventstest.pp svneol=native#text/plain +packages/fcl-db/examples/pqeventstest.pp svneol=native#text/plain packages/fcl-db/fpmake.pp svneol=native#text/plain packages/fcl-db/src/Dataset.txt svneol=native#text/plain packages/fcl-db/src/README.txt svneol=native#text/plain @@ -2059,6 +2060,7 @@ packages/fcl-db/src/sqldb/postgres/Makefile.fpc svneol=native#text/plain packages/fcl-db/src/sqldb/postgres/fpmake.inc svneol=native#text/plain packages/fcl-db/src/sqldb/postgres/fpmake.pp svneol=native#text/plain packages/fcl-db/src/sqldb/postgres/pqconnection.pp svneol=native#text/plain +packages/fcl-db/src/sqldb/postgres/pqeventmonitor.pp svneol=native#text/plain packages/fcl-db/src/sqldb/sqldb.pp svneol=native#text/plain packages/fcl-db/src/sqldb/sqlite/Makefile svneol=native#text/plain packages/fcl-db/src/sqldb/sqlite/Makefile.fpc svneol=native#text/plain diff --git a/packages/fcl-db/examples/pqeventstest.pp b/packages/fcl-db/examples/pqeventstest.pp new file mode 100644 index 0000000000..da395c22bd --- /dev/null +++ b/packages/fcl-db/examples/pqeventstest.pp @@ -0,0 +1,114 @@ +program PQEventsTest; + +{$mode delphi}{$H+} + +uses + {$IFDEF UNIX} + cthreads, + {$ENDIF} + Classes,sysutils, + PQEventMonitor,pqconnection,sqldb; + +const + MAXEVENTS=35; + NUMTESTS=100; + +type + + { TMyEventAlert } + + TMyEventAlert=class + class procedure OnPQEvent(Sender: TObject; EventName: string; EventCount: longint; + var CancelAlerts: boolean); + end; + +var + EvSent,EvReceived:Array [1..MAXEVENTS] of integer; + TotalRecieved:integer; + +function testNEvents(PQConnection:TPQConnection;n:integer):boolean; +var + EventsM:TPQEventMonitor; + i,j,k:integer; +begin + for i:=1 to MAXEVENTS do + begin + EvSent[i]:=0; + EvReceived[i]:=0; + end; + EventsM:=TPQEventMonitor.create(nil); + EventsM.Connection:=PQConnection; + for i:=1 to n do + EventsM.Events.Add('E'+IntToStr(i)); + EventsM.OnEventAlert:=TMyEventAlert.OnPQEvent; + EventsM.RegisterEvents; + i:=NUMTESTS; + TotalRecieved:=0; + Randomize; + while i>0 do + begin + k:=1+random(n); + PQConnection.ExecuteDirect('NOTIFY E'+IntTostr(k)); + PQConnection.Transaction.Commit; + EvSent[k]:=EvSent[k]+1; + EventsM.Poll; + i:=i-1; + end; + for i:=1 to 300 do //3 secs max + begin + Sleep(10); //wait until everything received + EventsM.Poll; + if TotalRecieved=NUMTESTS then + break; + end; + result:=true; + for i:=1 to n do + begin + result:=result and (EvSent[i]=EvReceived[i]); + end; + EventsM.Free; +end; + +{ TMyEventAlert } + +class procedure TMyEventAlert.OnPQEvent(Sender: TObject; EventName: string; + EventCount: longint; var CancelAlerts: boolean); +var i:integer; +begin + i:=StrToInt(copy(EventName,2,2)); + EvReceived[i]:=EvReceived[i]+EventCount; + TotalRecieved:=TotalRecieved+EventCount; +end; + +var + PQConnection1:TPQConnection; + SQLTransaction1: TSQLTransaction; + i:integer; + +begin + if paramcount<4 then + begin + WriteLn('Usage:'); + WriteLn(' '+Paramstr(0) +' database hostname username password'); + exit; + end; + PQConnection1:=TPQConnection.Create(nil); + SQLTransaction1:= TSQLTransaction.Create(nil); + PQConnection1.Transaction:=SQLTransaction1; + SQLTransaction1.DataBase:=PQConnection1; + PQConnection1.Password:=paramstr(4); + PQConnection1.UserName:=paramstr(3); + PQConnection1.HostName:=paramstr(2); + PQConnection1.DatabaseName:=paramstr(1); + for i:=1 to 16 do + begin + if testNEvents(PQConnection1,i) then + WriteLn(inttostr(i)+' succeeded') + else + WriteLn(inttostr(i)+' failed. Missed '+ IntToStr(NUMTESTS-TotalRecieved)+' Events'); + end; + SQLTransaction1.Free; + PQConnection1.Free; + WriteLn('Tests finished.'); +end. + diff --git a/packages/fcl-db/fpmake.pp b/packages/fcl-db/fpmake.pp index edc1eef0e8..472c1dc739 100644 --- a/packages/fcl-db/fpmake.pp +++ b/packages/fcl-db/fpmake.pp @@ -662,6 +662,16 @@ begin AddUnit('dbconst'); AddUnit('bufdataset'); end; + T:=P.Targets.AddUnit('pqeventmonitor.pp', SqldbConnectionOSes-SqldbWithoutPostgresOSes); + T.ResourceStrings:=true; + with T.Dependencies do + begin + AddUnit('sqldb'); + AddUnit('db'); + AddUnit('dbconst'); + AddUnit('bufdataset'); + AddUnit('pqconnection'); + end; T:=P.Targets.AddUnit('mssqlconn.pp', MSSQLOSes); with T.Dependencies do begin diff --git a/packages/fcl-db/src/sqldb/postgres/Makefile b/packages/fcl-db/src/sqldb/postgres/Makefile index 8d1f1f6486..d74f8a8d9d 100644 --- a/packages/fcl-db/src/sqldb/postgres/Makefile +++ b/packages/fcl-db/src/sqldb/postgres/Makefile @@ -1,10 +1,10 @@ # -# Don't edit, this file is generated by FPCMake Version 2.0.0 [2012/04/25] +# Don't edit, this file is generated by FPCMake Version 2.0.0 [2011/02/24] # default: all -MAKEFILETARGETS=i386-linux i386-go32v2 i386-win32 i386-os2 i386-freebsd i386-beos i386-haiku i386-netbsd i386-solaris i386-qnx i386-netware i386-openbsd i386-wdosx i386-darwin i386-emx i386-watcom i386-netwlibc i386-wince i386-embedded i386-symbian i386-nativent i386-iphonesim m68k-linux m68k-freebsd m68k-netbsd m68k-amiga m68k-atari m68k-openbsd m68k-palmos m68k-embedded powerpc-linux powerpc-netbsd powerpc-amiga powerpc-macos powerpc-darwin powerpc-morphos powerpc-embedded powerpc-wii powerpc-aix sparc-linux sparc-netbsd sparc-solaris sparc-embedded x86_64-linux x86_64-freebsd x86_64-netbsd x86_64-solaris x86_64-openbsd x86_64-darwin x86_64-win64 x86_64-embedded arm-linux arm-palmos arm-darwin arm-wince arm-gba arm-nds arm-embedded arm-symbian powerpc64-linux powerpc64-darwin powerpc64-embedded powerpc64-aix avr-embedded armeb-linux armeb-embedded mips-linux mipsel-linux +MAKEFILETARGETS=i386-linux i386-go32v2 i386-win32 i386-os2 i386-freebsd i386-beos i386-haiku i386-netbsd i386-solaris i386-qnx i386-netware i386-openbsd i386-wdosx i386-darwin i386-emx i386-watcom i386-netwlibc i386-wince i386-embedded i386-symbian i386-nativent i386-iphonesim m68k-linux m68k-freebsd m68k-netbsd m68k-amiga m68k-atari m68k-openbsd m68k-palmos m68k-embedded powerpc-linux powerpc-netbsd powerpc-amiga powerpc-macos powerpc-darwin powerpc-morphos powerpc-embedded sparc-linux sparc-netbsd sparc-solaris sparc-embedded x86_64-linux x86_64-freebsd x86_64-solaris x86_64-darwin x86_64-win64 x86_64-embedded arm-linux arm-palmos arm-darwin arm-wince arm-gba arm-nds arm-embedded arm-symbian powerpc64-linux powerpc64-darwin powerpc64-embedded avr-embedded armeb-linux armeb-embedded mipsel-linux BSDs = freebsd netbsd openbsd darwin -UNIXs = linux $(BSDs) solaris qnx haiku aix +UNIXs = linux $(BSDs) solaris qnx haiku LIMIT83fs = go32v2 os2 emx watcom OSNeedsComspecToRunBatch = go32v2 watcom FORCE: @@ -153,6 +153,12 @@ ifdef OS_TARGET_DEFAULT OS_TARGET=$(OS_TARGET_DEFAULT) endif endif +ifneq ($(words $(FPC_COMPILERINFO)),5) +FPC_COMPILERINFO+=$(shell $(FPC) -iSP) +FPC_COMPILERINFO+=$(shell $(FPC) -iTP) +FPC_COMPILERINFO+=$(shell $(FPC) -iSO) +FPC_COMPILERINFO+=$(shell $(FPC) -iTO) +endif ifndef CPU_SOURCE CPU_SOURCE:=$(word 2,$(FPC_COMPILERINFO)) endif @@ -178,21 +184,11 @@ else ARCH=$(CPU_TARGET) endif endif -ifeq ($(FULL_TARGET),arm-embedded) -ifeq ($(SUBARCH),) -$(error When compiling for arm-embedded, a sub-architecture (e.g. SUBARCH=armv4t or SUBARCH=armv7m) must be defined) -endif -override FPCOPT+=-Cp$(SUBARCH) -endif ifneq ($(findstring $(OS_SOURCE),$(LIMIT83fs)),) TARGETSUFFIX=$(OS_TARGET) SOURCESUFFIX=$(OS_SOURCE) else -ifneq ($(findstring $(OS_TARGET),$(LIMIT83fs)),) -TARGETSUFFIX=$(OS_TARGET) -else TARGETSUFFIX=$(FULL_TARGET) -endif SOURCESUFFIX=$(FULL_SOURCE) endif ifneq ($(FULL_TARGET),$(FULL_SOURCE)) @@ -268,235 +264,193 @@ ifeq ($(UNITSDIR),) UNITSDIR:=$(wildcard $(FPCDIR)/units/$(OS_TARGET)) endif PACKAGESDIR:=$(wildcard $(FPCDIR) $(FPCDIR)/packages $(FPCDIR)/packages/base $(FPCDIR)/packages/extra) -ifndef FPCFPMAKE -ifdef CROSSCOMPILE -ifeq ($(strip $(wildcard $(addsuffix /compiler/ppc$(SRCEXEEXT),$(FPCDIR)))),) -FPCPROG:=$(strip $(wildcard $(addsuffix /fpc$(SRCEXEEXT),$(SEARCHPATH)))) -ifneq ($(FPCPROG),) -FPCPROG:=$(firstword $(FPCPROG)) -FPCFPMAKE:=$(shell $(FPCPROG) -PB) -ifeq ($(strip $(wildcard $(FPCFPMAKE))),) -FPCFPMAKE:=$(firstword $(FPCPROG)) -endif -else -override FPCFPMAKE=$(firstword $(strip $(wildcard $(addsuffix /ppc386$(SRCEXEEXT),$(SEARCHPATH))))) -endif -else -FPCFPMAKE=$(strip $(wildcard $(addsuffix /compiler/ppc$(SRCEXEEXT),$(FPCDIR)))) -FPMAKE_SKIP_CONFIG=-n -export FPCFPMAKE -export FPMAKE_SKIP_CONFIG -endif -else -FPMAKE_SKIP_CONFIG=-n -FPCFPMAKE=$(FPC) -endif -endif override PACKAGE_NAME=fcl-db PACKAGEDIR_MAIN:=$(firstword $(subst /Makefile.fpc,,$(strip $(wildcard $(addsuffix /fcl-db/Makefile.fpc,$(PACKAGESDIR)))))) ifeq ($(FULL_TARGET),i386-linux) -override TARGET_UNITS+=pqconnection +override TARGET_UNITS+=pqconnection pqeventmonitor endif ifeq ($(FULL_TARGET),i386-go32v2) -override TARGET_UNITS+=pqconnection +override TARGET_UNITS+=pqconnection pqeventmonitor endif ifeq ($(FULL_TARGET),i386-win32) -override TARGET_UNITS+=pqconnection +override TARGET_UNITS+=pqconnection pqeventmonitor endif ifeq ($(FULL_TARGET),i386-os2) -override TARGET_UNITS+=pqconnection +override TARGET_UNITS+=pqconnection pqeventmonitor endif ifeq ($(FULL_TARGET),i386-freebsd) -override TARGET_UNITS+=pqconnection +override TARGET_UNITS+=pqconnection pqeventmonitor endif ifeq ($(FULL_TARGET),i386-beos) -override TARGET_UNITS+=pqconnection +override TARGET_UNITS+=pqconnection pqeventmonitor endif ifeq ($(FULL_TARGET),i386-haiku) -override TARGET_UNITS+=pqconnection +override TARGET_UNITS+=pqconnection pqeventmonitor endif ifeq ($(FULL_TARGET),i386-netbsd) -override TARGET_UNITS+=pqconnection +override TARGET_UNITS+=pqconnection pqeventmonitor endif ifeq ($(FULL_TARGET),i386-solaris) -override TARGET_UNITS+=pqconnection +override TARGET_UNITS+=pqconnection pqeventmonitor endif ifeq ($(FULL_TARGET),i386-qnx) -override TARGET_UNITS+=pqconnection +override TARGET_UNITS+=pqconnection pqeventmonitor endif ifeq ($(FULL_TARGET),i386-netware) -override TARGET_UNITS+=pqconnection +override TARGET_UNITS+=pqconnection pqeventmonitor endif ifeq ($(FULL_TARGET),i386-openbsd) -override TARGET_UNITS+=pqconnection +override TARGET_UNITS+=pqconnection pqeventmonitor endif ifeq ($(FULL_TARGET),i386-wdosx) -override TARGET_UNITS+=pqconnection +override TARGET_UNITS+=pqconnection pqeventmonitor endif ifeq ($(FULL_TARGET),i386-darwin) -override TARGET_UNITS+=pqconnection +override TARGET_UNITS+=pqconnection pqeventmonitor endif ifeq ($(FULL_TARGET),i386-emx) -override TARGET_UNITS+=pqconnection +override TARGET_UNITS+=pqconnection pqeventmonitor endif ifeq ($(FULL_TARGET),i386-watcom) -override TARGET_UNITS+=pqconnection +override TARGET_UNITS+=pqconnection pqeventmonitor endif ifeq ($(FULL_TARGET),i386-netwlibc) -override TARGET_UNITS+=pqconnection +override TARGET_UNITS+=pqconnection pqeventmonitor endif ifeq ($(FULL_TARGET),i386-wince) -override TARGET_UNITS+=pqconnection +override TARGET_UNITS+=pqconnection pqeventmonitor endif ifeq ($(FULL_TARGET),i386-embedded) -override TARGET_UNITS+=pqconnection +override TARGET_UNITS+=pqconnection pqeventmonitor endif ifeq ($(FULL_TARGET),i386-symbian) -override TARGET_UNITS+=pqconnection +override TARGET_UNITS+=pqconnection pqeventmonitor endif ifeq ($(FULL_TARGET),i386-nativent) -override TARGET_UNITS+=pqconnection +override TARGET_UNITS+=pqconnection pqeventmonitor endif ifeq ($(FULL_TARGET),i386-iphonesim) -override TARGET_UNITS+=pqconnection +override TARGET_UNITS+=pqconnection pqeventmonitor endif ifeq ($(FULL_TARGET),m68k-linux) -override TARGET_UNITS+=pqconnection +override TARGET_UNITS+=pqconnection pqeventmonitor endif ifeq ($(FULL_TARGET),m68k-freebsd) -override TARGET_UNITS+=pqconnection +override TARGET_UNITS+=pqconnection pqeventmonitor endif ifeq ($(FULL_TARGET),m68k-netbsd) -override TARGET_UNITS+=pqconnection +override TARGET_UNITS+=pqconnection pqeventmonitor endif ifeq ($(FULL_TARGET),m68k-amiga) -override TARGET_UNITS+=pqconnection +override TARGET_UNITS+=pqconnection pqeventmonitor endif ifeq ($(FULL_TARGET),m68k-atari) -override TARGET_UNITS+=pqconnection +override TARGET_UNITS+=pqconnection pqeventmonitor endif ifeq ($(FULL_TARGET),m68k-openbsd) -override TARGET_UNITS+=pqconnection +override TARGET_UNITS+=pqconnection pqeventmonitor endif ifeq ($(FULL_TARGET),m68k-palmos) -override TARGET_UNITS+=pqconnection +override TARGET_UNITS+=pqconnection pqeventmonitor endif ifeq ($(FULL_TARGET),m68k-embedded) -override TARGET_UNITS+=pqconnection +override TARGET_UNITS+=pqconnection pqeventmonitor endif ifeq ($(FULL_TARGET),powerpc-linux) -override TARGET_UNITS+=pqconnection +override TARGET_UNITS+=pqconnection pqeventmonitor endif ifeq ($(FULL_TARGET),powerpc-netbsd) -override TARGET_UNITS+=pqconnection +override TARGET_UNITS+=pqconnection pqeventmonitor endif ifeq ($(FULL_TARGET),powerpc-amiga) -override TARGET_UNITS+=pqconnection +override TARGET_UNITS+=pqconnection pqeventmonitor endif ifeq ($(FULL_TARGET),powerpc-macos) -override TARGET_UNITS+=pqconnection +override TARGET_UNITS+=pqconnection pqeventmonitor endif ifeq ($(FULL_TARGET),powerpc-darwin) -override TARGET_UNITS+=pqconnection +override TARGET_UNITS+=pqconnection pqeventmonitor endif ifeq ($(FULL_TARGET),powerpc-morphos) -override TARGET_UNITS+=pqconnection +override TARGET_UNITS+=pqconnection pqeventmonitor endif ifeq ($(FULL_TARGET),powerpc-embedded) -override TARGET_UNITS+=pqconnection -endif -ifeq ($(FULL_TARGET),powerpc-wii) -override TARGET_UNITS+=pqconnection -endif -ifeq ($(FULL_TARGET),powerpc-aix) -override TARGET_UNITS+=pqconnection +override TARGET_UNITS+=pqconnection pqeventmonitor endif ifeq ($(FULL_TARGET),sparc-linux) -override TARGET_UNITS+=pqconnection +override TARGET_UNITS+=pqconnection pqeventmonitor endif ifeq ($(FULL_TARGET),sparc-netbsd) -override TARGET_UNITS+=pqconnection +override TARGET_UNITS+=pqconnection pqeventmonitor endif ifeq ($(FULL_TARGET),sparc-solaris) -override TARGET_UNITS+=pqconnection +override TARGET_UNITS+=pqconnection pqeventmonitor endif ifeq ($(FULL_TARGET),sparc-embedded) -override TARGET_UNITS+=pqconnection +override TARGET_UNITS+=pqconnection pqeventmonitor endif ifeq ($(FULL_TARGET),x86_64-linux) -override TARGET_UNITS+=pqconnection +override TARGET_UNITS+=pqconnection pqeventmonitor endif ifeq ($(FULL_TARGET),x86_64-freebsd) -override TARGET_UNITS+=pqconnection -endif -ifeq ($(FULL_TARGET),x86_64-netbsd) -override TARGET_UNITS+=pqconnection +override TARGET_UNITS+=pqconnection pqeventmonitor endif ifeq ($(FULL_TARGET),x86_64-solaris) -override TARGET_UNITS+=pqconnection -endif -ifeq ($(FULL_TARGET),x86_64-openbsd) -override TARGET_UNITS+=pqconnection +override TARGET_UNITS+=pqconnection pqeventmonitor endif ifeq ($(FULL_TARGET),x86_64-darwin) -override TARGET_UNITS+=pqconnection +override TARGET_UNITS+=pqconnection pqeventmonitor endif ifeq ($(FULL_TARGET),x86_64-win64) -override TARGET_UNITS+=pqconnection +override TARGET_UNITS+=pqconnection pqeventmonitor endif ifeq ($(FULL_TARGET),x86_64-embedded) -override TARGET_UNITS+=pqconnection +override TARGET_UNITS+=pqconnection pqeventmonitor endif ifeq ($(FULL_TARGET),arm-linux) -override TARGET_UNITS+=pqconnection +override TARGET_UNITS+=pqconnection pqeventmonitor endif ifeq ($(FULL_TARGET),arm-palmos) -override TARGET_UNITS+=pqconnection +override TARGET_UNITS+=pqconnection pqeventmonitor endif ifeq ($(FULL_TARGET),arm-darwin) -override TARGET_UNITS+=pqconnection +override TARGET_UNITS+=pqconnection pqeventmonitor endif ifeq ($(FULL_TARGET),arm-wince) -override TARGET_UNITS+=pqconnection +override TARGET_UNITS+=pqconnection pqeventmonitor endif ifeq ($(FULL_TARGET),arm-gba) -override TARGET_UNITS+=pqconnection +override TARGET_UNITS+=pqconnection pqeventmonitor endif ifeq ($(FULL_TARGET),arm-nds) -override TARGET_UNITS+=pqconnection +override TARGET_UNITS+=pqconnection pqeventmonitor endif ifeq ($(FULL_TARGET),arm-embedded) -override TARGET_UNITS+=pqconnection +override TARGET_UNITS+=pqconnection pqeventmonitor endif ifeq ($(FULL_TARGET),arm-symbian) -override TARGET_UNITS+=pqconnection +override TARGET_UNITS+=pqconnection pqeventmonitor endif ifeq ($(FULL_TARGET),powerpc64-linux) -override TARGET_UNITS+=pqconnection +override TARGET_UNITS+=pqconnection pqeventmonitor endif ifeq ($(FULL_TARGET),powerpc64-darwin) -override TARGET_UNITS+=pqconnection +override TARGET_UNITS+=pqconnection pqeventmonitor endif ifeq ($(FULL_TARGET),powerpc64-embedded) -override TARGET_UNITS+=pqconnection -endif -ifeq ($(FULL_TARGET),powerpc64-aix) -override TARGET_UNITS+=pqconnection +override TARGET_UNITS+=pqconnection pqeventmonitor endif ifeq ($(FULL_TARGET),avr-embedded) -override TARGET_UNITS+=pqconnection +override TARGET_UNITS+=pqconnection pqeventmonitor endif ifeq ($(FULL_TARGET),armeb-linux) -override TARGET_UNITS+=pqconnection +override TARGET_UNITS+=pqconnection pqeventmonitor endif ifeq ($(FULL_TARGET),armeb-embedded) -override TARGET_UNITS+=pqconnection -endif -ifeq ($(FULL_TARGET),mips-linux) -override TARGET_UNITS+=pqconnection +override TARGET_UNITS+=pqconnection pqeventmonitor endif ifeq ($(FULL_TARGET),mipsel-linux) -override TARGET_UNITS+=pqconnection +override TARGET_UNITS+=pqconnection pqeventmonitor endif ifeq ($(FULL_TARGET),i386-linux) override TARGET_RSTS+=pqconnection @@ -609,12 +563,6 @@ endif ifeq ($(FULL_TARGET),powerpc-embedded) override TARGET_RSTS+=pqconnection endif -ifeq ($(FULL_TARGET),powerpc-wii) -override TARGET_RSTS+=pqconnection -endif -ifeq ($(FULL_TARGET),powerpc-aix) -override TARGET_RSTS+=pqconnection -endif ifeq ($(FULL_TARGET),sparc-linux) override TARGET_RSTS+=pqconnection endif @@ -633,15 +581,9 @@ endif ifeq ($(FULL_TARGET),x86_64-freebsd) override TARGET_RSTS+=pqconnection endif -ifeq ($(FULL_TARGET),x86_64-netbsd) -override TARGET_RSTS+=pqconnection -endif ifeq ($(FULL_TARGET),x86_64-solaris) override TARGET_RSTS+=pqconnection endif -ifeq ($(FULL_TARGET),x86_64-openbsd) -override TARGET_RSTS+=pqconnection -endif ifeq ($(FULL_TARGET),x86_64-darwin) override TARGET_RSTS+=pqconnection endif @@ -684,9 +626,6 @@ endif ifeq ($(FULL_TARGET),powerpc64-embedded) override TARGET_RSTS+=pqconnection endif -ifeq ($(FULL_TARGET),powerpc64-aix) -override TARGET_RSTS+=pqconnection -endif ifeq ($(FULL_TARGET),avr-embedded) override TARGET_RSTS+=pqconnection endif @@ -696,9 +635,6 @@ endif ifeq ($(FULL_TARGET),armeb-embedded) override TARGET_RSTS+=pqconnection endif -ifeq ($(FULL_TARGET),mips-linux) -override TARGET_RSTS+=pqconnection -endif ifeq ($(FULL_TARGET),mipsel-linux) override TARGET_RSTS+=pqconnection endif @@ -814,12 +750,6 @@ endif ifeq ($(FULL_TARGET),powerpc-embedded) override COMPILER_OPTIONS+=-S2 endif -ifeq ($(FULL_TARGET),powerpc-wii) -override COMPILER_OPTIONS+=-S2 -endif -ifeq ($(FULL_TARGET),powerpc-aix) -override COMPILER_OPTIONS+=-S2 -endif ifeq ($(FULL_TARGET),sparc-linux) override COMPILER_OPTIONS+=-S2 endif @@ -838,15 +768,9 @@ endif ifeq ($(FULL_TARGET),x86_64-freebsd) override COMPILER_OPTIONS+=-S2 endif -ifeq ($(FULL_TARGET),x86_64-netbsd) -override COMPILER_OPTIONS+=-S2 -endif ifeq ($(FULL_TARGET),x86_64-solaris) override COMPILER_OPTIONS+=-S2 endif -ifeq ($(FULL_TARGET),x86_64-openbsd) -override COMPILER_OPTIONS+=-S2 -endif ifeq ($(FULL_TARGET),x86_64-darwin) override COMPILER_OPTIONS+=-S2 endif @@ -889,9 +813,6 @@ endif ifeq ($(FULL_TARGET),powerpc64-embedded) override COMPILER_OPTIONS+=-S2 endif -ifeq ($(FULL_TARGET),powerpc64-aix) -override COMPILER_OPTIONS+=-S2 -endif ifeq ($(FULL_TARGET),avr-embedded) override COMPILER_OPTIONS+=-S2 endif @@ -901,9 +822,6 @@ endif ifeq ($(FULL_TARGET),armeb-embedded) override COMPILER_OPTIONS+=-S2 endif -ifeq ($(FULL_TARGET),mips-linux) -override COMPILER_OPTIONS+=-S2 -endif ifeq ($(FULL_TARGET),mipsel-linux) override COMPILER_OPTIONS+=-S2 endif @@ -1117,7 +1035,7 @@ SHAREDLIBPREFIX=libfp STATICLIBPREFIX=libp IMPORTLIBPREFIX=libimp RSTEXT=.rst -EXEDBGEXT=.dbg +ifeq ($(findstring 1.0.,$(FPC_VERSION)),) ifeq ($(OS_TARGET),go32v1) STATICLIBPREFIX= SHORTSUFFIX=v1 @@ -1239,7 +1157,6 @@ BATCHEXT=.sh EXEEXT= HASSHAREDLIB=1 SHORTSUFFIX=dwn -EXEDBGEXT=.dSYM endif ifeq ($(OS_TARGET),gba) EXEEXT=.gba @@ -1254,15 +1171,160 @@ ifeq ($(OS_TARGET),NativeNT) SHAREDLIBEXT=.dll SHORTSUFFIX=nativent endif -ifeq ($(OS_TARGET),wii) -EXEEXT=.dol -SHAREDLIBEXT=.so -SHORTSUFFIX=wii +else +ifeq ($(OS_TARGET),go32v1) +PPUEXT=.pp1 +OEXT=.o1 +ASMEXT=.s1 +SMARTEXT=.sl1 +STATICLIBEXT=.a1 +SHAREDLIBEXT=.so1 +STATICLIBPREFIX= +SHORTSUFFIX=v1 +IMPORTLIBPREFIX= endif -ifeq ($(OS_TARGET),aix) +ifeq ($(OS_TARGET),go32v2) +STATICLIBPREFIX= +SHORTSUFFIX=dos +IMPORTLIBPREFIX= +endif +ifeq ($(OS_TARGET),watcom) +STATICLIBPREFIX= +SHORTSUFFIX=wat +IMPORTLIBPREFIX= +endif +ifeq ($(OS_TARGET),linux) BATCHEXT=.sh EXEEXT= -SHORTSUFFIX=aix +HASSHAREDLIB=1 +SHORTSUFFIX=lnx +endif +ifeq ($(OS_TARGET),freebsd) +BATCHEXT=.sh +EXEEXT= +HASSHAREDLIB=1 +SHORTSUFFIX=fbs +endif +ifeq ($(OS_TARGET),netbsd) +BATCHEXT=.sh +EXEEXT= +HASSHAREDLIB=1 +SHORTSUFFIX=nbs +endif +ifeq ($(OS_TARGET),openbsd) +BATCHEXT=.sh +EXEEXT= +HASSHAREDLIB=1 +SHORTSUFFIX=obs +endif +ifeq ($(OS_TARGET),win32) +PPUEXT=.ppw +OEXT=.ow +ASMEXT=.sw +SMARTEXT=.slw +STATICLIBEXT=.aw +SHAREDLIBEXT=.dll +SHORTSUFFIX=w32 +endif +ifeq ($(OS_TARGET),os2) +BATCHEXT=.cmd +PPUEXT=.ppo +ASMEXT=.so2 +OEXT=.oo2 +AOUTEXT=.out +SMARTEXT=.sl2 +STATICLIBPREFIX= +STATICLIBEXT=.ao2 +SHAREDLIBEXT=.dll +SHORTSUFFIX=os2 +ECHO=echo +IMPORTLIBPREFIX= +endif +ifeq ($(OS_TARGET),amiga) +EXEEXT= +PPUEXT=.ppu +ASMEXT=.s +OEXT=.o +SMARTEXT=.sl +STATICLIBEXT=.a +SHAREDLIBEXT=.library +SHORTSUFFIX=amg +endif +ifeq ($(OS_TARGET),atari) +PPUEXT=.ppu +ASMEXT=.s +OEXT=.o +SMARTEXT=.sl +STATICLIBEXT=.a +EXEEXT=.ttp +SHORTSUFFIX=ata +endif +ifeq ($(OS_TARGET),beos) +BATCHEXT=.sh +PPUEXT=.ppu +ASMEXT=.s +OEXT=.o +SMARTEXT=.sl +STATICLIBEXT=.a +EXEEXT= +SHORTSUFFIX=be +endif +ifeq ($(OS_TARGET),solaris) +BATCHEXT=.sh +PPUEXT=.ppu +ASMEXT=.s +OEXT=.o +SMARTEXT=.sl +STATICLIBEXT=.a +EXEEXT= +SHORTSUFFIX=sun +endif +ifeq ($(OS_TARGET),qnx) +BATCHEXT=.sh +PPUEXT=.ppu +ASMEXT=.s +OEXT=.o +SMARTEXT=.sl +STATICLIBEXT=.a +EXEEXT= +SHORTSUFFIX=qnx +endif +ifeq ($(OS_TARGET),netware) +STATICLIBPREFIX= +PPUEXT=.ppu +OEXT=.o +ASMEXT=.s +SMARTEXT=.sl +STATICLIBEXT=.a +SHAREDLIBEXT=.nlm +EXEEXT=.nlm +SHORTSUFFIX=nw +IMPORTLIBPREFIX=imp +endif +ifeq ($(OS_TARGET),netwlibc) +STATICLIBPREFIX= +PPUEXT=.ppu +OEXT=.o +ASMEXT=.s +SMARTEXT=.sl +STATICLIBEXT=.a +SHAREDLIBEXT=.nlm +EXEEXT=.nlm +SHORTSUFFIX=nwl +IMPORTLIBPREFIX=imp +endif +ifeq ($(OS_TARGET),macos) +BATCHEXT= +PPUEXT=.ppu +ASMEXT=.s +OEXT=.o +SMARTEXT=.sl +STATICLIBEXT=.a +EXEEXT= +DEBUGSYMEXT=.xcoff +SHORTSUFFIX=mac +IMPORTLIBPREFIX=imp +endif endif ifneq ($(findstring $(OS_SOURCE),$(LIMIT83fs)),) FPCMADE=fpcmade.$(SHORTSUFFIX) @@ -1453,6 +1515,15 @@ ASNAME=$(BINUTILSPREFIX)as LDNAME=$(BINUTILSPREFIX)ld ARNAME=$(BINUTILSPREFIX)ar RCNAME=$(BINUTILSPREFIX)rc +ifneq ($(findstring 1.0.,$(FPC_VERSION)),) +ifeq ($(OS_TARGET),win32) +ifeq ($(CROSSBINDIR),) +ASNAME=asw +LDNAME=ldw +ARNAME=arw +endif +endif +endif ifndef ASPROG ifdef CROSSBINDIR ASPROG=$(CROSSBINDIR)/$(ASNAME)$(SRCEXEEXT) @@ -1496,6 +1567,25 @@ DATESTR:=$(shell $(DATE) +%Y%m%d) else DATESTR= endif +ifndef UPXPROG +ifeq ($(OS_TARGET),go32v2) +UPXPROG:=1 +endif +ifeq ($(OS_TARGET),win32) +UPXPROG:=1 +endif +ifdef UPXPROG +UPXPROG:=$(strip $(wildcard $(addsuffix /upx$(SRCEXEEXT),$(SEARCHPATH)))) +ifeq ($(UPXPROG),) +UPXPROG= +else +UPXPROG:=$(firstword $(UPXPROG)) +endif +else +UPXPROG= +endif +endif +export UPXPROG ZIPOPT=-9 ZIPEXT=.zip ifeq ($(USETAR),bz2) @@ -1839,24 +1929,6 @@ REQUIRE_PACKAGES_FPMKUNIT=1 REQUIRE_PACKAGES_FCL-XML=1 REQUIRE_PACKAGES_POSTGRES=1 endif -ifeq ($(FULL_TARGET),powerpc-wii) -REQUIRE_PACKAGES_RTL=1 -REQUIRE_PACKAGES_PASZLIB=1 -REQUIRE_PACKAGES_FCL-PROCESS=1 -REQUIRE_PACKAGES_HASH=1 -REQUIRE_PACKAGES_FPMKUNIT=1 -REQUIRE_PACKAGES_FCL-XML=1 -REQUIRE_PACKAGES_POSTGRES=1 -endif -ifeq ($(FULL_TARGET),powerpc-aix) -REQUIRE_PACKAGES_RTL=1 -REQUIRE_PACKAGES_PASZLIB=1 -REQUIRE_PACKAGES_FCL-PROCESS=1 -REQUIRE_PACKAGES_HASH=1 -REQUIRE_PACKAGES_FPMKUNIT=1 -REQUIRE_PACKAGES_FCL-XML=1 -REQUIRE_PACKAGES_POSTGRES=1 -endif ifeq ($(FULL_TARGET),sparc-linux) REQUIRE_PACKAGES_RTL=1 REQUIRE_PACKAGES_PASZLIB=1 @@ -1911,15 +1983,6 @@ REQUIRE_PACKAGES_FPMKUNIT=1 REQUIRE_PACKAGES_FCL-XML=1 REQUIRE_PACKAGES_POSTGRES=1 endif -ifeq ($(FULL_TARGET),x86_64-netbsd) -REQUIRE_PACKAGES_RTL=1 -REQUIRE_PACKAGES_PASZLIB=1 -REQUIRE_PACKAGES_FCL-PROCESS=1 -REQUIRE_PACKAGES_HASH=1 -REQUIRE_PACKAGES_FPMKUNIT=1 -REQUIRE_PACKAGES_FCL-XML=1 -REQUIRE_PACKAGES_POSTGRES=1 -endif ifeq ($(FULL_TARGET),x86_64-solaris) REQUIRE_PACKAGES_RTL=1 REQUIRE_PACKAGES_PASZLIB=1 @@ -1929,15 +1992,6 @@ REQUIRE_PACKAGES_FPMKUNIT=1 REQUIRE_PACKAGES_FCL-XML=1 REQUIRE_PACKAGES_POSTGRES=1 endif -ifeq ($(FULL_TARGET),x86_64-openbsd) -REQUIRE_PACKAGES_RTL=1 -REQUIRE_PACKAGES_PASZLIB=1 -REQUIRE_PACKAGES_FCL-PROCESS=1 -REQUIRE_PACKAGES_HASH=1 -REQUIRE_PACKAGES_FPMKUNIT=1 -REQUIRE_PACKAGES_FCL-XML=1 -REQUIRE_PACKAGES_POSTGRES=1 -endif ifeq ($(FULL_TARGET),x86_64-darwin) REQUIRE_PACKAGES_RTL=1 REQUIRE_PACKAGES_PASZLIB=1 @@ -2064,15 +2118,6 @@ REQUIRE_PACKAGES_FPMKUNIT=1 REQUIRE_PACKAGES_FCL-XML=1 REQUIRE_PACKAGES_POSTGRES=1 endif -ifeq ($(FULL_TARGET),powerpc64-aix) -REQUIRE_PACKAGES_RTL=1 -REQUIRE_PACKAGES_PASZLIB=1 -REQUIRE_PACKAGES_FCL-PROCESS=1 -REQUIRE_PACKAGES_HASH=1 -REQUIRE_PACKAGES_FPMKUNIT=1 -REQUIRE_PACKAGES_FCL-XML=1 -REQUIRE_PACKAGES_POSTGRES=1 -endif ifeq ($(FULL_TARGET),avr-embedded) REQUIRE_PACKAGES_RTL=1 REQUIRE_PACKAGES_PASZLIB=1 @@ -2100,15 +2145,6 @@ REQUIRE_PACKAGES_FPMKUNIT=1 REQUIRE_PACKAGES_FCL-XML=1 REQUIRE_PACKAGES_POSTGRES=1 endif -ifeq ($(FULL_TARGET),mips-linux) -REQUIRE_PACKAGES_RTL=1 -REQUIRE_PACKAGES_PASZLIB=1 -REQUIRE_PACKAGES_FCL-PROCESS=1 -REQUIRE_PACKAGES_HASH=1 -REQUIRE_PACKAGES_FPMKUNIT=1 -REQUIRE_PACKAGES_FCL-XML=1 -REQUIRE_PACKAGES_POSTGRES=1 -endif ifeq ($(FULL_TARGET),mipsel-linux) REQUIRE_PACKAGES_RTL=1 REQUIRE_PACKAGES_PASZLIB=1 @@ -2126,15 +2162,6 @@ UNITDIR_RTL=$(PACKAGEDIR_RTL)/units/$(TARGETSUFFIX) else UNITDIR_RTL=$(PACKAGEDIR_RTL) endif -ifneq ($(wildcard $(PACKAGEDIR_RTL)/units/$(SOURCESUFFIX)),) -UNITDIR_FPMAKE_RTL=$(PACKAGEDIR_RTL)/units/$(SOURCESUFFIX) -else -ifneq ($(wildcard $(PACKAGEDIR_RTL)/units_bs/$(SOURCESUFFIX)),) -UNITDIR_FPMAKE_RTL=$(PACKAGEDIR_RTL)/units_bs/$(SOURCESUFFIX) -else -UNITDIR_FPMAKE_RTL=$(PACKAGEDIR_RTL) -endif -endif ifdef CHECKDEPEND $(PACKAGEDIR_RTL)/$(OS_TARGET)/$(FPCMADE): $(MAKE) -C $(PACKAGEDIR_RTL)/$(OS_TARGET) $(FPCMADE) @@ -2152,9 +2179,6 @@ endif ifdef UNITDIR_RTL override COMPILER_UNITDIR+=$(UNITDIR_RTL) endif -ifdef UNITDIR_FPMAKE_RTL -override COMPILER_FPMAKE_UNITDIR+=$(UNITDIR_FPMAKE_RTL) -endif endif ifdef REQUIRE_PACKAGES_PASZLIB PACKAGEDIR_PASZLIB:=$(firstword $(subst /Makefile.fpc,,$(strip $(wildcard $(addsuffix /paszlib/Makefile.fpc,$(PACKAGESDIR)))))) @@ -2164,15 +2188,6 @@ UNITDIR_PASZLIB=$(PACKAGEDIR_PASZLIB)/units/$(TARGETSUFFIX) else UNITDIR_PASZLIB=$(PACKAGEDIR_PASZLIB) endif -ifneq ($(wildcard $(PACKAGEDIR_PASZLIB)/units/$(SOURCESUFFIX)),) -UNITDIR_FPMAKE_PASZLIB=$(PACKAGEDIR_PASZLIB)/units/$(SOURCESUFFIX) -else -ifneq ($(wildcard $(PACKAGEDIR_PASZLIB)/units_bs/$(SOURCESUFFIX)),) -UNITDIR_FPMAKE_PASZLIB=$(PACKAGEDIR_PASZLIB)/units_bs/$(SOURCESUFFIX) -else -UNITDIR_FPMAKE_PASZLIB=$(PACKAGEDIR_PASZLIB) -endif -endif ifdef CHECKDEPEND $(PACKAGEDIR_PASZLIB)/$(FPCMADE): $(MAKE) -C $(PACKAGEDIR_PASZLIB) $(FPCMADE) @@ -2190,9 +2205,6 @@ endif ifdef UNITDIR_PASZLIB override COMPILER_UNITDIR+=$(UNITDIR_PASZLIB) endif -ifdef UNITDIR_FPMAKE_PASZLIB -override COMPILER_FPMAKE_UNITDIR+=$(UNITDIR_FPMAKE_PASZLIB) -endif endif ifdef REQUIRE_PACKAGES_FCL-PROCESS PACKAGEDIR_FCL-PROCESS:=$(firstword $(subst /Makefile.fpc,,$(strip $(wildcard $(addsuffix /fcl-process/Makefile.fpc,$(PACKAGESDIR)))))) @@ -2202,15 +2214,6 @@ UNITDIR_FCL-PROCESS=$(PACKAGEDIR_FCL-PROCESS)/units/$(TARGETSUFFIX) else UNITDIR_FCL-PROCESS=$(PACKAGEDIR_FCL-PROCESS) endif -ifneq ($(wildcard $(PACKAGEDIR_FCL-PROCESS)/units/$(SOURCESUFFIX)),) -UNITDIR_FPMAKE_FCL-PROCESS=$(PACKAGEDIR_FCL-PROCESS)/units/$(SOURCESUFFIX) -else -ifneq ($(wildcard $(PACKAGEDIR_FCL-PROCESS)/units_bs/$(SOURCESUFFIX)),) -UNITDIR_FPMAKE_FCL-PROCESS=$(PACKAGEDIR_FCL-PROCESS)/units_bs/$(SOURCESUFFIX) -else -UNITDIR_FPMAKE_FCL-PROCESS=$(PACKAGEDIR_FCL-PROCESS) -endif -endif ifdef CHECKDEPEND $(PACKAGEDIR_FCL-PROCESS)/$(FPCMADE): $(MAKE) -C $(PACKAGEDIR_FCL-PROCESS) $(FPCMADE) @@ -2228,9 +2231,6 @@ endif ifdef UNITDIR_FCL-PROCESS override COMPILER_UNITDIR+=$(UNITDIR_FCL-PROCESS) endif -ifdef UNITDIR_FPMAKE_FCL-PROCESS -override COMPILER_FPMAKE_UNITDIR+=$(UNITDIR_FPMAKE_FCL-PROCESS) -endif endif ifdef REQUIRE_PACKAGES_HASH PACKAGEDIR_HASH:=$(firstword $(subst /Makefile.fpc,,$(strip $(wildcard $(addsuffix /hash/Makefile.fpc,$(PACKAGESDIR)))))) @@ -2240,15 +2240,6 @@ UNITDIR_HASH=$(PACKAGEDIR_HASH)/units/$(TARGETSUFFIX) else UNITDIR_HASH=$(PACKAGEDIR_HASH) endif -ifneq ($(wildcard $(PACKAGEDIR_HASH)/units/$(SOURCESUFFIX)),) -UNITDIR_FPMAKE_HASH=$(PACKAGEDIR_HASH)/units/$(SOURCESUFFIX) -else -ifneq ($(wildcard $(PACKAGEDIR_HASH)/units_bs/$(SOURCESUFFIX)),) -UNITDIR_FPMAKE_HASH=$(PACKAGEDIR_HASH)/units_bs/$(SOURCESUFFIX) -else -UNITDIR_FPMAKE_HASH=$(PACKAGEDIR_HASH) -endif -endif ifdef CHECKDEPEND $(PACKAGEDIR_HASH)/$(FPCMADE): $(MAKE) -C $(PACKAGEDIR_HASH) $(FPCMADE) @@ -2266,9 +2257,6 @@ endif ifdef UNITDIR_HASH override COMPILER_UNITDIR+=$(UNITDIR_HASH) endif -ifdef UNITDIR_FPMAKE_HASH -override COMPILER_FPMAKE_UNITDIR+=$(UNITDIR_FPMAKE_HASH) -endif endif ifdef REQUIRE_PACKAGES_FPMKUNIT PACKAGEDIR_FPMKUNIT:=$(firstword $(subst /Makefile.fpc,,$(strip $(wildcard $(addsuffix /fpmkunit/Makefile.fpc,$(PACKAGESDIR)))))) @@ -2278,15 +2266,6 @@ UNITDIR_FPMKUNIT=$(PACKAGEDIR_FPMKUNIT)/units/$(TARGETSUFFIX) else UNITDIR_FPMKUNIT=$(PACKAGEDIR_FPMKUNIT) endif -ifneq ($(wildcard $(PACKAGEDIR_FPMKUNIT)/units/$(SOURCESUFFIX)),) -UNITDIR_FPMAKE_FPMKUNIT=$(PACKAGEDIR_FPMKUNIT)/units/$(SOURCESUFFIX) -else -ifneq ($(wildcard $(PACKAGEDIR_FPMKUNIT)/units_bs/$(SOURCESUFFIX)),) -UNITDIR_FPMAKE_FPMKUNIT=$(PACKAGEDIR_FPMKUNIT)/units_bs/$(SOURCESUFFIX) -else -UNITDIR_FPMAKE_FPMKUNIT=$(PACKAGEDIR_FPMKUNIT) -endif -endif ifdef CHECKDEPEND $(PACKAGEDIR_FPMKUNIT)/$(FPCMADE): $(MAKE) -C $(PACKAGEDIR_FPMKUNIT) $(FPCMADE) @@ -2304,9 +2283,6 @@ endif ifdef UNITDIR_FPMKUNIT override COMPILER_UNITDIR+=$(UNITDIR_FPMKUNIT) endif -ifdef UNITDIR_FPMAKE_FPMKUNIT -override COMPILER_FPMAKE_UNITDIR+=$(UNITDIR_FPMAKE_FPMKUNIT) -endif endif ifdef REQUIRE_PACKAGES_FCL-XML PACKAGEDIR_FCL-XML:=$(firstword $(subst /Makefile.fpc,,$(strip $(wildcard $(addsuffix /fcl-xml/Makefile.fpc,$(PACKAGESDIR)))))) @@ -2316,15 +2292,6 @@ UNITDIR_FCL-XML=$(PACKAGEDIR_FCL-XML)/units/$(TARGETSUFFIX) else UNITDIR_FCL-XML=$(PACKAGEDIR_FCL-XML) endif -ifneq ($(wildcard $(PACKAGEDIR_FCL-XML)/units/$(SOURCESUFFIX)),) -UNITDIR_FPMAKE_FCL-XML=$(PACKAGEDIR_FCL-XML)/units/$(SOURCESUFFIX) -else -ifneq ($(wildcard $(PACKAGEDIR_FCL-XML)/units_bs/$(SOURCESUFFIX)),) -UNITDIR_FPMAKE_FCL-XML=$(PACKAGEDIR_FCL-XML)/units_bs/$(SOURCESUFFIX) -else -UNITDIR_FPMAKE_FCL-XML=$(PACKAGEDIR_FCL-XML) -endif -endif ifdef CHECKDEPEND $(PACKAGEDIR_FCL-XML)/$(FPCMADE): $(MAKE) -C $(PACKAGEDIR_FCL-XML) $(FPCMADE) @@ -2342,9 +2309,6 @@ endif ifdef UNITDIR_FCL-XML override COMPILER_UNITDIR+=$(UNITDIR_FCL-XML) endif -ifdef UNITDIR_FPMAKE_FCL-XML -override COMPILER_FPMAKE_UNITDIR+=$(UNITDIR_FPMAKE_FCL-XML) -endif endif ifdef REQUIRE_PACKAGES_POSTGRES PACKAGEDIR_POSTGRES:=$(firstword $(subst /Makefile.fpc,,$(strip $(wildcard $(addsuffix /postgres/Makefile.fpc,$(PACKAGESDIR)))))) @@ -2354,15 +2318,6 @@ UNITDIR_POSTGRES=$(PACKAGEDIR_POSTGRES)/units/$(TARGETSUFFIX) else UNITDIR_POSTGRES=$(PACKAGEDIR_POSTGRES) endif -ifneq ($(wildcard $(PACKAGEDIR_POSTGRES)/units/$(SOURCESUFFIX)),) -UNITDIR_FPMAKE_POSTGRES=$(PACKAGEDIR_POSTGRES)/units/$(SOURCESUFFIX) -else -ifneq ($(wildcard $(PACKAGEDIR_POSTGRES)/units_bs/$(SOURCESUFFIX)),) -UNITDIR_FPMAKE_POSTGRES=$(PACKAGEDIR_POSTGRES)/units_bs/$(SOURCESUFFIX) -else -UNITDIR_FPMAKE_POSTGRES=$(PACKAGEDIR_POSTGRES) -endif -endif ifdef CHECKDEPEND $(PACKAGEDIR_POSTGRES)/$(FPCMADE): $(MAKE) -C $(PACKAGEDIR_POSTGRES) $(FPCMADE) @@ -2380,9 +2335,6 @@ endif ifdef UNITDIR_POSTGRES override COMPILER_UNITDIR+=$(UNITDIR_POSTGRES) endif -ifdef UNITDIR_FPMAKE_POSTGRES -override COMPILER_FPMAKE_UNITDIR+=$(UNITDIR_FPMAKE_POSTGRES) -endif endif ifndef NOCPUDEF override FPCOPTDEF=$(ARCH) @@ -2395,7 +2347,6 @@ override FPCOPT+=-P$(ARCH) endif ifeq ($(OS_SOURCE),openbsd) override FPCOPT+=-FD$(NEW_BINUTILS_PATH) -override FPCMAKEOPT+=-FD$(NEW_BINUTILS_PATH) endif ifndef CROSSBOOTSTRAP ifneq ($(BINUTILSPREFIX),) @@ -2405,11 +2356,6 @@ ifneq ($(BINUTILSPREFIX),) override FPCOPT+=-Xr$(RLINKPATH) endif endif -ifndef CROSSCOMPILE -ifneq ($(BINUTILSPREFIX),) -override FPCMAKEOPT+=-XP$(BINUTILSPREFIX) -endif -endif ifdef UNITDIR override FPCOPT+=$(addprefix -Fu,$(UNITDIR)) endif @@ -2501,7 +2447,7 @@ override FPCOPT+=-Aas endif endif ifeq ($(findstring 2.0.,$(FPC_VERSION)),) -ifneq ($(findstring $(OS_TARGET),freebsd openbsd netbsd linux solaris),) +ifeq ($(OS_TARGET),linux) ifeq ($(CPU_TARGET),x86_64) override FPCOPT+=-Cg endif @@ -2653,6 +2599,9 @@ endif fpc_install: all $(INSTALLTARGET) ifdef INSTALLEXEFILES $(MKDIR) $(INSTALL_BINDIR) +ifdef UPXPROG + -$(UPXPROG) $(INSTALLEXEFILES) +endif $(INSTALLEXE) $(INSTALLEXEFILES) $(INSTALL_BINDIR) endif ifdef INSTALL_CREATEPACKAGEFPC @@ -2700,11 +2649,9 @@ endif .PHONY: fpc_clean fpc_cleanall fpc_distclean ifdef EXEFILES override CLEANEXEFILES:=$(addprefix $(TARGETDIRPREFIX),$(CLEANEXEFILES)) -override CLEANEXEDBGFILES:=$(addprefix $(TARGETDIRPREFIX),$(CLEANEXEDBGFILES)) endif ifdef CLEAN_PROGRAMS override CLEANEXEFILES+=$(addprefix $(TARGETDIRPREFIX),$(addsuffix $(EXEEXT), $(CLEAN_PROGRAMS))) -override CLEANEXEDBGFILES+=$(addprefix $(TARGETDIRPREFIX),$(addsuffix $(EXEDBGEXT), $(CLEAN_PROGRAMS))) endif ifdef CLEAN_UNITS override CLEANPPUFILES+=$(addsuffix $(PPUEXT),$(CLEAN_UNITS)) @@ -2721,9 +2668,6 @@ fpc_clean: $(CLEANTARGET) ifdef CLEANEXEFILES -$(DEL) $(CLEANEXEFILES) endif -ifdef CLEANEXEDBGFILES - -$(DELTREE) $(CLEANEXEDBGFILES) -endif ifdef CLEANPPUFILES -$(DEL) $(CLEANPPUFILES) endif @@ -2794,7 +2738,6 @@ fpc_baseinfo: @$(ECHO) Full Target.. $(FULL_TARGET) @$(ECHO) SourceSuffix. $(SOURCESUFFIX) @$(ECHO) TargetSuffix. $(TARGETSUFFIX) - @$(ECHO) FPC fpmake... $(FPCFPMAKE) @$(ECHO) @$(ECHO) == Directory info == @$(ECHO) @@ -2825,6 +2768,7 @@ fpc_baseinfo: @$(ECHO) Date...... $(DATE) @$(ECHO) FPCMake... $(FPCMAKE) @$(ECHO) PPUMove... $(PPUMOVE) + @$(ECHO) Upx....... $(UPXPROG) @$(ECHO) Zip....... $(ZIPPROG) @$(ECHO) @$(ECHO) == Object info == diff --git a/packages/fcl-db/src/sqldb/postgres/Makefile.fpc b/packages/fcl-db/src/sqldb/postgres/Makefile.fpc index 4d03708937..d6df0dc241 100644 --- a/packages/fcl-db/src/sqldb/postgres/Makefile.fpc +++ b/packages/fcl-db/src/sqldb/postgres/Makefile.fpc @@ -7,7 +7,7 @@ main=fcl-db [target] rsts=pqconnection -units=pqconnection +units=pqconnection pqeventmonitor [require] packages=fcl-xml postgres diff --git a/packages/fcl-db/src/sqldb/postgres/fpmake.inc b/packages/fcl-db/src/sqldb/postgres/fpmake.inc index 7d316f1676..d9c7a0a135 100644 --- a/packages/fcl-db/src/sqldb/postgres/fpmake.inc +++ b/packages/fcl-db/src/sqldb/postgres/fpmake.inc @@ -9,3 +9,5 @@ Targets.DefaultDir:='db/sqldb/postgres'; Targets.DefaultOS:=[win32,openbsd,netbsd,freebsd,darwin,linux,haiku]; T:=Targets.AddUnit('pqconnection'); T.ResourceStrings:=True; +T:=Targets.AddUnit('pqeventmonitor'); +T.Dependencies.Add('pqconnection'); diff --git a/packages/fcl-db/src/sqldb/postgres/pqeventmonitor.pp b/packages/fcl-db/src/sqldb/postgres/pqeventmonitor.pp new file mode 100644 index 0000000000..f463a3cfa4 --- /dev/null +++ b/packages/fcl-db/src/sqldb/postgres/pqeventmonitor.pp @@ -0,0 +1,251 @@ +unit PQEventMonitor; + +{ PostGresql notification monitor + + Copyright (C) 2012 Ludo Brands + + This library is free software; you can redistribute it and/or modify it + under the terms of the GNU Library General Public License as published by + the Free Software Foundation; either version 2 of the License, or (at your + option) any later version with the following modification: + + As a special exception, the copyright holders of this library give you + permission to link this library with independent modules to produce an + executable, regardless of the license terms of these independent modules,and + to copy and distribute the resulting executable under terms of your choice, + provided that you also meet, for each linked independent module, the terms + and conditions of the license of that module. An independent module is a + module which is not derived from or based on this library. If you modify + this library, you may extend this exception to your version of the library, + but you are not obligated to do so. If you do not wish to do so, delete this + exception statement from your version. + + This program is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License + for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; if not, write to the Free Software Foundation, + Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +} + +{$mode objfpc}{$H+} +{$Define LinkDynamically} + +interface + +uses + Classes, SysUtils,pqconnection,db,dbconst, +{$IfDef LinkDynamically} + postgres3dyn; +{$Else} + postgres3; +{$EndIf} + + +type + TEventAlert = procedure(Sender: TObject; EventName: string; EventCount: longint; + var CancelAlerts: boolean) of object; + TErrorEvent = procedure(Sender: TObject; ErrorCode: integer) of object; + +{ TPQEventMonitor } + + TPQEventMonitor=class (TComponent) + private + FConnection: TPQConnection; + FDBHandle: PPGconn; + FErrorMsg: string; + FEvents: TStrings; + FOnError: TErrorEvent; + FOnEventAlert: TEventAlert; + FRegistered: Boolean; + function GetNativeHandle: pointer; + procedure SetConnection(AValue: TPQConnection); + procedure SetEvents(AValue: TStrings); + procedure SetRegistered(AValue: Boolean); + public + constructor Create(AOwner: TComponent); override; + destructor Destroy; override; + procedure Poll; + procedure RegisterEvents; virtual; + procedure UnRegisterEvents; virtual; + property ErrorMsg:string read FErrorMsg; + property NativeHandle: pointer read GetNativeHandle; + published + property Connection: TPQConnection read FConnection write SetConnection; + property Events: TStrings read FEvents write SetEvents; + property Registered: Boolean read FRegistered write SetRegistered; + property OnEventAlert: TEventAlert read FOnEventAlert write FOnEventAlert; + property OnError: TErrorEvent read FOnError write FOnError; + end; + + +implementation + +ResourceString + SErrConnectionFailed = 'Connection to database failed'; + SErrExecuteFailed = 'Execution of query failed'; + +{ TPQEventMonitor } + +function TPQEventMonitor.GetNativeHandle: pointer; +begin + result:=FDBHandle; +end; + + +procedure TPQEventMonitor.SetConnection(AValue: TPQConnection); +begin + if FConnection=AValue then Exit; + If not (csDesigning in ComponentState) and FRegistered then + begin + if assigned(FConnection) then + FConnection.RemoveFreeNotification(self); // remove us from the old connection + UnRegisterEvents; + FConnection:=AValue; + if assigned(FConnection) then + begin + RegisterEvents; + end; + end + else + FConnection:=AValue; + if assigned(FConnection) then + FConnection.FreeNotification(Self); //in case Connection is destroyed before we are +end; + +procedure TPQEventMonitor.SetEvents(AValue: TStrings); +begin + FEvents.Assign(AValue); +end; + +procedure TPQEventMonitor.SetRegistered(AValue: Boolean); +begin + FRegistered := AValue; + if not (csDesigning in ComponentState) then + if AValue then + RegisterEvents + else + UnRegisterEvents; +end; + +constructor TPQEventMonitor.Create(AOwner: TComponent); +begin + inherited Create(AOwner); + FEvents:=TStringList.Create; + {$IfDef LinkDynamically} + InitialisePostgres3; // stick to library in case connection closes before us + {$EndIf} +end; + +destructor TPQEventMonitor.Destroy; +begin + if FRegistered then + UnRegisterEvents; + if assigned(FConnection) then + FConnection.RemoveFreeNotification(self); + FEvents.Free; + {$IfDef LinkDynamically} + ReleasePostgres3; + {$EndIf} + inherited Destroy; +end; + +procedure TPQEventMonitor.Poll; +var + notify:PpgNotify; + CancelAlerts:boolean; +begin + if FConnection.Connected and FRegistered and (PQconsumeInput(FDBHandle)=1) then + begin + CancelAlerts:=false; + repeat + notify:=PQnotifies(FDBHandle); + if assigned(notify) then + begin + if assigned(OnEventAlert) then + OnEventAlert(Self,notify^.relname,1,CancelAlerts); + PQfreemem(notify); + end; + until not assigned(notify) or CancelAlerts; + if CancelAlerts then + UnRegisterEvents; + end; +end; + +procedure TPQEventMonitor.RegisterEvents; +var + i:Integer; + sConn: String; + res: PPGresult; + msg:string; + notify:PpgNotify; + CancelAlerts:boolean; +begin + If not assigned(FConnection) then + DatabaseError(SErrNoDatabaseAvailable,Self); + if not(csDesigning in ComponentState) and not FRegistered and (Events.Count>0) then + begin + sConn := ''; + if (FConnection.UserName <> '') then sConn := sConn + ' user=''' + FConnection.UserName + ''''; + if (FConnection.Password <> '') then sConn := sConn + ' password=''' + FConnection.Password + ''''; + if (FConnection.HostName <> '') then sConn := sConn + ' host=''' + FConnection.HostName + ''''; + if (FConnection.DatabaseName <> '') then sConn := sConn + ' dbname=''' + FConnection.DatabaseName + ''''; + if (FConnection.Params.Text <> '') then sConn := sConn + ' '+FConnection.Params.Text; + + FDBHandle := PQconnectdb(pchar(sConn)); + if (PQstatus(FDBHandle) <> CONNECTION_OK) then + begin + msg := PQerrorMessage(FDBHandle); + PQFinish(FDBHandle); + DatabaseError(sErrConnectionFailed + ' (TPQEventMonitor: ' + Msg + ')',self); + end; + for i:=0 to Events.Count-1 do + begin + res := PQexec(FDBHandle,pchar('LISTEN '+ Events[i])); + if (PQresultStatus(res) <> PGRES_COMMAND_OK) then + begin + msg := PQerrorMessage(FDBHandle); + PQclear(res); + PQFinish(FDBHandle); + FDBHandle:=nil; + DatabaseError(SErrExecuteFailed + ' (TPQEventMonitor: ' + Msg + ')',self); + end + else + PQclear(res); + end; + FRegistered :=true; + end; +end; + +procedure TPQEventMonitor.UnRegisterEvents; +var + i: Integer; + res: PPGresult; + msg:string; +begin + if not (csDesigning in ComponentState) and FRegistered then + begin + for i:=0 to Events.Count-1 do + begin + res := PQexec(FDBHandle,pchar('unlisten '+ Events[i])); + if (PQresultStatus(res) <> PGRES_COMMAND_OK) then + begin + msg := PQerrorMessage(FDBHandle); + PQclear(res); + PQFinish(FDBHandle); + FDBHandle:=nil; + DatabaseError(SErrExecuteFailed + ' (TPQEventMonitor: ' + Msg + ')',self); + end + else + PQclear(res); + end; + PQFinish(FDBHandle); + FDBHandle:=nil; + FRegistered :=false; + end; +end; + +end. +