Browse Source

* Add Event notification component from Ludo Brands (22060)

git-svn-id: trunk@21323 -
michael 13 years ago
parent
commit
137b21223b

+ 2 - 0
.gitattributes

@@ -1879,6 +1879,7 @@ packages/fcl-db/Makefile svneol=native#text/plain
 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/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
@@ -2026,6 +2027,7 @@ packages/fcl-db/src/sqldb/fpmake.pp svneol=native#text/plain
 packages/fcl-db/src/sqldb/interbase/Makefile svneol=native#text/plain
 packages/fcl-db/src/sqldb/interbase/Makefile.fpc svneol=native#text/plain
 packages/fcl-db/src/sqldb/interbase/fbadmin.pp svneol=native#text/plain
+packages/fcl-db/src/sqldb/interbase/fbeventmonitor.pp svneol=native#text/plain
 packages/fcl-db/src/sqldb/interbase/fpmake.inc svneol=native#text/plain
 packages/fcl-db/src/sqldb/interbase/fpmake.pp svneol=native#text/plain
 packages/fcl-db/src/sqldb/interbase/ibconnection.pp svneol=native#text/plain

+ 151 - 0
packages/fcl-db/examples/fbeventstest.pp

@@ -0,0 +1,151 @@
+program fbeventstest;
+
+{$mode delphi}{$H+}
+
+uses
+  {$IFDEF UNIX}
+  cthreads,
+  {$ENDIF}
+  Classes,sysutils,
+  FBEventMonitor,ibconnection,sqldb;
+
+const
+  MAXEVENTS=35;
+  NUMTESTS=100;
+
+type
+
+  { TMyEventAlert }
+
+  TMyEventAlert=class
+    class procedure OnFBEvent(Sender: TObject; EventName: string; EventCount: longint;
+      var CancelAlerts: boolean);
+  end;
+
+var
+  EvSent,EvReceived:Array [1..MAXEVENTS] of integer;
+  TotalRecieved:integer;
+
+function testNEvents(IBConnection:TIBConnection;n:integer):boolean;
+var
+  EventsM:TFBEventMonitor;
+  i,j,k:integer;
+  IBConnection2:TIBConnection;
+  bExpectEvents:boolean;
+begin
+  IBConnection.Close;
+  //Create second connection to listen on. Events are not sent to current connection.
+  IBConnection2:=TIBConnection.Create(nil);
+  IBConnection2.HostName:=IBConnection.HostName;
+  IBConnection2.DatabaseName:=IBConnection.DatabaseName;
+  IBConnection2.UserName:=IBConnection.UserName;
+  IBConnection2.Password:=IBConnection.Password;
+  for i:=1 to MAXEVENTS do
+    begin
+    EvSent[i]:=0;
+    EvReceived[i]:=0;
+    end;
+  EventsM:=TFBEventMonitor.create(nil);
+  EventsM.Connection:=IBConnection2;
+  for i:=1 to n do
+    EventsM.Events.Add('E'+IntToStr(i));
+  EventsM.OnEventAlert:=TMyEventAlert.OnFBEvent;
+  EventsM.RegisterEvents;
+  i:=NUMTESTS;
+  TotalRecieved:=0;
+  bExpectEvents:=false;
+  Randomize;
+  IBConnection.Open;
+  IBConnection.ExecuteDirect('RECREATE PROCEDURE send_custom(event_name varchar(127)) '+
+     'AS '+
+     'BEGIN '+
+     'POST_EVENT event_name; '+
+     'END ');
+  IBConnection.Transaction.Commit;
+  j:=1+random(i);  //random number of events per transaction
+  while i>0 do
+    begin
+    k:=1+random(n);
+    IBConnection.ExecuteDirect('execute PROCEDURE send_custom(''E'+IntTostr(k)+''');');
+    EvSent[k]:=EvSent[k]+1;
+    if i<j then
+      begin
+      IBConnection.Transaction.Commit;
+      bExpectEvents:=true;
+      j:=1+random(i);
+      end;
+    if bExpectEvents then
+      CheckSynchronize;
+    i:=i-1;
+    end;
+  IBConnection.Transaction.Commit;
+  for i:=1 to 300 do  //3 secs max
+    begin
+    Sleep(10); //wait until everything received
+    CheckSynchronize;
+    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;
+  IBConnection2.Free;
+  IBConnection.Close;
+end;
+
+{ TMyEventAlert }
+
+class procedure TMyEventAlert.OnFBEvent(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
+  IBConnection1:TIBConnection;
+  SQLTransaction1: TSQLTransaction;
+  i:integer;
+
+begin
+  if paramcount=0 then
+    begin
+    WriteLn('Usage:');
+    WriteLn('  '+Paramstr(0) +' database [hostname] [username] [password]');
+    WriteLn('    database : database name.');
+    WriteLn('    hostname : default localhost');
+    WriteLn('    username : default SYSDBA.');
+    WriteLn('    password : default masterkey');
+    exit;
+    end;
+  IBConnection1:=TIBConnection.Create(nil);
+  SQLTransaction1:= TSQLTransaction.Create(nil);
+  IBConnection1.Transaction:=SQLTransaction1;
+  SQLTransaction1.DataBase:=IBConnection1;
+  IBConnection1.Password:='masterkey';
+  IBConnection1.UserName:='SYSDBA';
+  IBConnection1.HostName:='';
+  if paramcount=4 then
+    IBConnection1.Password:=paramstr(4);
+  if paramcount>=3 then
+    IBConnection1.UserName:=paramstr(3);
+  if paramcount>=2 then
+    IBConnection1.HostName:=paramstr(2);
+  IBConnection1.DatabaseName:=paramstr(1);
+  for i:=1 to 16 do
+    begin
+    if testNEvents(IBConnection1,i) then
+      WriteLn(inttostr(i)+' succeeded')
+    else
+      WriteLn(inttostr(i)+' failed. Missed '+ IntToStr(NUMTESTS-TotalRecieved)+' Events');
+    end;
+  SQLTransaction1.Free;
+  IBConnection1.Free;
+  WriteLn('Tests finished.');
+end.
+

+ 10 - 0
packages/fcl-db/fpmake.pp

@@ -542,6 +542,16 @@ begin
           AddUnit('bufdataset');
         end;
     T:=P.Targets.AddUnit('fbadmin.pp', SqldbConnectionOSes);
+    T.ResourceStrings:=true;
+      with T.Dependencies do
+        begin
+          AddUnit('sqldb');
+          AddUnit('db');
+          AddUnit('dbconst');
+          AddUnit('bufdataset');
+          AddUnit('ibconnection');
+        end;
+    T:=P.Targets.AddUnit('fbeventmonitor.pp', SqldbConnectionOSes);
     T.ResourceStrings:=true;
       with T.Dependencies do
         begin

+ 256 - 294
packages/fcl-db/src/sqldb/interbase/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+=ibconnection
+override TARGET_UNITS+=ibconnection fbadmin  fbeventmonitor
 endif
 ifeq ($(FULL_TARGET),i386-go32v2)
-override TARGET_UNITS+=ibconnection
+override TARGET_UNITS+=ibconnection fbadmin  fbeventmonitor
 endif
 ifeq ($(FULL_TARGET),i386-win32)
-override TARGET_UNITS+=ibconnection
+override TARGET_UNITS+=ibconnection fbadmin  fbeventmonitor
 endif
 ifeq ($(FULL_TARGET),i386-os2)
-override TARGET_UNITS+=ibconnection
+override TARGET_UNITS+=ibconnection fbadmin  fbeventmonitor
 endif
 ifeq ($(FULL_TARGET),i386-freebsd)
-override TARGET_UNITS+=ibconnection
+override TARGET_UNITS+=ibconnection fbadmin  fbeventmonitor
 endif
 ifeq ($(FULL_TARGET),i386-beos)
-override TARGET_UNITS+=ibconnection
+override TARGET_UNITS+=ibconnection fbadmin  fbeventmonitor
 endif
 ifeq ($(FULL_TARGET),i386-haiku)
-override TARGET_UNITS+=ibconnection
+override TARGET_UNITS+=ibconnection fbadmin  fbeventmonitor
 endif
 ifeq ($(FULL_TARGET),i386-netbsd)
-override TARGET_UNITS+=ibconnection
+override TARGET_UNITS+=ibconnection fbadmin  fbeventmonitor
 endif
 ifeq ($(FULL_TARGET),i386-solaris)
-override TARGET_UNITS+=ibconnection
+override TARGET_UNITS+=ibconnection fbadmin  fbeventmonitor
 endif
 ifeq ($(FULL_TARGET),i386-qnx)
-override TARGET_UNITS+=ibconnection
+override TARGET_UNITS+=ibconnection fbadmin  fbeventmonitor
 endif
 ifeq ($(FULL_TARGET),i386-netware)
-override TARGET_UNITS+=ibconnection
+override TARGET_UNITS+=ibconnection fbadmin  fbeventmonitor
 endif
 ifeq ($(FULL_TARGET),i386-openbsd)
-override TARGET_UNITS+=ibconnection
+override TARGET_UNITS+=ibconnection fbadmin  fbeventmonitor
 endif
 ifeq ($(FULL_TARGET),i386-wdosx)
-override TARGET_UNITS+=ibconnection
+override TARGET_UNITS+=ibconnection fbadmin  fbeventmonitor
 endif
 ifeq ($(FULL_TARGET),i386-darwin)
-override TARGET_UNITS+=ibconnection
+override TARGET_UNITS+=ibconnection fbadmin  fbeventmonitor
 endif
 ifeq ($(FULL_TARGET),i386-emx)
-override TARGET_UNITS+=ibconnection
+override TARGET_UNITS+=ibconnection fbadmin  fbeventmonitor
 endif
 ifeq ($(FULL_TARGET),i386-watcom)
-override TARGET_UNITS+=ibconnection
+override TARGET_UNITS+=ibconnection fbadmin  fbeventmonitor
 endif
 ifeq ($(FULL_TARGET),i386-netwlibc)
-override TARGET_UNITS+=ibconnection
+override TARGET_UNITS+=ibconnection fbadmin  fbeventmonitor
 endif
 ifeq ($(FULL_TARGET),i386-wince)
-override TARGET_UNITS+=ibconnection
+override TARGET_UNITS+=ibconnection fbadmin  fbeventmonitor
 endif
 ifeq ($(FULL_TARGET),i386-embedded)
-override TARGET_UNITS+=ibconnection
+override TARGET_UNITS+=ibconnection fbadmin  fbeventmonitor
 endif
 ifeq ($(FULL_TARGET),i386-symbian)
-override TARGET_UNITS+=ibconnection
+override TARGET_UNITS+=ibconnection fbadmin  fbeventmonitor
 endif
 ifeq ($(FULL_TARGET),i386-nativent)
-override TARGET_UNITS+=ibconnection
+override TARGET_UNITS+=ibconnection fbadmin  fbeventmonitor
 endif
 ifeq ($(FULL_TARGET),i386-iphonesim)
-override TARGET_UNITS+=ibconnection
+override TARGET_UNITS+=ibconnection fbadmin  fbeventmonitor
 endif
 ifeq ($(FULL_TARGET),m68k-linux)
-override TARGET_UNITS+=ibconnection
+override TARGET_UNITS+=ibconnection fbadmin  fbeventmonitor
 endif
 ifeq ($(FULL_TARGET),m68k-freebsd)
-override TARGET_UNITS+=ibconnection
+override TARGET_UNITS+=ibconnection fbadmin  fbeventmonitor
 endif
 ifeq ($(FULL_TARGET),m68k-netbsd)
-override TARGET_UNITS+=ibconnection
+override TARGET_UNITS+=ibconnection fbadmin  fbeventmonitor
 endif
 ifeq ($(FULL_TARGET),m68k-amiga)
-override TARGET_UNITS+=ibconnection
+override TARGET_UNITS+=ibconnection fbadmin  fbeventmonitor
 endif
 ifeq ($(FULL_TARGET),m68k-atari)
-override TARGET_UNITS+=ibconnection
+override TARGET_UNITS+=ibconnection fbadmin  fbeventmonitor
 endif
 ifeq ($(FULL_TARGET),m68k-openbsd)
-override TARGET_UNITS+=ibconnection
+override TARGET_UNITS+=ibconnection fbadmin  fbeventmonitor
 endif
 ifeq ($(FULL_TARGET),m68k-palmos)
-override TARGET_UNITS+=ibconnection
+override TARGET_UNITS+=ibconnection fbadmin  fbeventmonitor
 endif
 ifeq ($(FULL_TARGET),m68k-embedded)
-override TARGET_UNITS+=ibconnection
+override TARGET_UNITS+=ibconnection fbadmin  fbeventmonitor
 endif
 ifeq ($(FULL_TARGET),powerpc-linux)
-override TARGET_UNITS+=ibconnection
+override TARGET_UNITS+=ibconnection fbadmin  fbeventmonitor
 endif
 ifeq ($(FULL_TARGET),powerpc-netbsd)
-override TARGET_UNITS+=ibconnection
+override TARGET_UNITS+=ibconnection fbadmin  fbeventmonitor
 endif
 ifeq ($(FULL_TARGET),powerpc-amiga)
-override TARGET_UNITS+=ibconnection
+override TARGET_UNITS+=ibconnection fbadmin  fbeventmonitor
 endif
 ifeq ($(FULL_TARGET),powerpc-macos)
-override TARGET_UNITS+=ibconnection
+override TARGET_UNITS+=ibconnection fbadmin  fbeventmonitor
 endif
 ifeq ($(FULL_TARGET),powerpc-darwin)
-override TARGET_UNITS+=ibconnection
+override TARGET_UNITS+=ibconnection fbadmin  fbeventmonitor
 endif
 ifeq ($(FULL_TARGET),powerpc-morphos)
-override TARGET_UNITS+=ibconnection
+override TARGET_UNITS+=ibconnection fbadmin  fbeventmonitor
 endif
 ifeq ($(FULL_TARGET),powerpc-embedded)
-override TARGET_UNITS+=ibconnection
-endif
-ifeq ($(FULL_TARGET),powerpc-wii)
-override TARGET_UNITS+=ibconnection
-endif
-ifeq ($(FULL_TARGET),powerpc-aix)
-override TARGET_UNITS+=ibconnection
+override TARGET_UNITS+=ibconnection fbadmin  fbeventmonitor
 endif
 ifeq ($(FULL_TARGET),sparc-linux)
-override TARGET_UNITS+=ibconnection
+override TARGET_UNITS+=ibconnection fbadmin  fbeventmonitor
 endif
 ifeq ($(FULL_TARGET),sparc-netbsd)
-override TARGET_UNITS+=ibconnection
+override TARGET_UNITS+=ibconnection fbadmin  fbeventmonitor
 endif
 ifeq ($(FULL_TARGET),sparc-solaris)
-override TARGET_UNITS+=ibconnection
+override TARGET_UNITS+=ibconnection fbadmin  fbeventmonitor
 endif
 ifeq ($(FULL_TARGET),sparc-embedded)
-override TARGET_UNITS+=ibconnection
+override TARGET_UNITS+=ibconnection fbadmin  fbeventmonitor
 endif
 ifeq ($(FULL_TARGET),x86_64-linux)
-override TARGET_UNITS+=ibconnection
+override TARGET_UNITS+=ibconnection fbadmin  fbeventmonitor
 endif
 ifeq ($(FULL_TARGET),x86_64-freebsd)
-override TARGET_UNITS+=ibconnection
-endif
-ifeq ($(FULL_TARGET),x86_64-netbsd)
-override TARGET_UNITS+=ibconnection
+override TARGET_UNITS+=ibconnection fbadmin  fbeventmonitor
 endif
 ifeq ($(FULL_TARGET),x86_64-solaris)
-override TARGET_UNITS+=ibconnection
-endif
-ifeq ($(FULL_TARGET),x86_64-openbsd)
-override TARGET_UNITS+=ibconnection
+override TARGET_UNITS+=ibconnection fbadmin  fbeventmonitor
 endif
 ifeq ($(FULL_TARGET),x86_64-darwin)
-override TARGET_UNITS+=ibconnection
+override TARGET_UNITS+=ibconnection fbadmin  fbeventmonitor
 endif
 ifeq ($(FULL_TARGET),x86_64-win64)
-override TARGET_UNITS+=ibconnection
+override TARGET_UNITS+=ibconnection fbadmin  fbeventmonitor
 endif
 ifeq ($(FULL_TARGET),x86_64-embedded)
-override TARGET_UNITS+=ibconnection
+override TARGET_UNITS+=ibconnection fbadmin  fbeventmonitor
 endif
 ifeq ($(FULL_TARGET),arm-linux)
-override TARGET_UNITS+=ibconnection
+override TARGET_UNITS+=ibconnection fbadmin  fbeventmonitor
 endif
 ifeq ($(FULL_TARGET),arm-palmos)
-override TARGET_UNITS+=ibconnection
+override TARGET_UNITS+=ibconnection fbadmin  fbeventmonitor
 endif
 ifeq ($(FULL_TARGET),arm-darwin)
-override TARGET_UNITS+=ibconnection
+override TARGET_UNITS+=ibconnection fbadmin  fbeventmonitor
 endif
 ifeq ($(FULL_TARGET),arm-wince)
-override TARGET_UNITS+=ibconnection
+override TARGET_UNITS+=ibconnection fbadmin  fbeventmonitor
 endif
 ifeq ($(FULL_TARGET),arm-gba)
-override TARGET_UNITS+=ibconnection
+override TARGET_UNITS+=ibconnection fbadmin  fbeventmonitor
 endif
 ifeq ($(FULL_TARGET),arm-nds)
-override TARGET_UNITS+=ibconnection
+override TARGET_UNITS+=ibconnection fbadmin  fbeventmonitor
 endif
 ifeq ($(FULL_TARGET),arm-embedded)
-override TARGET_UNITS+=ibconnection
+override TARGET_UNITS+=ibconnection fbadmin  fbeventmonitor
 endif
 ifeq ($(FULL_TARGET),arm-symbian)
-override TARGET_UNITS+=ibconnection
+override TARGET_UNITS+=ibconnection fbadmin  fbeventmonitor
 endif
 ifeq ($(FULL_TARGET),powerpc64-linux)
-override TARGET_UNITS+=ibconnection
+override TARGET_UNITS+=ibconnection fbadmin  fbeventmonitor
 endif
 ifeq ($(FULL_TARGET),powerpc64-darwin)
-override TARGET_UNITS+=ibconnection
+override TARGET_UNITS+=ibconnection fbadmin  fbeventmonitor
 endif
 ifeq ($(FULL_TARGET),powerpc64-embedded)
-override TARGET_UNITS+=ibconnection
-endif
-ifeq ($(FULL_TARGET),powerpc64-aix)
-override TARGET_UNITS+=ibconnection
+override TARGET_UNITS+=ibconnection fbadmin  fbeventmonitor
 endif
 ifeq ($(FULL_TARGET),avr-embedded)
-override TARGET_UNITS+=ibconnection
+override TARGET_UNITS+=ibconnection fbadmin  fbeventmonitor
 endif
 ifeq ($(FULL_TARGET),armeb-linux)
-override TARGET_UNITS+=ibconnection
+override TARGET_UNITS+=ibconnection fbadmin  fbeventmonitor
 endif
 ifeq ($(FULL_TARGET),armeb-embedded)
-override TARGET_UNITS+=ibconnection
-endif
-ifeq ($(FULL_TARGET),mips-linux)
-override TARGET_UNITS+=ibconnection
+override TARGET_UNITS+=ibconnection fbadmin  fbeventmonitor
 endif
 ifeq ($(FULL_TARGET),mipsel-linux)
-override TARGET_UNITS+=ibconnection
+override TARGET_UNITS+=ibconnection fbadmin  fbeventmonitor
 endif
 override INSTALL_FPCPACKAGE=y
 ifeq ($(FULL_TARGET),i386-linux)
@@ -610,12 +564,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
@@ -634,15 +582,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
@@ -685,9 +627,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
@@ -697,9 +636,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
@@ -913,7 +849,7 @@ SHAREDLIBPREFIX=libfp
 STATICLIBPREFIX=libp
 IMPORTLIBPREFIX=libimp
 RSTEXT=.rst
-EXEDBGEXT=.dbg
+ifeq ($(findstring 1.0.,$(FPC_VERSION)),)
 ifeq ($(OS_TARGET),go32v1)
 STATICLIBPREFIX=
 SHORTSUFFIX=v1
@@ -1035,7 +971,6 @@ BATCHEXT=.sh
 EXEEXT=
 HASSHAREDLIB=1
 SHORTSUFFIX=dwn
-EXEDBGEXT=.dSYM
 endif
 ifeq ($(OS_TARGET),gba)
 EXEEXT=.gba
@@ -1050,15 +985,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),go32v2)
+STATICLIBPREFIX=
+SHORTSUFFIX=dos
+IMPORTLIBPREFIX=
+endif
+ifeq ($(OS_TARGET),watcom)
+STATICLIBPREFIX=
+SHORTSUFFIX=wat
+IMPORTLIBPREFIX=
 endif
-ifeq ($(OS_TARGET),aix)
+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)
@@ -1249,6 +1329,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)
@@ -1292,6 +1381,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)
@@ -1635,24 +1743,6 @@ REQUIRE_PACKAGES_FPMKUNIT=1
 REQUIRE_PACKAGES_FCL-XML=1
 REQUIRE_PACKAGES_IBASE=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_IBASE=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_IBASE=1
-endif
 ifeq ($(FULL_TARGET),sparc-linux)
 REQUIRE_PACKAGES_RTL=1
 REQUIRE_PACKAGES_PASZLIB=1
@@ -1707,15 +1797,6 @@ REQUIRE_PACKAGES_FPMKUNIT=1
 REQUIRE_PACKAGES_FCL-XML=1
 REQUIRE_PACKAGES_IBASE=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_IBASE=1
-endif
 ifeq ($(FULL_TARGET),x86_64-solaris)
 REQUIRE_PACKAGES_RTL=1
 REQUIRE_PACKAGES_PASZLIB=1
@@ -1725,15 +1806,6 @@ REQUIRE_PACKAGES_FPMKUNIT=1
 REQUIRE_PACKAGES_FCL-XML=1
 REQUIRE_PACKAGES_IBASE=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_IBASE=1
-endif
 ifeq ($(FULL_TARGET),x86_64-darwin)
 REQUIRE_PACKAGES_RTL=1
 REQUIRE_PACKAGES_PASZLIB=1
@@ -1860,15 +1932,6 @@ REQUIRE_PACKAGES_FPMKUNIT=1
 REQUIRE_PACKAGES_FCL-XML=1
 REQUIRE_PACKAGES_IBASE=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_IBASE=1
-endif
 ifeq ($(FULL_TARGET),avr-embedded)
 REQUIRE_PACKAGES_RTL=1
 REQUIRE_PACKAGES_PASZLIB=1
@@ -1896,15 +1959,6 @@ REQUIRE_PACKAGES_FPMKUNIT=1
 REQUIRE_PACKAGES_FCL-XML=1
 REQUIRE_PACKAGES_IBASE=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_IBASE=1
-endif
 ifeq ($(FULL_TARGET),mipsel-linux)
 REQUIRE_PACKAGES_RTL=1
 REQUIRE_PACKAGES_PASZLIB=1
@@ -1922,15 +1976,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)
@@ -1948,9 +1993,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))))))
@@ -1960,15 +2002,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)
@@ -1986,9 +2019,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))))))
@@ -1998,15 +2028,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)
@@ -2024,9 +2045,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))))))
@@ -2036,15 +2054,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)
@@ -2062,9 +2071,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))))))
@@ -2074,15 +2080,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)
@@ -2100,9 +2097,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))))))
@@ -2112,15 +2106,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)
@@ -2138,9 +2123,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_IBASE
 PACKAGEDIR_IBASE:=$(firstword $(subst /Makefile.fpc,,$(strip $(wildcard $(addsuffix /ibase/Makefile.fpc,$(PACKAGESDIR))))))
@@ -2150,15 +2132,6 @@ UNITDIR_IBASE=$(PACKAGEDIR_IBASE)/units/$(TARGETSUFFIX)
 else
 UNITDIR_IBASE=$(PACKAGEDIR_IBASE)
 endif
-ifneq ($(wildcard $(PACKAGEDIR_IBASE)/units/$(SOURCESUFFIX)),)
-UNITDIR_FPMAKE_IBASE=$(PACKAGEDIR_IBASE)/units/$(SOURCESUFFIX)
-else
-ifneq ($(wildcard $(PACKAGEDIR_IBASE)/units_bs/$(SOURCESUFFIX)),)
-UNITDIR_FPMAKE_IBASE=$(PACKAGEDIR_IBASE)/units_bs/$(SOURCESUFFIX)
-else
-UNITDIR_FPMAKE_IBASE=$(PACKAGEDIR_IBASE)
-endif
-endif
 ifdef CHECKDEPEND
 $(PACKAGEDIR_IBASE)/$(FPCMADE):
 	$(MAKE) -C $(PACKAGEDIR_IBASE) $(FPCMADE)
@@ -2176,9 +2149,6 @@ endif
 ifdef UNITDIR_IBASE
 override COMPILER_UNITDIR+=$(UNITDIR_IBASE)
 endif
-ifdef UNITDIR_FPMAKE_IBASE
-override COMPILER_FPMAKE_UNITDIR+=$(UNITDIR_FPMAKE_IBASE)
-endif
 endif
 ifndef NOCPUDEF
 override FPCOPTDEF=$(ARCH)
@@ -2191,7 +2161,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),)
@@ -2201,11 +2170,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
@@ -2297,7 +2261,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
@@ -2449,6 +2413,9 @@ endif
 fpc_install: all $(INSTALLTARGET)
 ifdef INSTALLEXEFILES
 	$(MKDIR) $(INSTALL_BINDIR)
+ifdef UPXPROG
+	-$(UPXPROG) $(INSTALLEXEFILES)
+endif
 	$(INSTALLEXE) $(INSTALLEXEFILES) $(INSTALL_BINDIR)
 endif
 ifdef INSTALL_CREATEPACKAGEFPC
@@ -2496,11 +2463,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))
@@ -2517,9 +2482,6 @@ fpc_clean: $(CLEANTARGET)
 ifdef CLEANEXEFILES
 	-$(DEL) $(CLEANEXEFILES)
 endif
-ifdef CLEANEXEDBGFILES
-	-$(DELTREE) $(CLEANEXEDBGFILES)
-endif
 ifdef CLEANPPUFILES
 	-$(DEL) $(CLEANPPUFILES)
 endif
@@ -2590,7 +2552,6 @@ fpc_baseinfo:
 	@$(ECHO)  Full Target.. $(FULL_TARGET)
 	@$(ECHO)  SourceSuffix. $(SOURCESUFFIX)
 	@$(ECHO)  TargetSuffix. $(TARGETSUFFIX)
-	@$(ECHO)  FPC fpmake... $(FPCFPMAKE)
 	@$(ECHO)
 	@$(ECHO)  == Directory info ==
 	@$(ECHO)
@@ -2621,6 +2582,7 @@ fpc_baseinfo:
 	@$(ECHO)  Date...... $(DATE)
 	@$(ECHO)  FPCMake... $(FPCMAKE)
 	@$(ECHO)  PPUMove... $(PPUMOVE)
+	@$(ECHO)  Upx....... $(UPXPROG)
 	@$(ECHO)  Zip....... $(ZIPPROG)
 	@$(ECHO)
 	@$(ECHO)  == Object info ==

+ 1 - 1
packages/fcl-db/src/sqldb/interbase/Makefile.fpc

@@ -6,7 +6,7 @@
 main=fcl-db
 
 [target]
-units=ibconnection
+units=ibconnection fbadmin  fbeventmonitor
 
 [require]
 packages=fcl-xml ibase 

+ 364 - 0
packages/fcl-db/src/sqldb/interbase/fbeventmonitor.pp

@@ -0,0 +1,364 @@
+unit FBEventMonitor;
+
+{ Interbase/Firebird Event 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,
+{$IfDef LinkDynamically}
+  ibase60dyn,
+{$Else}
+  ibase60,
+{$EndIf}
+  IBConnection,syncobjs,db,dbconst;
+
+type
+  TEventAlert = procedure(Sender: TObject; EventName: string; EventCount: longint;
+    var CancelAlerts: boolean) of object;
+  TErrorEvent = procedure(Sender: TObject; ErrorCode: integer) of object;
+
+  { TFBEventMonitor }
+
+  TFBEventMonitor=class (TComponent)
+  private
+    FConnection: TIBConnection;
+    FErrorMsg: string;
+    FEvents: TStrings;
+    FEventsThread: TThread;
+    FOnError: TErrorEvent;
+    FOnEventAlert: TEventAlert;
+    FRegistered: Boolean;
+    function GetNativeHandle: PISC_DB_HANDLE;
+    procedure SetConnection(AValue: TIBConnection);
+    procedure SetEvents(AValue: TStrings);
+    procedure SetRegistered(AValue: Boolean);
+  public
+    constructor Create(AOwner: TComponent); override;
+    destructor Destroy; override;
+    procedure RegisterEvents; virtual;
+    procedure UnRegisterEvents; virtual;
+    property ErrorMsg:string read FErrorMsg;
+    property NativeHandle: PISC_DB_HANDLE read GetNativeHandle;
+  published
+    property Connection: TIBConnection 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
+const
+  MAXEVENTSPEREPB=15;      //isc_event_block limitated to 15 events.
+type
+  TEPBpair=record
+    EventBuf:PChar;        //isc_event_block event block
+    ResultBuf:PChar;       //isc_event_block result block
+    Signal:pointer;        //pointer to TFBEventsThread.FSignal
+    Signaled:Boolean;      //this event block is signaled
+    Len:ISC_LONG;          //lenght returned by isc_event_block
+    Count:integer;         //number of events in this event block
+    EventID:ISC_LONG;      //handle of current event returned by isc_que_events
+    bStartup:boolean;      //results are not valid yet, don't generate event
+  end;
+  PEPBpair=^TEPBpair;
+
+  { TFBEventsThread }
+
+  TFBEventsThread=class(TThread)
+  protected
+    FCancelAlerts: Boolean;
+    FCounts: array [0..19] of longint; //FB manual says ISC_STATUS but FB code int32
+    FEPBs: array of TEPBpair;
+    FErrorCode: integer;
+    FEventCount: integer;
+    FEventNumber: integer;
+    FParent:TFBEventMonitor;
+    FSignal:TSimpleEvent;
+    FStatus: array [0..19] of ISC_STATUS;
+    procedure CheckError(Status: PISC_STATUS);
+    procedure DoErrorEvent;
+    procedure DoEventAlert;
+    procedure Execute; override;
+    procedure QueueEvents(DBHandle: pointer; block: integer);
+  public
+    constructor Create(Parent:TFBEventMonitor);
+    procedure DoTerminate;
+  end;
+
+  { THandleIBConnection }
+  // descendant to access protected GetHandle
+  THandleIBConnection=class(TIBConnection)
+  private
+    function GetDBHandle: pointer;
+  public
+    property Handle:pointer read GetDBHandle;
+  end;
+
+procedure event_function(ptr:pointer;len:ushort;updated: pchar);cdecl;
+begin
+  Move(updated^, PEPBpair(ptr)^.ResultBuf^, len);
+  PEPBpair(ptr)^.signaled:=true;
+  TEventObject(PEPBpair(ptr)^.signal^).SetEvent;
+end;
+
+function THandleIBConnection.GetDBHandle: pointer;
+begin
+  result:=GetHandle;
+end;
+
+{ TFBEventsThread }
+
+procedure TFBEventsThread.CheckError(Status: PISC_STATUS);
+var
+  buf : array [0..1023] of char;
+
+begin
+  if ((Status[0] = 1) and (Status[1] <> 0)) then
+  begin
+    FErrorCode := Status[1];
+    FParent.FErrorMsg := '';
+    while isc_interprete(Buf, @Status) > 0 do
+      FParent.FErrorMsg := FParent.FErrorMsg + LineEnding +' -' + StrPas(Buf);
+    if Assigned(FParent.FOnError) then
+      synchronize(@DoErrorEvent);
+  end;
+end;
+
+procedure TFBEventsThread.DoErrorEvent;
+begin
+  FParent.FOnError(FParent,FErrorCode);
+end;
+
+procedure TFBEventsThread.DoEventAlert;
+begin
+  FParent.FOnEventAlert(FParent, FParent.FEvents[FEventNumber],FEventCount, FCancelAlerts);
+end;
+
+procedure TFBEventsThread.Execute;
+var
+  i,j:integer;
+  DBHandle : pointer;
+  bStartup:boolean;
+
+  function P(num:integer):pchar;
+  begin
+    num:=num+i*MAXEVENTSPEREPB;
+    if num<FParent.FEvents.Count then
+      result:=pchar(FParent.FEvents[num])
+    else
+      result:=nil;
+  end;
+
+begin
+  // create event blocks and register events
+  DBHandle:=THandleIBConnection(FParent.Connection).GetDBHandle;
+  SetLength(FEPBs,1+(FParent.FEvents.Count -1) div MAXEVENTSPEREPB);
+  for i:=0 to high(FEPBs) do
+    begin
+    FEPBs[i].Signal:=@FSignal;
+    FEPBs[i].bStartup:=true;
+    FEPBs[i].Count:=FParent.FEvents.Count-i*MAXEVENTSPEREPB;
+    if FEPBs[i].Count > MAXEVENTSPEREPB then
+      FEPBs[i].Count:=MAXEVENTSPEREPB;
+    FEPBs[i].Len := isc_event_block(@FEPBs[i].EventBuf, @FEPBs[i].ResultBuf,
+        word(FEPBs[i].Count),[
+        P(0), P(1),P(2), P(3), P(4),P(5), P(6), P(7),
+        P(8), P(9), P(10), P(11), P(12), P(13), P(14)]);
+    QueueEvents(DBHandle,i);
+    end;
+  FCancelAlerts:=false;
+  bStartup:=true;
+  while not Terminated do
+    begin
+    if FSignal.WaitFor(100)=wrSignaled then
+      begin
+      FSignal.ResetEvent;
+      for i:=0 to high(FEPBs) do
+        if FEPBs[i].Signaled then
+          begin
+          FEPBs[i].Signaled:=false;
+          isc_event_counts(@FCounts[0], Short(FEPBs[i].Len), FEPBs[i].EventBuf, FEPBs[i].ResultBuf);
+          if not FEPBs[i].bStartup and Assigned(FParent.FOnEventAlert) then
+            begin
+            for j:=0 to FEPBs[i].Count-1 do
+              if (FCounts[j]<>0) and not FCancelAlerts then
+                begin
+                FEventNumber:=(i-low(FEPBs))*MAXEVENTSPEREPB+j;
+                FEventCount:=FCounts[j];
+                Synchronize(@DoEventAlert);
+                end;
+            end;
+          FEPBs[i].bStartup:=false;
+          QueueEvents(DBHandle,i);
+          end;
+      end;
+    if terminated or FCancelAlerts or not FParent.Connection.Connected then
+      break;
+  end;
+  // unregister events
+  if FParent.Connection.Connected then   // Don't do this if connection is gone
+    for i:=0 to high(FEPBs) do
+      begin
+      isc_cancel_events(@FStatus[0],@DBHandle,@FEPBs[i].EventID);
+      isc_free(FEPBs[i].EventBuf);   //points to unreachable memory if connection gone
+      isc_free(FEPBs[i].ResultBuf);
+      CheckError(FStatus);
+      end;
+  SetLength(FEPBs,0);
+  FSignal.destroy;
+  FParent.FRegistered :=false;
+end;
+
+procedure TFBEventsThread.QueueEvents(DBHandle:pointer;block: integer);
+begin
+  isc_que_events(@FStatus[0], @DBHandle, @FEPBs[block].EventID, Short(FEPBs[block].Len),
+    FEPBs[block].EventBuf,TISC_CALLBACK(@event_function), @FEPBs[block]);
+  CheckError(FStatus);
+end;
+
+constructor TFBEventsThread.Create(Parent: TFBEventMonitor);
+begin
+  FParent:=Parent;
+  FSignal:=TSimpleEvent.Create();
+  inherited create(false);
+end;
+
+procedure TFBEventsThread.DoTerminate;
+begin
+  if not Terminated then
+    begin
+    Terminate;
+    FSignal.SetEvent;
+    end;
+end;
+
+{ TFBEventMonitor }
+
+
+function TFBEventMonitor.GetNativeHandle: PISC_DB_HANDLE;
+begin
+  result:=THandleIBConnection(FConnection).GetDBHandle;
+end;
+
+
+procedure TFBEventMonitor.SetConnection(AValue: TIBConnection);
+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 TFBEventMonitor.SetEvents(AValue: TStrings);
+begin
+  FEvents.Assign(AValue);
+end;
+
+procedure TFBEventMonitor.SetRegistered(AValue: Boolean);
+begin
+  FRegistered := AValue;
+  if not (csDesigning in ComponentState) then
+    if AValue then
+      RegisterEvents
+    else
+      UnRegisterEvents;
+end;
+
+constructor TFBEventMonitor.Create(AOwner: TComponent);
+begin
+  inherited Create(AOwner);
+  FEvents:=TStringList.Create;
+  {$IfDef LinkDynamically}
+  InitialiseIBase60;             // stick to library in case connection closes before us
+  {$EndIf}
+end;
+
+destructor TFBEventMonitor.Destroy;
+begin
+  if FRegistered then
+    UnRegisterEvents;
+  if assigned(FConnection) then
+    FConnection.RemoveFreeNotification(self);
+  FEvents.Free;
+  {$IfDef LinkDynamically}
+  ReleaseIBase60;
+  {$EndIf}
+  inherited Destroy;
+end;
+
+procedure TFBEventMonitor.RegisterEvents;
+begin
+  If not assigned(FConnection) then
+    DatabaseError(SErrNoDatabaseAvailable,Self);
+  if not(csDesigning in ComponentState) and not FRegistered and (Events.Count>0) then
+    begin
+    if not Connection.Connected then
+       Connection.Connected:=true;
+    if Connection.Connected then
+      begin
+      FEventsThread:=TFBEventsThread.Create(Self);
+      FEventsThread.FreeOnTerminate:=true;
+      FRegistered :=assigned(FEventsThread);
+      end;
+    end;
+end;
+
+procedure TFBEventMonitor.UnRegisterEvents;
+begin
+  if not (csDesigning in ComponentState) and FRegistered then
+    begin
+    TFBEventsThread(FEventsThread).DoTerminate;
+    FEventsThread.WaitFor;
+    FRegistered :=false;
+    end;
+end;
+
+end.
+

+ 3 - 0
packages/fcl-db/src/sqldb/interbase/fpmake.inc

@@ -12,4 +12,7 @@ T.ResourceStrings:=True;
 T:=Targets.AddUnit('fbadmin');
 T.Dependencies.Add('ibconnection');
 T.ResourceStrings:=True;
+T:=Targets.AddUnit('fbeventmonitor');
+T.Dependencies.Add('ibconnection');
+T.ResourceStrings:=True;