Browse Source

* initial version

peter 26 years ago
parent
commit
a352b586ca
3 changed files with 1561 additions and 0 deletions
  1. 1103 0
      utils/fpcmake.ini
  2. 421 0
      utils/fpcmake.pp
  3. 37 0
      utils/makefile.exm

+ 1103 - 0
utils/fpcmake.ini

@@ -0,0 +1,1103 @@
+;
+; $Id$
+;
+; Templates used by fpcmake to create a Makefile from Makefile.fpc
+;
+
+[osdetect]
+#####################################################################
+# Autodetect OS (Linux or Dos or Windows NT)
+# define inlinux when running under linux
+# define inWinNT when running under WinNT
+#####################################################################
+
+# We need only / in the path
+override PATH:=$(subst \,/,$(PATH))
+
+# Search for PWD and determine also if we are under linux
+PWD=$(strip $(wildcard $(addsuffix /pwd.exe,$(subst ;, ,$(PATH)))))
+ifeq ($(PWD),)
+PWD=$(strip $(wildcard $(addsuffix /pwd,$(subst :, ,$(PATH)))))
+ifeq ($(PWD),)
+nopwd:
+        @echo You need the GNU utils package to use this Makefile!
+        @echo Get ftp://ftp.freepascal.org/pub/fpc/dist/go32v2/utilgo32.zip
+        @exit
+else
+inlinux=1
+endif
+else
+PWD:=$(firstword $(PWD))
+endif
+
+# Detect NT - NT sets OS to Windows_NT
+ifndef inlinux
+ifeq ($(OS),Windows_NT)
+inWinNT=1
+endif
+endif
+
+# Detect OS/2 - OS/2 has OS2_SHELL defined
+ifndef inlinux
+ifndef inWinNT
+ifdef OS2_SHELL
+inOS2=1
+endif
+endif
+endif
+
+# The extension of executables
+ifdef inlinux
+EXEEXT=
+else
+EXEEXT=.exe
+endif
+
+# The path which is search separated by spaces
+ifdef inlinux
+SEARCHPATH=$(subst :, ,$(PATH))
+else
+SEARCHPATH=$(subst ;, ,$(PATH))
+endif
+
+
+[fpcdetect]
+#####################################################################
+# FPC version/target Detection
+#####################################################################
+
+# What compiler to use ?
+ifndef FPC
+ifdef inOS2
+export FPC=ppos2$(EXEEXT)
+else
+export FPC=ppc386$(EXEEXT)
+endif
+endif
+
+# Target OS
+ifndef OS_TARGET
+export OS_TARGET=$(shell $(FPC) -iTO)
+endif
+
+# Source OS
+ifndef OS_SOURCE
+export OS_SOURCE=$(shell $(FPC) -iSO)
+endif
+
+# FPC_CPU
+ifndef FPC_CPU
+export FPC_CPU=$(shell $(FPC) -iTP)
+endif
+
+# FPC version
+ifndef FPC_VERSION
+export FPC_VERSION=$(shell $(FPC) -iV)
+endif
+
+
+[defaultsettings]
+#####################################################################
+# Default Settings
+#####################################################################
+
+# Release ? Then force OPT and don't use extra opts via commandline
+ifdef RELEASE
+override OPT:=-Xs -OG2p3 -n
+endif
+
+# Verbose settings (warning,note,info)
+ifdef VERBOSE
+override OPT+=-vwni
+endif
+
+
+[usersettings]
+#####################################################################
+# User Settings
+#####################################################################
+
+
+[command_begin]
+#####################################################################
+# Compiler Command Line
+#####################################################################
+
+# Load commandline OPTDEF and add FPC_CPU define
+override FPCOPTDEF:=-d$(FPC_CPU)
+
+# Load commandline OPT and add target and unit dir to be sure
+ifneq ($(OS_TARGET),$(OS_SOURCE))
+override FPCOPT+=-T$(OS_TARGET)
+endif
+
+[command_needopt]
+ifdef NEEDOPT
+override FPCOPT+=$(NEEDOPT)
+endif
+
+[command_rtl]
+# RTL first and then Unit dir (a unit can override RTLunit)
+ifdef RTLDIR
+override FPCOPT+=$(addprefix -Fu,$(RTLDIR))
+endif
+
+[command_needunit]
+ifdef NEEDUNITDIR
+override FPCOPT+=$(addprefix -Fu,$(NEEDUNITDIR))
+endif
+
+[command_needlib]
+ifdef NEEDLIBDIR
+override FPCOPT+=$(addprefix -Fl,$(NEEDLIBDIR))
+endif
+
+[command_needobj]
+ifdef NEEDOBJDIR
+override FPCOPT+=$(addprefix -Fo,$(NEEDOBJDIR))
+endif
+
+[command_gcclib]
+# Add GCC lib path if asked
+ifdef GCCLIBDIR
+override FPCOPT+=-Fl$(GCCLIBDIR)
+endif
+
+[command_otherlib]
+# Add Other dirs path if asked
+ifdef OTHERLIBDIR
+override FPCOPT+=$(addprefix -Fl,$(OTHERLIBDIR))
+endif
+
+[command_inc]
+# Add include dirs INC and PROCINC and OSINC
+ifdef INC
+override FPCOPT+=$(addprefix -Fi,$(INC))
+endif
+
+[command_procinc]
+ifdef PROCINC
+override FPCOPT+=$(addprefix -Fi,$(PROCINC))
+endif
+
+[command_osinc]
+ifdef OSINC
+override FPCOPT+=$(addprefix -Fi,$(OSINC))
+endif
+
+[command_target]
+# Target dirs
+ifdef TARGETDIR
+override FPCOPT+=-FE$(TARGETDIR)
+endif
+
+[command_unittarget]
+ifdef UNITTARGETDIR
+override FPCOPT+=-FU$(UNITTARGETDIR)
+endif
+
+[command_smartlink]
+# Smartlinking
+ifeq ($(SMARTLINK),YES)
+override FPCOPT+=-Cx
+endif
+
+[command_end]
+# Add commandline options
+ifdef OPT
+override FPCOPT+=OPT
+endif
+ifdef UNITDIR
+override FPCOPT+=$(addprefix -Fu,$(UNITDIR))
+endif
+ifdef LIBDIR
+override FPCOPT+=$(addprefix -Fl,$(LIBDIR))
+endif
+ifdef OBJDIR
+override FPCOPT+=$(addprefix -Fo,$(OBJDIR))
+endif
+
+# Add defines from FPCOPTDEF to FPCOPT
+ifdef FPCOPTDEF
+override FPCOPT+=$(FPCOPTDEF)
+endif
+
+# Was a config file specified ?
+ifdef CFGFILE
+override FPCOPT+=@$(CFGFILE)
+endif
+
+override COMPILER=$(FPC) $(FPCOPT)
+
+
+[shelltools]
+#####################################################################
+# Shell tools
+#####################################################################
+
+# To copy pograms
+ifndef COPY
+export COPY=cp -fp
+endif
+
+# To move pograms
+ifndef MOVE
+export MOVE=mv -f
+endif
+
+# Check delete program
+ifndef DEL
+export DEL=rm -f
+endif
+
+# Check deltree program
+ifndef DELTREE
+export DELTREE=rm -rf
+endif
+
+# To install files
+ifndef INSTALL
+ifdef inlinux
+export INSTALL=install -m 644
+else
+export INSTALL=$(COPY)
+# ginstall has the strange thing to stubify all .o files !
+#INSTALL=ginstall -m 644
+endif
+endif
+
+# To install programs
+ifndef INSTALLEXE
+ifdef inlinux
+export INSTALLEXE=install -m 755
+else
+export INSTALLEXE=$(COPY)
+# ginstall has the strange thing to stubify all .o files !
+#INSTALLEXE=ginstall -m 755
+endif
+endif
+
+# To make a directory.
+ifndef MKDIR
+ifdef inlinux
+export MKDIR=install -m 755 -d
+else
+export MKDIR=ginstall -m 755 -d
+endif
+endif
+
+
+[tool_default]
+#####################################################################
+# Default Tools
+#####################################################################
+
+# assembler, redefine it if cross compiling
+ifndef AS
+AS=as
+endif
+
+# linker, but probably not used
+ifndef LD
+LD=ld
+endif
+
+# Where is the ppumove program ?
+ifndef PPUMOVE
+PPUMOVE=ppumove
+endif
+
+# ppas.bat / ppas.sh
+ifdef inlinux
+PPAS=ppas.sh
+else
+ifdef inOS2
+PPAS=ppas.cmd
+else
+PPAS=ppas.bat
+endif
+endif
+
+# also call ppas if with command option -s
+ifeq (,$(findstring -s ,$(COMPILER)))
+EXECPPAS=
+else
+EXECPPAS=@$(PPAS)
+endif
+
+# ldconfig to rebuild .so cache
+ifdef inlinux
+LDCONFIG=ldconfig
+else
+LDCONFIG=
+endif
+
+# echo
+ifndef ECHO
+ECHO=$(strip $(wildcard $(addsuffix /echo$(EXEEXT),$(SEARCHPATH))))
+ifeq ($(ECHO),)
+export ECHO:=echo
+else
+export ECHO:=$(firstword $(ECHO))
+endif
+endif
+
+
+[tool_diff]
+# diff
+ifndef DIFF
+DIFF=$(strip $(wildcard $(addsuffix /diff$(EXEEXT),$(SEARCHPATH))))
+ifeq ($(DIFF),)
+DIFF=
+else
+export DIFF:=$(firstword $(DIFF))
+endif
+endif
+
+[tool_cmp]
+# cmp
+ifndef CMP
+CMP=$(strip $(wildcard $(addsuffix /cmp$(EXEEXT),$(SEARCHPATH))))
+ifeq ($(CMP),)
+CMP=
+else
+export CMP:=$(firstword $(CMP))
+endif
+endif
+
+[tool_sed]
+# Sed
+ifndef SED
+SED=$(strip $(wildcard $(addsuffix /sed$(EXEEXT),$(SEARCHPATH))))
+ifeq ($(SED),)
+SED=
+else
+export SED:=$(firstword $(SED))
+endif
+endif
+
+[tool_upx]
+# Look if UPX is found for go32v2 and win32. We can't use $UPX becuase
+# upx uses that one itself (PFV)
+ifndef UPXPROG
+ifeq ($(OS_TARGET),go32v2)
+UPXPROG=1
+endif
+ifeq ($(OS_TARGET),win32)
+UPXPROG=1
+endif
+ifdef UPXPROG
+UPXPROG=$(strip $(wildcard $(addsuffix /upx$(EXEEXT),$(SEARCHPATH))))
+ifeq ($(UPX),)
+UPXPROG=
+else
+export UPXPROG:=$(firstword $(UPX))
+endif
+else
+UPXPROG=
+endif
+endif
+
+[tool_date]
+# gdate/date
+ifndef DATE
+DATE=$(strip $(wildcard $(addsuffix /date$(EXEEXT),$(SEARCHPATH))))
+ifeq ($(DATE),)
+DATE=$(strip $(wildcard $(addsuffix /gdate$(EXEEXT),$(SEACHPATH))))
+ifeq ($(DATE),)
+DATE=
+else
+export DATE:=$(firstword $(DATE))
+endif
+else
+export DATE:=$(firstword $(DATE))
+endif
+endif
+
+ifdef DATE
+DATESTR=$(shell $(DATE) +%Y%m%d)
+else
+DATESTR=
+endif
+
+[tool_zip]
+# ZipProg, you can't use Zip as the var name (PFV)
+ifndef ZIPPROG
+ZIPPROG=$(strip $(wildcard $(addsuffix /zip$(EXEEXT),$(SEARCHPATH))))
+ifeq ($(ZIPPROG),)
+ZIPPROG=
+else
+export ZIPPROG:=$(firstword $(ZIPPROG)) -D9 -r
+endif
+endif
+
+ifndef ZIPEXT
+ZIPEXT=.zip
+endif
+
+
+[dir_default]
+#####################################################################
+# Default Directories
+#####################################################################
+
+# Base dir
+ifdef PWD
+BASEDIR:=$(shell $(PWD))
+else
+BASEDIR=.
+endif
+
+# set the prefix directory where to install everything
+ifndef PREFIXINSTALLDIR
+ifdef inlinux
+export PREFIXINSTALLDIR=/usr
+else
+export PREFIXINSTALLDIR=/pp
+endif
+endif
+
+
+[dir_rtl]
+# set the directory to the rtl base
+ifndef RTLDIR
+ifdef RTL
+RTLDIR:=$(RTL)/$(OS_TARGET)
+else
+RTLDIR:=$(FPCDIR)/rtl/$(OS_TARGET)
+endif
+endif
+
+
+[dir_units]
+# specify where units are.
+ifndef UNITDIR
+ifdef UNITS
+UNITDIR=$(UNITS)/$(OS_TARGET)
+else
+UNITDIR=$(FPCDIR)/units/$(OS_TARGET)
+endif
+endif
+ifeq ($(strip $(wildcard $(UNITDIR)/*)),)
+UNITDIR=
+endif
+
+
+[dir_gcclib]
+# On linux, try to find where libgcc.a is.
+ifdef inlinux
+ifndef GCCLIBDIR
+export GCCLIBDIR:=$(shell dirname `(gcc -v 2>&1)| head -n 1| awk '{ print $$4 } '`)
+endif
+endif
+
+
+[dir_otherlib]
+# Where to find other libraries
+ifdef inlinux
+ifndef OTHERLIBDIR
+export OTHERLIBDIR:=$(shell grep -v "^\#" /etc/ld.so.conf | awk '{ ORS=" "; print $1 }')
+endif
+endif
+
+
+[dir_install]
+#####################################################################
+# Install Directories based on BASEINSTALLDIR
+#####################################################################
+
+# set the base directory where to install everything
+ifndef BASEINSTALLDIR
+ifdef inlinux
+BASEINSTALLDIR=$(PREFIXINSTALLDIR)/lib/fpc/$(FPC_VERSION)
+else
+BASEINSTALLDIR=$(PREFIXINSTALLDIR)
+endif
+endif
+
+
+# Linux binary really goes to baseinstalldir
+ifndef LIBINSTALLDIR
+ifdef inlinux
+LIBINSTALLDIR=$(BASEINSTALLDIR)
+else
+LIBINSTALLDIR=$(BASEINSTALLDIR)/lib
+endif
+endif
+
+# set the directory where to install the binaries
+ifndef BININSTALLDIR
+ifdef inlinux
+BININSTALLDIR=$(PREFIXINSTALLDIR)/bin
+else
+BININSTALLDIR=$(BASEINSTALLDIR)/bin/$(OS_TARGET)
+endif
+endif
+
+# Where the .msg files will be stored
+ifndef MSGINSTALLDIR
+MSGINSTALLDIR=$(BASEINSTALLDIR)/msg
+endif
+
+# Where the .msg files will be stored
+ifndef SOURCEINSTALLDIR
+SOURCEINSTALLDIR=$(BASEINSTALLDIR)/source
+endif
+
+# Where the doc files will be stored
+ifndef DOCINSTALLDIR
+ifdef inlinux
+DOCINSTALLDIR=$(PREFIXINSTALLDIR)/doc/fpc/$(FPC_VERSION)
+else
+DOCINSTALLDIR=$(BASEINSTALLDIR)/doc
+endif
+endif
+
+########################
+# Unit Directories
+########################
+
+# this can be set to 'rtl' when the RTL units are installed
+ifndef UNITPREFIX
+UNITPREFIX=units
+endif
+
+# set the directory where to install the units.
+ifndef UNITINSTALLDIR
+UNITINSTALLDIR=$(BASEINSTALLDIR)/$(UNITPREFIX)/$(OS_TARGET)
+endif
+
+# set the directory where to install the units.
+ifndef STATIC_UNITINSTALLDIR
+STATIC_UNITINSTALLDIR=$(UNITINSTALLDIR)/static
+endif
+
+# set the directory where to install the units.
+ifndef SHARED_UNITINSTALLDIR
+SHARED_UNITINSTALLDIR=$(UNITINSTALLDIR)/shared
+endif
+
+# set the directory where to install the libs (must exist)
+ifndef STATIC_LIBINSTALLDIR
+STATIC_LIBINSTALLDIR=$(STATIC_UNITINSTALLDIR)
+endif
+
+# set the directory where to install the libs (must exist)
+ifndef SHARED_LIBINSTALLDIR
+ifdef inlinux
+SHARED_LIBINSTALLDIR=$(PREFIXINSTALLDIR)/lib
+else
+SHARED_LIBINSTALLDIR=$(SHARED_UNITINSTALLDIR)
+endif
+endif
+
+
+[extensions]
+#####################################################################
+# Default extensions
+#####################################################################
+
+# Default needed extensions (Go32v2,Linux)
+LOADEREXT=.as
+PPLEXT=.ppl
+PPUEXT=.ppu
+OEXT=.o
+ASMEXT=.s
+SMARTEXT=.sl
+STATICLIBEXT=.a
+SHAREDLIBEXT=.so
+PACKAGESUFFIX=
+
+# Go32v1
+ifeq ($(OS_TARGET),go32v1)
+PPUEXT=.pp1
+OEXT=.o1
+ASMEXT=.s1
+SMARTEXT=.sl1
+STATICLIBEXT=.a1
+SHAREDLIBEXT=.so1
+PACKAGESUFFIX=v1
+endif
+
+# Go32v2
+ifeq ($(OS_TARGET),go32v2)
+PACKAGESUFFIX=go32
+endif
+
+# Linux
+ifeq ($(OS_TARGET),linux)
+PACKAGESUFFIX=linux
+endif
+
+# Win32
+ifeq ($(OS_TARGET),win32)
+PPUEXT=.ppw
+OEXT=.ow
+ASMEXT=.sw
+SMARTEXT=.slw
+STATICLIBEXT=.aw
+SHAREDLIBEXT=.dll
+PACKAGESUFFIX=win32
+endif
+
+# OS/2
+ifeq ($(OS_TARGET),os2)
+PPUEXT=.ppo
+ASMEXT=.so2
+OEXT=.oo2
+SMARTEXT=.so
+STATICLIBEXT=.ao2
+SHAREDLIBEXT=.dll
+PACKAGESUFFIX=os2
+endif
+
+# library prefix
+LIBPREFIX=lib
+ifeq ($(OS_TARGET),go32v2)
+LIBPREFIX=
+endif
+ifeq ($(OS_TARGET),go32v1)
+LIBPREFIX=
+endif
+
+# determine which .pas extension is used
+ifndef PASEXT
+ifdef EXEOBJECTS
+override TESTPAS:=$(strip $(wildcard $(addsuffix .pas,$(firstword $(EXEOBJECTS)))))
+else
+override TESTPAS:=$(strip $(wildcard $(addsuffix .pas,$(firstword $(UNITOBJECTS)))))
+endif
+ifeq ($(TESTPAS),)
+PASEXT=.pp
+else
+PASEXT=.pas
+endif
+endif
+
+
+[defaultrules]
+#####################################################################
+# Default rules
+#####################################################################
+
+.PHONY: all staticlib sharedlib install staticinstall sharedinstall \
+        libinstall zipinstall zipinstalladd clean depend info
+
+
+[compilerules]
+#####################################################################
+# General compile rules
+#####################################################################
+
+.PHONY: fpc_all fpc_units fpc_exes fpc_loaders
+
+# Create Filenames
+LOADEROFILES=$(addsuffix $(OEXT),$(LOADEROBJECTS))
+EXEFILES=$(addsuffix $(EXEEXT),$(EXEOBJECTS))
+EXEOFILES=$(addsuffix $(OEXT),$(EXEOBJECTS))
+UNITPPUFILES=$(addsuffix $(PPUEXT),$(UNITOBJECTS))
+UNITOFILES=$(addsuffix $(OEXT),$(UNITOBJECTS))
+UNITAFILES=$(addsuffix $(STATICLIBEXT),$(UNITOBJECTS))
+
+.SUFFIXES: $(EXEEXT) $(PPUEXT) $(OEXT) .pas .pp
+
+ifdef DEFAULTUNITS
+fpc_all: fpc_loaders fpc_units
+else
+fpc_all: fpc_loaders fpc_units fpc_exes
+endif
+
+fpc_loaders: $(LOADEROFILES)
+
+fpc_units: $(UNITPPUFILES)
+
+fpc_exes: $(EXEFILES)
+
+# General compile rules, available for both possible PASEXT
+%$(PPUEXT): %.pp
+        $(COMPILER) $< $(REDIR)
+        $(EXECPASS)
+
+%$(PPUEXT): %.pas
+        $(COMPILER) $< $(REDIR)
+        $(EXECPASS)
+
+%$(EXEEXT): %.pp
+        $(COMPILER) $< $(REDIR)
+        $(EXECPASS)
+
+%$(EXEEXT): %.pas
+        $(COMPILER) $< $(REDIR)
+        $(EXECPASS)
+
+%$(OEXT): %$(LOADEREXT)
+        $(AS) -o $*$(OEXT) $<
+
+
+[libraryrules]
+#####################################################################
+# Library
+#####################################################################
+
+.PHONY: fpc_staticlib fpc_sharedlib
+
+# Default sharedlib units are all unit objects
+ifndef SHAREDLIBUNITOBJECTS
+SHAREDLIBUNITOBJECTS=$(UNITOBJECTS)
+endif
+
+fpc_staticlib:
+        $(MAKE) libsclean
+        $(MAKE) all SMARTLINK=YES
+
+fpc_sharedlib: all
+ifdef inlinux
+ifndef LIBNAME
+        @$(ECHO) LIBNAME not set
+else
+        $(PPUMOVE) $(SHAREDLIBUNITOBJECTS) -o$(LIBNAME)
+endif
+else
+        @$(ECHO) Shared Libraries not supported
+endif
+
+
+[installrules]
+#####################################################################
+# Install rules
+#####################################################################
+
+.PHONY: fpc_showinstallfiles fpc_install
+
+fpc_showinstallfiles : all
+ifndef DEFAULTUNITS
+ifdef EXEOBJECTS
+        @$(ECHO) $(addprefix "\n"$(BININSTALLDIR)/,$(EXEFILES))
+endif
+endif
+ifdef LOADEROBJECTS
+        @$(ECHO) $(addprefix "\n"$(UNITINSTALLDIR)/,$(LOADEROFILES))
+endif
+ifdef UNITOBJECTS
+        @$(ECHO) $(addprefix "\n"$(UNITINSTALLDIR)/,$(wildcard $(UNITPPUFILES) $(UNITOFILES) $(UNITAFILES)))
+endif
+ifdef EXTRAINSTALLUNITS
+        @$(ECHO) $(addprefix "\n"$(UNITINSTALLDIR)/,$(wildcard $(addsuffix $(OEXT),$(EXTRAINSTALLUNITS)) $(addsuffix $(STATICLIBEXT),$(EXTRAINSTALLUNITS)) $(addsuffix $(PPUEXT),$(EXTRAINSTALLUNITS))))
+endif
+
+fpc_install:
+# Create UnitInstallFiles
+ifdef EXTRAINSTALLUNITS
+override EXTRAINSTALLFILES=$(wildcard $(addsuffix $(OEXT),$(EXTRAINSTALLUNITS)) $(addsuffix $(STATICLIBEXT),$(EXTRAINSTALLUNITS)) $(addsuffix $(PPUEXT),$(EXTRAINSTALLUNITS)))
+endif
+ifndef DEFAULTUNITS
+ifdef EXEOBJECTS
+        $(MKDIR) $(BININSTALLDIR)
+# Compress the exes if upx is defined
+ifdef UPXPROG
+        -$(UPXPROG) $(EXEFILES)
+endif
+        $(INSTALLEXE) $(EXEFILES) $(BININSTALLDIR)
+endif
+endif
+ifdef LOADEROBJECTS
+        $(MKDIR) $(UNITINSTALLDIR)
+        $(INSTALL) $(LOADEROFILES) $(UNITINSTALLDIR)
+endif
+ifdef UNITOBJECTS
+        $(MKDIR) $(UNITINSTALLDIR)
+        $(INSTALL) $(wildcard $(UNITPPUFILES) $(UNITOFILES) $(UNITAFILES)) $(UNITINSTALLDIR)
+endif
+ifneq ($(wildcard $(addsuffix $(OEXT),$(EXTRAINSTALLUNITS)) $(addsuffix $(STATICLIBEXT),$(EXTRAINSTALLUNITS)) $(addsuffix $(PPUEXT),$(EXTRAINSTALLUNITS))),)
+        $(MKDIR) $(UNITINSTALLDIR)
+        $(INSTALL) $(wildcard $(addsuffix $(OEXT),$(EXTRAINSTALLUNITS)) $(addsuffix $(STATICLIBEXT),$(EXTRAINSTALLUNITS)) $(addsuffix $(PPUEXT),$(EXTRAINSTALLUNITS))) $(UNITINSTALLDIR)
+endif
+
+
+[libinstallrules]
+.PHONY: fpc_staticinstall fpc_sharedinstall fpc_libinstall
+
+fpc_staticinstall: staticlib
+        $(MKDIR) $(STATIC_UNITINSTALLDIR)
+        $(INSTALL) $(UNITINSTALLFILES) $(STATIC_UNITINSTALLDIR)
+        $(MKDIR) $(STATIC_LIBINSTALLDIR)
+        $(INSTALLEXE) *$(STATICLIBEXT) $(STATIC_LIBINSTALLDIR)
+
+fpc_sharedinstall: sharedlib
+        $(MKDIR) $(SHARED_UNITINSTALLDIR)
+ifdef UNITINSTALLFILES
+        $(INSTALL) $(UNITINSTALLFILES) $(SHARED_UNITINSTALLDIR)
+else
+        $(INSTALL) $(UNITOFILES) $(SHARED_UNITINSTALLDIR)
+endif
+        $(MKDIR) $(SHARED_LIBINSTALLDIR)
+        $(INSTALLEXE) *$(SHAREDLIBEXT) $(SHARED_LIBINSTALLDIR)
+
+# Target for the sharedlib install which is not avail for all targets
+ifdef inlinux
+SHAREDINSTALL=sharedinstall
+else
+SHAREDINSTALL=
+endif
+
+fpc_libinstall: staticinstall $(SHAREDINSTALL)
+
+
+[zipinstallrules]
+#####################################################################
+# Zip
+#####################################################################
+
+.PHONY: fpc_zipinstall fpc_zipinstalladd
+
+# Temporary path to pack a file
+ifndef PACKDIR
+ifndef inlinux
+PACKDIR=pack_tmp
+else
+PACKDIR=/tmp/fpc-pack
+endif
+endif
+
+# Test dir if none specified
+ifndef PACKAGEDIR
+PACKAGEDIR=$(BASEDIR)
+endif
+
+# Add .zip/.tar.gz extension
+ifdef ZIPNAME
+ifndef inlinux
+override ZIPNAME:=$(ZIPNAME)$(ZIPEXT)
+endif
+endif
+
+# Default target which is call before zipping
+ifndef ZIPTARGET
+ZIPTARGET=install
+endif
+
+# Note: This will not remove the zipfile first
+fpc_zipinstalladd:
+ifndef ZIPNAME
+        @$(ECHO) Please specify ZIPNAME!
+        @exit
+else
+        $(MAKE) $(ZIPTARGET) PREFIXINSTALLDIR=$(PACKDIR)
+ifdef inlinux
+        gzip -d $(PACKAGEDIR)/$(ZIPNAME).tar.gz
+        cd $(PACKDIR) ; tar rv --file $(PACKAGEDIR)/$(ZIPNAME).tar * ; cd $(BASEDIR)
+        gzip $(PACKAGEDIR)/$(ZIPNAME).tar
+else
+        cd $(PACKDIR) ; $(ZIPPROG) $(PACKAGEDIR)/$(ZIPNAME) * ; cd $(BASEDIR)
+endif
+        $(DELTREE) $(PACKDIR)
+endif
+
+# First remove the zip and then install
+fpc_zipinstall:
+ifndef ZIPNAME
+        @$(ECHO) Please specify ZIPNAME!
+        @exit
+else
+        $(DEL) $(PACKAGEDIR)/$(ZIPNAME)
+        $(MAKE) $(ZIPTARGET) PREFIXINSTALLDIR=$(PACKDIR)
+ifdef inlinux
+        cd $(PACKDIR) ; tar cvz --file $(PACKAGEDIR)/$(ZIPNAME).tar.gz * ; cd $(BASEDIR)
+else
+        cd $(PACKDIR) ; $(ZIPPROG) $(PACKAGEDIR)/$(ZIPNAME) * ; cd $(BASEDIR)
+endif
+        $(DELTREE) $(PACKDIR)
+endif
+
+
+[cleanrules]
+#####################################################################
+# Clean rules
+#####################################################################
+
+.PHONY: fpc_clean fpc_libsclean fpc_cleanall
+
+fpc_clean:
+ifdef EXEOBJECTS
+        -$(DEL) $(EXEFILES) $(EXEOFILES)
+endif
+ifdef LOADEROBJECTS
+        -$(DEL) $(LOADEROFILES)
+endif
+ifdef UNITOBJECTS
+        -$(DEL) $(wildcard $(UNITPPUFILES) $(UNITOFILES) $(UNITAFILES))
+endif
+ifneq ($(wildcard $(addsuffix $(OEXT),$(EXTRACLEANUNITS)) $(addsuffix $(STATICLIBEXT),$(EXTRACLEANUNITS)) $(addsuffix $(PPUEXT),$(EXTRACLEANUNITS))) ,)
+        -$(DEL) $(wildcard $(addsuffix $(OEXT),$(EXTRACLEANUNITS)) $(addsuffix $(STATICLIBEXT),$(EXTRACLEANUNITS)) $(addsuffix $(PPUEXT),$(EXTRACLEANUNITS)))
+endif
+        -$(DEL) $(PPAS) link.res log
+
+fpc_libsclean: clean
+        -$(DEL) *$(STATICLIBEXT) *$(SHAREDLIBEXT) *$(PPLEXT)
+
+fpc_cleanall:
+ifdef EXEOBJECTS
+        -$(DEL) $(EXEFILES)
+endif
+        -$(DEL) *$(OEXT) *$(PPUEXT) *$(ASMEXT) *$(STATICLIBEXT) *$(SHAREDLIBEXT) *$(PPLEXT)
+        -$(DELTREE) *$(SMARTEXT)
+
+
+[dependrules]
+#####################################################################
+# Depend rules
+#####################################################################
+
+.PHONY: fpc_depend
+
+fpc_depend:
+        makedep $(UNITOBJECTS)
+
+
+[inforules]
+#####################################################################
+# Info rules
+#####################################################################
+
+.PHONY: fpc_info fpc_cfginfo fpc_objectinfo fpc_toolsinfo fpc_installinfo \
+        fpc_dirinfo
+
+fpc_info: $(FPCINFO)
+
+[info_cfg]
+fpc_infocfg:
+        @$(ECHO)
+        @$(ECHO)  == Configuration info ==
+        @$(ECHO)
+        @$(ECHO)  FPC....... $(FPC)
+        @$(ECHO)  Version... $(FPC_VERSION)
+        @$(ECHO)  CPU....... $(FPC_CPU)
+        @$(ECHO)  Source.... $(OS_SOURCE)
+        @$(ECHO)  Target.... $(OS_TARGET)
+        @$(ECHO)
+
+[info_dir]
+fpc_infodir:
+ifdef inlinux
+        @$(ECHO)
+        @$(ECHO)  == Directory info ==
+        @$(ECHO)
+ifdef NEEDGCCLIB
+        @$(ECHO)  GCC library is needed.
+endif
+ifdef NEEDOTHERLIB
+        @$(ECHO)  Other library is needed.
+endif
+        @$(ECHO)  Basedir......... $(BASEDIR)
+        @$(ECHO)
+        @$(ECHO)  GCC library..... $(GCCLIBDIR)
+        @$(ECHO)  Other library... $(OTHERLIBDIR)
+        @$(ECHO)
+endif
+
+[info_tools]
+fpc_infotools:
+        @$(ECHO)
+        @$(ECHO)  == Tools info ==
+        @$(ECHO)
+        @$(ECHO)  Pwd....... $(PWD)
+        @$(ECHO)  Echo...... $(ECHO)
+ifdef SED
+        @$(ECHO)  Sed....... $(SED)
+endif
+ifdef DATE
+        @$(ECHO)  Date...... $(DATE)
+endif
+ifdef DIFF
+        @$(ECHO)  Diff...... $(DIFF)
+endif
+ifdef CMP
+        @$(ECHO)  Cmp....... $(CMP)
+endif
+ifdef UPXPROG
+        @$(ECHO)  Upx....... $(UPXPROG)
+endif
+ifdef ZIPPROG
+        @$(ECHO)  Zip....... $(ZIPPROG)
+endif
+        @$(ECHO)
+
+[info_object]
+fpc_infoobject:
+        @$(ECHO)
+        @$(ECHO)  == Object info ==
+        @$(ECHO)
+        @$(ECHO)  LoaderObjects..... $(LOADEROBJECTS)
+        @$(ECHO)  UnitObjects....... $(UNITOBJECTS)
+        @$(ECHO)  ExeObjects........ $(EXEOBJECTS)
+        @$(ECHO)
+        @$(ECHO)  ExtraCleanUnits... $(EXTRACLEANUNITS)
+        @$(ECHO)  ExtraInstallUnits. $(EXTRAINSTALLUNITS)
+        @$(ECHO)  ExtraInstallFiles. $(EXTRAINSTALLFILES)
+        @$(ECHO)
+        @$(ECHO)  == Unit info ==
+        @$(ECHO)
+        @$(ECHO)  UnitInstallFiles. $(UNITINSTALLFILES)
+        @$(ECHO)  UnitCleanFiles... $(UNITCLEANFILES)
+        @$(ECHO)
+
+[info_install]
+fpc_infoinstall:
+        @$(ECHO)
+        @$(ECHO)  == Install info ==
+        @$(ECHO)
+ifdef DATE
+        @$(ECHO)  DateStr.............. $(DATESTR)
+endif
+        @$(ECHO)  PackageSuffix........ $(PACKAGESUFFIX)
+        @$(ECHO)
+        @$(ECHO)  BaseInstallDir....... $(BASEINSTALLDIR)
+        @$(ECHO)  BinInstallDir........ $(BININSTALLDIR)
+        @$(ECHO)  UnitInstallDir....... $(UNITINSTALLDIR)
+        @$(ECHO)  StaticUnitInstallDir. $(STATIC_UNITINSTALLDIR)
+        @$(ECHO)  SharedUnitInstallDir. $(SHARED_UNITINSTALLDIR)
+        @$(ECHO)  LibInstallDir........ $(LIBINSTALLDIR)
+        @$(ECHO)  StaticLibInstallDir.. $(STATIC_LIBINSTALLDIR)
+        @$(ECHO)  SharedLibInstallDir.. $(SHARED_LIBINSTALLDIR)
+        @$(ECHO)  MsgInstallDir........ $(MSGINSTALLDIR)
+        @$(ECHO)  DocInstallDir........ $(DOCINSTALLDIR)
+        @$(ECHO)
+
+[info_files]
+# try to get the files in the currentdir
+PASFILES:=$(wildcard *.pas)
+PPFILES:=$(wildcard *.pp)
+INCFILES:=$(wildcard *.inc)
+MSGFILES:=$(wildcard *.msg)
+ASFILES:=$(wildcard *.as)
+fpc_infofiles:
+        @$(ECHO)
+        @$(ECHO)  == Files info ==
+        @$(ECHO)
+ifdef PASFILES
+        @$(ECHO)  Pas files are $(PASFILES)
+endif
+ifdef PPFILES
+        @$(ECHO)  PP  files are $(PPFILES)
+endif
+ifdef INCFILES
+        @$(ECHO)  Inc files are $(INCFILES)
+endif
+ifdef MSGFILES
+        @$(ECHO)  Msg files are $(MSGFILES)
+endif
+ifdef ASFILES
+        @$(ECHO)  As  files are $(ASFILES)
+endif
+
+[userrules]
+#####################################################################
+# Users rules
+#####################################################################
+
+;
+; $Log$
+; Revision 1.1  1999-11-02 23:57:40  peter
+;   * initial version
+;
+;

+ 421 - 0
utils/fpcmake.pp

@@ -0,0 +1,421 @@
+{
+    $Id$
+    Copyright (c) 1999 by Peter Vreman
+
+    Convert Makefile.fpc to Makefile
+
+    See the file COPYING.FPC, included in this distribution,
+    for details about the copyright.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+
+ **********************************************************************}
+{$ifdef fpc}{$mode objfpc}{$endif}
+{$H+}
+program fpcmake;
+uses
+{$ifdef go32v2}
+  dpmiexcp,
+{$endif}
+  sysutils,classes,inifiles;
+
+const
+  Version='v0.99.13';
+  Title='fpcmake '+Version;
+
+const
+  sec_dirs='dirs';
+  sec_libs='libs';
+  sec_targets='targets';
+  sec_info='info';
+  sec_misc='misc';
+  sec_rules='rules';
+
+type
+  TFpcMake=record
+    DefaultUnits   : boolean;
+    TargetUnits,
+    TargetPrograms : string;
+    DirUnit,
+    DirLib,
+    DirObj,
+    DirTarget,
+    DirUnitTarget,
+    DirInc,
+    DirProcInc,
+    DirOSInc       : string;
+    LibGCC,
+    LibOther       : boolean;
+    InfoCfg,
+    InfoDir,
+    InfoTools,
+    InfoInstall,
+    InfoObjects,
+    InfoFiles      : boolean;
+    Rules          : TStringList;
+  end;
+
+var
+  userini : TFpcMake;
+  fpcini  : TIniFile;
+
+{*****************************************************************************
+                                     Helpers
+*****************************************************************************}
+
+procedure Verbose(s:string);
+begin
+  writeln(s);
+end;
+
+
+procedure Error(s:string);
+begin
+  Writeln(s);
+  Halt(1);
+end;
+
+
+{*****************************************************************************
+                               Makefile.fpc reading
+*****************************************************************************}
+
+function ReadMakefilefpc:boolean;
+var
+  fn  : string;
+  ini : TIniFile;
+begin
+  ReadMakefilefpc:=false;
+  if FileExists('Makefile.fpc') then
+   fn:='Makefile.fpc'
+  else
+   if FileExists('makefile.fpc') then
+    fn:='makefile.fpc'
+  else
+   exit;
+
+  Verbose('Reading '+fn);
+  ini:=TIniFile.Create(fn);
+
+  with userini,ini do
+   begin
+   { targets }
+     DefaultUnits:=ReadBool(sec_targets,'defaultunits',false);
+     TargetUnits:=ReadString(sec_targets,'units','');
+     TargetPrograms:=ReadString(sec_targets,'programs','');
+   { dirs }
+     DirUnit:=ReadString(sec_dirs,'unit','');
+     DirLib:=ReadString(sec_dirs,'lib','');
+     DirObj:=ReadString(sec_dirs,'obj','');
+     DirTarget:=ReadString(sec_dirs,'target','');
+     DirUnitTarget:=ReadString(sec_dirs,'unittarget','');
+     DirInc:=ReadString(sec_dirs,'inc','');
+     DirProcInc:=ReadString(sec_dirs,'procinc','');
+     DirOSInc:=ReadString(sec_dirs,'osinc','');
+   { libs }
+     LibGcc:=ReadBool(sec_libs,'gcc',false);
+     LibOther:=ReadBool(sec_libs,'other',false);
+   { info }
+     InfoCfg:=ReadBool(sec_info,'config',true);
+     InfoDir:=ReadBool(sec_info,'dir',false);
+     InfoTools:=ReadBool(sec_info,'tools',false);
+     InfoInstall:=ReadBool(sec_info,'install',true);
+     InfoObjects:=ReadBool(sec_info,'objects',true);
+     InfoFiles:=ReadBool(sec_info,'files',false);
+   { rules }
+     rules:=TStringList.Create;
+     ReadSectionRaw(sec_rules,rules);
+   end;
+
+  ini.Destroy;
+  ReadMakefilefpc:=true;
+end;
+
+
+{*****************************************************************************
+                               userini.ini loading
+*****************************************************************************}
+
+function ReadFpcMakeIni:TIniFile;
+var
+  fn : string;
+begin
+  ReadFpcMakeIni:=nil;
+  if FileExists('userini.ini') then
+   fn:='userini.ini'
+  else
+{$ifdef linux}
+   if FileExists('/usr/lib/fpc/userini.ini') then
+    fn:='/usr/lib/fpc/userini.ini'
+{$else}
+   if FileExists(paramstr(0)+'/userini.ini') then
+    fn:=paramstr(0)+'/userini.ini'
+{$endif}
+  else
+   exit;
+
+  Verbose('Opening '+fn);
+  result:=TIniFile.Create(fn);
+end;
+
+
+{*****************************************************************************
+                               Makefile writing
+*****************************************************************************}
+
+function WriteMakefile:boolean;
+var
+  mf : TStringList;
+  ss : TStringList;
+
+  procedure FixTab(sl:TStringList);
+  var
+    i,j,k : integer;
+    s,s2  : string;
+  begin
+    i:=0;
+    while (i<sl.Count) do
+     begin
+       if sl[i][1] in [' ',#9] then
+        begin
+          s:=sl[i];
+          k:=0;
+          j:=0;
+          repeat
+            inc(j);
+            case s[j] of
+              ' ' :
+                inc(k);
+              #9 :
+                k:=(k+7) and not(7);
+              else
+                break;
+            end;
+          until (j=length(s));
+          if k>7 then
+           begin
+             s2:='';
+             Delete(s,1,j-1);
+             while (k>7) do
+              begin
+                s2:=s2+#9;
+                dec(k,8);
+              end;
+             while (k>0) do
+              begin
+                s2:=s2+' ';
+                dec(k);
+              end;
+             sl[i]:=s2+s;
+           end;
+        end;
+       inc(i);
+     end;
+  end;
+
+  procedure AddSection(b:boolean;s:string);
+  begin
+    if b then
+     begin
+       ss.Clear;
+       fpcini.ReadSectionRaw(s,ss);
+       mf.AddStrings(ss);
+       mf.Add('');
+     end;
+  end;
+
+  procedure AddRule(s:string);
+  var
+    i : integer;
+  begin
+    i:=0;
+    while (i<userini.rules.Count) do
+     begin
+       if (userini.rules[i][1]=s[1]) and
+          (Copy(userini.rules[i],1,length(s))=s) then
+         exit;
+       inc(i);
+     end;
+    mf.Add(s+': fpc_'+s);
+    mf.Add('');
+  end;
+
+var
+  hs : string;
+begin
+{ Open the Makefile }
+  Verbose('Creating Makefile');
+  mf:=TStringList.Create;
+{ Buffer for reading and writing the sections }
+  ss:=TStringList.Create;
+
+  with mf do
+   begin
+   { write header & autodetection }
+     Add('#');
+     Add('# Makefile generated from Makefile.fpc by '+Title);
+     Add('#');
+     Add('');
+     AddSection(true,'osdetect');
+     AddSection(true,'fpcdetect');
+
+   { write the default & user settings }
+     AddSection(true,'defaultsettings');
+     AddSection(true,'usersettings');
+
+   { Targets }
+     if userini.defaultunits then
+      Add('DEFAULTUNITS=1');
+     Add('UNITOBJECTS='+userini.targetunits);
+     Add('EXEOBJECTS='+userini.targetprograms);
+
+   { Dirs }
+     if userini.dirunit<>'' then
+      Add('NEEDUNITDIR='+userini.dirunit);
+     if userini.dirlib<>'' then
+      Add('NEEDLIBDIR='+userini.dirlib);
+     if userini.dirobj<>'' then
+      Add('NEEDOBJDIR='+userini.dirobj);
+     if userini.dirinc<>'' then
+      Add('INC='+userini.dirinc);
+     if userini.dirprocinc<>'' then
+      Add('PROCINC='+userini.dirprocinc);
+     if userini.dirosinc<>'' then
+      Add('OSINC='+userini.dirosinc);
+     if userini.dirtarget<>'' then
+      Add('TARGETDIR='+userini.dirtarget);
+     if userini.dirunittarget<>'' then
+      Add('UNITTARGETDIR='+userini.dirunittarget);
+
+   { Libs }
+     if userini.libgcc then
+      Add('NEEDGCCLIB=1');
+     if userini.libother then
+      Add('NEEDOTHERLIB=1');
+
+   { Info }
+     Add('');
+     hs:='';
+     if userini.infocfg then
+      hs:=hs+'fpc_infocfg ';
+     if userini.infodir then
+      hs:=hs+'fpc_infodir ';
+     if userini.infotools then
+      hs:=hs+'fpc_infotools ';
+     if userini.infoinstall then
+      hs:=hs+'fpc_infoinstall ';
+     if userini.infofiles then
+      hs:=hs+'fpc_infofiles ';
+     Add('FPCINFO='+hs);
+
+   { commandline }
+     Add('');
+     AddSection(true,'command_begin');
+     AddSection(true,'command_rtl');
+     AddSection(true,'command_needopt');
+     AddSection((userini.dirunit<>''),'command_needunit');
+     AddSection((userini.dirlib<>''),'command_needlib');
+     AddSection((userini.dirobj<>''),'command_needobj');
+     AddSection(userini.libgcc,'command_gcclib');
+     AddSection(userini.libother,'command_otherlib');
+     AddSection((userini.dirinc<>''),'command_inc');
+     AddSection((userini.dirprocinc<>''),'command_procinc');
+     AddSection((userini.dirosinc<>''),'command_osinc');
+     AddSection((userini.dirtarget<>''),'command_target');
+     AddSection((userini.dirunittarget<>''),'command_unittarget');
+     AddSection(true,'command_smartlink');
+     AddSection(true,'command_end');
+
+   { write tools }
+     AddSection(true,'shelltools');
+     AddSection(true,'tool_default');
+     AddSection(true,'tool_upx');
+     AddSection(true,'tool_sed');
+     AddSection(true,'tool_date');
+     AddSection(true,'tool_zip');
+     AddSection(true,'tool_cmp');
+     AddSection(true,'tool_diff');
+
+   { write dirs }
+     AddSection(true,'dir_default');
+     AddSection(true,'dir_rtl');
+     AddSection(true,'dir_units');
+     AddSection(true,'dir_gcclib');
+     AddSection(true,'dir_otherlib');
+     AddSection(true,'dir_install');
+
+   { extensions }
+     AddSection(true,'extensions');
+
+   { add default rules }
+     AddSection(true,'defaultrules');
+     AddRule('all');
+     AddRule('staticlib');
+     AddRule('sharedlib');
+     AddRule('install');
+     AddRule('staticinstall');
+     AddRule('sharedinstall');
+     AddRule('libinstall');
+     AddRule('zipinstall');
+     AddRule('zipinstalladd');
+     AddRule('clean');
+     AddRule('depend');
+     AddRule('info');
+
+   { default fpc_ rules }
+     AddSection(true,'compilerules');
+     AddSection(true,'libraryrules');
+     AddSection(true,'installrules');
+     AddSection(true,'zipinstallrules');
+     AddSection(true,'cleanrules');
+     AddSection(true,'dependrules');
+     AddSection(true,'inforules');
+     AddSection(userini.infocfg,'info_cfg');
+     AddSection(userini.infodir,'info_dir');
+     AddSection(userini.infotools,'info_tools');
+     AddSection(userini.infoobjects,'info_object');
+     AddSection(userini.infoinstall,'info_install');
+     AddSection(userini.infofiles,'info_files');
+
+   { insert users rules }
+     if userini.rules.count>0 then
+      begin
+        AddSection(true,'userrules');
+        AddStrings(userini.rules);
+      end;
+   end;
+
+{ Write the Makefile and cleanup }
+  Verbose('Writing Makefile');
+  FixTab(mf);
+  mf.SaveToFile('Makefile');
+  mf.Destroy;
+  ss.Destroy;
+  WriteMakefile:=true;
+end;
+
+
+begin
+{ Open userini.ini }
+  fpcini:=ReadFpcMakeIni;
+  if not assigned(fpcini) then
+   Error('Can''t read userini.ini');
+
+{ Open Makefile.fpc }
+  if not ReadMakefilefpc then
+   Error('Can''t read Makefile.fpc');
+
+{ Write Makefile }
+  if not WriteMakefile then
+   Error('Can''t write Makefile');
+
+  fpcini.destroy;
+end.
+{
+  $Log$
+  Revision 1.1  1999-11-02 23:57:40  peter
+    * initial version
+
+}

+ 37 - 0
utils/makefile.exm

@@ -0,0 +1,37 @@
+#
+#   $Id$
+#
+#   Example Makefile.fpc which shows the defaults
+#
+
+[targets]
+;defaultunits=0
+units=<your units>
+programs=<your programs>
+
+[dirs]
+;unitdir=
+;libdir=
+;objdir=
+;incdir=
+;procincdir=
+;osincdir=
+;targetdir=
+;unittargetdir=
+
+[libs]
+;libgcc=0
+;libother=0
+
+[info]
+;infocfg=1
+;infodir=0
+;infotools=0
+;infoinstall=1
+;infoobjects=1
+;infofiles=0
+
+[rules]
+; here you can add your own rules, the general rules will automaticly
+; remove the defaults which call fpc_<rule>.
+