Browse Source

* regenerated to support auto rtl compiling

peter 25 năm trước cách đây
mục cha
commit
fc6ef73478
62 tập tin đã thay đổi với 2510 bổ sung1079 xóa
  1. 43 13
      api/Makefile
  2. 47 17
      api/go32v2/Makefile
  3. 47 17
      api/linux/Makefile
  4. 47 17
      api/win32/Makefile
  5. 43 13
      base/Makefile
  6. 2 2
      bugs/readme.txt
  7. 59 27
      compiler/Makefile
  8. 12 10
      compiler/Makefile.fpc
  9. 47 21
      compiler/new/Makefile
  10. 4 3
      compiler/utils/samplecfg
  11. 43 13
      fcl/Makefile
  12. 46 22
      fcl/db/Makefile
  13. 46 22
      fcl/go32v2/Makefile
  14. 46 22
      fcl/linux/Makefile
  15. 46 22
      fcl/os2/Makefile
  16. 47 23
      fcl/shedit/Makefile
  17. 46 22
      fcl/tests/Makefile
  18. 46 22
      fcl/win32/Makefile
  19. 43 13
      ide/Makefile
  20. 43 13
      ide/fake/Makefile
  21. 51 13
      ide/fake/compiler/Makefile
  22. 51 13
      ide/fake/gdb/Makefile
  23. 46 22
      ide/text/Makefile
  24. 47 17
      install/Makefile
  25. 46 22
      install/demo/Makefile
  26. 47 17
      install/fpinst/Makefile
  27. 43 13
      packages/Makefile
  28. 46 22
      packages/forms/Makefile
  29. 46 22
      packages/forms/demo/Makefile
  30. 47 17
      packages/gdbint/Makefile
  31. 43 13
      packages/gdbint/libgdb/Makefile
  32. 47 17
      packages/ggi/Makefile
  33. 47 17
      packages/gtk/Makefile
  34. 47 21
      packages/gtk/examples/Makefile
  35. 47 21
      packages/gtk/tutorial/Makefile
  36. 47 17
      packages/ibase/Makefile
  37. 47 17
      packages/inet/Makefile
  38. 47 17
      packages/mysql/Makefile
  39. 47 17
      packages/ncurses/Makefile
  40. 43 13
      packages/opengl/Makefile
  41. 46 22
      packages/opengl/build/Makefile
  42. 46 22
      packages/opengl/examples/Makefile
  43. 46 22
      packages/opengl/linux/Makefile
  44. 47 17
      packages/paszlib/Makefile
  45. 47 17
      packages/postgres/Makefile
  46. 47 17
      packages/svgalib/Makefile
  47. 47 17
      packages/uncgi/Makefile
  48. 47 17
      packages/utmp/Makefile
  49. 47 17
      packages/x11/Makefile
  50. 47 17
      packages/zlib/Makefile
  51. 43 13
      rtl/Makefile
  52. 0 22
      rtl/go32v1/Makefile
  53. 0 22
      rtl/go32v2/Makefile
  54. 0 22
      rtl/linux/Makefile
  55. 0 22
      rtl/os2/Makefile
  56. 0 22
      rtl/win32/Makefile
  57. 43 13
      tests/Makefile
  58. 79 23
      utils/Makefile
  59. 2 2
      utils/Makefile.fpc
  60. 47 17
      utils/h2pas/Makefile
  61. 47 17
      utils/simulator/Makefile
  62. 47 17
      utils/tply/Makefile

+ 43 - 13
api/Makefile

@@ -129,7 +129,15 @@ endif
 ifndef COMPONENTDIR
 COMPONENTDIR=$(FPCDIR)/components
 endif
-# Check if packagedir really exists else turn it off
+# Create units dir
+ifneq ($(FPCDIR),.)
+UNITSDIR=$(FPCDIR)/units/$(OS_TARGET)
+endif
+
+# Check if the dirs really exists, else turn it off
+ifeq ($(wildcard $(UNITSDIR)),)
+UNITSDIR=
+endif
 ifeq ($(wildcard $(PACKAGEDIR)),)
 PACKAGEDIR=
 endif
@@ -137,16 +145,6 @@ ifeq ($(wildcard $(COMPONENTDIR)),)
 COMPONENTDIR=
 endif
 
-# Create rtl,units dir
-ifneq ($(FPCDIR),.)
-override UNITSDIR=$(FPCDIR)/units/$(OS_TARGET)
-ifneq ($(wildcard $(FPCDIR)/rtl),)
-override RTLDIR=$(FPCDIR)/rtl/$(OS_TARGET)
-else
-override RTLDIR=$(UNITSDIR)/rtl
-endif
-endif
-
 #####################################################################
 # Default Settings
 #####################################################################
@@ -189,8 +187,29 @@ ZIPTARGET=install
 
 # Packages
 
-override PACKAGES=rtl
+override PACKAGES+=rtl
+ifneq ($(wildcard $(FPCDIR)/rtl),)
+ifneq ($(wildcard $(FPCDIR)/rtl/$(OS_TARGET)),)
 PACKAGEDIR_RTL=$(FPCDIR)/rtl/$(OS_TARGET)
+else
+PACKAGEDIR_RTL=$(FPCDIR)/rtl
+endif
+UNITDIR_RTL=$(PACKAGEDIR_RTL)
+else
+PACKAGEDIR_RTL=
+ifneq ($(wildcard $(UNITSDIR)/rtl),)
+ifneq ($(wildcard $(UNITSDIR)/rtl/$(OS_TARGET)),)
+UNITDIR_RTL=$(UNITSDIR)/rtl/$(OS_TARGET)
+else
+UNITDIR_RTL=$(UNITSDIR)/rtl
+endif
+else
+UNITDIR_RTL=
+endif
+endif
+ifdef UNITDIR_RTL
+override NEEDUNITDIR+=$(UNITDIR_RTL)
+endif
 
 # Libraries
 
@@ -242,7 +261,18 @@ endif
 endif
 endif
 
-.PHONY:  rtl_package
+PACKAGERTL=1
+ifdef PACKAGERTL
+ifneq ($(wildcard $(PACKAGEDIR_RTL)),)
+ifeq ($(wildcard $(PACKAGEDIR_RTL)/$(FPCMADE)),)
+override COMPILEPACKAGES+=rtl
+rtl_package:
+	$(MAKE) -C $(PACKAGEDIR_RTL) all
+endif
+endif
+endif
+
+.PHONY:  rtl_package rtl_package
 
 
 # Target Dirs

+ 47 - 17
api/go32v2/Makefile

@@ -143,7 +143,15 @@ endif
 ifndef COMPONENTDIR
 COMPONENTDIR=$(FPCDIR)/components
 endif
-# Check if packagedir really exists else turn it off
+# Create units dir
+ifneq ($(FPCDIR),.)
+UNITSDIR=$(FPCDIR)/units/$(OS_TARGET)
+endif
+
+# Check if the dirs really exists, else turn it off
+ifeq ($(wildcard $(UNITSDIR)),)
+UNITSDIR=
+endif
 ifeq ($(wildcard $(PACKAGEDIR)),)
 PACKAGEDIR=
 endif
@@ -151,16 +159,6 @@ ifeq ($(wildcard $(COMPONENTDIR)),)
 COMPONENTDIR=
 endif
 
-# Create rtl,units dir
-ifneq ($(FPCDIR),.)
-override UNITSDIR=$(FPCDIR)/units/$(OS_TARGET)
-ifneq ($(wildcard $(FPCDIR)/rtl),)
-override RTLDIR=$(FPCDIR)/rtl/$(OS_TARGET)
-else
-override RTLDIR=$(UNITSDIR)/rtl
-endif
-endif
-
 #####################################################################
 # Default Settings
 #####################################################################
@@ -219,8 +217,29 @@ endif
 
 # Packages
 
-override PACKAGES=rtl
+override PACKAGES+=rtl
+ifneq ($(wildcard $(FPCDIR)/rtl),)
+ifneq ($(wildcard $(FPCDIR)/rtl/$(OS_TARGET)),)
 PACKAGEDIR_RTL=$(FPCDIR)/rtl/$(OS_TARGET)
+else
+PACKAGEDIR_RTL=$(FPCDIR)/rtl
+endif
+UNITDIR_RTL=$(PACKAGEDIR_RTL)
+else
+PACKAGEDIR_RTL=
+ifneq ($(wildcard $(UNITSDIR)/rtl),)
+ifneq ($(wildcard $(UNITSDIR)/rtl/$(OS_TARGET)),)
+UNITDIR_RTL=$(UNITSDIR)/rtl/$(OS_TARGET)
+else
+UNITDIR_RTL=$(UNITSDIR)/rtl
+endif
+else
+UNITDIR_RTL=
+endif
+endif
+ifdef UNITDIR_RTL
+override NEEDUNITDIR+=$(UNITDIR_RTL)
+endif
 
 # Libraries
 
@@ -326,12 +345,12 @@ ifneq ($(OS_TARGET),$(OS_SOURCE))
 override FPCOPT+=-T$(OS_TARGET)
 endif
 
-ifdef UNITSDIR
-override FPCOPT+=-Fu$(UNITSDIR)
+ifdef NEEDUNITDIR
+override FPCOPT+=$(addprefix -Fu,$(NEEDUNITDIR))
 endif
 
-ifdef RTLDIR
-override FPCOPT+=-Fu$(RTLDIR)
+ifdef UNITSDIR
+override FPCOPT+=-Fu$(UNITSDIR)
 endif
 
 # Target dirs
@@ -734,7 +753,18 @@ endif
 endif
 endif
 
-.PHONY:  rtl_package
+PACKAGERTL=1
+ifdef PACKAGERTL
+ifneq ($(wildcard $(PACKAGEDIR_RTL)),)
+ifeq ($(wildcard $(PACKAGEDIR_RTL)/$(FPCMADE)),)
+override COMPILEPACKAGES+=rtl
+rtl_package:
+	$(MAKE) -C $(PACKAGEDIR_RTL) all
+endif
+endif
+endif
+
+.PHONY:  rtl_package rtl_package
 
 #####################################################################
 # Units

+ 47 - 17
api/linux/Makefile

@@ -143,7 +143,15 @@ endif
 ifndef COMPONENTDIR
 COMPONENTDIR=$(FPCDIR)/components
 endif
-# Check if packagedir really exists else turn it off
+# Create units dir
+ifneq ($(FPCDIR),.)
+UNITSDIR=$(FPCDIR)/units/$(OS_TARGET)
+endif
+
+# Check if the dirs really exists, else turn it off
+ifeq ($(wildcard $(UNITSDIR)),)
+UNITSDIR=
+endif
 ifeq ($(wildcard $(PACKAGEDIR)),)
 PACKAGEDIR=
 endif
@@ -151,16 +159,6 @@ ifeq ($(wildcard $(COMPONENTDIR)),)
 COMPONENTDIR=
 endif
 
-# Create rtl,units dir
-ifneq ($(FPCDIR),.)
-override UNITSDIR=$(FPCDIR)/units/$(OS_TARGET)
-ifneq ($(wildcard $(FPCDIR)/rtl),)
-override RTLDIR=$(FPCDIR)/rtl/$(OS_TARGET)
-else
-override RTLDIR=$(UNITSDIR)/rtl
-endif
-endif
-
 #####################################################################
 # Default Settings
 #####################################################################
@@ -219,8 +217,29 @@ endif
 
 # Packages
 
-override PACKAGES=rtl
+override PACKAGES+=rtl
+ifneq ($(wildcard $(FPCDIR)/rtl),)
+ifneq ($(wildcard $(FPCDIR)/rtl/$(OS_TARGET)),)
 PACKAGEDIR_RTL=$(FPCDIR)/rtl/$(OS_TARGET)
+else
+PACKAGEDIR_RTL=$(FPCDIR)/rtl
+endif
+UNITDIR_RTL=$(PACKAGEDIR_RTL)
+else
+PACKAGEDIR_RTL=
+ifneq ($(wildcard $(UNITSDIR)/rtl),)
+ifneq ($(wildcard $(UNITSDIR)/rtl/$(OS_TARGET)),)
+UNITDIR_RTL=$(UNITSDIR)/rtl/$(OS_TARGET)
+else
+UNITDIR_RTL=$(UNITSDIR)/rtl
+endif
+else
+UNITDIR_RTL=
+endif
+endif
+ifdef UNITDIR_RTL
+override NEEDUNITDIR+=$(UNITDIR_RTL)
+endif
 
 # Libraries
 
@@ -326,12 +345,12 @@ ifneq ($(OS_TARGET),$(OS_SOURCE))
 override FPCOPT+=-T$(OS_TARGET)
 endif
 
-ifdef UNITSDIR
-override FPCOPT+=-Fu$(UNITSDIR)
+ifdef NEEDUNITDIR
+override FPCOPT+=$(addprefix -Fu,$(NEEDUNITDIR))
 endif
 
-ifdef RTLDIR
-override FPCOPT+=-Fu$(RTLDIR)
+ifdef UNITSDIR
+override FPCOPT+=-Fu$(UNITSDIR)
 endif
 
 # Target dirs
@@ -734,7 +753,18 @@ endif
 endif
 endif
 
-.PHONY:  rtl_package
+PACKAGERTL=1
+ifdef PACKAGERTL
+ifneq ($(wildcard $(PACKAGEDIR_RTL)),)
+ifeq ($(wildcard $(PACKAGEDIR_RTL)/$(FPCMADE)),)
+override COMPILEPACKAGES+=rtl
+rtl_package:
+	$(MAKE) -C $(PACKAGEDIR_RTL) all
+endif
+endif
+endif
+
+.PHONY:  rtl_package rtl_package
 
 #####################################################################
 # Units

+ 47 - 17
api/win32/Makefile

@@ -143,7 +143,15 @@ endif
 ifndef COMPONENTDIR
 COMPONENTDIR=$(FPCDIR)/components
 endif
-# Check if packagedir really exists else turn it off
+# Create units dir
+ifneq ($(FPCDIR),.)
+UNITSDIR=$(FPCDIR)/units/$(OS_TARGET)
+endif
+
+# Check if the dirs really exists, else turn it off
+ifeq ($(wildcard $(UNITSDIR)),)
+UNITSDIR=
+endif
 ifeq ($(wildcard $(PACKAGEDIR)),)
 PACKAGEDIR=
 endif
@@ -151,16 +159,6 @@ ifeq ($(wildcard $(COMPONENTDIR)),)
 COMPONENTDIR=
 endif
 
-# Create rtl,units dir
-ifneq ($(FPCDIR),.)
-override UNITSDIR=$(FPCDIR)/units/$(OS_TARGET)
-ifneq ($(wildcard $(FPCDIR)/rtl),)
-override RTLDIR=$(FPCDIR)/rtl/$(OS_TARGET)
-else
-override RTLDIR=$(UNITSDIR)/rtl
-endif
-endif
-
 #####################################################################
 # Default Settings
 #####################################################################
@@ -219,8 +217,29 @@ endif
 
 # Packages
 
-override PACKAGES=rtl
+override PACKAGES+=rtl
+ifneq ($(wildcard $(FPCDIR)/rtl),)
+ifneq ($(wildcard $(FPCDIR)/rtl/$(OS_TARGET)),)
 PACKAGEDIR_RTL=$(FPCDIR)/rtl/$(OS_TARGET)
+else
+PACKAGEDIR_RTL=$(FPCDIR)/rtl
+endif
+UNITDIR_RTL=$(PACKAGEDIR_RTL)
+else
+PACKAGEDIR_RTL=
+ifneq ($(wildcard $(UNITSDIR)/rtl),)
+ifneq ($(wildcard $(UNITSDIR)/rtl/$(OS_TARGET)),)
+UNITDIR_RTL=$(UNITSDIR)/rtl/$(OS_TARGET)
+else
+UNITDIR_RTL=$(UNITSDIR)/rtl
+endif
+else
+UNITDIR_RTL=
+endif
+endif
+ifdef UNITDIR_RTL
+override NEEDUNITDIR+=$(UNITDIR_RTL)
+endif
 
 # Libraries
 
@@ -326,12 +345,12 @@ ifneq ($(OS_TARGET),$(OS_SOURCE))
 override FPCOPT+=-T$(OS_TARGET)
 endif
 
-ifdef UNITSDIR
-override FPCOPT+=-Fu$(UNITSDIR)
+ifdef NEEDUNITDIR
+override FPCOPT+=$(addprefix -Fu,$(NEEDUNITDIR))
 endif
 
-ifdef RTLDIR
-override FPCOPT+=-Fu$(RTLDIR)
+ifdef UNITSDIR
+override FPCOPT+=-Fu$(UNITSDIR)
 endif
 
 # Target dirs
@@ -734,7 +753,18 @@ endif
 endif
 endif
 
-.PHONY:  rtl_package
+PACKAGERTL=1
+ifdef PACKAGERTL
+ifneq ($(wildcard $(PACKAGEDIR_RTL)),)
+ifeq ($(wildcard $(PACKAGEDIR_RTL)/$(FPCMADE)),)
+override COMPILEPACKAGES+=rtl
+rtl_package:
+	$(MAKE) -C $(PACKAGEDIR_RTL) all
+endif
+endif
+endif
+
+.PHONY:  rtl_package rtl_package
 
 #####################################################################
 # Units

+ 43 - 13
base/Makefile

@@ -137,7 +137,15 @@ endif
 ifndef COMPONENTDIR
 COMPONENTDIR=$(FPCDIR)/components
 endif
-# Check if packagedir really exists else turn it off
+# Create units dir
+ifneq ($(FPCDIR),.)
+UNITSDIR=$(FPCDIR)/units/$(OS_TARGET)
+endif
+
+# Check if the dirs really exists, else turn it off
+ifeq ($(wildcard $(UNITSDIR)),)
+UNITSDIR=
+endif
 ifeq ($(wildcard $(PACKAGEDIR)),)
 PACKAGEDIR=
 endif
@@ -145,16 +153,6 @@ ifeq ($(wildcard $(COMPONENTDIR)),)
 COMPONENTDIR=
 endif
 
-# Create rtl,units dir
-ifneq ($(FPCDIR),.)
-override UNITSDIR=$(FPCDIR)/units/$(OS_TARGET)
-ifneq ($(wildcard $(FPCDIR)/rtl),)
-override RTLDIR=$(FPCDIR)/rtl/$(OS_TARGET)
-else
-override RTLDIR=$(UNITSDIR)/rtl
-endif
-endif
-
 #####################################################################
 # Default Settings
 #####################################################################
@@ -197,8 +195,29 @@ ZIPTARGET=install
 
 # Packages
 
-override PACKAGES=rtl
+override PACKAGES+=rtl
+ifneq ($(wildcard $(FPCDIR)/rtl),)
+ifneq ($(wildcard $(FPCDIR)/rtl/$(OS_TARGET)),)
 PACKAGEDIR_RTL=$(FPCDIR)/rtl/$(OS_TARGET)
+else
+PACKAGEDIR_RTL=$(FPCDIR)/rtl
+endif
+UNITDIR_RTL=$(PACKAGEDIR_RTL)
+else
+PACKAGEDIR_RTL=
+ifneq ($(wildcard $(UNITSDIR)/rtl),)
+ifneq ($(wildcard $(UNITSDIR)/rtl/$(OS_TARGET)),)
+UNITDIR_RTL=$(UNITSDIR)/rtl/$(OS_TARGET)
+else
+UNITDIR_RTL=$(UNITSDIR)/rtl
+endif
+else
+UNITDIR_RTL=
+endif
+endif
+ifdef UNITDIR_RTL
+override NEEDUNITDIR+=$(UNITDIR_RTL)
+endif
 
 # Libraries
 
@@ -619,7 +638,18 @@ endif
 endif
 endif
 
-.PHONY:  rtl_package
+PACKAGERTL=1
+ifdef PACKAGERTL
+ifneq ($(wildcard $(PACKAGEDIR_RTL)),)
+ifeq ($(wildcard $(PACKAGEDIR_RTL)/$(FPCMADE)),)
+override COMPILEPACKAGES+=rtl
+rtl_package:
+	$(MAKE) -C $(PACKAGEDIR_RTL) all
+endif
+endif
+endif
+
+.PHONY:  rtl_package rtl_package
 
 
 # Target Dirs

+ 2 - 2
bugs/readme.txt

@@ -360,6 +360,8 @@ Fixed bugs:
   bug0301.pp   crash if destructor without object name is parsed    OK 0.99.13 (PFV)
   bug0302.pp   inherited property generates wrong assembler         OK 0.99.13 (PFV)
   bug0303.pp   One more InternalError(10) out of register !         OK 0.99.13 (FK)
+  bug0304.pp   Label redefined when inlining assembler              OK 0.99.13 (PFV)
+  bug0306.pp   Address is not popped with exit in try...except block OK 0.99.13 (PFV)
 
 
 Unproducable bugs:
@@ -393,6 +395,4 @@ Unfixed bugs:
 bug0262.pp   problems with virtual and overloaded methods
 bug0293.pp   no error with variable name = type name
 bug0299.pp   passing Array[0..1] of char by value to proc leads to problems
-bug0304.pp   Label redefined when inlining assembler
 bug0305.pp   Finally is not handled correctly after inputting 0
-bug0306.pp   Address is not popped with exit in try...except block

+ 59 - 27
compiler/Makefile

@@ -137,7 +137,15 @@ endif
 ifndef COMPONENTDIR
 COMPONENTDIR=$(FPCDIR)/components
 endif
-# Check if packagedir really exists else turn it off
+# Create units dir
+ifneq ($(FPCDIR),.)
+UNITSDIR=$(FPCDIR)/units/$(OS_TARGET)
+endif
+
+# Check if the dirs really exists, else turn it off
+ifeq ($(wildcard $(UNITSDIR)),)
+UNITSDIR=
+endif
 ifeq ($(wildcard $(PACKAGEDIR)),)
 PACKAGEDIR=
 endif
@@ -145,16 +153,6 @@ ifeq ($(wildcard $(COMPONENTDIR)),)
 COMPONENTDIR=
 endif
 
-# Create rtl,units dir
-ifneq ($(FPCDIR),.)
-override UNITSDIR=$(FPCDIR)/units/$(OS_TARGET)
-ifneq ($(wildcard $(FPCDIR)/rtl),)
-override RTLDIR=$(FPCDIR)/rtl/$(OS_TARGET)
-else
-override RTLDIR=$(UNITSDIR)/rtl
-endif
-endif
-
 #####################################################################
 # Default Settings
 #####################################################################
@@ -248,8 +246,29 @@ endif
 
 # Packages
 
-override PACKAGES=rtl
+override PACKAGES+=rtl
+ifneq ($(wildcard $(FPCDIR)/rtl),)
+ifneq ($(wildcard $(FPCDIR)/rtl/$(OS_TARGET)),)
 PACKAGEDIR_RTL=$(FPCDIR)/rtl/$(OS_TARGET)
+else
+PACKAGEDIR_RTL=$(FPCDIR)/rtl
+endif
+UNITDIR_RTL=$(PACKAGEDIR_RTL)
+else
+PACKAGEDIR_RTL=
+ifneq ($(wildcard $(UNITSDIR)/rtl),)
+ifneq ($(wildcard $(UNITSDIR)/rtl/$(OS_TARGET)),)
+UNITDIR_RTL=$(UNITSDIR)/rtl/$(OS_TARGET)
+else
+UNITDIR_RTL=$(UNITSDIR)/rtl
+endif
+else
+UNITDIR_RTL=
+endif
+endif
+ifdef UNITDIR_RTL
+override NEEDUNITDIR+=$(UNITDIR_RTL)
+endif
 
 # Libraries
 
@@ -380,12 +399,12 @@ ifdef NEEDOPT
 override FPCOPT+=$(NEEDOPT)
 endif
 
-ifdef UNITSDIR
-override FPCOPT+=-Fu$(UNITSDIR)
+ifdef NEEDUNITDIR
+override FPCOPT+=$(addprefix -Fu,$(NEEDUNITDIR))
 endif
 
-ifdef RTLDIR
-override FPCOPT+=-Fu$(RTLDIR)
+ifdef UNITSDIR
+override FPCOPT+=-Fu$(UNITSDIR)
 endif
 
 # Target dirs
@@ -800,7 +819,18 @@ endif
 endif
 endif
 
-.PHONY:  rtl_package
+PACKAGERTL=1
+ifdef PACKAGERTL
+ifneq ($(wildcard $(PACKAGEDIR_RTL)),)
+ifeq ($(wildcard $(PACKAGEDIR_RTL)/$(FPCMADE)),)
+override COMPILEPACKAGES+=rtl
+rtl_package:
+	$(MAKE) -C $(PACKAGEDIR_RTL) all
+endif
+endif
+endif
+
+.PHONY:  rtl_package rtl_package
 
 #####################################################################
 # General compile rules
@@ -1172,8 +1202,8 @@ next :
 else
 next :
 	$(MAKE) execlean
-	$(MAKE) -C $(RTLDIR) clean
-	$(MAKE) -C $(RTLDIR) 'FPC=$(FPC)' 'OPT=$(RTLOPTS)' all
+	$(MAKE) -C $(UNITDIR_RTL) clean
+	$(MAKE) -C $(UNITDIR_RTL) 'FPC=$(FPC)' 'OPT=$(RTLOPTS)' all
 	$(MAKE) clean
 	$(MAKE) all
 endif
@@ -1245,7 +1275,7 @@ tokens.dat : $(wildcard *.pas) $(wildcard *.inc)
 remake: $(EXENAME)
 	$(MOVE) $(EXENAME) $(TEMPNAME)
 	$(MAKE) execlean
-	$(MAKE) -C $(RTLDIR) clean
+	$(MAKE) -C $(UNITDIR_RTL) clean
 	$(MAKE) clean
 	$(MAKE) 'FPC=$(BASEDIR)/$(TEMPNAME)' all
 
@@ -1269,8 +1299,8 @@ $(TEMPNAME3) : $(TEMPNAME2)
 
 cycle:
 	$(MAKE) clean
-	$(MAKE) -C $(RTLDIR) clean
-	$(MAKE) -C $(RTLDIR) 'OPT=$(RTLOPTS)' all
+	$(MAKE) -C $(UNITDIR_RTL) clean
+	$(MAKE) -C $(UNITDIR_RTL) 'OPT=$(RTLOPTS)' all
 	$(MAKE) remake3
 	$(MAKE) echotime
 
@@ -1319,14 +1349,16 @@ endif
 # Misc
 #####################################################################
 
-rtl :
-	$(MAKE) -C $(RTLDIR) all
+.PHONY: rtl rtlclean rtlinstall
+
+rtl:
+	$(MAKE) -C $(UNITDIR_RTL) all
 
-rtlclean :
-	$(MAKE) -C $(RTLDIR) clean
+rtlclean:
+	$(MAKE) -C $(UNITDIR_RTL) clean
 
 rtlinstall:
-	$(MAKE) -C $(RTLDIR) install
+	$(MAKE) -C $(UNITDIR_RTL) install
 
 #####################################################################
 # local user configurable file

+ 12 - 10
compiler/Makefile.fpc

@@ -157,8 +157,8 @@ next :
 else
 next :
         $(MAKE) execlean
-        $(MAKE) -C $(RTLDIR) clean
-        $(MAKE) -C $(RTLDIR) 'FPC=$(FPC)' 'OPT=$(RTLOPTS)' all
+        $(MAKE) -C $(UNITDIR_RTL) clean
+        $(MAKE) -C $(UNITDIR_RTL) 'FPC=$(FPC)' 'OPT=$(RTLOPTS)' all
         $(MAKE) clean
         $(MAKE) all
 endif
@@ -230,7 +230,7 @@ tokens.dat : $(wildcard *.pas) $(wildcard *.inc)
 remake: $(EXENAME)
         $(MOVE) $(EXENAME) $(TEMPNAME)
         $(MAKE) execlean
-        $(MAKE) -C $(RTLDIR) clean
+        $(MAKE) -C $(UNITDIR_RTL) clean
         $(MAKE) clean
         $(MAKE) 'FPC=$(BASEDIR)/$(TEMPNAME)' all
 
@@ -254,8 +254,8 @@ $(TEMPNAME3) : $(TEMPNAME2)
 
 cycle:
         $(MAKE) clean
-        $(MAKE) -C $(RTLDIR) clean
-        $(MAKE) -C $(RTLDIR) 'OPT=$(RTLOPTS)' all
+        $(MAKE) -C $(UNITDIR_RTL) clean
+        $(MAKE) -C $(UNITDIR_RTL) 'OPT=$(RTLOPTS)' all
         $(MAKE) remake3
         $(MAKE) echotime
 
@@ -304,14 +304,16 @@ endif
 # Misc
 #####################################################################
 
-rtl :
-        $(MAKE) -C $(RTLDIR) all
+.PHONY: rtl rtlclean rtlinstall
 
-rtlclean :
-        $(MAKE) -C $(RTLDIR) clean
+rtl:
+        $(MAKE) -C $(UNITDIR_RTL) all
+
+rtlclean:
+        $(MAKE) -C $(UNITDIR_RTL) clean
 
 rtlinstall:
-        $(MAKE) -C $(RTLDIR) install
+        $(MAKE) -C $(UNITDIR_RTL) install
 
 #####################################################################
 # local user configurable file

+ 47 - 21
compiler/new/Makefile

@@ -137,7 +137,15 @@ endif
 ifndef COMPONENTDIR
 COMPONENTDIR=$(FPCDIR)/components
 endif
-# Check if packagedir really exists else turn it off
+# Create units dir
+ifneq ($(FPCDIR),.)
+UNITSDIR=$(FPCDIR)/units/$(OS_TARGET)
+endif
+
+# Check if the dirs really exists, else turn it off
+ifeq ($(wildcard $(UNITSDIR)),)
+UNITSDIR=
+endif
 ifeq ($(wildcard $(PACKAGEDIR)),)
 PACKAGEDIR=
 endif
@@ -145,16 +153,6 @@ ifeq ($(wildcard $(COMPONENTDIR)),)
 COMPONENTDIR=
 endif
 
-# Create rtl,units dir
-ifneq ($(FPCDIR),.)
-override UNITSDIR=$(FPCDIR)/units/$(OS_TARGET)
-ifneq ($(wildcard $(FPCDIR)/rtl),)
-override RTLDIR=$(FPCDIR)/rtl/$(OS_TARGET)
-else
-override RTLDIR=$(UNITSDIR)/rtl
-endif
-endif
-
 #####################################################################
 # Default Settings
 #####################################################################
@@ -265,8 +263,29 @@ endif
 
 # Packages
 
-override PACKAGES=rtl
+override PACKAGES+=rtl
+ifneq ($(wildcard $(FPCDIR)/rtl),)
+ifneq ($(wildcard $(FPCDIR)/rtl/$(OS_TARGET)),)
 PACKAGEDIR_RTL=$(FPCDIR)/rtl/$(OS_TARGET)
+else
+PACKAGEDIR_RTL=$(FPCDIR)/rtl
+endif
+UNITDIR_RTL=$(PACKAGEDIR_RTL)
+else
+PACKAGEDIR_RTL=
+ifneq ($(wildcard $(UNITSDIR)/rtl),)
+ifneq ($(wildcard $(UNITSDIR)/rtl/$(OS_TARGET)),)
+UNITDIR_RTL=$(UNITSDIR)/rtl/$(OS_TARGET)
+else
+UNITDIR_RTL=$(UNITSDIR)/rtl
+endif
+else
+UNITDIR_RTL=
+endif
+endif
+ifdef UNITDIR_RTL
+override NEEDUNITDIR+=$(UNITDIR_RTL)
+endif
 
 # Libraries
 
@@ -397,18 +416,14 @@ ifdef NEEDOPT
 override FPCOPT+=$(NEEDOPT)
 endif
 
-ifdef UNITSDIR
-override FPCOPT+=-Fu$(UNITSDIR)
-endif
-
-ifdef RTLDIR
-override FPCOPT+=-Fu$(RTLDIR)
-endif
-
 ifdef NEEDUNITDIR
 override FPCOPT+=$(addprefix -Fu,$(NEEDUNITDIR))
 endif
 
+ifdef UNITSDIR
+override FPCOPT+=-Fu$(UNITSDIR)
+endif
+
 ifdef NEEDINCDIR
 override FPCOPT+=$(addprefix -Fi,$(NEEDINCDIR))
 endif
@@ -826,7 +841,18 @@ endif
 endif
 endif
 
-.PHONY:  rtl_package
+PACKAGERTL=1
+ifdef PACKAGERTL
+ifneq ($(wildcard $(PACKAGEDIR_RTL)),)
+ifeq ($(wildcard $(PACKAGEDIR_RTL)/$(FPCMADE)),)
+override COMPILEPACKAGES+=rtl
+rtl_package:
+	$(MAKE) -C $(PACKAGEDIR_RTL) all
+endif
+endif
+endif
+
+.PHONY:  rtl_package rtl_package
 
 #####################################################################
 # General compile rules

+ 4 - 3
compiler/utils/samplecfg

@@ -150,9 +150,10 @@ cat <<EOFCFG > $thefile
 #-Fi/pp/inc;/pp/rtl/inc
 
 # searchpath for units and other system dependent things
--Fu$1/rtl/$target/
--Fu$1/units/$target
-#-Fu~/fpc/units;~/fpc/rtl/linux
+-Fu$1/units/\$target
+-Fu$1/units/\$target/*
+-Fu$1/units/\$target/rtl
+#-Fu~/fpc/packages/*;~/fpc/rtl/linux
 
 # searchpath for libraries
 -Fl$GCCDIR

+ 43 - 13
fcl/Makefile

@@ -129,7 +129,15 @@ endif
 ifndef COMPONENTDIR
 COMPONENTDIR=$(FPCDIR)/components
 endif
-# Check if packagedir really exists else turn it off
+# Create units dir
+ifneq ($(FPCDIR),.)
+UNITSDIR=$(FPCDIR)/units/$(OS_TARGET)
+endif
+
+# Check if the dirs really exists, else turn it off
+ifeq ($(wildcard $(UNITSDIR)),)
+UNITSDIR=
+endif
 ifeq ($(wildcard $(PACKAGEDIR)),)
 PACKAGEDIR=
 endif
@@ -137,16 +145,6 @@ ifeq ($(wildcard $(COMPONENTDIR)),)
 COMPONENTDIR=
 endif
 
-# Create rtl,units dir
-ifneq ($(FPCDIR),.)
-override UNITSDIR=$(FPCDIR)/units/$(OS_TARGET)
-ifneq ($(wildcard $(FPCDIR)/rtl),)
-override RTLDIR=$(FPCDIR)/rtl/$(OS_TARGET)
-else
-override RTLDIR=$(UNITSDIR)/rtl
-endif
-endif
-
 #####################################################################
 # Default Settings
 #####################################################################
@@ -189,8 +187,29 @@ ZIPTARGET=install
 
 # Packages
 
-override PACKAGES=rtl
+override PACKAGES+=rtl
+ifneq ($(wildcard $(FPCDIR)/rtl),)
+ifneq ($(wildcard $(FPCDIR)/rtl/$(OS_TARGET)),)
 PACKAGEDIR_RTL=$(FPCDIR)/rtl/$(OS_TARGET)
+else
+PACKAGEDIR_RTL=$(FPCDIR)/rtl
+endif
+UNITDIR_RTL=$(PACKAGEDIR_RTL)
+else
+PACKAGEDIR_RTL=
+ifneq ($(wildcard $(UNITSDIR)/rtl),)
+ifneq ($(wildcard $(UNITSDIR)/rtl/$(OS_TARGET)),)
+UNITDIR_RTL=$(UNITSDIR)/rtl/$(OS_TARGET)
+else
+UNITDIR_RTL=$(UNITSDIR)/rtl
+endif
+else
+UNITDIR_RTL=
+endif
+endif
+ifdef UNITDIR_RTL
+override NEEDUNITDIR+=$(UNITDIR_RTL)
+endif
 
 # Libraries
 
@@ -242,7 +261,18 @@ endif
 endif
 endif
 
-.PHONY:  rtl_package
+PACKAGERTL=1
+ifdef PACKAGERTL
+ifneq ($(wildcard $(PACKAGEDIR_RTL)),)
+ifeq ($(wildcard $(PACKAGEDIR_RTL)/$(FPCMADE)),)
+override COMPILEPACKAGES+=rtl
+rtl_package:
+	$(MAKE) -C $(PACKAGEDIR_RTL) all
+endif
+endif
+endif
+
+.PHONY:  rtl_package rtl_package
 
 
 # Target Dirs

+ 46 - 22
fcl/db/Makefile

@@ -143,7 +143,15 @@ endif
 ifndef COMPONENTDIR
 COMPONENTDIR=$(FPCDIR)/components
 endif
-# Check if packagedir really exists else turn it off
+# Create units dir
+ifneq ($(FPCDIR),.)
+UNITSDIR=$(FPCDIR)/units/$(OS_TARGET)
+endif
+
+# Check if the dirs really exists, else turn it off
+ifeq ($(wildcard $(UNITSDIR)),)
+UNITSDIR=
+endif
 ifeq ($(wildcard $(PACKAGEDIR)),)
 PACKAGEDIR=
 endif
@@ -151,16 +159,6 @@ ifeq ($(wildcard $(COMPONENTDIR)),)
 COMPONENTDIR=
 endif
 
-# Create rtl,units dir
-ifneq ($(FPCDIR),.)
-override UNITSDIR=$(FPCDIR)/units/$(OS_TARGET)
-ifneq ($(wildcard $(FPCDIR)/rtl),)
-override RTLDIR=$(FPCDIR)/rtl/$(OS_TARGET)
-else
-override RTLDIR=$(UNITSDIR)/rtl
-endif
-endif
-
 #####################################################################
 # Default Settings
 #####################################################################
@@ -208,9 +206,29 @@ endif
 
 # Packages
 
-override PACKAGES=rtl
+override PACKAGES+=rtl fcl mysql
+ifneq ($(wildcard $(FPCDIR)/rtl),)
+ifneq ($(wildcard $(FPCDIR)/rtl/$(OS_TARGET)),)
 PACKAGEDIR_RTL=$(FPCDIR)/rtl/$(OS_TARGET)
-override PACKAGES+=fcl mysql
+else
+PACKAGEDIR_RTL=$(FPCDIR)/rtl
+endif
+UNITDIR_RTL=$(PACKAGEDIR_RTL)
+else
+PACKAGEDIR_RTL=
+ifneq ($(wildcard $(UNITSDIR)/rtl),)
+ifneq ($(wildcard $(UNITSDIR)/rtl/$(OS_TARGET)),)
+UNITDIR_RTL=$(UNITSDIR)/rtl/$(OS_TARGET)
+else
+UNITDIR_RTL=$(UNITSDIR)/rtl
+endif
+else
+UNITDIR_RTL=
+endif
+endif
+ifdef UNITDIR_RTL
+override NEEDUNITDIR+=$(UNITDIR_RTL)
+endif
 ifneq ($(wildcard $(FPCDIR)/fcl),)
 ifneq ($(wildcard $(FPCDIR)/fcl/$(OS_TARGET)),)
 PACKAGEDIR_FCL=$(FPCDIR)/fcl/$(OS_TARGET)
@@ -372,18 +390,14 @@ ifdef NEEDOPT
 override FPCOPT+=$(NEEDOPT)
 endif
 
-ifdef UNITSDIR
-override FPCOPT+=-Fu$(UNITSDIR)
-endif
-
-ifdef RTLDIR
-override FPCOPT+=-Fu$(RTLDIR)
-endif
-
 ifdef NEEDUNITDIR
 override FPCOPT+=$(addprefix -Fu,$(NEEDUNITDIR))
 endif
 
+ifdef UNITSDIR
+override FPCOPT+=-Fu$(UNITSDIR)
+endif
+
 # Add GCC lib path if asked
 ifdef GCCLIBDIR
 override FPCOPT+=-Fl$(GCCLIBDIR)
@@ -789,8 +803,18 @@ endif
 endif
 endif
 
+PACKAGERTL=1
 PACKAGEFCL=1
 PACKAGEMYSQL=1
+ifdef PACKAGERTL
+ifneq ($(wildcard $(PACKAGEDIR_RTL)),)
+ifeq ($(wildcard $(PACKAGEDIR_RTL)/$(FPCMADE)),)
+override COMPILEPACKAGES+=rtl
+rtl_package:
+	$(MAKE) -C $(PACKAGEDIR_RTL) all
+endif
+endif
+endif
 ifdef PACKAGEFCL
 ifneq ($(wildcard $(PACKAGEDIR_FCL)),)
 ifeq ($(wildcard $(PACKAGEDIR_FCL)/$(FPCMADE)),)
@@ -810,7 +834,7 @@ endif
 endif
 endif
 
-.PHONY:  rtl_package fcl_package mysql_package
+.PHONY:  rtl_package rtl_package fcl_package mysql_package
 
 #####################################################################
 # Units

+ 46 - 22
fcl/go32v2/Makefile

@@ -143,7 +143,15 @@ endif
 ifndef COMPONENTDIR
 COMPONENTDIR=$(FPCDIR)/components
 endif
-# Check if packagedir really exists else turn it off
+# Create units dir
+ifneq ($(FPCDIR),.)
+UNITSDIR=$(FPCDIR)/units/$(OS_TARGET)
+endif
+
+# Check if the dirs really exists, else turn it off
+ifeq ($(wildcard $(UNITSDIR)),)
+UNITSDIR=
+endif
 ifeq ($(wildcard $(PACKAGEDIR)),)
 PACKAGEDIR=
 endif
@@ -151,16 +159,6 @@ ifeq ($(wildcard $(COMPONENTDIR)),)
 COMPONENTDIR=
 endif
 
-# Create rtl,units dir
-ifneq ($(FPCDIR),.)
-override UNITSDIR=$(FPCDIR)/units/$(OS_TARGET)
-ifneq ($(wildcard $(FPCDIR)/rtl),)
-override RTLDIR=$(FPCDIR)/rtl/$(OS_TARGET)
-else
-override RTLDIR=$(UNITSDIR)/rtl
-endif
-endif
-
 #####################################################################
 # Default Settings
 #####################################################################
@@ -223,9 +221,29 @@ endif
 
 # Packages
 
-override PACKAGES=rtl
+override PACKAGES+=rtl paszlib
+ifneq ($(wildcard $(FPCDIR)/rtl),)
+ifneq ($(wildcard $(FPCDIR)/rtl/$(OS_TARGET)),)
 PACKAGEDIR_RTL=$(FPCDIR)/rtl/$(OS_TARGET)
-override PACKAGES+=paszlib
+else
+PACKAGEDIR_RTL=$(FPCDIR)/rtl
+endif
+UNITDIR_RTL=$(PACKAGEDIR_RTL)
+else
+PACKAGEDIR_RTL=
+ifneq ($(wildcard $(UNITSDIR)/rtl),)
+ifneq ($(wildcard $(UNITSDIR)/rtl/$(OS_TARGET)),)
+UNITDIR_RTL=$(UNITSDIR)/rtl/$(OS_TARGET)
+else
+UNITDIR_RTL=$(UNITSDIR)/rtl
+endif
+else
+UNITDIR_RTL=
+endif
+endif
+ifdef UNITDIR_RTL
+override NEEDUNITDIR+=$(UNITDIR_RTL)
+endif
 ifneq ($(wildcard $(PACKAGEDIR)/paszlib),)
 ifneq ($(wildcard $(PACKAGEDIR)/paszlib/$(OS_TARGET)),)
 PACKAGEDIR_PASZLIB=$(PACKAGEDIR)/paszlib/$(OS_TARGET)
@@ -357,18 +375,14 @@ ifdef NEEDOPT
 override FPCOPT+=$(NEEDOPT)
 endif
 
-ifdef UNITSDIR
-override FPCOPT+=-Fu$(UNITSDIR)
-endif
-
-ifdef RTLDIR
-override FPCOPT+=-Fu$(RTLDIR)
-endif
-
 ifdef NEEDUNITDIR
 override FPCOPT+=$(addprefix -Fu,$(NEEDUNITDIR))
 endif
 
+ifdef UNITSDIR
+override FPCOPT+=-Fu$(UNITSDIR)
+endif
+
 ifdef NEEDINCDIR
 override FPCOPT+=$(addprefix -Fi,$(NEEDINCDIR))
 endif
@@ -770,7 +784,17 @@ endif
 endif
 endif
 
+PACKAGERTL=1
 PACKAGEPASZLIB=1
+ifdef PACKAGERTL
+ifneq ($(wildcard $(PACKAGEDIR_RTL)),)
+ifeq ($(wildcard $(PACKAGEDIR_RTL)/$(FPCMADE)),)
+override COMPILEPACKAGES+=rtl
+rtl_package:
+	$(MAKE) -C $(PACKAGEDIR_RTL) all
+endif
+endif
+endif
 ifdef PACKAGEPASZLIB
 ifneq ($(wildcard $(PACKAGEDIR_PASZLIB)),)
 ifeq ($(wildcard $(PACKAGEDIR_PASZLIB)/$(FPCMADE)),)
@@ -781,7 +805,7 @@ endif
 endif
 endif
 
-.PHONY:  rtl_package paszlib_package
+.PHONY:  rtl_package rtl_package paszlib_package
 
 #####################################################################
 # Units

+ 46 - 22
fcl/linux/Makefile

@@ -143,7 +143,15 @@ endif
 ifndef COMPONENTDIR
 COMPONENTDIR=$(FPCDIR)/components
 endif
-# Check if packagedir really exists else turn it off
+# Create units dir
+ifneq ($(FPCDIR),.)
+UNITSDIR=$(FPCDIR)/units/$(OS_TARGET)
+endif
+
+# Check if the dirs really exists, else turn it off
+ifeq ($(wildcard $(UNITSDIR)),)
+UNITSDIR=
+endif
 ifeq ($(wildcard $(PACKAGEDIR)),)
 PACKAGEDIR=
 endif
@@ -151,16 +159,6 @@ ifeq ($(wildcard $(COMPONENTDIR)),)
 COMPONENTDIR=
 endif
 
-# Create rtl,units dir
-ifneq ($(FPCDIR),.)
-override UNITSDIR=$(FPCDIR)/units/$(OS_TARGET)
-ifneq ($(wildcard $(FPCDIR)/rtl),)
-override RTLDIR=$(FPCDIR)/rtl/$(OS_TARGET)
-else
-override RTLDIR=$(UNITSDIR)/rtl
-endif
-endif
-
 #####################################################################
 # Default Settings
 #####################################################################
@@ -223,9 +221,29 @@ endif
 
 # Packages
 
-override PACKAGES=rtl
+override PACKAGES+=rtl zlib
+ifneq ($(wildcard $(FPCDIR)/rtl),)
+ifneq ($(wildcard $(FPCDIR)/rtl/$(OS_TARGET)),)
 PACKAGEDIR_RTL=$(FPCDIR)/rtl/$(OS_TARGET)
-override PACKAGES+=zlib
+else
+PACKAGEDIR_RTL=$(FPCDIR)/rtl
+endif
+UNITDIR_RTL=$(PACKAGEDIR_RTL)
+else
+PACKAGEDIR_RTL=
+ifneq ($(wildcard $(UNITSDIR)/rtl),)
+ifneq ($(wildcard $(UNITSDIR)/rtl/$(OS_TARGET)),)
+UNITDIR_RTL=$(UNITSDIR)/rtl/$(OS_TARGET)
+else
+UNITDIR_RTL=$(UNITSDIR)/rtl
+endif
+else
+UNITDIR_RTL=
+endif
+endif
+ifdef UNITDIR_RTL
+override NEEDUNITDIR+=$(UNITDIR_RTL)
+endif
 ifneq ($(wildcard $(PACKAGEDIR)/zlib),)
 ifneq ($(wildcard $(PACKAGEDIR)/zlib/$(OS_TARGET)),)
 PACKAGEDIR_ZLIB=$(PACKAGEDIR)/zlib/$(OS_TARGET)
@@ -357,18 +375,14 @@ ifdef NEEDOPT
 override FPCOPT+=$(NEEDOPT)
 endif
 
-ifdef UNITSDIR
-override FPCOPT+=-Fu$(UNITSDIR)
-endif
-
-ifdef RTLDIR
-override FPCOPT+=-Fu$(RTLDIR)
-endif
-
 ifdef NEEDUNITDIR
 override FPCOPT+=$(addprefix -Fu,$(NEEDUNITDIR))
 endif
 
+ifdef UNITSDIR
+override FPCOPT+=-Fu$(UNITSDIR)
+endif
+
 ifdef NEEDINCDIR
 override FPCOPT+=$(addprefix -Fi,$(NEEDINCDIR))
 endif
@@ -770,7 +784,17 @@ endif
 endif
 endif
 
+PACKAGERTL=1
 PACKAGEZLIB=1
+ifdef PACKAGERTL
+ifneq ($(wildcard $(PACKAGEDIR_RTL)),)
+ifeq ($(wildcard $(PACKAGEDIR_RTL)/$(FPCMADE)),)
+override COMPILEPACKAGES+=rtl
+rtl_package:
+	$(MAKE) -C $(PACKAGEDIR_RTL) all
+endif
+endif
+endif
 ifdef PACKAGEZLIB
 ifneq ($(wildcard $(PACKAGEDIR_ZLIB)),)
 ifeq ($(wildcard $(PACKAGEDIR_ZLIB)/$(FPCMADE)),)
@@ -781,7 +805,7 @@ endif
 endif
 endif
 
-.PHONY:  rtl_package zlib_package
+.PHONY:  rtl_package rtl_package zlib_package
 
 #####################################################################
 # Units

+ 46 - 22
fcl/os2/Makefile

@@ -143,7 +143,15 @@ endif
 ifndef COMPONENTDIR
 COMPONENTDIR=$(FPCDIR)/components
 endif
-# Check if packagedir really exists else turn it off
+# Create units dir
+ifneq ($(FPCDIR),.)
+UNITSDIR=$(FPCDIR)/units/$(OS_TARGET)
+endif
+
+# Check if the dirs really exists, else turn it off
+ifeq ($(wildcard $(UNITSDIR)),)
+UNITSDIR=
+endif
 ifeq ($(wildcard $(PACKAGEDIR)),)
 PACKAGEDIR=
 endif
@@ -151,16 +159,6 @@ ifeq ($(wildcard $(COMPONENTDIR)),)
 COMPONENTDIR=
 endif
 
-# Create rtl,units dir
-ifneq ($(FPCDIR),.)
-override UNITSDIR=$(FPCDIR)/units/$(OS_TARGET)
-ifneq ($(wildcard $(FPCDIR)/rtl),)
-override RTLDIR=$(FPCDIR)/rtl/$(OS_TARGET)
-else
-override RTLDIR=$(UNITSDIR)/rtl
-endif
-endif
-
 #####################################################################
 # Default Settings
 #####################################################################
@@ -223,9 +221,29 @@ endif
 
 # Packages
 
-override PACKAGES=rtl
+override PACKAGES+=rtl paszlib
+ifneq ($(wildcard $(FPCDIR)/rtl),)
+ifneq ($(wildcard $(FPCDIR)/rtl/$(OS_TARGET)),)
 PACKAGEDIR_RTL=$(FPCDIR)/rtl/$(OS_TARGET)
-override PACKAGES+=paszlib
+else
+PACKAGEDIR_RTL=$(FPCDIR)/rtl
+endif
+UNITDIR_RTL=$(PACKAGEDIR_RTL)
+else
+PACKAGEDIR_RTL=
+ifneq ($(wildcard $(UNITSDIR)/rtl),)
+ifneq ($(wildcard $(UNITSDIR)/rtl/$(OS_TARGET)),)
+UNITDIR_RTL=$(UNITSDIR)/rtl/$(OS_TARGET)
+else
+UNITDIR_RTL=$(UNITSDIR)/rtl
+endif
+else
+UNITDIR_RTL=
+endif
+endif
+ifdef UNITDIR_RTL
+override NEEDUNITDIR+=$(UNITDIR_RTL)
+endif
 ifneq ($(wildcard $(PACKAGEDIR)/paszlib),)
 ifneq ($(wildcard $(PACKAGEDIR)/paszlib/$(OS_TARGET)),)
 PACKAGEDIR_PASZLIB=$(PACKAGEDIR)/paszlib/$(OS_TARGET)
@@ -357,18 +375,14 @@ ifdef NEEDOPT
 override FPCOPT+=$(NEEDOPT)
 endif
 
-ifdef UNITSDIR
-override FPCOPT+=-Fu$(UNITSDIR)
-endif
-
-ifdef RTLDIR
-override FPCOPT+=-Fu$(RTLDIR)
-endif
-
 ifdef NEEDUNITDIR
 override FPCOPT+=$(addprefix -Fu,$(NEEDUNITDIR))
 endif
 
+ifdef UNITSDIR
+override FPCOPT+=-Fu$(UNITSDIR)
+endif
+
 ifdef NEEDINCDIR
 override FPCOPT+=$(addprefix -Fi,$(NEEDINCDIR))
 endif
@@ -770,7 +784,17 @@ endif
 endif
 endif
 
+PACKAGERTL=1
 PACKAGEPASZLIB=1
+ifdef PACKAGERTL
+ifneq ($(wildcard $(PACKAGEDIR_RTL)),)
+ifeq ($(wildcard $(PACKAGEDIR_RTL)/$(FPCMADE)),)
+override COMPILEPACKAGES+=rtl
+rtl_package:
+	$(MAKE) -C $(PACKAGEDIR_RTL) all
+endif
+endif
+endif
 ifdef PACKAGEPASZLIB
 ifneq ($(wildcard $(PACKAGEDIR_PASZLIB)),)
 ifeq ($(wildcard $(PACKAGEDIR_PASZLIB)/$(FPCMADE)),)
@@ -781,7 +805,7 @@ endif
 endif
 endif
 
-.PHONY:  rtl_package paszlib_package
+.PHONY:  rtl_package rtl_package paszlib_package
 
 #####################################################################
 # Units

+ 47 - 23
fcl/shedit/Makefile

@@ -137,7 +137,15 @@ endif
 ifndef COMPONENTDIR
 COMPONENTDIR=$(FPCDIR)/components
 endif
-# Check if packagedir really exists else turn it off
+# Create units dir
+ifneq ($(FPCDIR),.)
+UNITSDIR=$(FPCDIR)/units/$(OS_TARGET)
+endif
+
+# Check if the dirs really exists, else turn it off
+ifeq ($(wildcard $(UNITSDIR)),)
+UNITSDIR=
+endif
 ifeq ($(wildcard $(PACKAGEDIR)),)
 PACKAGEDIR=
 endif
@@ -145,16 +153,6 @@ ifeq ($(wildcard $(COMPONENTDIR)),)
 COMPONENTDIR=
 endif
 
-# Create rtl,units dir
-ifneq ($(FPCDIR),.)
-override UNITSDIR=$(FPCDIR)/units/$(OS_TARGET)
-ifneq ($(wildcard $(FPCDIR)/rtl),)
-override RTLDIR=$(FPCDIR)/rtl/$(OS_TARGET)
-else
-override RTLDIR=$(UNITSDIR)/rtl
-endif
-endif
-
 #####################################################################
 # Default Settings
 #####################################################################
@@ -209,15 +207,35 @@ endif
 
 # Packages
 
-override PACKAGES=rtl
-PACKAGEDIR_RTL=$(FPCDIR)/rtl/$(OS_TARGET)
-override PACKAGES+=fcl
+override PACKAGES+=rtl fcl
 ifeq ($(OS_TARGET),linux)
 override PACKAGES+=gtk
 endif
 ifeq ($(OS_TARGET),win32)
 override PACKAGES+=gtk
 endif
+ifneq ($(wildcard $(FPCDIR)/rtl),)
+ifneq ($(wildcard $(FPCDIR)/rtl/$(OS_TARGET)),)
+PACKAGEDIR_RTL=$(FPCDIR)/rtl/$(OS_TARGET)
+else
+PACKAGEDIR_RTL=$(FPCDIR)/rtl
+endif
+UNITDIR_RTL=$(PACKAGEDIR_RTL)
+else
+PACKAGEDIR_RTL=
+ifneq ($(wildcard $(UNITSDIR)/rtl),)
+ifneq ($(wildcard $(UNITSDIR)/rtl/$(OS_TARGET)),)
+UNITDIR_RTL=$(UNITSDIR)/rtl/$(OS_TARGET)
+else
+UNITDIR_RTL=$(UNITSDIR)/rtl
+endif
+else
+UNITDIR_RTL=
+endif
+endif
+ifdef UNITDIR_RTL
+override NEEDUNITDIR+=$(UNITDIR_RTL)
+endif
 ifneq ($(wildcard $(FPCDIR)/fcl),)
 ifneq ($(wildcard $(FPCDIR)/fcl/$(OS_TARGET)),)
 PACKAGEDIR_FCL=$(FPCDIR)/fcl/$(OS_TARGET)
@@ -388,18 +406,14 @@ ifneq ($(OS_TARGET),$(OS_SOURCE))
 override FPCOPT+=-T$(OS_TARGET)
 endif
 
-ifdef UNITSDIR
-override FPCOPT+=-Fu$(UNITSDIR)
-endif
-
-ifdef RTLDIR
-override FPCOPT+=-Fu$(RTLDIR)
-endif
-
 ifdef NEEDUNITDIR
 override FPCOPT+=$(addprefix -Fu,$(NEEDUNITDIR))
 endif
 
+ifdef UNITSDIR
+override FPCOPT+=-Fu$(UNITSDIR)
+endif
+
 # Target dirs
 ifdef TARGETDIR
 override FPCOPT+=-FE$(TARGETDIR)
@@ -796,6 +810,7 @@ endif
 endif
 endif
 
+PACKAGERTL=1
 PACKAGEFCL=1
 ifeq ($(OS_TARGET),linux)
 PACKAGEGTK=1
@@ -803,6 +818,15 @@ endif
 ifeq ($(OS_TARGET),win32)
 PACKAGEGTK=1
 endif
+ifdef PACKAGERTL
+ifneq ($(wildcard $(PACKAGEDIR_RTL)),)
+ifeq ($(wildcard $(PACKAGEDIR_RTL)/$(FPCMADE)),)
+override COMPILEPACKAGES+=rtl
+rtl_package:
+	$(MAKE) -C $(PACKAGEDIR_RTL) all
+endif
+endif
+endif
 ifdef PACKAGEFCL
 ifneq ($(wildcard $(PACKAGEDIR_FCL)),)
 ifeq ($(wildcard $(PACKAGEDIR_FCL)/$(FPCMADE)),)
@@ -822,7 +846,7 @@ endif
 endif
 endif
 
-.PHONY:  rtl_package fcl_package gtk_package
+.PHONY:  rtl_package rtl_package fcl_package gtk_package
 
 #####################################################################
 # Units

+ 46 - 22
fcl/tests/Makefile

@@ -137,7 +137,15 @@ endif
 ifndef COMPONENTDIR
 COMPONENTDIR=$(FPCDIR)/components
 endif
-# Check if packagedir really exists else turn it off
+# Create units dir
+ifneq ($(FPCDIR),.)
+UNITSDIR=$(FPCDIR)/units/$(OS_TARGET)
+endif
+
+# Check if the dirs really exists, else turn it off
+ifeq ($(wildcard $(UNITSDIR)),)
+UNITSDIR=
+endif
 ifeq ($(wildcard $(PACKAGEDIR)),)
 PACKAGEDIR=
 endif
@@ -145,16 +153,6 @@ ifeq ($(wildcard $(COMPONENTDIR)),)
 COMPONENTDIR=
 endif
 
-# Create rtl,units dir
-ifneq ($(FPCDIR),.)
-override UNITSDIR=$(FPCDIR)/units/$(OS_TARGET)
-ifneq ($(wildcard $(FPCDIR)/rtl),)
-override RTLDIR=$(FPCDIR)/rtl/$(OS_TARGET)
-else
-override RTLDIR=$(UNITSDIR)/rtl
-endif
-endif
-
 #####################################################################
 # Default Settings
 #####################################################################
@@ -202,9 +200,29 @@ endif
 
 # Packages
 
-override PACKAGES=rtl
+override PACKAGES+=rtl fcl
+ifneq ($(wildcard $(FPCDIR)/rtl),)
+ifneq ($(wildcard $(FPCDIR)/rtl/$(OS_TARGET)),)
 PACKAGEDIR_RTL=$(FPCDIR)/rtl/$(OS_TARGET)
-override PACKAGES+=fcl
+else
+PACKAGEDIR_RTL=$(FPCDIR)/rtl
+endif
+UNITDIR_RTL=$(PACKAGEDIR_RTL)
+else
+PACKAGEDIR_RTL=
+ifneq ($(wildcard $(UNITSDIR)/rtl),)
+ifneq ($(wildcard $(UNITSDIR)/rtl/$(OS_TARGET)),)
+UNITDIR_RTL=$(UNITSDIR)/rtl/$(OS_TARGET)
+else
+UNITDIR_RTL=$(UNITSDIR)/rtl
+endif
+else
+UNITDIR_RTL=
+endif
+endif
+ifdef UNITDIR_RTL
+override NEEDUNITDIR+=$(UNITDIR_RTL)
+endif
 ifneq ($(wildcard $(FPCDIR)/fcl),)
 ifneq ($(wildcard $(FPCDIR)/fcl/$(OS_TARGET)),)
 PACKAGEDIR_FCL=$(FPCDIR)/fcl/$(OS_TARGET)
@@ -335,18 +353,14 @@ ifdef NEEDOPT
 override FPCOPT+=$(NEEDOPT)
 endif
 
-ifdef UNITSDIR
-override FPCOPT+=-Fu$(UNITSDIR)
-endif
-
-ifdef RTLDIR
-override FPCOPT+=-Fu$(RTLDIR)
-endif
-
 ifdef NEEDUNITDIR
 override FPCOPT+=$(addprefix -Fu,$(NEEDUNITDIR))
 endif
 
+ifdef UNITSDIR
+override FPCOPT+=-Fu$(UNITSDIR)
+endif
+
 # Target dirs
 ifdef TARGETDIR
 override FPCOPT+=-FE$(TARGETDIR)
@@ -743,7 +757,17 @@ endif
 endif
 endif
 
+PACKAGERTL=1
 PACKAGEFCL=1
+ifdef PACKAGERTL
+ifneq ($(wildcard $(PACKAGEDIR_RTL)),)
+ifeq ($(wildcard $(PACKAGEDIR_RTL)/$(FPCMADE)),)
+override COMPILEPACKAGES+=rtl
+rtl_package:
+	$(MAKE) -C $(PACKAGEDIR_RTL) all
+endif
+endif
+endif
 ifdef PACKAGEFCL
 ifneq ($(wildcard $(PACKAGEDIR_FCL)),)
 ifeq ($(wildcard $(PACKAGEDIR_FCL)/$(FPCMADE)),)
@@ -754,7 +778,7 @@ endif
 endif
 endif
 
-.PHONY:  rtl_package fcl_package
+.PHONY:  rtl_package rtl_package fcl_package
 
 #####################################################################
 # Exes

+ 46 - 22
fcl/win32/Makefile

@@ -143,7 +143,15 @@ endif
 ifndef COMPONENTDIR
 COMPONENTDIR=$(FPCDIR)/components
 endif
-# Check if packagedir really exists else turn it off
+# Create units dir
+ifneq ($(FPCDIR),.)
+UNITSDIR=$(FPCDIR)/units/$(OS_TARGET)
+endif
+
+# Check if the dirs really exists, else turn it off
+ifeq ($(wildcard $(UNITSDIR)),)
+UNITSDIR=
+endif
 ifeq ($(wildcard $(PACKAGEDIR)),)
 PACKAGEDIR=
 endif
@@ -151,16 +159,6 @@ ifeq ($(wildcard $(COMPONENTDIR)),)
 COMPONENTDIR=
 endif
 
-# Create rtl,units dir
-ifneq ($(FPCDIR),.)
-override UNITSDIR=$(FPCDIR)/units/$(OS_TARGET)
-ifneq ($(wildcard $(FPCDIR)/rtl),)
-override RTLDIR=$(FPCDIR)/rtl/$(OS_TARGET)
-else
-override RTLDIR=$(UNITSDIR)/rtl
-endif
-endif
-
 #####################################################################
 # Default Settings
 #####################################################################
@@ -223,9 +221,29 @@ endif
 
 # Packages
 
-override PACKAGES=rtl
+override PACKAGES+=rtl paszlib
+ifneq ($(wildcard $(FPCDIR)/rtl),)
+ifneq ($(wildcard $(FPCDIR)/rtl/$(OS_TARGET)),)
 PACKAGEDIR_RTL=$(FPCDIR)/rtl/$(OS_TARGET)
-override PACKAGES+=paszlib
+else
+PACKAGEDIR_RTL=$(FPCDIR)/rtl
+endif
+UNITDIR_RTL=$(PACKAGEDIR_RTL)
+else
+PACKAGEDIR_RTL=
+ifneq ($(wildcard $(UNITSDIR)/rtl),)
+ifneq ($(wildcard $(UNITSDIR)/rtl/$(OS_TARGET)),)
+UNITDIR_RTL=$(UNITSDIR)/rtl/$(OS_TARGET)
+else
+UNITDIR_RTL=$(UNITSDIR)/rtl
+endif
+else
+UNITDIR_RTL=
+endif
+endif
+ifdef UNITDIR_RTL
+override NEEDUNITDIR+=$(UNITDIR_RTL)
+endif
 ifneq ($(wildcard $(PACKAGEDIR)/paszlib),)
 ifneq ($(wildcard $(PACKAGEDIR)/paszlib/$(OS_TARGET)),)
 PACKAGEDIR_PASZLIB=$(PACKAGEDIR)/paszlib/$(OS_TARGET)
@@ -357,18 +375,14 @@ ifdef NEEDOPT
 override FPCOPT+=$(NEEDOPT)
 endif
 
-ifdef UNITSDIR
-override FPCOPT+=-Fu$(UNITSDIR)
-endif
-
-ifdef RTLDIR
-override FPCOPT+=-Fu$(RTLDIR)
-endif
-
 ifdef NEEDUNITDIR
 override FPCOPT+=$(addprefix -Fu,$(NEEDUNITDIR))
 endif
 
+ifdef UNITSDIR
+override FPCOPT+=-Fu$(UNITSDIR)
+endif
+
 ifdef NEEDINCDIR
 override FPCOPT+=$(addprefix -Fi,$(NEEDINCDIR))
 endif
@@ -770,7 +784,17 @@ endif
 endif
 endif
 
+PACKAGERTL=1
 PACKAGEPASZLIB=1
+ifdef PACKAGERTL
+ifneq ($(wildcard $(PACKAGEDIR_RTL)),)
+ifeq ($(wildcard $(PACKAGEDIR_RTL)/$(FPCMADE)),)
+override COMPILEPACKAGES+=rtl
+rtl_package:
+	$(MAKE) -C $(PACKAGEDIR_RTL) all
+endif
+endif
+endif
 ifdef PACKAGEPASZLIB
 ifneq ($(wildcard $(PACKAGEDIR_PASZLIB)),)
 ifeq ($(wildcard $(PACKAGEDIR_PASZLIB)/$(FPCMADE)),)
@@ -781,7 +805,7 @@ endif
 endif
 endif
 
-.PHONY:  rtl_package paszlib_package
+.PHONY:  rtl_package rtl_package paszlib_package
 
 #####################################################################
 # Units

+ 43 - 13
ide/Makefile

@@ -129,7 +129,15 @@ endif
 ifndef COMPONENTDIR
 COMPONENTDIR=$(FPCDIR)/components
 endif
-# Check if packagedir really exists else turn it off
+# Create units dir
+ifneq ($(FPCDIR),.)
+UNITSDIR=$(FPCDIR)/units/$(OS_TARGET)
+endif
+
+# Check if the dirs really exists, else turn it off
+ifeq ($(wildcard $(UNITSDIR)),)
+UNITSDIR=
+endif
 ifeq ($(wildcard $(PACKAGEDIR)),)
 PACKAGEDIR=
 endif
@@ -137,16 +145,6 @@ ifeq ($(wildcard $(COMPONENTDIR)),)
 COMPONENTDIR=
 endif
 
-# Create rtl,units dir
-ifneq ($(FPCDIR),.)
-override UNITSDIR=$(FPCDIR)/units/$(OS_TARGET)
-ifneq ($(wildcard $(FPCDIR)/rtl),)
-override RTLDIR=$(FPCDIR)/rtl/$(OS_TARGET)
-else
-override RTLDIR=$(UNITSDIR)/rtl
-endif
-endif
-
 #####################################################################
 # Default Settings
 #####################################################################
@@ -189,8 +187,29 @@ ZIPTARGET=install
 
 # Packages
 
-override PACKAGES=rtl
+override PACKAGES+=rtl
+ifneq ($(wildcard $(FPCDIR)/rtl),)
+ifneq ($(wildcard $(FPCDIR)/rtl/$(OS_TARGET)),)
 PACKAGEDIR_RTL=$(FPCDIR)/rtl/$(OS_TARGET)
+else
+PACKAGEDIR_RTL=$(FPCDIR)/rtl
+endif
+UNITDIR_RTL=$(PACKAGEDIR_RTL)
+else
+PACKAGEDIR_RTL=
+ifneq ($(wildcard $(UNITSDIR)/rtl),)
+ifneq ($(wildcard $(UNITSDIR)/rtl/$(OS_TARGET)),)
+UNITDIR_RTL=$(UNITSDIR)/rtl/$(OS_TARGET)
+else
+UNITDIR_RTL=$(UNITSDIR)/rtl
+endif
+else
+UNITDIR_RTL=
+endif
+endif
+ifdef UNITDIR_RTL
+override NEEDUNITDIR+=$(UNITDIR_RTL)
+endif
 
 # Libraries
 
@@ -234,7 +253,18 @@ endif
 endif
 endif
 
-.PHONY:  rtl_package
+PACKAGERTL=1
+ifdef PACKAGERTL
+ifneq ($(wildcard $(PACKAGEDIR_RTL)),)
+ifeq ($(wildcard $(PACKAGEDIR_RTL)/$(FPCMADE)),)
+override COMPILEPACKAGES+=rtl
+rtl_package:
+	$(MAKE) -C $(PACKAGEDIR_RTL) all
+endif
+endif
+endif
+
+.PHONY:  rtl_package rtl_package
 
 
 # Target Dirs

+ 43 - 13
ide/fake/Makefile

@@ -129,7 +129,15 @@ endif
 ifndef COMPONENTDIR
 COMPONENTDIR=$(FPCDIR)/components
 endif
-# Check if packagedir really exists else turn it off
+# Create units dir
+ifneq ($(FPCDIR),.)
+UNITSDIR=$(FPCDIR)/units/$(OS_TARGET)
+endif
+
+# Check if the dirs really exists, else turn it off
+ifeq ($(wildcard $(UNITSDIR)),)
+UNITSDIR=
+endif
 ifeq ($(wildcard $(PACKAGEDIR)),)
 PACKAGEDIR=
 endif
@@ -137,16 +145,6 @@ ifeq ($(wildcard $(COMPONENTDIR)),)
 COMPONENTDIR=
 endif
 
-# Create rtl,units dir
-ifneq ($(FPCDIR),.)
-override UNITSDIR=$(FPCDIR)/units/$(OS_TARGET)
-ifneq ($(wildcard $(FPCDIR)/rtl),)
-override RTLDIR=$(FPCDIR)/rtl/$(OS_TARGET)
-else
-override RTLDIR=$(UNITSDIR)/rtl
-endif
-endif
-
 #####################################################################
 # Default Settings
 #####################################################################
@@ -189,8 +187,29 @@ ZIPTARGET=install
 
 # Packages
 
-override PACKAGES=rtl
+override PACKAGES+=rtl
+ifneq ($(wildcard $(FPCDIR)/rtl),)
+ifneq ($(wildcard $(FPCDIR)/rtl/$(OS_TARGET)),)
 PACKAGEDIR_RTL=$(FPCDIR)/rtl/$(OS_TARGET)
+else
+PACKAGEDIR_RTL=$(FPCDIR)/rtl
+endif
+UNITDIR_RTL=$(PACKAGEDIR_RTL)
+else
+PACKAGEDIR_RTL=
+ifneq ($(wildcard $(UNITSDIR)/rtl),)
+ifneq ($(wildcard $(UNITSDIR)/rtl/$(OS_TARGET)),)
+UNITDIR_RTL=$(UNITSDIR)/rtl/$(OS_TARGET)
+else
+UNITDIR_RTL=$(UNITSDIR)/rtl
+endif
+else
+UNITDIR_RTL=
+endif
+endif
+ifdef UNITDIR_RTL
+override NEEDUNITDIR+=$(UNITDIR_RTL)
+endif
 
 # Libraries
 
@@ -236,7 +255,18 @@ endif
 endif
 endif
 
-.PHONY:  rtl_package
+PACKAGERTL=1
+ifdef PACKAGERTL
+ifneq ($(wildcard $(PACKAGEDIR_RTL)),)
+ifeq ($(wildcard $(PACKAGEDIR_RTL)/$(FPCMADE)),)
+override COMPILEPACKAGES+=rtl
+rtl_package:
+	$(MAKE) -C $(PACKAGEDIR_RTL) all
+endif
+endif
+endif
+
+.PHONY:  rtl_package rtl_package
 
 
 # Target Dirs

+ 51 - 13
ide/fake/compiler/Makefile

@@ -129,7 +129,15 @@ endif
 ifndef COMPONENTDIR
 COMPONENTDIR=$(FPCDIR)/components
 endif
-# Check if packagedir really exists else turn it off
+# Create units dir
+ifneq ($(FPCDIR),.)
+UNITSDIR=$(FPCDIR)/units/$(OS_TARGET)
+endif
+
+# Check if the dirs really exists, else turn it off
+ifeq ($(wildcard $(UNITSDIR)),)
+UNITSDIR=
+endif
 ifeq ($(wildcard $(PACKAGEDIR)),)
 PACKAGEDIR=
 endif
@@ -137,16 +145,6 @@ ifeq ($(wildcard $(COMPONENTDIR)),)
 COMPONENTDIR=
 endif
 
-# Create rtl,units dir
-ifneq ($(FPCDIR),.)
-override UNITSDIR=$(FPCDIR)/units/$(OS_TARGET)
-ifneq ($(wildcard $(FPCDIR)/rtl),)
-override RTLDIR=$(FPCDIR)/rtl/$(OS_TARGET)
-else
-override RTLDIR=$(UNITSDIR)/rtl
-endif
-endif
-
 #####################################################################
 # Default Settings
 #####################################################################
@@ -189,8 +187,29 @@ ZIPTARGET=install
 
 # Packages
 
-override PACKAGES=rtl
+override PACKAGES+=rtl
+ifneq ($(wildcard $(FPCDIR)/rtl),)
+ifneq ($(wildcard $(FPCDIR)/rtl/$(OS_TARGET)),)
 PACKAGEDIR_RTL=$(FPCDIR)/rtl/$(OS_TARGET)
+else
+PACKAGEDIR_RTL=$(FPCDIR)/rtl
+endif
+UNITDIR_RTL=$(PACKAGEDIR_RTL)
+else
+PACKAGEDIR_RTL=
+ifneq ($(wildcard $(UNITSDIR)/rtl),)
+ifneq ($(wildcard $(UNITSDIR)/rtl/$(OS_TARGET)),)
+UNITDIR_RTL=$(UNITSDIR)/rtl/$(OS_TARGET)
+else
+UNITDIR_RTL=$(UNITSDIR)/rtl
+endif
+else
+UNITDIR_RTL=
+endif
+endif
+ifdef UNITDIR_RTL
+override NEEDUNITDIR+=$(UNITDIR_RTL)
+endif
 
 # Libraries
 
@@ -295,6 +314,14 @@ ifneq ($(OS_TARGET),$(OS_SOURCE))
 override FPCOPT+=-T$(OS_TARGET)
 endif
 
+ifdef NEEDUNITDIR
+override FPCOPT+=$(addprefix -Fu,$(NEEDUNITDIR))
+endif
+
+ifdef UNITSDIR
+override FPCOPT+=-Fu$(UNITSDIR)
+endif
+
 # Smartlinking
 ifdef SMARTLINK
 override FPCOPT+=-CX
@@ -686,7 +713,18 @@ endif
 endif
 endif
 
-.PHONY:  rtl_package
+PACKAGERTL=1
+ifdef PACKAGERTL
+ifneq ($(wildcard $(PACKAGEDIR_RTL)),)
+ifeq ($(wildcard $(PACKAGEDIR_RTL)/$(FPCMADE)),)
+override COMPILEPACKAGES+=rtl
+rtl_package:
+	$(MAKE) -C $(PACKAGEDIR_RTL) all
+endif
+endif
+endif
+
+.PHONY:  rtl_package rtl_package
 
 #####################################################################
 # Units

+ 51 - 13
ide/fake/gdb/Makefile

@@ -129,7 +129,15 @@ endif
 ifndef COMPONENTDIR
 COMPONENTDIR=$(FPCDIR)/components
 endif
-# Check if packagedir really exists else turn it off
+# Create units dir
+ifneq ($(FPCDIR),.)
+UNITSDIR=$(FPCDIR)/units/$(OS_TARGET)
+endif
+
+# Check if the dirs really exists, else turn it off
+ifeq ($(wildcard $(UNITSDIR)),)
+UNITSDIR=
+endif
 ifeq ($(wildcard $(PACKAGEDIR)),)
 PACKAGEDIR=
 endif
@@ -137,16 +145,6 @@ ifeq ($(wildcard $(COMPONENTDIR)),)
 COMPONENTDIR=
 endif
 
-# Create rtl,units dir
-ifneq ($(FPCDIR),.)
-override UNITSDIR=$(FPCDIR)/units/$(OS_TARGET)
-ifneq ($(wildcard $(FPCDIR)/rtl),)
-override RTLDIR=$(FPCDIR)/rtl/$(OS_TARGET)
-else
-override RTLDIR=$(UNITSDIR)/rtl
-endif
-endif
-
 #####################################################################
 # Default Settings
 #####################################################################
@@ -189,8 +187,29 @@ ZIPTARGET=install
 
 # Packages
 
-override PACKAGES=rtl
+override PACKAGES+=rtl
+ifneq ($(wildcard $(FPCDIR)/rtl),)
+ifneq ($(wildcard $(FPCDIR)/rtl/$(OS_TARGET)),)
 PACKAGEDIR_RTL=$(FPCDIR)/rtl/$(OS_TARGET)
+else
+PACKAGEDIR_RTL=$(FPCDIR)/rtl
+endif
+UNITDIR_RTL=$(PACKAGEDIR_RTL)
+else
+PACKAGEDIR_RTL=
+ifneq ($(wildcard $(UNITSDIR)/rtl),)
+ifneq ($(wildcard $(UNITSDIR)/rtl/$(OS_TARGET)),)
+UNITDIR_RTL=$(UNITSDIR)/rtl/$(OS_TARGET)
+else
+UNITDIR_RTL=$(UNITSDIR)/rtl
+endif
+else
+UNITDIR_RTL=
+endif
+endif
+ifdef UNITDIR_RTL
+override NEEDUNITDIR+=$(UNITDIR_RTL)
+endif
 
 # Libraries
 
@@ -295,6 +314,14 @@ ifneq ($(OS_TARGET),$(OS_SOURCE))
 override FPCOPT+=-T$(OS_TARGET)
 endif
 
+ifdef NEEDUNITDIR
+override FPCOPT+=$(addprefix -Fu,$(NEEDUNITDIR))
+endif
+
+ifdef UNITSDIR
+override FPCOPT+=-Fu$(UNITSDIR)
+endif
+
 # Smartlinking
 ifdef SMARTLINK
 override FPCOPT+=-CX
@@ -686,7 +713,18 @@ endif
 endif
 endif
 
-.PHONY:  rtl_package
+PACKAGERTL=1
+ifdef PACKAGERTL
+ifneq ($(wildcard $(PACKAGEDIR_RTL)),)
+ifeq ($(wildcard $(PACKAGEDIR_RTL)/$(FPCMADE)),)
+override COMPILEPACKAGES+=rtl
+rtl_package:
+	$(MAKE) -C $(PACKAGEDIR_RTL) all
+endif
+endif
+endif
+
+.PHONY:  rtl_package rtl_package
 
 #####################################################################
 # Units

+ 46 - 22
ide/text/Makefile

@@ -137,7 +137,15 @@ endif
 ifndef COMPONENTDIR
 COMPONENTDIR=$(FPCDIR)/components
 endif
-# Check if packagedir really exists else turn it off
+# Create units dir
+ifneq ($(FPCDIR),.)
+UNITSDIR=$(FPCDIR)/units/$(OS_TARGET)
+endif
+
+# Check if the dirs really exists, else turn it off
+ifeq ($(wildcard $(UNITSDIR)),)
+UNITSDIR=
+endif
 ifeq ($(wildcard $(PACKAGEDIR)),)
 PACKAGEDIR=
 endif
@@ -145,16 +153,6 @@ ifeq ($(wildcard $(COMPONENTDIR)),)
 COMPONENTDIR=
 endif
 
-# Create rtl,units dir
-ifneq ($(FPCDIR),.)
-override UNITSDIR=$(FPCDIR)/units/$(OS_TARGET)
-ifneq ($(wildcard $(FPCDIR)/rtl),)
-override RTLDIR=$(FPCDIR)/rtl/$(OS_TARGET)
-else
-override RTLDIR=$(UNITSDIR)/rtl
-endif
-endif
-
 #####################################################################
 # Default Settings
 #####################################################################
@@ -228,9 +226,29 @@ override NEEDOBJDIR=$(GDBOBJDIR)
 
 # Packages
 
-override PACKAGES=rtl
+override PACKAGES+=rtl api fv gdbint
+ifneq ($(wildcard $(FPCDIR)/rtl),)
+ifneq ($(wildcard $(FPCDIR)/rtl/$(OS_TARGET)),)
 PACKAGEDIR_RTL=$(FPCDIR)/rtl/$(OS_TARGET)
-override PACKAGES+=api fv gdbint
+else
+PACKAGEDIR_RTL=$(FPCDIR)/rtl
+endif
+UNITDIR_RTL=$(PACKAGEDIR_RTL)
+else
+PACKAGEDIR_RTL=
+ifneq ($(wildcard $(UNITSDIR)/rtl),)
+ifneq ($(wildcard $(UNITSDIR)/rtl/$(OS_TARGET)),)
+UNITDIR_RTL=$(UNITSDIR)/rtl/$(OS_TARGET)
+else
+UNITDIR_RTL=$(UNITSDIR)/rtl
+endif
+else
+UNITDIR_RTL=
+endif
+endif
+ifdef UNITDIR_RTL
+override NEEDUNITDIR+=$(UNITDIR_RTL)
+endif
 ifneq ($(wildcard $(FPCDIR)/api),)
 ifneq ($(wildcard $(FPCDIR)/api/$(OS_TARGET)),)
 PACKAGEDIR_API=$(FPCDIR)/api/$(OS_TARGET)
@@ -420,18 +438,14 @@ ifdef NEEDOPT
 override FPCOPT+=$(NEEDOPT)
 endif
 
-ifdef UNITSDIR
-override FPCOPT+=-Fu$(UNITSDIR)
-endif
-
-ifdef RTLDIR
-override FPCOPT+=-Fu$(RTLDIR)
-endif
-
 ifdef NEEDUNITDIR
 override FPCOPT+=$(addprefix -Fu,$(NEEDUNITDIR))
 endif
 
+ifdef UNITSDIR
+override FPCOPT+=-Fu$(UNITSDIR)
+endif
+
 ifdef NEEDLIBDIR
 override FPCOPT+=$(addprefix -Fl,$(NEEDLIBDIR))
 endif
@@ -832,9 +846,19 @@ endif
 endif
 endif
 
+PACKAGERTL=1
 PACKAGEAPI=1
 PACKAGEFV=1
 PACKAGEGDBINT=1
+ifdef PACKAGERTL
+ifneq ($(wildcard $(PACKAGEDIR_RTL)),)
+ifeq ($(wildcard $(PACKAGEDIR_RTL)/$(FPCMADE)),)
+override COMPILEPACKAGES+=rtl
+rtl_package:
+	$(MAKE) -C $(PACKAGEDIR_RTL) all
+endif
+endif
+endif
 ifdef PACKAGEAPI
 ifneq ($(wildcard $(PACKAGEDIR_API)),)
 ifeq ($(wildcard $(PACKAGEDIR_API)/$(FPCMADE)),)
@@ -863,7 +887,7 @@ endif
 endif
 endif
 
-.PHONY:  rtl_package api_package fv_package gdbint_package
+.PHONY:  rtl_package rtl_package api_package fv_package gdbint_package
 
 #####################################################################
 # Exes

+ 47 - 17
install/Makefile

@@ -137,7 +137,15 @@ endif
 ifndef COMPONENTDIR
 COMPONENTDIR=$(FPCDIR)/components
 endif
-# Check if packagedir really exists else turn it off
+# Create units dir
+ifneq ($(FPCDIR),.)
+UNITSDIR=$(FPCDIR)/units/$(OS_TARGET)
+endif
+
+# Check if the dirs really exists, else turn it off
+ifeq ($(wildcard $(UNITSDIR)),)
+UNITSDIR=
+endif
 ifeq ($(wildcard $(PACKAGEDIR)),)
 PACKAGEDIR=
 endif
@@ -145,16 +153,6 @@ ifeq ($(wildcard $(COMPONENTDIR)),)
 COMPONENTDIR=
 endif
 
-# Create rtl,units dir
-ifneq ($(FPCDIR),.)
-override UNITSDIR=$(FPCDIR)/units/$(OS_TARGET)
-ifneq ($(wildcard $(FPCDIR)/rtl),)
-override RTLDIR=$(FPCDIR)/rtl/$(OS_TARGET)
-else
-override RTLDIR=$(UNITSDIR)/rtl
-endif
-endif
-
 #####################################################################
 # Default Settings
 #####################################################################
@@ -224,8 +222,29 @@ ZIPTARGET=install
 
 # Packages
 
-override PACKAGES=rtl
+override PACKAGES+=rtl
+ifneq ($(wildcard $(FPCDIR)/rtl),)
+ifneq ($(wildcard $(FPCDIR)/rtl/$(OS_TARGET)),)
 PACKAGEDIR_RTL=$(FPCDIR)/rtl/$(OS_TARGET)
+else
+PACKAGEDIR_RTL=$(FPCDIR)/rtl
+endif
+UNITDIR_RTL=$(PACKAGEDIR_RTL)
+else
+PACKAGEDIR_RTL=
+ifneq ($(wildcard $(UNITSDIR)/rtl),)
+ifneq ($(wildcard $(UNITSDIR)/rtl/$(OS_TARGET)),)
+UNITDIR_RTL=$(UNITSDIR)/rtl/$(OS_TARGET)
+else
+UNITDIR_RTL=$(UNITSDIR)/rtl
+endif
+else
+UNITDIR_RTL=
+endif
+endif
+ifdef UNITDIR_RTL
+override NEEDUNITDIR+=$(UNITDIR_RTL)
+endif
 
 # Libraries
 
@@ -326,12 +345,12 @@ ifneq ($(OS_TARGET),$(OS_SOURCE))
 override FPCOPT+=-T$(OS_TARGET)
 endif
 
-ifdef UNITSDIR
-override FPCOPT+=-Fu$(UNITSDIR)
+ifdef NEEDUNITDIR
+override FPCOPT+=$(addprefix -Fu,$(NEEDUNITDIR))
 endif
 
-ifdef RTLDIR
-override FPCOPT+=-Fu$(RTLDIR)
+ifdef UNITSDIR
+override FPCOPT+=-Fu$(UNITSDIR)
 endif
 
 # Smartlinking
@@ -723,7 +742,18 @@ endif
 endif
 endif
 
-.PHONY:  rtl_package
+PACKAGERTL=1
+ifdef PACKAGERTL
+ifneq ($(wildcard $(PACKAGEDIR_RTL)),)
+ifeq ($(wildcard $(PACKAGEDIR_RTL)/$(FPCMADE)),)
+override COMPILEPACKAGES+=rtl
+rtl_package:
+	$(MAKE) -C $(PACKAGEDIR_RTL) all
+endif
+endif
+endif
+
+.PHONY:  rtl_package rtl_package
 
 #####################################################################
 # General compile rules

+ 46 - 22
install/demo/Makefile

@@ -137,7 +137,15 @@ endif
 ifndef COMPONENTDIR
 COMPONENTDIR=$(FPCDIR)/components
 endif
-# Check if packagedir really exists else turn it off
+# Create units dir
+ifneq ($(FPCDIR),.)
+UNITSDIR=$(FPCDIR)/units/$(OS_TARGET)
+endif
+
+# Check if the dirs really exists, else turn it off
+ifeq ($(wildcard $(UNITSDIR)),)
+UNITSDIR=
+endif
 ifeq ($(wildcard $(PACKAGEDIR)),)
 PACKAGEDIR=
 endif
@@ -145,16 +153,6 @@ ifeq ($(wildcard $(COMPONENTDIR)),)
 COMPONENTDIR=
 endif
 
-# Create rtl,units dir
-ifneq ($(FPCDIR),.)
-override UNITSDIR=$(FPCDIR)/units/$(OS_TARGET)
-ifneq ($(wildcard $(FPCDIR)/rtl),)
-override RTLDIR=$(FPCDIR)/rtl/$(OS_TARGET)
-else
-override RTLDIR=$(UNITSDIR)/rtl
-endif
-endif
-
 #####################################################################
 # Default Settings
 #####################################################################
@@ -211,9 +209,29 @@ endif
 
 # Packages
 
-override PACKAGES=rtl
+override PACKAGES+=rtl api
+ifneq ($(wildcard $(FPCDIR)/rtl),)
+ifneq ($(wildcard $(FPCDIR)/rtl/$(OS_TARGET)),)
 PACKAGEDIR_RTL=$(FPCDIR)/rtl/$(OS_TARGET)
-override PACKAGES+=api
+else
+PACKAGEDIR_RTL=$(FPCDIR)/rtl
+endif
+UNITDIR_RTL=$(PACKAGEDIR_RTL)
+else
+PACKAGEDIR_RTL=
+ifneq ($(wildcard $(UNITSDIR)/rtl),)
+ifneq ($(wildcard $(UNITSDIR)/rtl/$(OS_TARGET)),)
+UNITDIR_RTL=$(UNITSDIR)/rtl/$(OS_TARGET)
+else
+UNITDIR_RTL=$(UNITSDIR)/rtl
+endif
+else
+UNITDIR_RTL=
+endif
+endif
+ifdef UNITDIR_RTL
+override NEEDUNITDIR+=$(UNITDIR_RTL)
+endif
 ifneq ($(wildcard $(FPCDIR)/api),)
 ifneq ($(wildcard $(FPCDIR)/api/$(OS_TARGET)),)
 PACKAGEDIR_API=$(FPCDIR)/api/$(OS_TARGET)
@@ -346,18 +364,14 @@ ifneq ($(OS_TARGET),$(OS_SOURCE))
 override FPCOPT+=-T$(OS_TARGET)
 endif
 
-ifdef UNITSDIR
-override FPCOPT+=-Fu$(UNITSDIR)
-endif
-
-ifdef RTLDIR
-override FPCOPT+=-Fu$(RTLDIR)
-endif
-
 ifdef NEEDUNITDIR
 override FPCOPT+=$(addprefix -Fu,$(NEEDUNITDIR))
 endif
 
+ifdef UNITSDIR
+override FPCOPT+=-Fu$(UNITSDIR)
+endif
+
 # Target dirs
 ifdef TARGETDIR
 override FPCOPT+=-FE$(TARGETDIR)
@@ -752,7 +766,17 @@ endif
 endif
 endif
 
+PACKAGERTL=1
 PACKAGEAPI=1
+ifdef PACKAGERTL
+ifneq ($(wildcard $(PACKAGEDIR_RTL)),)
+ifeq ($(wildcard $(PACKAGEDIR_RTL)/$(FPCMADE)),)
+override COMPILEPACKAGES+=rtl
+rtl_package:
+	$(MAKE) -C $(PACKAGEDIR_RTL) all
+endif
+endif
+endif
 ifdef PACKAGEAPI
 ifneq ($(wildcard $(PACKAGEDIR_API)),)
 ifeq ($(wildcard $(PACKAGEDIR_API)/$(FPCMADE)),)
@@ -763,7 +787,7 @@ endif
 endif
 endif
 
-.PHONY:  rtl_package api_package
+.PHONY:  rtl_package rtl_package api_package
 
 #####################################################################
 # Units

+ 47 - 17
install/fpinst/Makefile

@@ -137,7 +137,15 @@ endif
 ifndef COMPONENTDIR
 COMPONENTDIR=$(FPCDIR)/components
 endif
-# Check if packagedir really exists else turn it off
+# Create units dir
+ifneq ($(FPCDIR),.)
+UNITSDIR=$(FPCDIR)/units/$(OS_TARGET)
+endif
+
+# Check if the dirs really exists, else turn it off
+ifeq ($(wildcard $(UNITSDIR)),)
+UNITSDIR=
+endif
 ifeq ($(wildcard $(PACKAGEDIR)),)
 PACKAGEDIR=
 endif
@@ -145,16 +153,6 @@ ifeq ($(wildcard $(COMPONENTDIR)),)
 COMPONENTDIR=
 endif
 
-# Create rtl,units dir
-ifneq ($(FPCDIR),.)
-override UNITSDIR=$(FPCDIR)/units/$(OS_TARGET)
-ifneq ($(wildcard $(FPCDIR)/rtl),)
-override RTLDIR=$(FPCDIR)/rtl/$(OS_TARGET)
-else
-override RTLDIR=$(UNITSDIR)/rtl
-endif
-endif
-
 #####################################################################
 # Default Settings
 #####################################################################
@@ -204,8 +202,29 @@ endif
 
 # Packages
 
-override PACKAGES=rtl
+override PACKAGES+=rtl
+ifneq ($(wildcard $(FPCDIR)/rtl),)
+ifneq ($(wildcard $(FPCDIR)/rtl/$(OS_TARGET)),)
 PACKAGEDIR_RTL=$(FPCDIR)/rtl/$(OS_TARGET)
+else
+PACKAGEDIR_RTL=$(FPCDIR)/rtl
+endif
+UNITDIR_RTL=$(PACKAGEDIR_RTL)
+else
+PACKAGEDIR_RTL=
+ifneq ($(wildcard $(UNITSDIR)/rtl),)
+ifneq ($(wildcard $(UNITSDIR)/rtl/$(OS_TARGET)),)
+UNITDIR_RTL=$(UNITSDIR)/rtl/$(OS_TARGET)
+else
+UNITDIR_RTL=$(UNITSDIR)/rtl
+endif
+else
+UNITDIR_RTL=
+endif
+endif
+ifdef UNITDIR_RTL
+override NEEDUNITDIR+=$(UNITDIR_RTL)
+endif
 
 # Libraries
 
@@ -310,12 +329,12 @@ ifneq ($(OS_TARGET),$(OS_SOURCE))
 override FPCOPT+=-T$(OS_TARGET)
 endif
 
-ifdef UNITSDIR
-override FPCOPT+=-Fu$(UNITSDIR)
+ifdef NEEDUNITDIR
+override FPCOPT+=$(addprefix -Fu,$(NEEDUNITDIR))
 endif
 
-ifdef RTLDIR
-override FPCOPT+=-Fu$(RTLDIR)
+ifdef UNITSDIR
+override FPCOPT+=-Fu$(UNITSDIR)
 endif
 
 # Target dirs
@@ -714,7 +733,18 @@ endif
 endif
 endif
 
-.PHONY:  rtl_package
+PACKAGERTL=1
+ifdef PACKAGERTL
+ifneq ($(wildcard $(PACKAGEDIR_RTL)),)
+ifeq ($(wildcard $(PACKAGEDIR_RTL)/$(FPCMADE)),)
+override COMPILEPACKAGES+=rtl
+rtl_package:
+	$(MAKE) -C $(PACKAGEDIR_RTL) all
+endif
+endif
+endif
+
+.PHONY:  rtl_package rtl_package
 
 #####################################################################
 # Exes

+ 43 - 13
packages/Makefile

@@ -129,7 +129,15 @@ endif
 ifndef COMPONENTDIR
 COMPONENTDIR=$(FPCDIR)/components
 endif
-# Check if packagedir really exists else turn it off
+# Create units dir
+ifneq ($(FPCDIR),.)
+UNITSDIR=$(FPCDIR)/units/$(OS_TARGET)
+endif
+
+# Check if the dirs really exists, else turn it off
+ifeq ($(wildcard $(UNITSDIR)),)
+UNITSDIR=
+endif
 ifeq ($(wildcard $(PACKAGEDIR)),)
 PACKAGEDIR=
 endif
@@ -137,16 +145,6 @@ ifeq ($(wildcard $(COMPONENTDIR)),)
 COMPONENTDIR=
 endif
 
-# Create rtl,units dir
-ifneq ($(FPCDIR),.)
-override UNITSDIR=$(FPCDIR)/units/$(OS_TARGET)
-ifneq ($(wildcard $(FPCDIR)/rtl),)
-override RTLDIR=$(FPCDIR)/rtl/$(OS_TARGET)
-else
-override RTLDIR=$(UNITSDIR)/rtl
-endif
-endif
-
 #####################################################################
 # Default Settings
 #####################################################################
@@ -198,8 +196,29 @@ ZIPTARGET=install
 
 # Packages
 
-override PACKAGES=rtl
+override PACKAGES+=rtl
+ifneq ($(wildcard $(FPCDIR)/rtl),)
+ifneq ($(wildcard $(FPCDIR)/rtl/$(OS_TARGET)),)
 PACKAGEDIR_RTL=$(FPCDIR)/rtl/$(OS_TARGET)
+else
+PACKAGEDIR_RTL=$(FPCDIR)/rtl
+endif
+UNITDIR_RTL=$(PACKAGEDIR_RTL)
+else
+PACKAGEDIR_RTL=
+ifneq ($(wildcard $(UNITSDIR)/rtl),)
+ifneq ($(wildcard $(UNITSDIR)/rtl/$(OS_TARGET)),)
+UNITDIR_RTL=$(UNITSDIR)/rtl/$(OS_TARGET)
+else
+UNITDIR_RTL=$(UNITSDIR)/rtl
+endif
+else
+UNITDIR_RTL=
+endif
+endif
+ifdef UNITDIR_RTL
+override NEEDUNITDIR+=$(UNITDIR_RTL)
+endif
 
 # Libraries
 
@@ -245,7 +264,18 @@ endif
 endif
 endif
 
-.PHONY:  rtl_package
+PACKAGERTL=1
+ifdef PACKAGERTL
+ifneq ($(wildcard $(PACKAGEDIR_RTL)),)
+ifeq ($(wildcard $(PACKAGEDIR_RTL)/$(FPCMADE)),)
+override COMPILEPACKAGES+=rtl
+rtl_package:
+	$(MAKE) -C $(PACKAGEDIR_RTL) all
+endif
+endif
+endif
+
+.PHONY:  rtl_package rtl_package
 
 
 # Target Dirs

+ 46 - 22
packages/forms/Makefile

@@ -137,7 +137,15 @@ endif
 ifndef COMPONENTDIR
 COMPONENTDIR=$(FPCDIR)/components
 endif
-# Check if packagedir really exists else turn it off
+# Create units dir
+ifneq ($(FPCDIR),.)
+UNITSDIR=$(FPCDIR)/units/$(OS_TARGET)
+endif
+
+# Check if the dirs really exists, else turn it off
+ifeq ($(wildcard $(UNITSDIR)),)
+UNITSDIR=
+endif
 ifeq ($(wildcard $(PACKAGEDIR)),)
 PACKAGEDIR=
 endif
@@ -145,16 +153,6 @@ ifeq ($(wildcard $(COMPONENTDIR)),)
 COMPONENTDIR=
 endif
 
-# Create rtl,units dir
-ifneq ($(FPCDIR),.)
-override UNITSDIR=$(FPCDIR)/units/$(OS_TARGET)
-ifneq ($(wildcard $(FPCDIR)/rtl),)
-override RTLDIR=$(FPCDIR)/rtl/$(OS_TARGET)
-else
-override RTLDIR=$(UNITSDIR)/rtl
-endif
-endif
-
 #####################################################################
 # Default Settings
 #####################################################################
@@ -198,9 +196,29 @@ ZIPTARGET=install
 
 # Packages
 
-override PACKAGES=rtl
+override PACKAGES+=rtl x11
+ifneq ($(wildcard $(FPCDIR)/rtl),)
+ifneq ($(wildcard $(FPCDIR)/rtl/$(OS_TARGET)),)
 PACKAGEDIR_RTL=$(FPCDIR)/rtl/$(OS_TARGET)
-override PACKAGES+=x11
+else
+PACKAGEDIR_RTL=$(FPCDIR)/rtl
+endif
+UNITDIR_RTL=$(PACKAGEDIR_RTL)
+else
+PACKAGEDIR_RTL=
+ifneq ($(wildcard $(UNITSDIR)/rtl),)
+ifneq ($(wildcard $(UNITSDIR)/rtl/$(OS_TARGET)),)
+UNITDIR_RTL=$(UNITSDIR)/rtl/$(OS_TARGET)
+else
+UNITDIR_RTL=$(UNITSDIR)/rtl
+endif
+else
+UNITDIR_RTL=
+endif
+endif
+ifdef UNITDIR_RTL
+override NEEDUNITDIR+=$(UNITDIR_RTL)
+endif
 ifneq ($(wildcard $(PACKAGEDIR)/x11),)
 ifneq ($(wildcard $(PACKAGEDIR)/x11/$(OS_TARGET)),)
 PACKAGEDIR_X11=$(PACKAGEDIR)/x11/$(OS_TARGET)
@@ -327,18 +345,14 @@ ifneq ($(OS_TARGET),$(OS_SOURCE))
 override FPCOPT+=-T$(OS_TARGET)
 endif
 
-ifdef UNITSDIR
-override FPCOPT+=-Fu$(UNITSDIR)
-endif
-
-ifdef RTLDIR
-override FPCOPT+=-Fu$(RTLDIR)
-endif
-
 ifdef NEEDUNITDIR
 override FPCOPT+=$(addprefix -Fu,$(NEEDUNITDIR))
 endif
 
+ifdef UNITSDIR
+override FPCOPT+=-Fu$(UNITSDIR)
+endif
+
 # Smartlinking
 ifdef SMARTLINK
 override FPCOPT+=-CX
@@ -730,7 +744,17 @@ endif
 endif
 endif
 
+PACKAGERTL=1
 PACKAGEX11=1
+ifdef PACKAGERTL
+ifneq ($(wildcard $(PACKAGEDIR_RTL)),)
+ifeq ($(wildcard $(PACKAGEDIR_RTL)/$(FPCMADE)),)
+override COMPILEPACKAGES+=rtl
+rtl_package:
+	$(MAKE) -C $(PACKAGEDIR_RTL) all
+endif
+endif
+endif
 ifdef PACKAGEX11
 ifneq ($(wildcard $(PACKAGEDIR_X11)),)
 ifeq ($(wildcard $(PACKAGEDIR_X11)/$(FPCMADE)),)
@@ -741,7 +765,7 @@ endif
 endif
 endif
 
-.PHONY:  rtl_package x11_package
+.PHONY:  rtl_package rtl_package x11_package
 
 #####################################################################
 # Units

+ 46 - 22
packages/forms/demo/Makefile

@@ -137,7 +137,15 @@ endif
 ifndef COMPONENTDIR
 COMPONENTDIR=$(FPCDIR)/components
 endif
-# Check if packagedir really exists else turn it off
+# Create units dir
+ifneq ($(FPCDIR),.)
+UNITSDIR=$(FPCDIR)/units/$(OS_TARGET)
+endif
+
+# Check if the dirs really exists, else turn it off
+ifeq ($(wildcard $(UNITSDIR)),)
+UNITSDIR=
+endif
 ifeq ($(wildcard $(PACKAGEDIR)),)
 PACKAGEDIR=
 endif
@@ -145,16 +153,6 @@ ifeq ($(wildcard $(COMPONENTDIR)),)
 COMPONENTDIR=
 endif
 
-# Create rtl,units dir
-ifneq ($(FPCDIR),.)
-override UNITSDIR=$(FPCDIR)/units/$(OS_TARGET)
-ifneq ($(wildcard $(FPCDIR)/rtl),)
-override RTLDIR=$(FPCDIR)/rtl/$(OS_TARGET)
-else
-override RTLDIR=$(UNITSDIR)/rtl
-endif
-endif
-
 #####################################################################
 # Default Settings
 #####################################################################
@@ -197,9 +195,29 @@ ZIPTARGET=install
 
 # Packages
 
-override PACKAGES=rtl
+override PACKAGES+=rtl forms x11
+ifneq ($(wildcard $(FPCDIR)/rtl),)
+ifneq ($(wildcard $(FPCDIR)/rtl/$(OS_TARGET)),)
 PACKAGEDIR_RTL=$(FPCDIR)/rtl/$(OS_TARGET)
-override PACKAGES+=forms x11
+else
+PACKAGEDIR_RTL=$(FPCDIR)/rtl
+endif
+UNITDIR_RTL=$(PACKAGEDIR_RTL)
+else
+PACKAGEDIR_RTL=
+ifneq ($(wildcard $(UNITSDIR)/rtl),)
+ifneq ($(wildcard $(UNITSDIR)/rtl/$(OS_TARGET)),)
+UNITDIR_RTL=$(UNITSDIR)/rtl/$(OS_TARGET)
+else
+UNITDIR_RTL=$(UNITSDIR)/rtl
+endif
+else
+UNITDIR_RTL=
+endif
+endif
+ifdef UNITDIR_RTL
+override NEEDUNITDIR+=$(UNITDIR_RTL)
+endif
 ifneq ($(wildcard $(PACKAGEDIR)/forms),)
 ifneq ($(wildcard $(PACKAGEDIR)/forms/$(OS_TARGET)),)
 PACKAGEDIR_FORMS=$(PACKAGEDIR)/forms/$(OS_TARGET)
@@ -357,18 +375,14 @@ ifneq ($(OS_TARGET),$(OS_SOURCE))
 override FPCOPT+=-T$(OS_TARGET)
 endif
 
-ifdef UNITSDIR
-override FPCOPT+=-Fu$(UNITSDIR)
-endif
-
-ifdef RTLDIR
-override FPCOPT+=-Fu$(RTLDIR)
-endif
-
 ifdef NEEDUNITDIR
 override FPCOPT+=$(addprefix -Fu,$(NEEDUNITDIR))
 endif
 
+ifdef UNITSDIR
+override FPCOPT+=-Fu$(UNITSDIR)
+endif
+
 # Add Other dirs path if asked
 ifdef OTHERLIBDIR
 override FPCOPT+=$(addprefix -Fl,$(OTHERLIBDIR))
@@ -765,8 +779,18 @@ endif
 endif
 endif
 
+PACKAGERTL=1
 PACKAGEFORMS=1
 PACKAGEX11=1
+ifdef PACKAGERTL
+ifneq ($(wildcard $(PACKAGEDIR_RTL)),)
+ifeq ($(wildcard $(PACKAGEDIR_RTL)/$(FPCMADE)),)
+override COMPILEPACKAGES+=rtl
+rtl_package:
+	$(MAKE) -C $(PACKAGEDIR_RTL) all
+endif
+endif
+endif
 ifdef PACKAGEFORMS
 ifneq ($(wildcard $(PACKAGEDIR_FORMS)),)
 ifeq ($(wildcard $(PACKAGEDIR_FORMS)/$(FPCMADE)),)
@@ -786,7 +810,7 @@ endif
 endif
 endif
 
-.PHONY:  rtl_package forms_package x11_package
+.PHONY:  rtl_package rtl_package forms_package x11_package
 
 #####################################################################
 # Exes

+ 47 - 17
packages/gdbint/Makefile

@@ -137,7 +137,15 @@ endif
 ifndef COMPONENTDIR
 COMPONENTDIR=$(FPCDIR)/components
 endif
-# Check if packagedir really exists else turn it off
+# Create units dir
+ifneq ($(FPCDIR),.)
+UNITSDIR=$(FPCDIR)/units/$(OS_TARGET)
+endif
+
+# Check if the dirs really exists, else turn it off
+ifeq ($(wildcard $(UNITSDIR)),)
+UNITSDIR=
+endif
 ifeq ($(wildcard $(PACKAGEDIR)),)
 PACKAGEDIR=
 endif
@@ -145,16 +153,6 @@ ifeq ($(wildcard $(COMPONENTDIR)),)
 COMPONENTDIR=
 endif
 
-# Create rtl,units dir
-ifneq ($(FPCDIR),.)
-override UNITSDIR=$(FPCDIR)/units/$(OS_TARGET)
-ifneq ($(wildcard $(FPCDIR)/rtl),)
-override RTLDIR=$(FPCDIR)/rtl/$(OS_TARGET)
-else
-override RTLDIR=$(UNITSDIR)/rtl
-endif
-endif
-
 #####################################################################
 # Default Settings
 #####################################################################
@@ -203,8 +201,29 @@ endif
 
 # Packages
 
-override PACKAGES=rtl
+override PACKAGES+=rtl
+ifneq ($(wildcard $(FPCDIR)/rtl),)
+ifneq ($(wildcard $(FPCDIR)/rtl/$(OS_TARGET)),)
 PACKAGEDIR_RTL=$(FPCDIR)/rtl/$(OS_TARGET)
+else
+PACKAGEDIR_RTL=$(FPCDIR)/rtl
+endif
+UNITDIR_RTL=$(PACKAGEDIR_RTL)
+else
+PACKAGEDIR_RTL=
+ifneq ($(wildcard $(UNITSDIR)/rtl),)
+ifneq ($(wildcard $(UNITSDIR)/rtl/$(OS_TARGET)),)
+UNITDIR_RTL=$(UNITSDIR)/rtl/$(OS_TARGET)
+else
+UNITDIR_RTL=$(UNITSDIR)/rtl
+endif
+else
+UNITDIR_RTL=
+endif
+endif
+ifdef UNITDIR_RTL
+override NEEDUNITDIR+=$(UNITDIR_RTL)
+endif
 
 # Libraries
 
@@ -318,12 +337,12 @@ ifneq ($(OS_TARGET),$(OS_SOURCE))
 override FPCOPT+=-T$(OS_TARGET)
 endif
 
-ifdef UNITSDIR
-override FPCOPT+=-Fu$(UNITSDIR)
+ifdef NEEDUNITDIR
+override FPCOPT+=$(addprefix -Fu,$(NEEDUNITDIR))
 endif
 
-ifdef RTLDIR
-override FPCOPT+=-Fu$(RTLDIR)
+ifdef UNITSDIR
+override FPCOPT+=-Fu$(UNITSDIR)
 endif
 
 ifdef NEEDLIBDIR
@@ -737,7 +756,18 @@ endif
 endif
 endif
 
-.PHONY:  rtl_package
+PACKAGERTL=1
+ifdef PACKAGERTL
+ifneq ($(wildcard $(PACKAGEDIR_RTL)),)
+ifeq ($(wildcard $(PACKAGEDIR_RTL)/$(FPCMADE)),)
+override COMPILEPACKAGES+=rtl
+rtl_package:
+	$(MAKE) -C $(PACKAGEDIR_RTL) all
+endif
+endif
+endif
+
+.PHONY:  rtl_package rtl_package
 
 #####################################################################
 # Units

+ 43 - 13
packages/gdbint/libgdb/Makefile

@@ -129,7 +129,15 @@ endif
 ifndef COMPONENTDIR
 COMPONENTDIR=$(FPCDIR)/components
 endif
-# Check if packagedir really exists else turn it off
+# Create units dir
+ifneq ($(FPCDIR),.)
+UNITSDIR=$(FPCDIR)/units/$(OS_TARGET)
+endif
+
+# Check if the dirs really exists, else turn it off
+ifeq ($(wildcard $(UNITSDIR)),)
+UNITSDIR=
+endif
 ifeq ($(wildcard $(PACKAGEDIR)),)
 PACKAGEDIR=
 endif
@@ -137,16 +145,6 @@ ifeq ($(wildcard $(COMPONENTDIR)),)
 COMPONENTDIR=
 endif
 
-# Create rtl,units dir
-ifneq ($(FPCDIR),.)
-override UNITSDIR=$(FPCDIR)/units/$(OS_TARGET)
-ifneq ($(wildcard $(FPCDIR)/rtl),)
-override RTLDIR=$(FPCDIR)/rtl/$(OS_TARGET)
-else
-override RTLDIR=$(UNITSDIR)/rtl
-endif
-endif
-
 #####################################################################
 # Default Settings
 #####################################################################
@@ -188,8 +186,29 @@ ZIPTARGET=install
 
 # Packages
 
-override PACKAGES=rtl
+override PACKAGES+=rtl
+ifneq ($(wildcard $(FPCDIR)/rtl),)
+ifneq ($(wildcard $(FPCDIR)/rtl/$(OS_TARGET)),)
 PACKAGEDIR_RTL=$(FPCDIR)/rtl/$(OS_TARGET)
+else
+PACKAGEDIR_RTL=$(FPCDIR)/rtl
+endif
+UNITDIR_RTL=$(PACKAGEDIR_RTL)
+else
+PACKAGEDIR_RTL=
+ifneq ($(wildcard $(UNITSDIR)/rtl),)
+ifneq ($(wildcard $(UNITSDIR)/rtl/$(OS_TARGET)),)
+UNITDIR_RTL=$(UNITSDIR)/rtl/$(OS_TARGET)
+else
+UNITDIR_RTL=$(UNITSDIR)/rtl
+endif
+else
+UNITDIR_RTL=
+endif
+endif
+ifdef UNITDIR_RTL
+override NEEDUNITDIR+=$(UNITDIR_RTL)
+endif
 
 # Libraries
 
@@ -209,7 +228,18 @@ endif
 endif
 endif
 
-.PHONY:  rtl_package
+PACKAGERTL=1
+ifdef PACKAGERTL
+ifneq ($(wildcard $(PACKAGEDIR_RTL)),)
+ifeq ($(wildcard $(PACKAGEDIR_RTL)/$(FPCMADE)),)
+override COMPILEPACKAGES+=rtl
+rtl_package:
+	$(MAKE) -C $(PACKAGEDIR_RTL) all
+endif
+endif
+endif
+
+.PHONY:  rtl_package rtl_package
 
 #####################################################################
 # Users rules

+ 47 - 17
packages/ggi/Makefile

@@ -137,7 +137,15 @@ endif
 ifndef COMPONENTDIR
 COMPONENTDIR=$(FPCDIR)/components
 endif
-# Check if packagedir really exists else turn it off
+# Create units dir
+ifneq ($(FPCDIR),.)
+UNITSDIR=$(FPCDIR)/units/$(OS_TARGET)
+endif
+
+# Check if the dirs really exists, else turn it off
+ifeq ($(wildcard $(UNITSDIR)),)
+UNITSDIR=
+endif
 ifeq ($(wildcard $(PACKAGEDIR)),)
 PACKAGEDIR=
 endif
@@ -145,16 +153,6 @@ ifeq ($(wildcard $(COMPONENTDIR)),)
 COMPONENTDIR=
 endif
 
-# Create rtl,units dir
-ifneq ($(FPCDIR),.)
-override UNITSDIR=$(FPCDIR)/units/$(OS_TARGET)
-ifneq ($(wildcard $(FPCDIR)/rtl),)
-override RTLDIR=$(FPCDIR)/rtl/$(OS_TARGET)
-else
-override RTLDIR=$(UNITSDIR)/rtl
-endif
-endif
-
 #####################################################################
 # Default Settings
 #####################################################################
@@ -198,8 +196,29 @@ ZIPTARGET=install
 
 # Packages
 
-override PACKAGES=rtl
+override PACKAGES+=rtl
+ifneq ($(wildcard $(FPCDIR)/rtl),)
+ifneq ($(wildcard $(FPCDIR)/rtl/$(OS_TARGET)),)
 PACKAGEDIR_RTL=$(FPCDIR)/rtl/$(OS_TARGET)
+else
+PACKAGEDIR_RTL=$(FPCDIR)/rtl
+endif
+UNITDIR_RTL=$(PACKAGEDIR_RTL)
+else
+PACKAGEDIR_RTL=
+ifneq ($(wildcard $(UNITSDIR)/rtl),)
+ifneq ($(wildcard $(UNITSDIR)/rtl/$(OS_TARGET)),)
+UNITDIR_RTL=$(UNITSDIR)/rtl/$(OS_TARGET)
+else
+UNITDIR_RTL=$(UNITSDIR)/rtl
+endif
+else
+UNITDIR_RTL=
+endif
+endif
+ifdef UNITDIR_RTL
+override NEEDUNITDIR+=$(UNITDIR_RTL)
+endif
 
 # Libraries
 
@@ -304,12 +323,12 @@ ifneq ($(OS_TARGET),$(OS_SOURCE))
 override FPCOPT+=-T$(OS_TARGET)
 endif
 
-ifdef UNITSDIR
-override FPCOPT+=-Fu$(UNITSDIR)
+ifdef NEEDUNITDIR
+override FPCOPT+=$(addprefix -Fu,$(NEEDUNITDIR))
 endif
 
-ifdef RTLDIR
-override FPCOPT+=-Fu$(RTLDIR)
+ifdef UNITSDIR
+override FPCOPT+=-Fu$(UNITSDIR)
 endif
 
 # Smartlinking
@@ -707,7 +726,18 @@ endif
 endif
 endif
 
-.PHONY:  rtl_package
+PACKAGERTL=1
+ifdef PACKAGERTL
+ifneq ($(wildcard $(PACKAGEDIR_RTL)),)
+ifeq ($(wildcard $(PACKAGEDIR_RTL)/$(FPCMADE)),)
+override COMPILEPACKAGES+=rtl
+rtl_package:
+	$(MAKE) -C $(PACKAGEDIR_RTL) all
+endif
+endif
+endif
+
+.PHONY:  rtl_package rtl_package
 
 #####################################################################
 # Units

+ 47 - 17
packages/gtk/Makefile

@@ -137,7 +137,15 @@ endif
 ifndef COMPONENTDIR
 COMPONENTDIR=$(FPCDIR)/components
 endif
-# Check if packagedir really exists else turn it off
+# Create units dir
+ifneq ($(FPCDIR),.)
+UNITSDIR=$(FPCDIR)/units/$(OS_TARGET)
+endif
+
+# Check if the dirs really exists, else turn it off
+ifeq ($(wildcard $(UNITSDIR)),)
+UNITSDIR=
+endif
 ifeq ($(wildcard $(PACKAGEDIR)),)
 PACKAGEDIR=
 endif
@@ -145,16 +153,6 @@ ifeq ($(wildcard $(COMPONENTDIR)),)
 COMPONENTDIR=
 endif
 
-# Create rtl,units dir
-ifneq ($(FPCDIR),.)
-override UNITSDIR=$(FPCDIR)/units/$(OS_TARGET)
-ifneq ($(wildcard $(FPCDIR)/rtl),)
-override RTLDIR=$(FPCDIR)/rtl/$(OS_TARGET)
-else
-override RTLDIR=$(UNITSDIR)/rtl
-endif
-endif
-
 #####################################################################
 # Default Settings
 #####################################################################
@@ -201,8 +199,29 @@ endif
 
 # Packages
 
-override PACKAGES=rtl
+override PACKAGES+=rtl
+ifneq ($(wildcard $(FPCDIR)/rtl),)
+ifneq ($(wildcard $(FPCDIR)/rtl/$(OS_TARGET)),)
 PACKAGEDIR_RTL=$(FPCDIR)/rtl/$(OS_TARGET)
+else
+PACKAGEDIR_RTL=$(FPCDIR)/rtl
+endif
+UNITDIR_RTL=$(PACKAGEDIR_RTL)
+else
+PACKAGEDIR_RTL=
+ifneq ($(wildcard $(UNITSDIR)/rtl),)
+ifneq ($(wildcard $(UNITSDIR)/rtl/$(OS_TARGET)),)
+UNITDIR_RTL=$(UNITSDIR)/rtl/$(OS_TARGET)
+else
+UNITDIR_RTL=$(UNITSDIR)/rtl
+endif
+else
+UNITDIR_RTL=
+endif
+endif
+ifdef UNITDIR_RTL
+override NEEDUNITDIR+=$(UNITDIR_RTL)
+endif
 
 # Libraries
 
@@ -308,12 +327,12 @@ ifneq ($(OS_TARGET),$(OS_SOURCE))
 override FPCOPT+=-T$(OS_TARGET)
 endif
 
-ifdef UNITSDIR
-override FPCOPT+=-Fu$(UNITSDIR)
+ifdef NEEDUNITDIR
+override FPCOPT+=$(addprefix -Fu,$(NEEDUNITDIR))
 endif
 
-ifdef RTLDIR
-override FPCOPT+=-Fu$(RTLDIR)
+ifdef UNITSDIR
+override FPCOPT+=-Fu$(UNITSDIR)
 endif
 
 # Target dirs
@@ -710,7 +729,18 @@ endif
 endif
 endif
 
-.PHONY:  rtl_package
+PACKAGERTL=1
+ifdef PACKAGERTL
+ifneq ($(wildcard $(PACKAGEDIR_RTL)),)
+ifeq ($(wildcard $(PACKAGEDIR_RTL)/$(FPCMADE)),)
+override COMPILEPACKAGES+=rtl
+rtl_package:
+	$(MAKE) -C $(PACKAGEDIR_RTL) all
+endif
+endif
+endif
+
+.PHONY:  rtl_package rtl_package
 
 #####################################################################
 # Units

+ 47 - 21
packages/gtk/examples/Makefile

@@ -137,7 +137,15 @@ endif
 ifndef COMPONENTDIR
 COMPONENTDIR=$(FPCDIR)/components
 endif
-# Check if packagedir really exists else turn it off
+# Create units dir
+ifneq ($(FPCDIR),.)
+UNITSDIR=$(FPCDIR)/units/$(OS_TARGET)
+endif
+
+# Check if the dirs really exists, else turn it off
+ifeq ($(wildcard $(UNITSDIR)),)
+UNITSDIR=
+endif
 ifeq ($(wildcard $(PACKAGEDIR)),)
 PACKAGEDIR=
 endif
@@ -145,16 +153,6 @@ ifeq ($(wildcard $(COMPONENTDIR)),)
 COMPONENTDIR=
 endif
 
-# Create rtl,units dir
-ifneq ($(FPCDIR),.)
-override UNITSDIR=$(FPCDIR)/units/$(OS_TARGET)
-ifneq ($(wildcard $(FPCDIR)/rtl),)
-override RTLDIR=$(FPCDIR)/rtl/$(OS_TARGET)
-else
-override RTLDIR=$(UNITSDIR)/rtl
-endif
-endif
-
 #####################################################################
 # Default Settings
 #####################################################################
@@ -202,8 +200,29 @@ endif
 
 # Packages
 
-override PACKAGES=rtl
+override PACKAGES+=rtl
+ifneq ($(wildcard $(FPCDIR)/rtl),)
+ifneq ($(wildcard $(FPCDIR)/rtl/$(OS_TARGET)),)
 PACKAGEDIR_RTL=$(FPCDIR)/rtl/$(OS_TARGET)
+else
+PACKAGEDIR_RTL=$(FPCDIR)/rtl
+endif
+UNITDIR_RTL=$(PACKAGEDIR_RTL)
+else
+PACKAGEDIR_RTL=
+ifneq ($(wildcard $(UNITSDIR)/rtl),)
+ifneq ($(wildcard $(UNITSDIR)/rtl/$(OS_TARGET)),)
+UNITDIR_RTL=$(UNITSDIR)/rtl/$(OS_TARGET)
+else
+UNITDIR_RTL=$(UNITSDIR)/rtl
+endif
+else
+UNITDIR_RTL=
+endif
+endif
+ifdef UNITDIR_RTL
+override NEEDUNITDIR+=$(UNITDIR_RTL)
+endif
 
 # Libraries
 
@@ -326,18 +345,14 @@ ifneq ($(OS_TARGET),$(OS_SOURCE))
 override FPCOPT+=-T$(OS_TARGET)
 endif
 
-ifdef UNITSDIR
-override FPCOPT+=-Fu$(UNITSDIR)
-endif
-
-ifdef RTLDIR
-override FPCOPT+=-Fu$(RTLDIR)
-endif
-
 ifdef NEEDUNITDIR
 override FPCOPT+=$(addprefix -Fu,$(NEEDUNITDIR))
 endif
 
+ifdef UNITSDIR
+override FPCOPT+=-Fu$(UNITSDIR)
+endif
+
 # Add GCC lib path if asked
 ifdef GCCLIBDIR
 override FPCOPT+=-Fl$(GCCLIBDIR)
@@ -744,7 +759,18 @@ endif
 endif
 endif
 
-.PHONY:  rtl_package
+PACKAGERTL=1
+ifdef PACKAGERTL
+ifneq ($(wildcard $(PACKAGEDIR_RTL)),)
+ifeq ($(wildcard $(PACKAGEDIR_RTL)/$(FPCMADE)),)
+override COMPILEPACKAGES+=rtl
+rtl_package:
+	$(MAKE) -C $(PACKAGEDIR_RTL) all
+endif
+endif
+endif
+
+.PHONY:  rtl_package rtl_package
 
 #####################################################################
 # Exes

+ 47 - 21
packages/gtk/tutorial/Makefile

@@ -137,7 +137,15 @@ endif
 ifndef COMPONENTDIR
 COMPONENTDIR=$(FPCDIR)/components
 endif
-# Check if packagedir really exists else turn it off
+# Create units dir
+ifneq ($(FPCDIR),.)
+UNITSDIR=$(FPCDIR)/units/$(OS_TARGET)
+endif
+
+# Check if the dirs really exists, else turn it off
+ifeq ($(wildcard $(UNITSDIR)),)
+UNITSDIR=
+endif
 ifeq ($(wildcard $(PACKAGEDIR)),)
 PACKAGEDIR=
 endif
@@ -145,16 +153,6 @@ ifeq ($(wildcard $(COMPONENTDIR)),)
 COMPONENTDIR=
 endif
 
-# Create rtl,units dir
-ifneq ($(FPCDIR),.)
-override UNITSDIR=$(FPCDIR)/units/$(OS_TARGET)
-ifneq ($(wildcard $(FPCDIR)/rtl),)
-override RTLDIR=$(FPCDIR)/rtl/$(OS_TARGET)
-else
-override RTLDIR=$(UNITSDIR)/rtl
-endif
-endif
-
 #####################################################################
 # Default Settings
 #####################################################################
@@ -201,8 +199,29 @@ endif
 
 # Packages
 
-override PACKAGES=rtl
+override PACKAGES+=rtl
+ifneq ($(wildcard $(FPCDIR)/rtl),)
+ifneq ($(wildcard $(FPCDIR)/rtl/$(OS_TARGET)),)
 PACKAGEDIR_RTL=$(FPCDIR)/rtl/$(OS_TARGET)
+else
+PACKAGEDIR_RTL=$(FPCDIR)/rtl
+endif
+UNITDIR_RTL=$(PACKAGEDIR_RTL)
+else
+PACKAGEDIR_RTL=
+ifneq ($(wildcard $(UNITSDIR)/rtl),)
+ifneq ($(wildcard $(UNITSDIR)/rtl/$(OS_TARGET)),)
+UNITDIR_RTL=$(UNITSDIR)/rtl/$(OS_TARGET)
+else
+UNITDIR_RTL=$(UNITSDIR)/rtl
+endif
+else
+UNITDIR_RTL=
+endif
+endif
+ifdef UNITDIR_RTL
+override NEEDUNITDIR+=$(UNITDIR_RTL)
+endif
 
 # Libraries
 
@@ -325,18 +344,14 @@ ifneq ($(OS_TARGET),$(OS_SOURCE))
 override FPCOPT+=-T$(OS_TARGET)
 endif
 
-ifdef UNITSDIR
-override FPCOPT+=-Fu$(UNITSDIR)
-endif
-
-ifdef RTLDIR
-override FPCOPT+=-Fu$(RTLDIR)
-endif
-
 ifdef NEEDUNITDIR
 override FPCOPT+=$(addprefix -Fu,$(NEEDUNITDIR))
 endif
 
+ifdef UNITSDIR
+override FPCOPT+=-Fu$(UNITSDIR)
+endif
+
 # Add GCC lib path if asked
 ifdef GCCLIBDIR
 override FPCOPT+=-Fl$(GCCLIBDIR)
@@ -743,7 +758,18 @@ endif
 endif
 endif
 
-.PHONY:  rtl_package
+PACKAGERTL=1
+ifdef PACKAGERTL
+ifneq ($(wildcard $(PACKAGEDIR_RTL)),)
+ifeq ($(wildcard $(PACKAGEDIR_RTL)/$(FPCMADE)),)
+override COMPILEPACKAGES+=rtl
+rtl_package:
+	$(MAKE) -C $(PACKAGEDIR_RTL) all
+endif
+endif
+endif
+
+.PHONY:  rtl_package rtl_package
 
 #####################################################################
 # Exes

+ 47 - 17
packages/ibase/Makefile

@@ -137,7 +137,15 @@ endif
 ifndef COMPONENTDIR
 COMPONENTDIR=$(FPCDIR)/components
 endif
-# Check if packagedir really exists else turn it off
+# Create units dir
+ifneq ($(FPCDIR),.)
+UNITSDIR=$(FPCDIR)/units/$(OS_TARGET)
+endif
+
+# Check if the dirs really exists, else turn it off
+ifeq ($(wildcard $(UNITSDIR)),)
+UNITSDIR=
+endif
 ifeq ($(wildcard $(PACKAGEDIR)),)
 PACKAGEDIR=
 endif
@@ -145,16 +153,6 @@ ifeq ($(wildcard $(COMPONENTDIR)),)
 COMPONENTDIR=
 endif
 
-# Create rtl,units dir
-ifneq ($(FPCDIR),.)
-override UNITSDIR=$(FPCDIR)/units/$(OS_TARGET)
-ifneq ($(wildcard $(FPCDIR)/rtl),)
-override RTLDIR=$(FPCDIR)/rtl/$(OS_TARGET)
-else
-override RTLDIR=$(UNITSDIR)/rtl
-endif
-endif
-
 #####################################################################
 # Default Settings
 #####################################################################
@@ -198,8 +196,29 @@ ZIPTARGET=install
 
 # Packages
 
-override PACKAGES=rtl
+override PACKAGES+=rtl
+ifneq ($(wildcard $(FPCDIR)/rtl),)
+ifneq ($(wildcard $(FPCDIR)/rtl/$(OS_TARGET)),)
 PACKAGEDIR_RTL=$(FPCDIR)/rtl/$(OS_TARGET)
+else
+PACKAGEDIR_RTL=$(FPCDIR)/rtl
+endif
+UNITDIR_RTL=$(PACKAGEDIR_RTL)
+else
+PACKAGEDIR_RTL=
+ifneq ($(wildcard $(UNITSDIR)/rtl),)
+ifneq ($(wildcard $(UNITSDIR)/rtl/$(OS_TARGET)),)
+UNITDIR_RTL=$(UNITSDIR)/rtl/$(OS_TARGET)
+else
+UNITDIR_RTL=$(UNITSDIR)/rtl
+endif
+else
+UNITDIR_RTL=
+endif
+endif
+ifdef UNITDIR_RTL
+override NEEDUNITDIR+=$(UNITDIR_RTL)
+endif
 
 # Libraries
 
@@ -304,12 +323,12 @@ ifneq ($(OS_TARGET),$(OS_SOURCE))
 override FPCOPT+=-T$(OS_TARGET)
 endif
 
-ifdef UNITSDIR
-override FPCOPT+=-Fu$(UNITSDIR)
+ifdef NEEDUNITDIR
+override FPCOPT+=$(addprefix -Fu,$(NEEDUNITDIR))
 endif
 
-ifdef RTLDIR
-override FPCOPT+=-Fu$(RTLDIR)
+ifdef UNITSDIR
+override FPCOPT+=-Fu$(UNITSDIR)
 endif
 
 # Smartlinking
@@ -707,7 +726,18 @@ endif
 endif
 endif
 
-.PHONY:  rtl_package
+PACKAGERTL=1
+ifdef PACKAGERTL
+ifneq ($(wildcard $(PACKAGEDIR_RTL)),)
+ifeq ($(wildcard $(PACKAGEDIR_RTL)/$(FPCMADE)),)
+override COMPILEPACKAGES+=rtl
+rtl_package:
+	$(MAKE) -C $(PACKAGEDIR_RTL) all
+endif
+endif
+endif
+
+.PHONY:  rtl_package rtl_package
 
 #####################################################################
 # Units

+ 47 - 17
packages/inet/Makefile

@@ -137,7 +137,15 @@ endif
 ifndef COMPONENTDIR
 COMPONENTDIR=$(FPCDIR)/components
 endif
-# Check if packagedir really exists else turn it off
+# Create units dir
+ifneq ($(FPCDIR),.)
+UNITSDIR=$(FPCDIR)/units/$(OS_TARGET)
+endif
+
+# Check if the dirs really exists, else turn it off
+ifeq ($(wildcard $(UNITSDIR)),)
+UNITSDIR=
+endif
 ifeq ($(wildcard $(PACKAGEDIR)),)
 PACKAGEDIR=
 endif
@@ -145,16 +153,6 @@ ifeq ($(wildcard $(COMPONENTDIR)),)
 COMPONENTDIR=
 endif
 
-# Create rtl,units dir
-ifneq ($(FPCDIR),.)
-override UNITSDIR=$(FPCDIR)/units/$(OS_TARGET)
-ifneq ($(wildcard $(FPCDIR)/rtl),)
-override RTLDIR=$(FPCDIR)/rtl/$(OS_TARGET)
-else
-override RTLDIR=$(UNITSDIR)/rtl
-endif
-endif
-
 #####################################################################
 # Default Settings
 #####################################################################
@@ -198,8 +196,29 @@ ZIPTARGET=install
 
 # Packages
 
-override PACKAGES=rtl
+override PACKAGES+=rtl
+ifneq ($(wildcard $(FPCDIR)/rtl),)
+ifneq ($(wildcard $(FPCDIR)/rtl/$(OS_TARGET)),)
 PACKAGEDIR_RTL=$(FPCDIR)/rtl/$(OS_TARGET)
+else
+PACKAGEDIR_RTL=$(FPCDIR)/rtl
+endif
+UNITDIR_RTL=$(PACKAGEDIR_RTL)
+else
+PACKAGEDIR_RTL=
+ifneq ($(wildcard $(UNITSDIR)/rtl),)
+ifneq ($(wildcard $(UNITSDIR)/rtl/$(OS_TARGET)),)
+UNITDIR_RTL=$(UNITSDIR)/rtl/$(OS_TARGET)
+else
+UNITDIR_RTL=$(UNITSDIR)/rtl
+endif
+else
+UNITDIR_RTL=
+endif
+endif
+ifdef UNITDIR_RTL
+override NEEDUNITDIR+=$(UNITDIR_RTL)
+endif
 
 # Libraries
 
@@ -304,12 +323,12 @@ ifneq ($(OS_TARGET),$(OS_SOURCE))
 override FPCOPT+=-T$(OS_TARGET)
 endif
 
-ifdef UNITSDIR
-override FPCOPT+=-Fu$(UNITSDIR)
+ifdef NEEDUNITDIR
+override FPCOPT+=$(addprefix -Fu,$(NEEDUNITDIR))
 endif
 
-ifdef RTLDIR
-override FPCOPT+=-Fu$(RTLDIR)
+ifdef UNITSDIR
+override FPCOPT+=-Fu$(UNITSDIR)
 endif
 
 # Smartlinking
@@ -707,7 +726,18 @@ endif
 endif
 endif
 
-.PHONY:  rtl_package
+PACKAGERTL=1
+ifdef PACKAGERTL
+ifneq ($(wildcard $(PACKAGEDIR_RTL)),)
+ifeq ($(wildcard $(PACKAGEDIR_RTL)/$(FPCMADE)),)
+override COMPILEPACKAGES+=rtl
+rtl_package:
+	$(MAKE) -C $(PACKAGEDIR_RTL) all
+endif
+endif
+endif
+
+.PHONY:  rtl_package rtl_package
 
 #####################################################################
 # Units

+ 47 - 17
packages/mysql/Makefile

@@ -137,7 +137,15 @@ endif
 ifndef COMPONENTDIR
 COMPONENTDIR=$(FPCDIR)/components
 endif
-# Check if packagedir really exists else turn it off
+# Create units dir
+ifneq ($(FPCDIR),.)
+UNITSDIR=$(FPCDIR)/units/$(OS_TARGET)
+endif
+
+# Check if the dirs really exists, else turn it off
+ifeq ($(wildcard $(UNITSDIR)),)
+UNITSDIR=
+endif
 ifeq ($(wildcard $(PACKAGEDIR)),)
 PACKAGEDIR=
 endif
@@ -145,16 +153,6 @@ ifeq ($(wildcard $(COMPONENTDIR)),)
 COMPONENTDIR=
 endif
 
-# Create rtl,units dir
-ifneq ($(FPCDIR),.)
-override UNITSDIR=$(FPCDIR)/units/$(OS_TARGET)
-ifneq ($(wildcard $(FPCDIR)/rtl),)
-override RTLDIR=$(FPCDIR)/rtl/$(OS_TARGET)
-else
-override RTLDIR=$(UNITSDIR)/rtl
-endif
-endif
-
 #####################################################################
 # Default Settings
 #####################################################################
@@ -198,8 +196,29 @@ ZIPTARGET=install
 
 # Packages
 
-override PACKAGES=rtl
+override PACKAGES+=rtl
+ifneq ($(wildcard $(FPCDIR)/rtl),)
+ifneq ($(wildcard $(FPCDIR)/rtl/$(OS_TARGET)),)
 PACKAGEDIR_RTL=$(FPCDIR)/rtl/$(OS_TARGET)
+else
+PACKAGEDIR_RTL=$(FPCDIR)/rtl
+endif
+UNITDIR_RTL=$(PACKAGEDIR_RTL)
+else
+PACKAGEDIR_RTL=
+ifneq ($(wildcard $(UNITSDIR)/rtl),)
+ifneq ($(wildcard $(UNITSDIR)/rtl/$(OS_TARGET)),)
+UNITDIR_RTL=$(UNITSDIR)/rtl/$(OS_TARGET)
+else
+UNITDIR_RTL=$(UNITSDIR)/rtl
+endif
+else
+UNITDIR_RTL=
+endif
+endif
+ifdef UNITDIR_RTL
+override NEEDUNITDIR+=$(UNITDIR_RTL)
+endif
 
 # Libraries
 
@@ -304,12 +323,12 @@ ifneq ($(OS_TARGET),$(OS_SOURCE))
 override FPCOPT+=-T$(OS_TARGET)
 endif
 
-ifdef UNITSDIR
-override FPCOPT+=-Fu$(UNITSDIR)
+ifdef NEEDUNITDIR
+override FPCOPT+=$(addprefix -Fu,$(NEEDUNITDIR))
 endif
 
-ifdef RTLDIR
-override FPCOPT+=-Fu$(RTLDIR)
+ifdef UNITSDIR
+override FPCOPT+=-Fu$(UNITSDIR)
 endif
 
 # Smartlinking
@@ -707,7 +726,18 @@ endif
 endif
 endif
 
-.PHONY:  rtl_package
+PACKAGERTL=1
+ifdef PACKAGERTL
+ifneq ($(wildcard $(PACKAGEDIR_RTL)),)
+ifeq ($(wildcard $(PACKAGEDIR_RTL)/$(FPCMADE)),)
+override COMPILEPACKAGES+=rtl
+rtl_package:
+	$(MAKE) -C $(PACKAGEDIR_RTL) all
+endif
+endif
+endif
+
+.PHONY:  rtl_package rtl_package
 
 #####################################################################
 # Units

+ 47 - 17
packages/ncurses/Makefile

@@ -137,7 +137,15 @@ endif
 ifndef COMPONENTDIR
 COMPONENTDIR=$(FPCDIR)/components
 endif
-# Check if packagedir really exists else turn it off
+# Create units dir
+ifneq ($(FPCDIR),.)
+UNITSDIR=$(FPCDIR)/units/$(OS_TARGET)
+endif
+
+# Check if the dirs really exists, else turn it off
+ifeq ($(wildcard $(UNITSDIR)),)
+UNITSDIR=
+endif
 ifeq ($(wildcard $(PACKAGEDIR)),)
 PACKAGEDIR=
 endif
@@ -145,16 +153,6 @@ ifeq ($(wildcard $(COMPONENTDIR)),)
 COMPONENTDIR=
 endif
 
-# Create rtl,units dir
-ifneq ($(FPCDIR),.)
-override UNITSDIR=$(FPCDIR)/units/$(OS_TARGET)
-ifneq ($(wildcard $(FPCDIR)/rtl),)
-override RTLDIR=$(FPCDIR)/rtl/$(OS_TARGET)
-else
-override RTLDIR=$(UNITSDIR)/rtl
-endif
-endif
-
 #####################################################################
 # Default Settings
 #####################################################################
@@ -198,8 +196,29 @@ ZIPTARGET=install
 
 # Packages
 
-override PACKAGES=rtl
+override PACKAGES+=rtl
+ifneq ($(wildcard $(FPCDIR)/rtl),)
+ifneq ($(wildcard $(FPCDIR)/rtl/$(OS_TARGET)),)
 PACKAGEDIR_RTL=$(FPCDIR)/rtl/$(OS_TARGET)
+else
+PACKAGEDIR_RTL=$(FPCDIR)/rtl
+endif
+UNITDIR_RTL=$(PACKAGEDIR_RTL)
+else
+PACKAGEDIR_RTL=
+ifneq ($(wildcard $(UNITSDIR)/rtl),)
+ifneq ($(wildcard $(UNITSDIR)/rtl/$(OS_TARGET)),)
+UNITDIR_RTL=$(UNITSDIR)/rtl/$(OS_TARGET)
+else
+UNITDIR_RTL=$(UNITSDIR)/rtl
+endif
+else
+UNITDIR_RTL=
+endif
+endif
+ifdef UNITDIR_RTL
+override NEEDUNITDIR+=$(UNITDIR_RTL)
+endif
 
 # Libraries
 
@@ -304,12 +323,12 @@ ifneq ($(OS_TARGET),$(OS_SOURCE))
 override FPCOPT+=-T$(OS_TARGET)
 endif
 
-ifdef UNITSDIR
-override FPCOPT+=-Fu$(UNITSDIR)
+ifdef NEEDUNITDIR
+override FPCOPT+=$(addprefix -Fu,$(NEEDUNITDIR))
 endif
 
-ifdef RTLDIR
-override FPCOPT+=-Fu$(RTLDIR)
+ifdef UNITSDIR
+override FPCOPT+=-Fu$(UNITSDIR)
 endif
 
 # Smartlinking
@@ -707,7 +726,18 @@ endif
 endif
 endif
 
-.PHONY:  rtl_package
+PACKAGERTL=1
+ifdef PACKAGERTL
+ifneq ($(wildcard $(PACKAGEDIR_RTL)),)
+ifeq ($(wildcard $(PACKAGEDIR_RTL)/$(FPCMADE)),)
+override COMPILEPACKAGES+=rtl
+rtl_package:
+	$(MAKE) -C $(PACKAGEDIR_RTL) all
+endif
+endif
+endif
+
+.PHONY:  rtl_package rtl_package
 
 #####################################################################
 # Units

+ 43 - 13
packages/opengl/Makefile

@@ -129,7 +129,15 @@ endif
 ifndef COMPONENTDIR
 COMPONENTDIR=$(FPCDIR)/components
 endif
-# Check if packagedir really exists else turn it off
+# Create units dir
+ifneq ($(FPCDIR),.)
+UNITSDIR=$(FPCDIR)/units/$(OS_TARGET)
+endif
+
+# Check if the dirs really exists, else turn it off
+ifeq ($(wildcard $(UNITSDIR)),)
+UNITSDIR=
+endif
 ifeq ($(wildcard $(PACKAGEDIR)),)
 PACKAGEDIR=
 endif
@@ -137,16 +145,6 @@ ifeq ($(wildcard $(COMPONENTDIR)),)
 COMPONENTDIR=
 endif
 
-# Create rtl,units dir
-ifneq ($(FPCDIR),.)
-override UNITSDIR=$(FPCDIR)/units/$(OS_TARGET)
-ifneq ($(wildcard $(FPCDIR)/rtl),)
-override RTLDIR=$(FPCDIR)/rtl/$(OS_TARGET)
-else
-override RTLDIR=$(UNITSDIR)/rtl
-endif
-endif
-
 #####################################################################
 # Default Settings
 #####################################################################
@@ -189,8 +187,29 @@ ZIPTARGET=install
 
 # Packages
 
-override PACKAGES=rtl
+override PACKAGES+=rtl
+ifneq ($(wildcard $(FPCDIR)/rtl),)
+ifneq ($(wildcard $(FPCDIR)/rtl/$(OS_TARGET)),)
 PACKAGEDIR_RTL=$(FPCDIR)/rtl/$(OS_TARGET)
+else
+PACKAGEDIR_RTL=$(FPCDIR)/rtl
+endif
+UNITDIR_RTL=$(PACKAGEDIR_RTL)
+else
+PACKAGEDIR_RTL=
+ifneq ($(wildcard $(UNITSDIR)/rtl),)
+ifneq ($(wildcard $(UNITSDIR)/rtl/$(OS_TARGET)),)
+UNITDIR_RTL=$(UNITSDIR)/rtl/$(OS_TARGET)
+else
+UNITDIR_RTL=$(UNITSDIR)/rtl
+endif
+else
+UNITDIR_RTL=
+endif
+endif
+ifdef UNITDIR_RTL
+override NEEDUNITDIR+=$(UNITDIR_RTL)
+endif
 
 # Libraries
 
@@ -238,7 +257,18 @@ endif
 endif
 endif
 
-.PHONY:  rtl_package
+PACKAGERTL=1
+ifdef PACKAGERTL
+ifneq ($(wildcard $(PACKAGEDIR_RTL)),)
+ifeq ($(wildcard $(PACKAGEDIR_RTL)/$(FPCMADE)),)
+override COMPILEPACKAGES+=rtl
+rtl_package:
+	$(MAKE) -C $(PACKAGEDIR_RTL) all
+endif
+endif
+endif
+
+.PHONY:  rtl_package rtl_package
 
 
 # Target Dirs

+ 46 - 22
packages/opengl/build/Makefile

@@ -137,7 +137,15 @@ endif
 ifndef COMPONENTDIR
 COMPONENTDIR=$(FPCDIR)/components
 endif
-# Check if packagedir really exists else turn it off
+# Create units dir
+ifneq ($(FPCDIR),.)
+UNITSDIR=$(FPCDIR)/units/$(OS_TARGET)
+endif
+
+# Check if the dirs really exists, else turn it off
+ifeq ($(wildcard $(UNITSDIR)),)
+UNITSDIR=
+endif
 ifeq ($(wildcard $(PACKAGEDIR)),)
 PACKAGEDIR=
 endif
@@ -145,16 +153,6 @@ ifeq ($(wildcard $(COMPONENTDIR)),)
 COMPONENTDIR=
 endif
 
-# Create rtl,units dir
-ifneq ($(FPCDIR),.)
-override UNITSDIR=$(FPCDIR)/units/$(OS_TARGET)
-ifneq ($(wildcard $(FPCDIR)/rtl),)
-override RTLDIR=$(FPCDIR)/rtl/$(OS_TARGET)
-else
-override RTLDIR=$(UNITSDIR)/rtl
-endif
-endif
-
 #####################################################################
 # Default Settings
 #####################################################################
@@ -198,9 +196,29 @@ ZIPTARGET=install
 
 # Packages
 
-override PACKAGES=rtl
+override PACKAGES+=rtl fcl
+ifneq ($(wildcard $(FPCDIR)/rtl),)
+ifneq ($(wildcard $(FPCDIR)/rtl/$(OS_TARGET)),)
 PACKAGEDIR_RTL=$(FPCDIR)/rtl/$(OS_TARGET)
-override PACKAGES+=fcl
+else
+PACKAGEDIR_RTL=$(FPCDIR)/rtl
+endif
+UNITDIR_RTL=$(PACKAGEDIR_RTL)
+else
+PACKAGEDIR_RTL=
+ifneq ($(wildcard $(UNITSDIR)/rtl),)
+ifneq ($(wildcard $(UNITSDIR)/rtl/$(OS_TARGET)),)
+UNITDIR_RTL=$(UNITSDIR)/rtl/$(OS_TARGET)
+else
+UNITDIR_RTL=$(UNITSDIR)/rtl
+endif
+else
+UNITDIR_RTL=
+endif
+endif
+ifdef UNITDIR_RTL
+override NEEDUNITDIR+=$(UNITDIR_RTL)
+endif
 ifneq ($(wildcard $(FPCDIR)/fcl),)
 ifneq ($(wildcard $(FPCDIR)/fcl/$(OS_TARGET)),)
 PACKAGEDIR_FCL=$(FPCDIR)/fcl/$(OS_TARGET)
@@ -327,18 +345,14 @@ ifneq ($(OS_TARGET),$(OS_SOURCE))
 override FPCOPT+=-T$(OS_TARGET)
 endif
 
-ifdef UNITSDIR
-override FPCOPT+=-Fu$(UNITSDIR)
-endif
-
-ifdef RTLDIR
-override FPCOPT+=-Fu$(RTLDIR)
-endif
-
 ifdef NEEDUNITDIR
 override FPCOPT+=$(addprefix -Fu,$(NEEDUNITDIR))
 endif
 
+ifdef UNITSDIR
+override FPCOPT+=-Fu$(UNITSDIR)
+endif
+
 # Smartlinking
 ifdef SMARTLINK
 override FPCOPT+=-CX
@@ -730,7 +744,17 @@ endif
 endif
 endif
 
+PACKAGERTL=1
 PACKAGEFCL=1
+ifdef PACKAGERTL
+ifneq ($(wildcard $(PACKAGEDIR_RTL)),)
+ifeq ($(wildcard $(PACKAGEDIR_RTL)/$(FPCMADE)),)
+override COMPILEPACKAGES+=rtl
+rtl_package:
+	$(MAKE) -C $(PACKAGEDIR_RTL) all
+endif
+endif
+endif
 ifdef PACKAGEFCL
 ifneq ($(wildcard $(PACKAGEDIR_FCL)),)
 ifeq ($(wildcard $(PACKAGEDIR_FCL)/$(FPCMADE)),)
@@ -741,7 +765,7 @@ endif
 endif
 endif
 
-.PHONY:  rtl_package fcl_package
+.PHONY:  rtl_package rtl_package fcl_package
 
 #####################################################################
 # Units

+ 46 - 22
packages/opengl/examples/Makefile

@@ -137,7 +137,15 @@ endif
 ifndef COMPONENTDIR
 COMPONENTDIR=$(FPCDIR)/components
 endif
-# Check if packagedir really exists else turn it off
+# Create units dir
+ifneq ($(FPCDIR),.)
+UNITSDIR=$(FPCDIR)/units/$(OS_TARGET)
+endif
+
+# Check if the dirs really exists, else turn it off
+ifeq ($(wildcard $(UNITSDIR)),)
+UNITSDIR=
+endif
 ifeq ($(wildcard $(PACKAGEDIR)),)
 PACKAGEDIR=
 endif
@@ -145,16 +153,6 @@ ifeq ($(wildcard $(COMPONENTDIR)),)
 COMPONENTDIR=
 endif
 
-# Create rtl,units dir
-ifneq ($(FPCDIR),.)
-override UNITSDIR=$(FPCDIR)/units/$(OS_TARGET)
-ifneq ($(wildcard $(FPCDIR)/rtl),)
-override RTLDIR=$(FPCDIR)/rtl/$(OS_TARGET)
-else
-override RTLDIR=$(UNITSDIR)/rtl
-endif
-endif
-
 #####################################################################
 # Default Settings
 #####################################################################
@@ -197,9 +195,29 @@ ZIPTARGET=install
 
 # Packages
 
-override PACKAGES=rtl
+override PACKAGES+=rtl opengl x11
+ifneq ($(wildcard $(FPCDIR)/rtl),)
+ifneq ($(wildcard $(FPCDIR)/rtl/$(OS_TARGET)),)
 PACKAGEDIR_RTL=$(FPCDIR)/rtl/$(OS_TARGET)
-override PACKAGES+=opengl x11
+else
+PACKAGEDIR_RTL=$(FPCDIR)/rtl
+endif
+UNITDIR_RTL=$(PACKAGEDIR_RTL)
+else
+PACKAGEDIR_RTL=
+ifneq ($(wildcard $(UNITSDIR)/rtl),)
+ifneq ($(wildcard $(UNITSDIR)/rtl/$(OS_TARGET)),)
+UNITDIR_RTL=$(UNITSDIR)/rtl/$(OS_TARGET)
+else
+UNITDIR_RTL=$(UNITSDIR)/rtl
+endif
+else
+UNITDIR_RTL=
+endif
+endif
+ifdef UNITDIR_RTL
+override NEEDUNITDIR+=$(UNITDIR_RTL)
+endif
 ifneq ($(wildcard $(PACKAGEDIR)/opengl),)
 ifneq ($(wildcard $(PACKAGEDIR)/opengl/$(OS_TARGET)),)
 PACKAGEDIR_OPENGL=$(PACKAGEDIR)/opengl/$(OS_TARGET)
@@ -357,18 +375,14 @@ ifneq ($(OS_TARGET),$(OS_SOURCE))
 override FPCOPT+=-T$(OS_TARGET)
 endif
 
-ifdef UNITSDIR
-override FPCOPT+=-Fu$(UNITSDIR)
-endif
-
-ifdef RTLDIR
-override FPCOPT+=-Fu$(RTLDIR)
-endif
-
 ifdef NEEDUNITDIR
 override FPCOPT+=$(addprefix -Fu,$(NEEDUNITDIR))
 endif
 
+ifdef UNITSDIR
+override FPCOPT+=-Fu$(UNITSDIR)
+endif
+
 # Add Other dirs path if asked
 ifdef OTHERLIBDIR
 override FPCOPT+=$(addprefix -Fl,$(OTHERLIBDIR))
@@ -765,8 +779,18 @@ endif
 endif
 endif
 
+PACKAGERTL=1
 PACKAGEOPENGL=1
 PACKAGEX11=1
+ifdef PACKAGERTL
+ifneq ($(wildcard $(PACKAGEDIR_RTL)),)
+ifeq ($(wildcard $(PACKAGEDIR_RTL)/$(FPCMADE)),)
+override COMPILEPACKAGES+=rtl
+rtl_package:
+	$(MAKE) -C $(PACKAGEDIR_RTL) all
+endif
+endif
+endif
 ifdef PACKAGEOPENGL
 ifneq ($(wildcard $(PACKAGEDIR_OPENGL)),)
 ifeq ($(wildcard $(PACKAGEDIR_OPENGL)/$(FPCMADE)),)
@@ -786,7 +810,7 @@ endif
 endif
 endif
 
-.PHONY:  rtl_package opengl_package x11_package
+.PHONY:  rtl_package rtl_package opengl_package x11_package
 
 #####################################################################
 # Exes

+ 46 - 22
packages/opengl/linux/Makefile

@@ -143,7 +143,15 @@ endif
 ifndef COMPONENTDIR
 COMPONENTDIR=$(FPCDIR)/components
 endif
-# Check if packagedir really exists else turn it off
+# Create units dir
+ifneq ($(FPCDIR),.)
+UNITSDIR=$(FPCDIR)/units/$(OS_TARGET)
+endif
+
+# Check if the dirs really exists, else turn it off
+ifeq ($(wildcard $(UNITSDIR)),)
+UNITSDIR=
+endif
 ifeq ($(wildcard $(PACKAGEDIR)),)
 PACKAGEDIR=
 endif
@@ -151,16 +159,6 @@ ifeq ($(wildcard $(COMPONENTDIR)),)
 COMPONENTDIR=
 endif
 
-# Create rtl,units dir
-ifneq ($(FPCDIR),.)
-override UNITSDIR=$(FPCDIR)/units/$(OS_TARGET)
-ifneq ($(wildcard $(FPCDIR)/rtl),)
-override RTLDIR=$(FPCDIR)/rtl/$(OS_TARGET)
-else
-override RTLDIR=$(UNITSDIR)/rtl
-endif
-endif
-
 #####################################################################
 # Default Settings
 #####################################################################
@@ -203,9 +201,29 @@ ZIPTARGET=install
 
 # Packages
 
-override PACKAGES=rtl
+override PACKAGES+=rtl x11
+ifneq ($(wildcard $(FPCDIR)/rtl),)
+ifneq ($(wildcard $(FPCDIR)/rtl/$(OS_TARGET)),)
 PACKAGEDIR_RTL=$(FPCDIR)/rtl/$(OS_TARGET)
-override PACKAGES+=x11
+else
+PACKAGEDIR_RTL=$(FPCDIR)/rtl
+endif
+UNITDIR_RTL=$(PACKAGEDIR_RTL)
+else
+PACKAGEDIR_RTL=
+ifneq ($(wildcard $(UNITSDIR)/rtl),)
+ifneq ($(wildcard $(UNITSDIR)/rtl/$(OS_TARGET)),)
+UNITDIR_RTL=$(UNITSDIR)/rtl/$(OS_TARGET)
+else
+UNITDIR_RTL=$(UNITSDIR)/rtl
+endif
+else
+UNITDIR_RTL=
+endif
+endif
+ifdef UNITDIR_RTL
+override NEEDUNITDIR+=$(UNITDIR_RTL)
+endif
 ifneq ($(wildcard $(PACKAGEDIR)/x11),)
 ifneq ($(wildcard $(PACKAGEDIR)/x11/$(OS_TARGET)),)
 PACKAGEDIR_X11=$(PACKAGEDIR)/x11/$(OS_TARGET)
@@ -332,18 +350,14 @@ ifneq ($(OS_TARGET),$(OS_SOURCE))
 override FPCOPT+=-T$(OS_TARGET)
 endif
 
-ifdef UNITSDIR
-override FPCOPT+=-Fu$(UNITSDIR)
-endif
-
-ifdef RTLDIR
-override FPCOPT+=-Fu$(RTLDIR)
-endif
-
 ifdef NEEDUNITDIR
 override FPCOPT+=$(addprefix -Fu,$(NEEDUNITDIR))
 endif
 
+ifdef UNITSDIR
+override FPCOPT+=-Fu$(UNITSDIR)
+endif
+
 # Smartlinking
 ifdef SMARTLINK
 override FPCOPT+=-CX
@@ -735,7 +749,17 @@ endif
 endif
 endif
 
+PACKAGERTL=1
 PACKAGEX11=1
+ifdef PACKAGERTL
+ifneq ($(wildcard $(PACKAGEDIR_RTL)),)
+ifeq ($(wildcard $(PACKAGEDIR_RTL)/$(FPCMADE)),)
+override COMPILEPACKAGES+=rtl
+rtl_package:
+	$(MAKE) -C $(PACKAGEDIR_RTL) all
+endif
+endif
+endif
 ifdef PACKAGEX11
 ifneq ($(wildcard $(PACKAGEDIR_X11)),)
 ifeq ($(wildcard $(PACKAGEDIR_X11)/$(FPCMADE)),)
@@ -746,7 +770,7 @@ endif
 endif
 endif
 
-.PHONY:  rtl_package x11_package
+.PHONY:  rtl_package rtl_package x11_package
 
 #####################################################################
 # Units

+ 47 - 17
packages/paszlib/Makefile

@@ -137,7 +137,15 @@ endif
 ifndef COMPONENTDIR
 COMPONENTDIR=$(FPCDIR)/components
 endif
-# Check if packagedir really exists else turn it off
+# Create units dir
+ifneq ($(FPCDIR),.)
+UNITSDIR=$(FPCDIR)/units/$(OS_TARGET)
+endif
+
+# Check if the dirs really exists, else turn it off
+ifeq ($(wildcard $(UNITSDIR)),)
+UNITSDIR=
+endif
 ifeq ($(wildcard $(PACKAGEDIR)),)
 PACKAGEDIR=
 endif
@@ -145,16 +153,6 @@ ifeq ($(wildcard $(COMPONENTDIR)),)
 COMPONENTDIR=
 endif
 
-# Create rtl,units dir
-ifneq ($(FPCDIR),.)
-override UNITSDIR=$(FPCDIR)/units/$(OS_TARGET)
-ifneq ($(wildcard $(FPCDIR)/rtl),)
-override RTLDIR=$(FPCDIR)/rtl/$(OS_TARGET)
-else
-override RTLDIR=$(UNITSDIR)/rtl
-endif
-endif
-
 #####################################################################
 # Default Settings
 #####################################################################
@@ -199,8 +197,29 @@ ZIPTARGET=install
 
 # Packages
 
-override PACKAGES=rtl
+override PACKAGES+=rtl
+ifneq ($(wildcard $(FPCDIR)/rtl),)
+ifneq ($(wildcard $(FPCDIR)/rtl/$(OS_TARGET)),)
 PACKAGEDIR_RTL=$(FPCDIR)/rtl/$(OS_TARGET)
+else
+PACKAGEDIR_RTL=$(FPCDIR)/rtl
+endif
+UNITDIR_RTL=$(PACKAGEDIR_RTL)
+else
+PACKAGEDIR_RTL=
+ifneq ($(wildcard $(UNITSDIR)/rtl),)
+ifneq ($(wildcard $(UNITSDIR)/rtl/$(OS_TARGET)),)
+UNITDIR_RTL=$(UNITSDIR)/rtl/$(OS_TARGET)
+else
+UNITDIR_RTL=$(UNITSDIR)/rtl
+endif
+else
+UNITDIR_RTL=
+endif
+endif
+ifdef UNITDIR_RTL
+override NEEDUNITDIR+=$(UNITDIR_RTL)
+endif
 
 # Libraries
 
@@ -305,12 +324,12 @@ ifneq ($(OS_TARGET),$(OS_SOURCE))
 override FPCOPT+=-T$(OS_TARGET)
 endif
 
-ifdef UNITSDIR
-override FPCOPT+=-Fu$(UNITSDIR)
+ifdef NEEDUNITDIR
+override FPCOPT+=$(addprefix -Fu,$(NEEDUNITDIR))
 endif
 
-ifdef RTLDIR
-override FPCOPT+=-Fu$(RTLDIR)
+ifdef UNITSDIR
+override FPCOPT+=-Fu$(UNITSDIR)
 endif
 
 # Smartlinking
@@ -708,7 +727,18 @@ endif
 endif
 endif
 
-.PHONY:  rtl_package
+PACKAGERTL=1
+ifdef PACKAGERTL
+ifneq ($(wildcard $(PACKAGEDIR_RTL)),)
+ifeq ($(wildcard $(PACKAGEDIR_RTL)/$(FPCMADE)),)
+override COMPILEPACKAGES+=rtl
+rtl_package:
+	$(MAKE) -C $(PACKAGEDIR_RTL) all
+endif
+endif
+endif
+
+.PHONY:  rtl_package rtl_package
 
 #####################################################################
 # Units

+ 47 - 17
packages/postgres/Makefile

@@ -137,7 +137,15 @@ endif
 ifndef COMPONENTDIR
 COMPONENTDIR=$(FPCDIR)/components
 endif
-# Check if packagedir really exists else turn it off
+# Create units dir
+ifneq ($(FPCDIR),.)
+UNITSDIR=$(FPCDIR)/units/$(OS_TARGET)
+endif
+
+# Check if the dirs really exists, else turn it off
+ifeq ($(wildcard $(UNITSDIR)),)
+UNITSDIR=
+endif
 ifeq ($(wildcard $(PACKAGEDIR)),)
 PACKAGEDIR=
 endif
@@ -145,16 +153,6 @@ ifeq ($(wildcard $(COMPONENTDIR)),)
 COMPONENTDIR=
 endif
 
-# Create rtl,units dir
-ifneq ($(FPCDIR),.)
-override UNITSDIR=$(FPCDIR)/units/$(OS_TARGET)
-ifneq ($(wildcard $(FPCDIR)/rtl),)
-override RTLDIR=$(FPCDIR)/rtl/$(OS_TARGET)
-else
-override RTLDIR=$(UNITSDIR)/rtl
-endif
-endif
-
 #####################################################################
 # Default Settings
 #####################################################################
@@ -198,8 +196,29 @@ ZIPTARGET=install
 
 # Packages
 
-override PACKAGES=rtl
+override PACKAGES+=rtl
+ifneq ($(wildcard $(FPCDIR)/rtl),)
+ifneq ($(wildcard $(FPCDIR)/rtl/$(OS_TARGET)),)
 PACKAGEDIR_RTL=$(FPCDIR)/rtl/$(OS_TARGET)
+else
+PACKAGEDIR_RTL=$(FPCDIR)/rtl
+endif
+UNITDIR_RTL=$(PACKAGEDIR_RTL)
+else
+PACKAGEDIR_RTL=
+ifneq ($(wildcard $(UNITSDIR)/rtl),)
+ifneq ($(wildcard $(UNITSDIR)/rtl/$(OS_TARGET)),)
+UNITDIR_RTL=$(UNITSDIR)/rtl/$(OS_TARGET)
+else
+UNITDIR_RTL=$(UNITSDIR)/rtl
+endif
+else
+UNITDIR_RTL=
+endif
+endif
+ifdef UNITDIR_RTL
+override NEEDUNITDIR+=$(UNITDIR_RTL)
+endif
 
 # Libraries
 
@@ -304,12 +323,12 @@ ifneq ($(OS_TARGET),$(OS_SOURCE))
 override FPCOPT+=-T$(OS_TARGET)
 endif
 
-ifdef UNITSDIR
-override FPCOPT+=-Fu$(UNITSDIR)
+ifdef NEEDUNITDIR
+override FPCOPT+=$(addprefix -Fu,$(NEEDUNITDIR))
 endif
 
-ifdef RTLDIR
-override FPCOPT+=-Fu$(RTLDIR)
+ifdef UNITSDIR
+override FPCOPT+=-Fu$(UNITSDIR)
 endif
 
 # Smartlinking
@@ -707,7 +726,18 @@ endif
 endif
 endif
 
-.PHONY:  rtl_package
+PACKAGERTL=1
+ifdef PACKAGERTL
+ifneq ($(wildcard $(PACKAGEDIR_RTL)),)
+ifeq ($(wildcard $(PACKAGEDIR_RTL)/$(FPCMADE)),)
+override COMPILEPACKAGES+=rtl
+rtl_package:
+	$(MAKE) -C $(PACKAGEDIR_RTL) all
+endif
+endif
+endif
+
+.PHONY:  rtl_package rtl_package
 
 #####################################################################
 # Units

+ 47 - 17
packages/svgalib/Makefile

@@ -137,7 +137,15 @@ endif
 ifndef COMPONENTDIR
 COMPONENTDIR=$(FPCDIR)/components
 endif
-# Check if packagedir really exists else turn it off
+# Create units dir
+ifneq ($(FPCDIR),.)
+UNITSDIR=$(FPCDIR)/units/$(OS_TARGET)
+endif
+
+# Check if the dirs really exists, else turn it off
+ifeq ($(wildcard $(UNITSDIR)),)
+UNITSDIR=
+endif
 ifeq ($(wildcard $(PACKAGEDIR)),)
 PACKAGEDIR=
 endif
@@ -145,16 +153,6 @@ ifeq ($(wildcard $(COMPONENTDIR)),)
 COMPONENTDIR=
 endif
 
-# Create rtl,units dir
-ifneq ($(FPCDIR),.)
-override UNITSDIR=$(FPCDIR)/units/$(OS_TARGET)
-ifneq ($(wildcard $(FPCDIR)/rtl),)
-override RTLDIR=$(FPCDIR)/rtl/$(OS_TARGET)
-else
-override RTLDIR=$(UNITSDIR)/rtl
-endif
-endif
-
 #####################################################################
 # Default Settings
 #####################################################################
@@ -198,8 +196,29 @@ ZIPTARGET=install
 
 # Packages
 
-override PACKAGES=rtl
+override PACKAGES+=rtl
+ifneq ($(wildcard $(FPCDIR)/rtl),)
+ifneq ($(wildcard $(FPCDIR)/rtl/$(OS_TARGET)),)
 PACKAGEDIR_RTL=$(FPCDIR)/rtl/$(OS_TARGET)
+else
+PACKAGEDIR_RTL=$(FPCDIR)/rtl
+endif
+UNITDIR_RTL=$(PACKAGEDIR_RTL)
+else
+PACKAGEDIR_RTL=
+ifneq ($(wildcard $(UNITSDIR)/rtl),)
+ifneq ($(wildcard $(UNITSDIR)/rtl/$(OS_TARGET)),)
+UNITDIR_RTL=$(UNITSDIR)/rtl/$(OS_TARGET)
+else
+UNITDIR_RTL=$(UNITSDIR)/rtl
+endif
+else
+UNITDIR_RTL=
+endif
+endif
+ifdef UNITDIR_RTL
+override NEEDUNITDIR+=$(UNITDIR_RTL)
+endif
 
 # Libraries
 
@@ -304,12 +323,12 @@ ifneq ($(OS_TARGET),$(OS_SOURCE))
 override FPCOPT+=-T$(OS_TARGET)
 endif
 
-ifdef UNITSDIR
-override FPCOPT+=-Fu$(UNITSDIR)
+ifdef NEEDUNITDIR
+override FPCOPT+=$(addprefix -Fu,$(NEEDUNITDIR))
 endif
 
-ifdef RTLDIR
-override FPCOPT+=-Fu$(RTLDIR)
+ifdef UNITSDIR
+override FPCOPT+=-Fu$(UNITSDIR)
 endif
 
 # Smartlinking
@@ -707,7 +726,18 @@ endif
 endif
 endif
 
-.PHONY:  rtl_package
+PACKAGERTL=1
+ifdef PACKAGERTL
+ifneq ($(wildcard $(PACKAGEDIR_RTL)),)
+ifeq ($(wildcard $(PACKAGEDIR_RTL)/$(FPCMADE)),)
+override COMPILEPACKAGES+=rtl
+rtl_package:
+	$(MAKE) -C $(PACKAGEDIR_RTL) all
+endif
+endif
+endif
+
+.PHONY:  rtl_package rtl_package
 
 #####################################################################
 # Units

+ 47 - 17
packages/uncgi/Makefile

@@ -137,7 +137,15 @@ endif
 ifndef COMPONENTDIR
 COMPONENTDIR=$(FPCDIR)/components
 endif
-# Check if packagedir really exists else turn it off
+# Create units dir
+ifneq ($(FPCDIR),.)
+UNITSDIR=$(FPCDIR)/units/$(OS_TARGET)
+endif
+
+# Check if the dirs really exists, else turn it off
+ifeq ($(wildcard $(UNITSDIR)),)
+UNITSDIR=
+endif
 ifeq ($(wildcard $(PACKAGEDIR)),)
 PACKAGEDIR=
 endif
@@ -145,16 +153,6 @@ ifeq ($(wildcard $(COMPONENTDIR)),)
 COMPONENTDIR=
 endif
 
-# Create rtl,units dir
-ifneq ($(FPCDIR),.)
-override UNITSDIR=$(FPCDIR)/units/$(OS_TARGET)
-ifneq ($(wildcard $(FPCDIR)/rtl),)
-override RTLDIR=$(FPCDIR)/rtl/$(OS_TARGET)
-else
-override RTLDIR=$(UNITSDIR)/rtl
-endif
-endif
-
 #####################################################################
 # Default Settings
 #####################################################################
@@ -198,8 +196,29 @@ ZIPTARGET=install
 
 # Packages
 
-override PACKAGES=rtl
+override PACKAGES+=rtl
+ifneq ($(wildcard $(FPCDIR)/rtl),)
+ifneq ($(wildcard $(FPCDIR)/rtl/$(OS_TARGET)),)
 PACKAGEDIR_RTL=$(FPCDIR)/rtl/$(OS_TARGET)
+else
+PACKAGEDIR_RTL=$(FPCDIR)/rtl
+endif
+UNITDIR_RTL=$(PACKAGEDIR_RTL)
+else
+PACKAGEDIR_RTL=
+ifneq ($(wildcard $(UNITSDIR)/rtl),)
+ifneq ($(wildcard $(UNITSDIR)/rtl/$(OS_TARGET)),)
+UNITDIR_RTL=$(UNITSDIR)/rtl/$(OS_TARGET)
+else
+UNITDIR_RTL=$(UNITSDIR)/rtl
+endif
+else
+UNITDIR_RTL=
+endif
+endif
+ifdef UNITDIR_RTL
+override NEEDUNITDIR+=$(UNITDIR_RTL)
+endif
 
 # Libraries
 
@@ -304,12 +323,12 @@ ifneq ($(OS_TARGET),$(OS_SOURCE))
 override FPCOPT+=-T$(OS_TARGET)
 endif
 
-ifdef UNITSDIR
-override FPCOPT+=-Fu$(UNITSDIR)
+ifdef NEEDUNITDIR
+override FPCOPT+=$(addprefix -Fu,$(NEEDUNITDIR))
 endif
 
-ifdef RTLDIR
-override FPCOPT+=-Fu$(RTLDIR)
+ifdef UNITSDIR
+override FPCOPT+=-Fu$(UNITSDIR)
 endif
 
 # Smartlinking
@@ -707,7 +726,18 @@ endif
 endif
 endif
 
-.PHONY:  rtl_package
+PACKAGERTL=1
+ifdef PACKAGERTL
+ifneq ($(wildcard $(PACKAGEDIR_RTL)),)
+ifeq ($(wildcard $(PACKAGEDIR_RTL)/$(FPCMADE)),)
+override COMPILEPACKAGES+=rtl
+rtl_package:
+	$(MAKE) -C $(PACKAGEDIR_RTL) all
+endif
+endif
+endif
+
+.PHONY:  rtl_package rtl_package
 
 #####################################################################
 # Units

+ 47 - 17
packages/utmp/Makefile

@@ -137,7 +137,15 @@ endif
 ifndef COMPONENTDIR
 COMPONENTDIR=$(FPCDIR)/components
 endif
-# Check if packagedir really exists else turn it off
+# Create units dir
+ifneq ($(FPCDIR),.)
+UNITSDIR=$(FPCDIR)/units/$(OS_TARGET)
+endif
+
+# Check if the dirs really exists, else turn it off
+ifeq ($(wildcard $(UNITSDIR)),)
+UNITSDIR=
+endif
 ifeq ($(wildcard $(PACKAGEDIR)),)
 PACKAGEDIR=
 endif
@@ -145,16 +153,6 @@ ifeq ($(wildcard $(COMPONENTDIR)),)
 COMPONENTDIR=
 endif
 
-# Create rtl,units dir
-ifneq ($(FPCDIR),.)
-override UNITSDIR=$(FPCDIR)/units/$(OS_TARGET)
-ifneq ($(wildcard $(FPCDIR)/rtl),)
-override RTLDIR=$(FPCDIR)/rtl/$(OS_TARGET)
-else
-override RTLDIR=$(UNITSDIR)/rtl
-endif
-endif
-
 #####################################################################
 # Default Settings
 #####################################################################
@@ -198,8 +196,29 @@ ZIPTARGET=install
 
 # Packages
 
-override PACKAGES=rtl
+override PACKAGES+=rtl
+ifneq ($(wildcard $(FPCDIR)/rtl),)
+ifneq ($(wildcard $(FPCDIR)/rtl/$(OS_TARGET)),)
 PACKAGEDIR_RTL=$(FPCDIR)/rtl/$(OS_TARGET)
+else
+PACKAGEDIR_RTL=$(FPCDIR)/rtl
+endif
+UNITDIR_RTL=$(PACKAGEDIR_RTL)
+else
+PACKAGEDIR_RTL=
+ifneq ($(wildcard $(UNITSDIR)/rtl),)
+ifneq ($(wildcard $(UNITSDIR)/rtl/$(OS_TARGET)),)
+UNITDIR_RTL=$(UNITSDIR)/rtl/$(OS_TARGET)
+else
+UNITDIR_RTL=$(UNITSDIR)/rtl
+endif
+else
+UNITDIR_RTL=
+endif
+endif
+ifdef UNITDIR_RTL
+override NEEDUNITDIR+=$(UNITDIR_RTL)
+endif
 
 # Libraries
 
@@ -304,12 +323,12 @@ ifneq ($(OS_TARGET),$(OS_SOURCE))
 override FPCOPT+=-T$(OS_TARGET)
 endif
 
-ifdef UNITSDIR
-override FPCOPT+=-Fu$(UNITSDIR)
+ifdef NEEDUNITDIR
+override FPCOPT+=$(addprefix -Fu,$(NEEDUNITDIR))
 endif
 
-ifdef RTLDIR
-override FPCOPT+=-Fu$(RTLDIR)
+ifdef UNITSDIR
+override FPCOPT+=-Fu$(UNITSDIR)
 endif
 
 # Smartlinking
@@ -707,7 +726,18 @@ endif
 endif
 endif
 
-.PHONY:  rtl_package
+PACKAGERTL=1
+ifdef PACKAGERTL
+ifneq ($(wildcard $(PACKAGEDIR_RTL)),)
+ifeq ($(wildcard $(PACKAGEDIR_RTL)/$(FPCMADE)),)
+override COMPILEPACKAGES+=rtl
+rtl_package:
+	$(MAKE) -C $(PACKAGEDIR_RTL) all
+endif
+endif
+endif
+
+.PHONY:  rtl_package rtl_package
 
 #####################################################################
 # Units

+ 47 - 17
packages/x11/Makefile

@@ -137,7 +137,15 @@ endif
 ifndef COMPONENTDIR
 COMPONENTDIR=$(FPCDIR)/components
 endif
-# Check if packagedir really exists else turn it off
+# Create units dir
+ifneq ($(FPCDIR),.)
+UNITSDIR=$(FPCDIR)/units/$(OS_TARGET)
+endif
+
+# Check if the dirs really exists, else turn it off
+ifeq ($(wildcard $(UNITSDIR)),)
+UNITSDIR=
+endif
 ifeq ($(wildcard $(PACKAGEDIR)),)
 PACKAGEDIR=
 endif
@@ -145,16 +153,6 @@ ifeq ($(wildcard $(COMPONENTDIR)),)
 COMPONENTDIR=
 endif
 
-# Create rtl,units dir
-ifneq ($(FPCDIR),.)
-override UNITSDIR=$(FPCDIR)/units/$(OS_TARGET)
-ifneq ($(wildcard $(FPCDIR)/rtl),)
-override RTLDIR=$(FPCDIR)/rtl/$(OS_TARGET)
-else
-override RTLDIR=$(UNITSDIR)/rtl
-endif
-endif
-
 #####################################################################
 # Default Settings
 #####################################################################
@@ -197,8 +195,29 @@ ZIPTARGET=install
 
 # Packages
 
-override PACKAGES=rtl
+override PACKAGES+=rtl
+ifneq ($(wildcard $(FPCDIR)/rtl),)
+ifneq ($(wildcard $(FPCDIR)/rtl/$(OS_TARGET)),)
 PACKAGEDIR_RTL=$(FPCDIR)/rtl/$(OS_TARGET)
+else
+PACKAGEDIR_RTL=$(FPCDIR)/rtl
+endif
+UNITDIR_RTL=$(PACKAGEDIR_RTL)
+else
+PACKAGEDIR_RTL=
+ifneq ($(wildcard $(UNITSDIR)/rtl),)
+ifneq ($(wildcard $(UNITSDIR)/rtl/$(OS_TARGET)),)
+UNITDIR_RTL=$(UNITSDIR)/rtl/$(OS_TARGET)
+else
+UNITDIR_RTL=$(UNITSDIR)/rtl
+endif
+else
+UNITDIR_RTL=
+endif
+endif
+ifdef UNITDIR_RTL
+override NEEDUNITDIR+=$(UNITDIR_RTL)
+endif
 
 # Libraries
 
@@ -303,12 +322,12 @@ ifneq ($(OS_TARGET),$(OS_SOURCE))
 override FPCOPT+=-T$(OS_TARGET)
 endif
 
-ifdef UNITSDIR
-override FPCOPT+=-Fu$(UNITSDIR)
+ifdef NEEDUNITDIR
+override FPCOPT+=$(addprefix -Fu,$(NEEDUNITDIR))
 endif
 
-ifdef RTLDIR
-override FPCOPT+=-Fu$(RTLDIR)
+ifdef UNITSDIR
+override FPCOPT+=-Fu$(UNITSDIR)
 endif
 
 # Smartlinking
@@ -702,7 +721,18 @@ endif
 endif
 endif
 
-.PHONY:  rtl_package
+PACKAGERTL=1
+ifdef PACKAGERTL
+ifneq ($(wildcard $(PACKAGEDIR_RTL)),)
+ifeq ($(wildcard $(PACKAGEDIR_RTL)/$(FPCMADE)),)
+override COMPILEPACKAGES+=rtl
+rtl_package:
+	$(MAKE) -C $(PACKAGEDIR_RTL) all
+endif
+endif
+endif
+
+.PHONY:  rtl_package rtl_package
 
 #####################################################################
 # Units

+ 47 - 17
packages/zlib/Makefile

@@ -137,7 +137,15 @@ endif
 ifndef COMPONENTDIR
 COMPONENTDIR=$(FPCDIR)/components
 endif
-# Check if packagedir really exists else turn it off
+# Create units dir
+ifneq ($(FPCDIR),.)
+UNITSDIR=$(FPCDIR)/units/$(OS_TARGET)
+endif
+
+# Check if the dirs really exists, else turn it off
+ifeq ($(wildcard $(UNITSDIR)),)
+UNITSDIR=
+endif
 ifeq ($(wildcard $(PACKAGEDIR)),)
 PACKAGEDIR=
 endif
@@ -145,16 +153,6 @@ ifeq ($(wildcard $(COMPONENTDIR)),)
 COMPONENTDIR=
 endif
 
-# Create rtl,units dir
-ifneq ($(FPCDIR),.)
-override UNITSDIR=$(FPCDIR)/units/$(OS_TARGET)
-ifneq ($(wildcard $(FPCDIR)/rtl),)
-override RTLDIR=$(FPCDIR)/rtl/$(OS_TARGET)
-else
-override RTLDIR=$(UNITSDIR)/rtl
-endif
-endif
-
 #####################################################################
 # Default Settings
 #####################################################################
@@ -197,8 +195,29 @@ ZIPTARGET=install
 
 # Packages
 
-override PACKAGES=rtl
+override PACKAGES+=rtl
+ifneq ($(wildcard $(FPCDIR)/rtl),)
+ifneq ($(wildcard $(FPCDIR)/rtl/$(OS_TARGET)),)
 PACKAGEDIR_RTL=$(FPCDIR)/rtl/$(OS_TARGET)
+else
+PACKAGEDIR_RTL=$(FPCDIR)/rtl
+endif
+UNITDIR_RTL=$(PACKAGEDIR_RTL)
+else
+PACKAGEDIR_RTL=
+ifneq ($(wildcard $(UNITSDIR)/rtl),)
+ifneq ($(wildcard $(UNITSDIR)/rtl/$(OS_TARGET)),)
+UNITDIR_RTL=$(UNITSDIR)/rtl/$(OS_TARGET)
+else
+UNITDIR_RTL=$(UNITSDIR)/rtl
+endif
+else
+UNITDIR_RTL=
+endif
+endif
+ifdef UNITDIR_RTL
+override NEEDUNITDIR+=$(UNITDIR_RTL)
+endif
 
 # Libraries
 
@@ -303,12 +322,12 @@ ifneq ($(OS_TARGET),$(OS_SOURCE))
 override FPCOPT+=-T$(OS_TARGET)
 endif
 
-ifdef UNITSDIR
-override FPCOPT+=-Fu$(UNITSDIR)
+ifdef NEEDUNITDIR
+override FPCOPT+=$(addprefix -Fu,$(NEEDUNITDIR))
 endif
 
-ifdef RTLDIR
-override FPCOPT+=-Fu$(RTLDIR)
+ifdef UNITSDIR
+override FPCOPT+=-Fu$(UNITSDIR)
 endif
 
 # Smartlinking
@@ -702,7 +721,18 @@ endif
 endif
 endif
 
-.PHONY:  rtl_package
+PACKAGERTL=1
+ifdef PACKAGERTL
+ifneq ($(wildcard $(PACKAGEDIR_RTL)),)
+ifeq ($(wildcard $(PACKAGEDIR_RTL)/$(FPCMADE)),)
+override COMPILEPACKAGES+=rtl
+rtl_package:
+	$(MAKE) -C $(PACKAGEDIR_RTL) all
+endif
+endif
+endif
+
+.PHONY:  rtl_package rtl_package
 
 #####################################################################
 # Units

+ 43 - 13
rtl/Makefile

@@ -129,7 +129,15 @@ endif
 ifndef COMPONENTDIR
 COMPONENTDIR=$(FPCDIR)/components
 endif
-# Check if packagedir really exists else turn it off
+# Create units dir
+ifneq ($(FPCDIR),.)
+UNITSDIR=$(FPCDIR)/units/$(OS_TARGET)
+endif
+
+# Check if the dirs really exists, else turn it off
+ifeq ($(wildcard $(UNITSDIR)),)
+UNITSDIR=
+endif
 ifeq ($(wildcard $(PACKAGEDIR)),)
 PACKAGEDIR=
 endif
@@ -137,16 +145,6 @@ ifeq ($(wildcard $(COMPONENTDIR)),)
 COMPONENTDIR=
 endif
 
-# Create rtl,units dir
-ifneq ($(FPCDIR),.)
-override UNITSDIR=$(FPCDIR)/units/$(OS_TARGET)
-ifneq ($(wildcard $(FPCDIR)/rtl),)
-override RTLDIR=$(FPCDIR)/rtl/$(OS_TARGET)
-else
-override RTLDIR=$(UNITSDIR)/rtl
-endif
-endif
-
 #####################################################################
 # Default Settings
 #####################################################################
@@ -189,8 +187,29 @@ ZIPTARGET=install
 
 # Packages
 
-override PACKAGES=rtl
+override PACKAGES+=rtl
+ifneq ($(wildcard $(FPCDIR)/rtl),)
+ifneq ($(wildcard $(FPCDIR)/rtl/$(OS_TARGET)),)
 PACKAGEDIR_RTL=$(FPCDIR)/rtl/$(OS_TARGET)
+else
+PACKAGEDIR_RTL=$(FPCDIR)/rtl
+endif
+UNITDIR_RTL=$(PACKAGEDIR_RTL)
+else
+PACKAGEDIR_RTL=
+ifneq ($(wildcard $(UNITSDIR)/rtl),)
+ifneq ($(wildcard $(UNITSDIR)/rtl/$(OS_TARGET)),)
+UNITDIR_RTL=$(UNITSDIR)/rtl/$(OS_TARGET)
+else
+UNITDIR_RTL=$(UNITSDIR)/rtl
+endif
+else
+UNITDIR_RTL=
+endif
+endif
+ifdef UNITDIR_RTL
+override NEEDUNITDIR+=$(UNITDIR_RTL)
+endif
 
 # Libraries
 
@@ -242,7 +261,18 @@ endif
 endif
 endif
 
-.PHONY:  rtl_package
+PACKAGERTL=1
+ifdef PACKAGERTL
+ifneq ($(wildcard $(PACKAGEDIR_RTL)),)
+ifeq ($(wildcard $(PACKAGEDIR_RTL)/$(FPCMADE)),)
+override COMPILEPACKAGES+=rtl
+rtl_package:
+	$(MAKE) -C $(PACKAGEDIR_RTL) all
+endif
+endif
+endif
+
+.PHONY:  rtl_package rtl_package
 
 
 # Target Dirs

+ 0 - 22
rtl/go32v1/Makefile

@@ -144,24 +144,6 @@ endif
 ifndef COMPONENTDIR
 COMPONENTDIR=$(FPCDIR)/components
 endif
-# Check if packagedir really exists else turn it off
-ifeq ($(wildcard $(PACKAGEDIR)),)
-PACKAGEDIR=
-endif
-ifeq ($(wildcard $(COMPONENTDIR)),)
-COMPONENTDIR=
-endif
-
-# Create rtl,units dir
-ifneq ($(FPCDIR),.)
-override UNITSDIR=$(FPCDIR)/units/$(OS_TARGET)
-ifneq ($(wildcard $(FPCDIR)/rtl),)
-override RTLDIR=$(FPCDIR)/rtl/$(OS_TARGET)
-else
-override RTLDIR=$(UNITSDIR)/rtl
-endif
-endif
-
 #####################################################################
 # Default Settings
 #####################################################################
@@ -352,10 +334,6 @@ ifdef UNITSDIR
 override FPCOPT+=-Fu$(UNITSDIR)
 endif
 
-ifdef RTLDIR
-override FPCOPT+=-Fu$(RTLDIR)
-endif
-
 ifdef NEEDINCDIR
 override FPCOPT+=$(addprefix -Fi,$(NEEDINCDIR))
 endif

+ 0 - 22
rtl/go32v2/Makefile

@@ -144,24 +144,6 @@ endif
 ifndef COMPONENTDIR
 COMPONENTDIR=$(FPCDIR)/components
 endif
-# Check if packagedir really exists else turn it off
-ifeq ($(wildcard $(PACKAGEDIR)),)
-PACKAGEDIR=
-endif
-ifeq ($(wildcard $(COMPONENTDIR)),)
-COMPONENTDIR=
-endif
-
-# Create rtl,units dir
-ifneq ($(FPCDIR),.)
-override UNITSDIR=$(FPCDIR)/units/$(OS_TARGET)
-ifneq ($(wildcard $(FPCDIR)/rtl),)
-override RTLDIR=$(FPCDIR)/rtl/$(OS_TARGET)
-else
-override RTLDIR=$(UNITSDIR)/rtl
-endif
-endif
-
 #####################################################################
 # Default Settings
 #####################################################################
@@ -352,10 +334,6 @@ ifdef UNITSDIR
 override FPCOPT+=-Fu$(UNITSDIR)
 endif
 
-ifdef RTLDIR
-override FPCOPT+=-Fu$(RTLDIR)
-endif
-
 ifdef NEEDINCDIR
 override FPCOPT+=$(addprefix -Fi,$(NEEDINCDIR))
 endif

+ 0 - 22
rtl/linux/Makefile

@@ -144,24 +144,6 @@ endif
 ifndef COMPONENTDIR
 COMPONENTDIR=$(FPCDIR)/components
 endif
-# Check if packagedir really exists else turn it off
-ifeq ($(wildcard $(PACKAGEDIR)),)
-PACKAGEDIR=
-endif
-ifeq ($(wildcard $(COMPONENTDIR)),)
-COMPONENTDIR=
-endif
-
-# Create rtl,units dir
-ifneq ($(FPCDIR),.)
-override UNITSDIR=$(FPCDIR)/units/$(OS_TARGET)
-ifneq ($(wildcard $(FPCDIR)/rtl),)
-override RTLDIR=$(FPCDIR)/rtl/$(OS_TARGET)
-else
-override RTLDIR=$(UNITSDIR)/rtl
-endif
-endif
-
 #####################################################################
 # Default Settings
 #####################################################################
@@ -363,10 +345,6 @@ ifdef UNITSDIR
 override FPCOPT+=-Fu$(UNITSDIR)
 endif
 
-ifdef RTLDIR
-override FPCOPT+=-Fu$(RTLDIR)
-endif
-
 ifdef NEEDINCDIR
 override FPCOPT+=$(addprefix -Fi,$(NEEDINCDIR))
 endif

+ 0 - 22
rtl/os2/Makefile

@@ -144,24 +144,6 @@ endif
 ifndef COMPONENTDIR
 COMPONENTDIR=$(FPCDIR)/components
 endif
-# Check if packagedir really exists else turn it off
-ifeq ($(wildcard $(PACKAGEDIR)),)
-PACKAGEDIR=
-endif
-ifeq ($(wildcard $(COMPONENTDIR)),)
-COMPONENTDIR=
-endif
-
-# Create rtl,units dir
-ifneq ($(FPCDIR),.)
-override UNITSDIR=$(FPCDIR)/units/$(OS_TARGET)
-ifneq ($(wildcard $(FPCDIR)/rtl),)
-override RTLDIR=$(FPCDIR)/rtl/$(OS_TARGET)
-else
-override RTLDIR=$(UNITSDIR)/rtl
-endif
-endif
-
 #####################################################################
 # Default Settings
 #####################################################################
@@ -352,10 +334,6 @@ ifdef UNITSDIR
 override FPCOPT+=-Fu$(UNITSDIR)
 endif
 
-ifdef RTLDIR
-override FPCOPT+=-Fu$(RTLDIR)
-endif
-
 ifdef NEEDINCDIR
 override FPCOPT+=$(addprefix -Fi,$(NEEDINCDIR))
 endif

+ 0 - 22
rtl/win32/Makefile

@@ -144,24 +144,6 @@ endif
 ifndef COMPONENTDIR
 COMPONENTDIR=$(FPCDIR)/components
 endif
-# Check if packagedir really exists else turn it off
-ifeq ($(wildcard $(PACKAGEDIR)),)
-PACKAGEDIR=
-endif
-ifeq ($(wildcard $(COMPONENTDIR)),)
-COMPONENTDIR=
-endif
-
-# Create rtl,units dir
-ifneq ($(FPCDIR),.)
-override UNITSDIR=$(FPCDIR)/units/$(OS_TARGET)
-ifneq ($(wildcard $(FPCDIR)/rtl),)
-override RTLDIR=$(FPCDIR)/rtl/$(OS_TARGET)
-else
-override RTLDIR=$(UNITSDIR)/rtl
-endif
-endif
-
 #####################################################################
 # Default Settings
 #####################################################################
@@ -357,10 +339,6 @@ ifdef UNITSDIR
 override FPCOPT+=-Fu$(UNITSDIR)
 endif
 
-ifdef RTLDIR
-override FPCOPT+=-Fu$(RTLDIR)
-endif
-
 ifdef NEEDINCDIR
 override FPCOPT+=$(addprefix -Fi,$(NEEDINCDIR))
 endif

+ 43 - 13
tests/Makefile

@@ -129,7 +129,15 @@ endif
 ifndef COMPONENTDIR
 COMPONENTDIR=$(FPCDIR)/components
 endif
-# Check if packagedir really exists else turn it off
+# Create units dir
+ifneq ($(FPCDIR),.)
+UNITSDIR=$(FPCDIR)/units/$(OS_TARGET)
+endif
+
+# Check if the dirs really exists, else turn it off
+ifeq ($(wildcard $(UNITSDIR)),)
+UNITSDIR=
+endif
 ifeq ($(wildcard $(PACKAGEDIR)),)
 PACKAGEDIR=
 endif
@@ -137,16 +145,6 @@ ifeq ($(wildcard $(COMPONENTDIR)),)
 COMPONENTDIR=
 endif
 
-# Create rtl,units dir
-ifneq ($(FPCDIR),.)
-override UNITSDIR=$(FPCDIR)/units/$(OS_TARGET)
-ifneq ($(wildcard $(FPCDIR)/rtl),)
-override RTLDIR=$(FPCDIR)/rtl/$(OS_TARGET)
-else
-override RTLDIR=$(UNITSDIR)/rtl
-endif
-endif
-
 #####################################################################
 # Default Settings
 #####################################################################
@@ -188,8 +186,29 @@ ZIPTARGET=install
 
 # Packages
 
-override PACKAGES=rtl
+override PACKAGES+=rtl
+ifneq ($(wildcard $(FPCDIR)/rtl),)
+ifneq ($(wildcard $(FPCDIR)/rtl/$(OS_TARGET)),)
 PACKAGEDIR_RTL=$(FPCDIR)/rtl/$(OS_TARGET)
+else
+PACKAGEDIR_RTL=$(FPCDIR)/rtl
+endif
+UNITDIR_RTL=$(PACKAGEDIR_RTL)
+else
+PACKAGEDIR_RTL=
+ifneq ($(wildcard $(UNITSDIR)/rtl),)
+ifneq ($(wildcard $(UNITSDIR)/rtl/$(OS_TARGET)),)
+UNITDIR_RTL=$(UNITSDIR)/rtl/$(OS_TARGET)
+else
+UNITDIR_RTL=$(UNITSDIR)/rtl
+endif
+else
+UNITDIR_RTL=
+endif
+endif
+ifdef UNITDIR_RTL
+override NEEDUNITDIR+=$(UNITDIR_RTL)
+endif
 
 # Libraries
 
@@ -297,7 +316,18 @@ endif
 endif
 endif
 
-.PHONY:  rtl_package
+PACKAGERTL=1
+ifdef PACKAGERTL
+ifneq ($(wildcard $(PACKAGEDIR_RTL)),)
+ifeq ($(wildcard $(PACKAGEDIR_RTL)/$(FPCMADE)),)
+override COMPILEPACKAGES+=rtl
+rtl_package:
+	$(MAKE) -C $(PACKAGEDIR_RTL) all
+endif
+endif
+endif
+
+.PHONY:  rtl_package rtl_package
 
 #####################################################################
 # Users rules

+ 79 - 23
utils/Makefile

@@ -137,7 +137,15 @@ endif
 ifndef COMPONENTDIR
 COMPONENTDIR=$(FPCDIR)/components
 endif
-# Check if packagedir really exists else turn it off
+# Create units dir
+ifneq ($(FPCDIR),.)
+UNITSDIR=$(FPCDIR)/units/$(OS_TARGET)
+endif
+
+# Check if the dirs really exists, else turn it off
+ifeq ($(wildcard $(UNITSDIR)),)
+UNITSDIR=
+endif
 ifeq ($(wildcard $(PACKAGEDIR)),)
 PACKAGEDIR=
 endif
@@ -145,16 +153,6 @@ ifeq ($(wildcard $(COMPONENTDIR)),)
 COMPONENTDIR=
 endif
 
-# Create rtl,units dir
-ifneq ($(FPCDIR),.)
-override UNITSDIR=$(FPCDIR)/units/$(OS_TARGET)
-ifneq ($(wildcard $(FPCDIR)/rtl),)
-override RTLDIR=$(FPCDIR)/rtl/$(OS_TARGET)
-else
-override RTLDIR=$(UNITSDIR)/rtl
-endif
-endif
-
 #####################################################################
 # Default Settings
 #####################################################################
@@ -181,7 +179,7 @@ endif
 # Targets
 
 override DIROBJECTS+=$(wildcard tply h2pas)
-override EXEOBJECTS+=ppufiles ppudump ppumove ppdep ptop rstconv data2inc fpcmake delp
+override EXEOBJECTS+=ppufiles ppudump ppumove ppdep ptop rstconv data2inc fpcmake delp bin2obj
 
 # Clean
 
@@ -202,9 +200,29 @@ endif
 
 # Packages
 
-override PACKAGES=rtl
+override PACKAGES+=rtl fcl zlib
+ifneq ($(wildcard $(FPCDIR)/rtl),)
+ifneq ($(wildcard $(FPCDIR)/rtl/$(OS_TARGET)),)
 PACKAGEDIR_RTL=$(FPCDIR)/rtl/$(OS_TARGET)
-override PACKAGES+=fcl
+else
+PACKAGEDIR_RTL=$(FPCDIR)/rtl
+endif
+UNITDIR_RTL=$(PACKAGEDIR_RTL)
+else
+PACKAGEDIR_RTL=
+ifneq ($(wildcard $(UNITSDIR)/rtl),)
+ifneq ($(wildcard $(UNITSDIR)/rtl/$(OS_TARGET)),)
+UNITDIR_RTL=$(UNITSDIR)/rtl/$(OS_TARGET)
+else
+UNITDIR_RTL=$(UNITSDIR)/rtl
+endif
+else
+UNITDIR_RTL=
+endif
+endif
+ifdef UNITDIR_RTL
+override NEEDUNITDIR+=$(UNITDIR_RTL)
+endif
 ifneq ($(wildcard $(FPCDIR)/fcl),)
 ifneq ($(wildcard $(FPCDIR)/fcl/$(OS_TARGET)),)
 PACKAGEDIR_FCL=$(FPCDIR)/fcl/$(OS_TARGET)
@@ -227,6 +245,28 @@ endif
 ifdef UNITDIR_FCL
 override NEEDUNITDIR+=$(UNITDIR_FCL)
 endif
+ifneq ($(wildcard $(PACKAGEDIR)/zlib),)
+ifneq ($(wildcard $(PACKAGEDIR)/zlib/$(OS_TARGET)),)
+PACKAGEDIR_ZLIB=$(PACKAGEDIR)/zlib/$(OS_TARGET)
+else
+PACKAGEDIR_ZLIB=$(PACKAGEDIR)/zlib
+endif
+UNITDIR_ZLIB=$(PACKAGEDIR_ZLIB)
+else
+PACKAGEDIR_ZLIB=
+ifneq ($(wildcard $(UNITSDIR)/zlib),)
+ifneq ($(wildcard $(UNITSDIR)/zlib/$(OS_TARGET)),)
+UNITDIR_ZLIB=$(UNITSDIR)/zlib/$(OS_TARGET)
+else
+UNITDIR_ZLIB=$(UNITSDIR)/zlib
+endif
+else
+UNITDIR_ZLIB=
+endif
+endif
+ifdef UNITDIR_ZLIB
+override NEEDUNITDIR+=$(UNITDIR_ZLIB)
+endif
 
 # Libraries
 
@@ -331,18 +371,14 @@ ifneq ($(OS_TARGET),$(OS_SOURCE))
 override FPCOPT+=-T$(OS_TARGET)
 endif
 
-ifdef UNITSDIR
-override FPCOPT+=-Fu$(UNITSDIR)
-endif
-
-ifdef RTLDIR
-override FPCOPT+=-Fu$(RTLDIR)
-endif
-
 ifdef NEEDUNITDIR
 override FPCOPT+=$(addprefix -Fu,$(NEEDUNITDIR))
 endif
 
+ifdef UNITSDIR
+override FPCOPT+=-Fu$(UNITSDIR)
+endif
+
 # Target dirs
 ifdef TARGETDIR
 override FPCOPT+=-FE$(TARGETDIR)
@@ -756,7 +792,18 @@ endif
 endif
 endif
 
+PACKAGERTL=1
 PACKAGEFCL=1
+PACKAGEZLIB=1
+ifdef PACKAGERTL
+ifneq ($(wildcard $(PACKAGEDIR_RTL)),)
+ifeq ($(wildcard $(PACKAGEDIR_RTL)/$(FPCMADE)),)
+override COMPILEPACKAGES+=rtl
+rtl_package:
+	$(MAKE) -C $(PACKAGEDIR_RTL) all
+endif
+endif
+endif
 ifdef PACKAGEFCL
 ifneq ($(wildcard $(PACKAGEDIR_FCL)),)
 ifeq ($(wildcard $(PACKAGEDIR_FCL)/$(FPCMADE)),)
@@ -766,8 +813,17 @@ fcl_package:
 endif
 endif
 endif
+ifdef PACKAGEZLIB
+ifneq ($(wildcard $(PACKAGEDIR_ZLIB)),)
+ifeq ($(wildcard $(PACKAGEDIR_ZLIB)/$(FPCMADE)),)
+override COMPILEPACKAGES+=zlib
+zlib_package:
+	$(MAKE) -C $(PACKAGEDIR_ZLIB) all
+endif
+endif
+endif
 
-.PHONY:  rtl_package fcl_package
+.PHONY:  rtl_package rtl_package fcl_package zlib_package
 
 #####################################################################
 # Exes

+ 2 - 2
utils/Makefile.fpc

@@ -4,13 +4,13 @@
 
 [targets]
 dirs=tply h2pas
-programs=ppufiles ppudump ppumove ppdep ptop rstconv data2inc fpcmake delp
+programs=ppufiles ppudump ppumove ppdep ptop rstconv data2inc fpcmake delp bin2obj
 
 [clean]
 units=ppu ptopu
 
 [require]
-packages=fcl
+packages=fcl zlib
 
 [tools]
 tooldata2inc=1

+ 47 - 17
utils/h2pas/Makefile

@@ -137,7 +137,15 @@ endif
 ifndef COMPONENTDIR
 COMPONENTDIR=$(FPCDIR)/components
 endif
-# Check if packagedir really exists else turn it off
+# Create units dir
+ifneq ($(FPCDIR),.)
+UNITSDIR=$(FPCDIR)/units/$(OS_TARGET)
+endif
+
+# Check if the dirs really exists, else turn it off
+ifeq ($(wildcard $(UNITSDIR)),)
+UNITSDIR=
+endif
 ifeq ($(wildcard $(PACKAGEDIR)),)
 PACKAGEDIR=
 endif
@@ -145,16 +153,6 @@ ifeq ($(wildcard $(COMPONENTDIR)),)
 COMPONENTDIR=
 endif
 
-# Create rtl,units dir
-ifneq ($(FPCDIR),.)
-override UNITSDIR=$(FPCDIR)/units/$(OS_TARGET)
-ifneq ($(wildcard $(FPCDIR)/rtl),)
-override RTLDIR=$(FPCDIR)/rtl/$(OS_TARGET)
-else
-override RTLDIR=$(UNITSDIR)/rtl
-endif
-endif
-
 #####################################################################
 # Default Settings
 #####################################################################
@@ -199,8 +197,29 @@ override NEEDOPT=-Sg
 
 # Packages
 
-override PACKAGES=rtl
+override PACKAGES+=rtl
+ifneq ($(wildcard $(FPCDIR)/rtl),)
+ifneq ($(wildcard $(FPCDIR)/rtl/$(OS_TARGET)),)
 PACKAGEDIR_RTL=$(FPCDIR)/rtl/$(OS_TARGET)
+else
+PACKAGEDIR_RTL=$(FPCDIR)/rtl
+endif
+UNITDIR_RTL=$(PACKAGEDIR_RTL)
+else
+PACKAGEDIR_RTL=
+ifneq ($(wildcard $(UNITSDIR)/rtl),)
+ifneq ($(wildcard $(UNITSDIR)/rtl/$(OS_TARGET)),)
+UNITDIR_RTL=$(UNITSDIR)/rtl/$(OS_TARGET)
+else
+UNITDIR_RTL=$(UNITSDIR)/rtl
+endif
+else
+UNITDIR_RTL=
+endif
+endif
+ifdef UNITDIR_RTL
+override NEEDUNITDIR+=$(UNITDIR_RTL)
+endif
 
 # Libraries
 
@@ -309,12 +328,12 @@ ifdef NEEDOPT
 override FPCOPT+=$(NEEDOPT)
 endif
 
-ifdef UNITSDIR
-override FPCOPT+=-Fu$(UNITSDIR)
+ifdef NEEDUNITDIR
+override FPCOPT+=$(addprefix -Fu,$(NEEDUNITDIR))
 endif
 
-ifdef RTLDIR
-override FPCOPT+=-Fu$(RTLDIR)
+ifdef UNITSDIR
+override FPCOPT+=-Fu$(UNITSDIR)
 endif
 
 # Smartlinking
@@ -708,7 +727,18 @@ endif
 endif
 endif
 
-.PHONY:  rtl_package
+PACKAGERTL=1
+ifdef PACKAGERTL
+ifneq ($(wildcard $(PACKAGEDIR_RTL)),)
+ifeq ($(wildcard $(PACKAGEDIR_RTL)/$(FPCMADE)),)
+override COMPILEPACKAGES+=rtl
+rtl_package:
+	$(MAKE) -C $(PACKAGEDIR_RTL) all
+endif
+endif
+endif
+
+.PHONY:  rtl_package rtl_package
 
 #####################################################################
 # Exes

+ 47 - 17
utils/simulator/Makefile

@@ -137,7 +137,15 @@ endif
 ifndef COMPONENTDIR
 COMPONENTDIR=$(FPCDIR)/components
 endif
-# Check if packagedir really exists else turn it off
+# Create units dir
+ifneq ($(FPCDIR),.)
+UNITSDIR=$(FPCDIR)/units/$(OS_TARGET)
+endif
+
+# Check if the dirs really exists, else turn it off
+ifeq ($(wildcard $(UNITSDIR)),)
+UNITSDIR=
+endif
 ifeq ($(wildcard $(PACKAGEDIR)),)
 PACKAGEDIR=
 endif
@@ -145,16 +153,6 @@ ifeq ($(wildcard $(COMPONENTDIR)),)
 COMPONENTDIR=
 endif
 
-# Create rtl,units dir
-ifneq ($(FPCDIR),.)
-override UNITSDIR=$(FPCDIR)/units/$(OS_TARGET)
-ifneq ($(wildcard $(FPCDIR)/rtl),)
-override RTLDIR=$(FPCDIR)/rtl/$(OS_TARGET)
-else
-override RTLDIR=$(UNITSDIR)/rtl
-endif
-endif
-
 #####################################################################
 # Default Settings
 #####################################################################
@@ -198,8 +196,29 @@ ZIPTARGET=install
 
 # Packages
 
-override PACKAGES=rtl
+override PACKAGES+=rtl
+ifneq ($(wildcard $(FPCDIR)/rtl),)
+ifneq ($(wildcard $(FPCDIR)/rtl/$(OS_TARGET)),)
 PACKAGEDIR_RTL=$(FPCDIR)/rtl/$(OS_TARGET)
+else
+PACKAGEDIR_RTL=$(FPCDIR)/rtl
+endif
+UNITDIR_RTL=$(PACKAGEDIR_RTL)
+else
+PACKAGEDIR_RTL=
+ifneq ($(wildcard $(UNITSDIR)/rtl),)
+ifneq ($(wildcard $(UNITSDIR)/rtl/$(OS_TARGET)),)
+UNITDIR_RTL=$(UNITSDIR)/rtl/$(OS_TARGET)
+else
+UNITDIR_RTL=$(UNITSDIR)/rtl
+endif
+else
+UNITDIR_RTL=
+endif
+endif
+ifdef UNITDIR_RTL
+override NEEDUNITDIR+=$(UNITDIR_RTL)
+endif
 
 # Libraries
 
@@ -304,12 +323,12 @@ ifneq ($(OS_TARGET),$(OS_SOURCE))
 override FPCOPT+=-T$(OS_TARGET)
 endif
 
-ifdef UNITSDIR
-override FPCOPT+=-Fu$(UNITSDIR)
+ifdef NEEDUNITDIR
+override FPCOPT+=$(addprefix -Fu,$(NEEDUNITDIR))
 endif
 
-ifdef RTLDIR
-override FPCOPT+=-Fu$(RTLDIR)
+ifdef UNITSDIR
+override FPCOPT+=-Fu$(UNITSDIR)
 endif
 
 # Smartlinking
@@ -703,7 +722,18 @@ endif
 endif
 endif
 
-.PHONY:  rtl_package
+PACKAGERTL=1
+ifdef PACKAGERTL
+ifneq ($(wildcard $(PACKAGEDIR_RTL)),)
+ifeq ($(wildcard $(PACKAGEDIR_RTL)/$(FPCMADE)),)
+override COMPILEPACKAGES+=rtl
+rtl_package:
+	$(MAKE) -C $(PACKAGEDIR_RTL) all
+endif
+endif
+endif
+
+.PHONY:  rtl_package rtl_package
 
 #####################################################################
 # Exes

+ 47 - 17
utils/tply/Makefile

@@ -137,7 +137,15 @@ endif
 ifndef COMPONENTDIR
 COMPONENTDIR=$(FPCDIR)/components
 endif
-# Check if packagedir really exists else turn it off
+# Create units dir
+ifneq ($(FPCDIR),.)
+UNITSDIR=$(FPCDIR)/units/$(OS_TARGET)
+endif
+
+# Check if the dirs really exists, else turn it off
+ifeq ($(wildcard $(UNITSDIR)),)
+UNITSDIR=
+endif
 ifeq ($(wildcard $(PACKAGEDIR)),)
 PACKAGEDIR=
 endif
@@ -145,16 +153,6 @@ ifeq ($(wildcard $(COMPONENTDIR)),)
 COMPONENTDIR=
 endif
 
-# Create rtl,units dir
-ifneq ($(FPCDIR),.)
-override UNITSDIR=$(FPCDIR)/units/$(OS_TARGET)
-ifneq ($(wildcard $(FPCDIR)/rtl),)
-override RTLDIR=$(FPCDIR)/rtl/$(OS_TARGET)
-else
-override RTLDIR=$(UNITSDIR)/rtl
-endif
-endif
-
 #####################################################################
 # Default Settings
 #####################################################################
@@ -210,8 +208,29 @@ override NEEDOPT=-Sg
 
 # Packages
 
-override PACKAGES=rtl
+override PACKAGES+=rtl
+ifneq ($(wildcard $(FPCDIR)/rtl),)
+ifneq ($(wildcard $(FPCDIR)/rtl/$(OS_TARGET)),)
 PACKAGEDIR_RTL=$(FPCDIR)/rtl/$(OS_TARGET)
+else
+PACKAGEDIR_RTL=$(FPCDIR)/rtl
+endif
+UNITDIR_RTL=$(PACKAGEDIR_RTL)
+else
+PACKAGEDIR_RTL=
+ifneq ($(wildcard $(UNITSDIR)/rtl),)
+ifneq ($(wildcard $(UNITSDIR)/rtl/$(OS_TARGET)),)
+UNITDIR_RTL=$(UNITSDIR)/rtl/$(OS_TARGET)
+else
+UNITDIR_RTL=$(UNITSDIR)/rtl
+endif
+else
+UNITDIR_RTL=
+endif
+endif
+ifdef UNITDIR_RTL
+override NEEDUNITDIR+=$(UNITDIR_RTL)
+endif
 
 # Libraries
 
@@ -320,12 +339,12 @@ ifdef NEEDOPT
 override FPCOPT+=$(NEEDOPT)
 endif
 
-ifdef UNITSDIR
-override FPCOPT+=-Fu$(UNITSDIR)
+ifdef NEEDUNITDIR
+override FPCOPT+=$(addprefix -Fu,$(NEEDUNITDIR))
 endif
 
-ifdef RTLDIR
-override FPCOPT+=-Fu$(RTLDIR)
+ifdef UNITSDIR
+override FPCOPT+=-Fu$(UNITSDIR)
 endif
 
 # Smartlinking
@@ -719,7 +738,18 @@ endif
 endif
 endif
 
-.PHONY:  rtl_package
+PACKAGERTL=1
+ifdef PACKAGERTL
+ifneq ($(wildcard $(PACKAGEDIR_RTL)),)
+ifeq ($(wildcard $(PACKAGEDIR_RTL)/$(FPCMADE)),)
+override COMPILEPACKAGES+=rtl
+rtl_package:
+	$(MAKE) -C $(PACKAGEDIR_RTL) all
+endif
+endif
+endif
+
+.PHONY:  rtl_package rtl_package
 
 #####################################################################
 # Units