diff --git a/utils/fpcm/fpcmake.inc b/utils/fpcm/fpcmake.inc new file mode 100644 index 0000000000..f0f2ad3974 --- /dev/null +++ b/utils/fpcm/fpcmake.inc @@ -0,0 +1,1285 @@ +{$ifdef Delphi} +const fpcmakeini : array[0..117] of string[240]=( +{$else Delphi} +const fpcmakeini : array[0..117,1..240] of char=( +{$endif Delphi} + ';'#010+ + '; Templates used by fpcmake to create a Makefile from Makefile.fpc'#010+ + ';'#010+ + #010+ + '[osdetect]'#010+ + '#####################################################################'#010+ + '# Autodetect OS (Linux or Dos or Windows NT or OS/2)'#010+ + '# define inUnix when running under',' Unix (Linux,FreeBSD)'#010+ + '# define inWinNT when running under WinNT'#010+ + '# define inOS2 when running under OS/2'#010+ + '#####################################################################'#010+ + #010+ + '# We need only / in the path'#010+ + 'override PATH:=$(subst \,/,$(PATH))'#010+ + #010, + '# Search for PWD and determine also if we are under linux'#010+ + 'PWD:=$(strip $(wildcard $(addsuffix /pwd.exe,$(subst ;, ,$(PATH)))))'#010+ + 'ifeq ($(PWD),)'#010+ + 'PWD:=$(strip $(wildcard $(addsuffix /pwd,$(subst :, ,$(PATH)))))'#010+ + 'ifeq ($(PWD),)'#010+ + 'nopwd:'#010+ + ' @ec','ho You need the GNU utils package to use this Makefile!'#010+ + ' @echo Get ftp://ftp.freepascal.org/pub/fpc/dist/go32v2/utilgo3'+ + '2.zip'#010+ + ' @exit'#010+ + 'else'#010+ + 'inUnix=1'#010+ + 'PWD:=$(firstword $(PWD))'#010+ + 'endif'#010+ + 'else'#010+ + 'PWD:=$(firstword $(PWD))'#010+ + 'endif'#010+ + #010+ + '# Detect NT ','- NT sets OS to Windows_NT'#010+ + '# Detect OS/2 - OS/2 has OS2_SHELL defined'#010+ + 'ifndef inUnix'#010+ + 'ifeq ($(OS),Windows_NT)'#010+ + 'inWinNT=1'#010+ + 'else'#010+ + 'ifdef OS2_SHELL'#010+ + 'inOS2=1'#010+ + 'endif'#010+ + 'endif'#010+ + 'endif'#010+ + #010+ + '# The extension of executables'#010+ + 'ifdef inUnix'#010+ + 'SRCEXEEXT='#010+ + 'else'#010+ + 'SRCEXEEXT=.exe',#010+ + 'endif'#010+ + #010+ + '# The extension of batch files / scripts'#010+ + 'ifdef inUnix'#010+ + 'BATCHEXT=.sh'#010+ + 'else'#010+ + 'ifdef inOS2'#010+ + 'BATCHEXT=.cmd'#010+ + 'else'#010+ + 'BATCHEXT=.bat'#010+ + 'endif'#010+ + 'endif'#010+ + #010+ + '# Path Separator, the subst trick is necessary for the \ that can'#039't'+ + ' exists'#010+ + '# at the end of a line'#010+ + 'ifde','f inUnix'#010+ + 'PATHSEP=/'#010+ + 'else'#010+ + 'PATHSEP=$(subst /,\,/)'#010+ + 'endif'#010+ + #010+ + '# The path which is searched separated by spaces'#010+ + 'ifdef inUnix'#010+ + 'SEARCHPATH=$(subst :, ,$(PATH))'#010+ + 'else'#010+ + 'SEARCHPATH=$(subst ;, ,$(PATH))'#010+ + 'endif'#010+ + #010+ + '# Base dir'#010+ + 'ifdef PWD'#010+ + 'BASEDIR:=$(shell $(PWD))'#010+ + 'el','se'#010+ + 'BASEDIR=.'#010+ + 'endif'#010+ + #010+ + '[fpcdetect]'#010+ + '#####################################################################'#010+ + '# FPC version/target Detection'#010+ + '#####################################################################'#010+ + #010+ + '# What compiler to use ?'#010+ + 'ifndef FPC'#010, + '# Compatibility with old makefiles'#010+ + 'ifdef PP'#010+ + 'FPC=$(PP)'#010+ + 'else'#010+ + 'FPC=ppc386'#010+ + 'endif'#010+ + 'endif'#010+ + 'override FPC:=$(subst $(SRCEXEEXT),,$(FPC))'#010+ + 'override FPC:=$(subst \,/,$(FPC))$(SRCEXEEXT)'#010+ + #010+ + '# Target OS'#010+ + 'ifndef OS_TARGET'#010+ + 'OS_TARGET:=$(shell $(FPC) -iTO)'#010+ + 'endif'#010, + #010+ + '# Source OS'#010+ + 'ifndef OS_SOURCE'#010+ + 'OS_SOURCE:=$(shell $(FPC) -iSO)'#010+ + 'endif'#010+ + #010+ + '# Target CPU'#010+ + 'ifndef CPU_TARGET'#010+ + 'CPU_TARGET:=$(shell $(FPC) -iTP)'#010+ + 'endif'#010+ + #010+ + '# Source CPU'#010+ + 'ifndef CPU_SOURCE'#010+ + 'CPU_SOURCE:=$(shell $(FPC) -iSP)'#010+ + 'endif'#010+ + #010+ + '# FPC version'#010+ + 'ifndef FPC_VERS','ION'#010+ + 'FPC_VERSION:=$(shell $(FPC) -iV)'#010+ + 'endif'#010+ + #010+ + 'export FPC OS_TARGET OS_SOURCE CPU_TARGET CPU_SOURCE FPC_VERSION'#010+ + #010+ + #010+ + '[fpcdirdetect]'#010+ + '#####################################################################'#010+ + '# FPCDIR Setting'#010+ + '###########################','#########################################'+ + '#'#010+ + #010+ + '# Test FPCDIR to look if the RTL dir exists'#010+ + 'ifdef FPCDIR'#010+ + 'override FPCDIR:=$(subst \,/,$(FPCDIR))'#010+ + 'ifeq ($(wildcard $(FPCDIR)/rtl),)'#010+ + 'ifeq ($(wildcard $(FPCDIR)/units),)'#010+ + 'override FPCDIR=wrong'#010+ + 'endif'#010+ + 'e','ndif'#010+ + 'else'#010+ + 'override FPCDIR=wrong'#010+ + 'endif'#010+ + #010+ + '# Detect FPCDIR'#010+ + 'ifeq ($(FPCDIR),wrong)'#010+ + 'ifdef inUnix'#010+ + 'override FPCDIR=/usr/local/lib/fpc/$(FPC_VERSION)'#010+ + 'ifeq ($(wildcard $(FPCDIR)/units),)'#010+ + 'override FPCDIR=/usr/lib/fpc/$(FPC_VERSION)'#010+ + 'endif'#010+ + 'else'#010+ + 'override',' FPCDIR:=$(subst /$(FPC),,$(firstword $(strip $(wildcard $(a'+ + 'ddsuffix /$(FPC),$(SEARCHPATH))))))'#010+ + 'override FPCDIR:=$(FPCDIR)/..'#010+ + 'ifeq ($(wildcard $(FPCDIR)/rtl),)'#010+ + 'ifeq ($(wildcard $(FPCDIR)/units),)'#010+ + 'override FPCDIR:=$(FPCDIR)/..'#010+ + 'ifeq ($(wildca','rd $(FPCDIR)/rtl),)'#010+ + 'ifeq ($(wildcard $(FPCDIR)/units),)'#010+ + 'override FPCDIR=c:/pp'#010+ + 'endif'#010+ + 'endif'#010+ + 'endif'#010+ + 'endif'#010+ + 'endif'#010+ + 'endif'#010+ + 'override FPCDIR:=$(wildcard $(FPCDIR))'#010+ + #010+ + '# Units dir'#010+ + 'UNITSDIR=$(wildcard $(FPCDIR)/units/$(OS_TARGET))'#010+ + #010+ + '# Packages dir'#010+ + 'PACKAGES','DIR=$(wildcard $(FPCDIR) $(FPCDIR)/packages)'#010+ + #010+ + #010+ + '[shelltools]'#010+ + '#####################################################################'#010+ + '# Shell tools'#010+ + '#####################################################################'#010+ + #010+ + '# echo'#010+ + 'ifndef ECHO'#010+ + 'ECHO:=','$(strip $(wildcard $(addsuffix /gecho$(EXEEXT),$(SEARCHPATH)))'+ + ')'#010+ + 'ifeq ($(ECHO),)'#010+ + 'ECHO:=$(strip $(wildcard $(addsuffix /echo$(SRCEXEEXT),$(SEARCHPATH)))'+ + ')'#010+ + 'ifeq ($(ECHO),)'#010+ + 'ECHO:=echo'#010+ + 'else'#010+ + 'ECHO:=$(firstword $(ECHO))'#010+ + 'endif'#010+ + 'else'#010+ + 'ECHO:=$(firstword ','$(ECHO))'#010+ + 'endif'#010+ + 'endif'#010+ + #010+ + '# To copy pograms'#010+ + 'ifndef COPY'#010+ + 'COPY:=cp -fp'#010+ + 'endif'#010+ + #010+ + '# Copy a whole tree'#010+ + 'ifndef COPYTREE'#010+ + 'COPYTREE:=cp -rfp'#010+ + 'endif'#010+ + #010+ + '# To move pograms'#010+ + 'ifndef MOVE'#010+ + 'MOVE:=mv -f'#010+ + 'endif'#010+ + #010+ + '# Check delete program'#010+ + 'ifndef DEL'#010+ + 'DEL:=rm -f'#010+ + 'endif'#010+ + #010+ + '# Chec','k deltree program'#010+ + 'ifndef DELTREE'#010+ + 'DELTREE:=rm -rf'#010+ + 'endif'#010+ + #010+ + '# To install files'#010+ + 'ifndef INSTALL'#010+ + 'ifdef inUnix'#010+ + 'INSTALL:=install -c -m 644'#010+ + 'else'#010+ + 'INSTALL:=$(COPY)'#010+ + 'endif'#010+ + 'endif'#010+ + #010+ + '# To install programs'#010+ + 'ifndef INSTALLEXE'#010+ + 'ifdef inUnix'#010+ + 'INSTALLEXE:=install -c',' -m 755'#010+ + 'else'#010+ + 'INSTALLEXE:=$(COPY)'#010+ + 'endif'#010+ + 'endif'#010+ + #010+ + '# To make a directory.'#010+ + 'ifndef MKDIR'#010+ + 'ifdef inUnix'#010+ + 'MKDIR:=install -m 755 -d'#010+ + 'else'#010+ + 'MKDIR:=ginstall -m 755 -d'#010+ + 'endif'#010+ + 'endif'#010+ + #010+ + 'export ECHO COPY COPYTREE MOVE DEL DELTREE INSTALL INSTALLEXE MKDIR'#010+ + #010+ + #010+ + '[defau','lttools]'#010+ + '#####################################################################'#010+ + '# Default Tools'#010+ + '#####################################################################'#010+ + #010+ + '# assembler, redefine it if cross compiling'#010+ + 'ifndef AS'#010+ + 'AS=as'#010+ + 'endif'#010+ + #010+ + '# linke','r, but probably not used'#010+ + 'ifndef LD'#010+ + 'LD=ld'#010+ + 'endif'#010+ + #010+ + '# ppas.bat / ppas.sh'#010+ + 'PPAS=$(BATCHEXT)'#010+ + #010+ + '# ldconfig to rebuild .so cache'#010+ + 'ifdef inUnix'#010+ + 'LDCONFIG=ldconfig'#010+ + 'else'#010+ + 'LDCONFIG='#010+ + 'endif'#010+ + #010+ + '# ppumove'#010+ + 'ifndef PPUMOVE'#010+ + 'PPUMOVE:=$(strip $(wildcard $(addsuffix /pp','umove$(SRCEXEEXT),$(SEARC'+ + 'HPATH))))'#010+ + 'ifeq ($(PPUMOVE),)'#010+ + 'PPUMOVE='#010+ + 'else'#010+ + 'PPUMOVE:=$(firstword $(PPUMOVE))'#010+ + 'endif'#010+ + 'endif'#010+ + 'export PPUMOVE'#010+ + #010+ + '# ppufiles'#010+ + 'ifndef PPUFILES'#010+ + 'PPUFILES:=$(strip $(wildcard $(addsuffix /ppufiles$(SRCEXEEXT),$(SEARC'+ + 'HPATH))))'#010+ + 'ifeq',' ($(PPUFILES),)'#010+ + 'PPUFILES='#010+ + 'else'#010+ + 'PPUFILES:=$(firstword $(PPUFILES))'#010+ + 'endif'#010+ + 'endif'#010+ + 'export PPUFILES'#010+ + #010+ + '# gdate/date'#010+ + 'ifndef DATE'#010+ + 'DATE:=$(strip $(wildcard $(addsuffix /date$(SRCEXEEXT),$(SEARCHPATH)))'+ + ')'#010+ + 'ifeq ($(DATE),)'#010+ + 'DATE:=$(strip $(wildcard $(addsu','ffix /gdate$(SRCEXEEXT),$(SEACHPATH)'+ + ')))'#010+ + 'ifeq ($(DATE),)'#010+ + 'DATE='#010+ + 'else'#010+ + 'DATE:=$(firstword $(DATE))'#010+ + 'endif'#010+ + 'else'#010+ + 'DATE:=$(firstword $(DATE))'#010+ + 'endif'#010+ + 'endif'#010+ + 'export DATE'#010+ + #010+ + 'ifdef DATE'#010+ + 'DATESTR:=$(shell $(DATE) +%Y%m%d)'#010+ + 'else'#010+ + 'DATESTR='#010+ + 'endif'#010+ + #010+ + '# Look if UPX is ','found for go32v2 and win32. We can'#039't use $UPX b'+ + 'ecuase'#010+ + '# upx uses that one itself (PFV)'#010+ + 'ifndef UPXPROG'#010+ + 'ifeq ($(OS_TARGET),go32v2)'#010+ + 'UPXPROG:=1'#010+ + 'endif'#010+ + 'ifeq ($(OS_TARGET),win32)'#010+ + 'UPXPROG:=1'#010+ + 'endif'#010+ + 'ifdef UPXPROG'#010+ + 'UPXPROG:=$(strip $(wildcard $(addsuff','ix /upx$(SRCEXEEXT),$(SEARCHPAT'+ + 'H))))'#010+ + 'ifeq ($(UPXPROG),)'#010+ + 'UPXPROG='#010+ + 'else'#010+ + 'UPXPROG:=$(firstword $(UPXPROG))'#010+ + 'endif'#010+ + 'else'#010+ + 'UPXPROG='#010+ + 'endif'#010+ + 'endif'#010+ + 'export UPXPROG'#010+ + #010+ + '# ZipProg, you can'#039't use Zip as the var name (PFV)'#010+ + 'ifndef ZIPPROG'#010+ + 'ZIPPROG:=$(strip $(wild','card $(addsuffix /zip$(SRCEXEEXT),$(SEARCHPAT'+ + 'H))))'#010+ + 'ifeq ($(ZIPPROG),)'#010+ + 'ZIPPROG='#010+ + 'else'#010+ + 'ZIPPROG:=$(firstword $(ZIPPROG))'#010+ + 'endif'#010+ + 'endif'#010+ + 'export ZIPPROG'#010+ + #010+ + 'ZIPOPT=-9'#010+ + 'ZIPEXT=.zip'#010+ + #010+ + '# Tar'#010+ + 'ifndef TARPROG'#010+ + 'TARPROG:=$(strip $(wildcard $(addsuffix /tar$(SRCEX','EEXT),$(SEARCHPAT'+ + 'H))))'#010+ + 'ifeq ($(TARPROG),)'#010+ + 'TARPROG='#010+ + 'else'#010+ + 'TARPROG:=$(firstword $(TARPROG))'#010+ + 'endif'#010+ + 'endif'#010+ + 'export TARPROG'#010+ + #010+ + 'ifeq ($(USETAR),bz2)'#010+ + 'TAROPT=vI'#010+ + 'TAREXT=.tar.bz2'#010+ + 'else'#010+ + 'TAROPT=vz'#010+ + 'TAREXT=.tar.gz'#010+ + 'endif'#010+ + #010+ + #010+ + '[extensions]'#010+ + '#########################','###########################################'+ + '#'#010+ + '# Default extensions'#010+ + '#####################################################################'#010+ + #010+ + '# Default needed extensions (Go32v2,Linux)'#010+ + 'LOADEREXT=.as'#010+ + 'EXEEXT=.exe'#010+ + 'PPLEXT=.ppl'#010+ + 'PPUEXT=.ppu'#010+ + 'OEXT=.o'#010+ + 'AS','MEXT=.s'#010+ + 'SMARTEXT=.sl'#010+ + 'STATICLIBEXT=.a'#010+ + 'SHAREDLIBEXT=.so'#010+ + 'LIBPREFIX=lib'#010+ + 'RSTEXT=.rst'#010+ + 'FPCMADE=fpcmade'#010+ + #010+ + #010+ + '# Go32v1'#010+ + 'ifeq ($(OS_TARGET),go32v1)'#010+ + 'PPUEXT=.pp1'#010+ + 'OEXT=.o1'#010+ + 'ASMEXT=.s1'#010+ + 'SMARTEXT=.sl1'#010+ + 'STATICLIBEXT=.a1'#010+ + 'SHAREDLIBEXT=.so1'#010+ + 'LIBPREFIX='#010+ + 'FPCMADE=fpcmad','e.v1'#010+ + 'PACKAGESUFFIX=v1'#010+ + 'endif'#010+ + #010+ + '# Go32v2'#010+ + 'ifeq ($(OS_TARGET),go32v2)'#010+ + 'LIBPREFIX='#010+ + 'FPCMADE=fpcmade.dos'#010+ + 'ZIPSUFFIX=go32'#010+ + 'endif'#010+ + #010+ + '# Linux'#010+ + 'ifeq ($(OS_TARGET),linux)'#010+ + 'EXEEXT='#010+ + 'HASSHAREDLIB=1'#010+ + 'FPCMADE=fpcmade.lnx'#010+ + 'ZIPSUFFIX=linux'#010+ + 'endif'#010+ + #010+ + '# Linux'#010+ + 'ifeq ($(OS_TAR','GET),freebsd)'#010+ + 'EXEEXT='#010+ + 'HASSHAREDLIB=1'#010+ + 'FPCMADE=fpcmade.freebsd'#010+ + 'ZIPSUFFIX=freebsd'#010+ + 'endif'#010+ + #010+ + '# Win32'#010+ + 'ifeq ($(OS_TARGET),win32)'#010+ + 'PPUEXT=.ppw'#010+ + 'OEXT=.ow'#010+ + 'ASMEXT=.sw'#010+ + 'SMARTEXT=.slw'#010+ + 'STATICLIBEXT=.aw'#010+ + 'SHAREDLIBEXT=.dll'#010+ + 'FPCMADE=fpcmade.w32'#010+ + 'ZIPSUFFIX=w32'#010+ + 'endif',#010+ + #010+ + '# OS/2'#010+ + 'ifeq ($(OS_TARGET),os2)'#010+ + 'PPUEXT=.ppo'#010+ + 'ASMEXT=.so2'#010+ + 'OEXT=.oo2'#010+ + 'SMARTEXT=.so'#010+ + 'STATICLIBEXT=.ao2'#010+ + 'SHAREDLIBEXT=.dll'#010+ + 'FPCMADE=fpcmade.os2'#010+ + 'ZIPSUFFIX=emx'#010+ + 'endif'#010+ + #010+ + '[defaultdirs]'#010+ + '#####################################################################', + #010+ + '# Default Directories'#010+ + '#####################################################################'#010+ + #010+ + '# Units dir'#010+ + 'ifdef REQUIRE_UNITSDIR'#010+ + 'override UNITSDIR+=$(REQUIRE_UNITSDIR)'#010+ + 'endif'#010+ + #010+ + '# Units dir'#010+ + 'ifdef REQUIRE_PACKAGESDIR'#010+ + 'override PACKAGESDIR+=$(REQ','UIRE_PACKAGESDIR)'#010+ + 'endif'#010+ + #010+ + #010+ + '# Linux and freebsd use unix dirs with /usr/bin, /usr/lib'#010+ + '# When zipping use the target as default, when normal install then'#010+ + '# use the source os as default'#010+ + 'ifdef ZIPTARGET'#010+ + '# Zipinstall'#010+ + 'ifeq ($(OS_TARGET),linux)'#010+ + 'UNI','XINSTALLDIR=1'#010+ + 'endif'#010+ + 'ifeq ($(OS_TARGET),freebsd)'#010+ + 'UNIXINSTALLDIR=1'#010+ + 'endif'#010+ + 'else'#010+ + '# Normal install'#010+ + 'ifeq ($(OS_SOURCE),linux)'#010+ + 'UNIXINSTALLDIR=1'#010+ + 'endif'#010+ + 'ifeq ($(OS_SOURCE),freebsd)'#010+ + 'UNIXINSTALLDIR=1'#010+ + 'endif'#010+ + 'endif'#010+ + #010+ + '# set the prefix directory where to inst','all everything'#010+ + 'ifndef INSTALL_PREFIX'#010+ + 'ifdef UNIXINSTALLDIR'#010+ + 'INSTALL_PREFIX=/usr'#010+ + 'else'#010+ + 'INSTALL_PREFIX=/pp'#010+ + 'endif'#010+ + 'endif'#010+ + 'export INSTALL_PREFIX'#010+ + #010+ + '# Where to place the resulting zip files'#010+ + 'ifndef DIST_DESTDIR'#010+ + 'DIST_DESTDIR:=$(BASEDIR)'#010+ + 'endif'#010+ + 'export DIST','_DESTDIR'#010+ + #010+ + #010+ + '#####################################################################'#010+ + '# Install Directories'#010+ + '#####################################################################'#010+ + #010+ + '# set the base directory where to install everything'#010+ + 'ifndef INSTAL','L_BASEDIR'#010+ + 'ifdef UNIXINSTALLDIR'#010+ + 'INSTALL_BASEDIR=$(INSTALL_PREFIX)/lib/fpc/$(FPC_VERSION)'#010+ + 'else'#010+ + 'INSTALL_BASEDIR=$(INSTALL_PREFIX)'#010+ + 'endif'#010+ + 'endif'#010+ + #010+ + '# set the directory where to install the binaries'#010+ + 'ifndef INSTALL_BINDIR'#010+ + 'ifdef UNIXINSTALLDIR'#010+ + 'INSTALL','_BINDIR=$(INSTALL_PREFIX)/bin'#010+ + 'else'#010+ + 'INSTALL_BINDIR=$(INSTALL_BASEDIR)/bin/$(OS_TARGET)'#010+ + 'endif'#010+ + 'endif'#010+ + #010+ + '# set the directory where to install the units.'#010+ + 'ifndef INSTALL_UNITDIR'#010+ + 'INSTALL_UNITDIR=$(INSTALL_BASEDIR)/units/$(OS_TARGET)'#010+ + 'ifdef PACKAGE_NA','ME'#010+ + 'INSTALL_UNITDIR:=$(INSTALL_UNITDIR)/$(PACKAGE_NAME)'#010+ + 'endif'#010+ + 'endif'#010+ + #010+ + '# Where to install shared libraries'#010+ + 'ifndef INSTALL_LIBDIR'#010+ + 'ifdef UNIXINSTALLDIR'#010+ + 'INSTALL_LIBDIR=$(INSTALL_PREFIX)/lib'#010+ + 'else'#010+ + 'INSTALL_LIBDIR=$(INSTALL_UNITDIR)'#010+ + 'endif'#010+ + 'endif'#010+ + #010+ + '# Wh','ere the source files will be stored'#010+ + 'ifndef INSTALL_SOURCEDIR'#010+ + 'ifdef UNIXINSTALLDIR'#010+ + 'INSTALL_SOURCEDIR=$(INSTALL_PREFIX)/src/fpc-$(FPC_VERSION)'#010+ + 'else'#010+ + 'INSTALL_SOURCEDIR=$(INSTALL_BASEDIR)/source'#010+ + 'endif'#010+ + 'ifdef PACKAGE_NAME'#010+ + 'INSTALL_SOURCEDIR:=$(INST','ALL_SOURCEDIR)/$(PACKAGE_NAME)'#010+ + 'endif'#010+ + 'endif'#010+ + #010+ + '# Where the doc files will be stored'#010+ + 'ifndef INSTALL_DOCDIR'#010+ + 'ifdef UNIXINSTALLDIR'#010+ + 'INSTALL_DOCDIR=$(INSTALL_PREFIX)/doc/fpc-$(FPC_VERSION)'#010+ + 'else'#010+ + 'INSTALL_DOCDIR=$(INSTALL_BASEDIR)/doc'#010+ + 'endif'#010+ + 'endif'#010+ + #010+ + '# Wh','ere to install the examples, under linux we use the doc dir'#010+ + '# because the copytree command will create a subdir itself'#010+ + 'ifndef INSTALL_EXAMPLEDIR'#010+ + 'ifdef UNIXINSTALLDIR'#010+ + 'INSTALL_EXAMPLEDIR=$(INSTALL_DOCDIR)/examples'#010+ + 'else'#010+ + 'INSTALL_EXAMPLEDIR=$(IN','STALL_BASEDIR)/examples'#010+ + 'endif'#010+ + 'ifdef EXAMPLESUBDIR'#010+ + 'INSTALL_EXAMPLEDIR:=$(INSTALL_EXAMPLEDIR)/$(EXAMPLESUBDIR)'#010+ + 'endif'#010+ + 'endif'#010+ + #010+ + '# Where the some extra (data)files will be stored'#010+ + 'ifndef INSTALL_DATADIR'#010+ + 'INSTALL_DATADIR=$(INSTALL_BASEDIR)'#010+ + 'endif'#010+ + #010+ + #010+ + '[d','irlibc]'#010+ + '# On linux, try to find where libgcc.a is.'#010+ + 'ifdef inUnix'#010+ + 'ifndef GCCLIBDIR'#010+ + 'GCCLIBDIR:=$(shell dirname `(gcc -v 2>&1)| head -n 1| awk '#039'{ print'+ + ' $$4 } '#039'`)'#010+ + 'endif'#010+ + 'ifndef OTHERLIBDIR'#010+ + 'OTHERLIBDIR:=$(shell grep -v "^\#" /etc/ld.so.conf | awk ',#039'{ ORS=" '+ + '"; print $1 }'#039')'#010+ + 'endif'#010+ + 'export GCCLIBDIR OTHERLIB'#010+ + 'endif'#010+ + #010+ + #010+ + '[command_begin]'#010+ + '#####################################################################'#010+ + '# Compiler Command Line'#010+ + '#################################################################','###'+ + '#'#010+ + #010+ + '# Load commandline OPTDEF and add FPC_CPU define'#010+ + 'override FPCOPTDEF=$(CPU_TARGET)'#010+ + #010+ + '# Load commandline OPT and add target and unit dir to be sure'#010+ + 'ifneq ($(OS_TARGET),$(OS_SOURCE))'#010+ + 'override FPCOPT+=-T$(OS_TARGET)'#010+ + 'endif'#010+ + #010+ + '# User dirs shou','ld be first, so they are looked at first'#010+ + 'ifdef UNITDIR'#010+ + 'override FPCOPT+=$(addprefix -Fu,$(UNITDIR))'#010+ + 'endif'#010+ + 'ifdef LIBDIR'#010+ + 'override FPCOPT+=$(addprefix -Fl,$(LIBDIR))'#010+ + 'endif'#010+ + 'ifdef OBJDIR'#010+ + 'override FPCOPT+=$(addprefix -Fo,$(OBJDIR))'#010+ + 'endif'#010+ + 'ifdef IN','CDIR'#010+ + 'override FPCOPT+=$(addprefix -Fi,$(INCDIR))'#010+ + 'endif'#010+ + #010+ + '# Smartlinking'#010+ + 'ifdef LINKSMART'#010+ + 'override FPCOPT+=-XX'#010+ + 'endif'#010+ + #010+ + '# Smartlinking creation'#010+ + 'ifdef CREATESMART'#010+ + 'override FPCOPT+=-CX'#010+ + 'endif'#010+ + #010+ + '# Debug'#010+ + 'ifdef DEBUG'#010+ + 'override FPCOPT+=-gl'#010+ + 'override FPCOP','TDEF+=DEBUG'#010+ + 'endif'#010+ + #010+ + '# Release mode (strip, optimize and don'#039't load ppc386.cfg)'#010+ + 'ifdef RELEASE'#010+ + 'override FPCOPT+=-Xs -OG2p3 -n'#010+ + 'override FPCOPTDEF+=RELEASE'#010+ + 'endif'#010+ + #010+ + '# Strip'#010+ + 'ifdef STRIP'#010+ + 'override FPCOPT+=-Xs'#010+ + 'endif'#010+ + #010+ + '# Optimizer'#010+ + 'ifdef OPTIMIZE'#010+ + 'overrid','e FPCOPT+=-OG2p3'#010+ + 'endif'#010+ + #010+ + '# Verbose settings (warning,note,info)'#010+ + 'ifdef VERBOSE'#010+ + 'override FPCOPT+=-vwni'#010+ + 'endif'#010+ + #010+ + '# Needed compiler options'#010+ + 'ifdef COMPILER_OPTIONS'#010+ + 'override FPCOPT+=$(COMPILER_OPTIONS)'#010+ + 'endif'#010+ + 'ifdef COMPILER_UNITDIR'#010+ + 'override FPCOPT+=$','(addprefix -Fu,$(COMPILER_UNITDIR))'#010+ + 'endif'#010+ + 'ifdef COMPILER_LIBRARYDIR'#010+ + 'override FPCOPT+=$(addprefix -Fl,$(COMPILER_LIBRARYDIR))'#010+ + 'endif'#010+ + 'ifdef COMPILER_OBJECTDIR'#010+ + 'override FPCOPT+=$(addprefix -Fo,$(COMPILER_OBJECTDIR))'#010+ + 'endif'#010+ + 'ifdef COMPILER_INCLUDE','DIR'#010+ + 'override FPCOPT+=$(addprefix -Fi,$(COMPILER_INCLUDEDIR))'#010+ + 'endif'#010+ + #010+ + '# Target dirs and the prefix to use for clean/install'#010+ + 'ifdef COMPILER_TARGETDIR'#010+ + 'override FPCOPT+=-FE$(COMPILER_TARGETDIR)'#010+ + 'ifeq ($(COMPILER_TARGETDIR),.)'#010+ + 'override TARGETDIRPR','EFIX='#010+ + 'else'#010+ + 'override TARGETDIRPREFIX=$(COMPILER_TARGETDIR)/'#010+ + 'endif'#010+ + 'endif'#010+ + #010+ + '# Unit target dir'#010+ + 'ifdef COMPILER_UNITTARGETDIR'#010+ + 'override FPCOPT+=-FU$(COMPILER_UNITTARGETDIR)'#010+ + 'ifeq ($(COMPILER_UNITTARGETDIR),.)'#010+ + 'override UNITTARGETDIRPREFIX='#010+ + 'else'#010+ + 'overr','ide UNITTARGETDIRPREFIX=$(COMPILER_TARGETDIR)/'#010+ + 'endif'#010+ + 'else'#010+ + 'ifdef COMPILER_TARGETDIR'#010+ + 'override COMPILER_UNITTARGETDIR=$(COMPILER_TARGETDIR)'#010+ + 'override UNITTARGETDIRPREFIX=$(TARGETDIRPREFIX)'#010+ + 'endif'#010+ + 'endif'#010+ + #010+ + '[command_libc]'#010+ + '# Add GCC lib path if asked',#010+ + 'ifdef GCCLIBDIR'#010+ + 'override FPCOPT+=-Fl$(GCCLIBDIR)'#010+ + 'endif'#010+ + 'ifdef OTHERLIBDIR'#010+ + 'override FPCOPT+=$(addprefix -Fl,$(OTHERLIBDIR))'#010+ + 'endif'#010+ + #010+ + #010+ + '[command_end]'#010+ + '# Add commandline options last so they can override'#010+ + 'ifdef OPT'#010+ + 'override FPCOPT+=$(OPT)'#010+ + 'endif'#010+ + #010+ + '# ','Add defines from FPCOPTDEF to FPCOPT'#010+ + 'ifdef FPCOPTDEF'#010+ + 'override FPCOPT+=$(addprefix -d,$(FPCOPTDEF))'#010+ + 'endif'#010+ + #010+ + '# Was a config file specified ?'#010+ + 'ifdef CFGFILE'#010+ + 'override FPCOPT+=@$(CFGFILE)'#010+ + 'endif'#010+ + #010+ + '# For win32 the options are passed using the environ','ment FPCEXTCMD'#010+ + 'ifeq ($(OS_SOURCE),win32)'#010+ + 'override FPCEXTCMD:=$(FPCOPT)'#010+ + 'override FPCOPT:=!FPCEXTCMD'#010+ + 'export FPCEXTCMD'#010+ + 'endif'#010+ + #010+ + '# Compiler commandline'#010+ + 'override COMPILER:=$(FPC) $(FPCOPT)'#010+ + #010+ + '# also call ppas if with command option -s'#010+ + '# but only if ','the OS_SOURCE and OS_TARGET are equal'#010+ + 'ifeq (,$(findstring -s ,$(COMPILER)))'#010+ + 'EXECPPAS='#010+ + 'else'#010+ + 'ifeq ($(OS_SOURCE),$(OS_TARGET))'#010+ + 'EXECPPAS:=@$(PPAS)'#010+ + 'endif'#010+ + 'endif'#010+ + #010+ + #010+ + '[loaderrules]'#010+ + '#####################################################################', + #010+ + '# Loaders'#010+ + '#####################################################################'#010+ + #010+ + '.PHONY: fpc_loaders'#010+ + #010+ + 'ifdef TARGET_LOADERS'#010+ + 'override ALLTARGET+=fpc_loaders'#010+ + 'override CLEANTARGET+=fpc_loaders_clean'#010+ + 'override INSTALLTARGET+=fpc_loaders_install'#010, + #010+ + 'override LOADEROFILES:=$(addsuffix $(OEXT),$(TARGET_LOADERS))'#010+ + 'endif'#010+ + #010+ + '%$(OEXT): %$(LOADEREXT)'#010+ + ' $(AS) -o $*$(OEXT) $<'#010+ + #010+ + 'fpc_loaders: $(LOADEROFILES)'#010+ + #010+ + 'fpc_loaders_clean:'#010+ + ' -$(DEL) $(LOADEROFILES)'#010+ + #010+ + 'fpc_loaders_install:'#010+ + ' $(MK','DIR) $(INSTALL_UNITDIR)'#010+ + ' $(INSTALL) $(LOADEROFILES) $(INSTALL_UNITDIR)'#010+ + #010+ + #010+ + '[unitrules]'#010+ + '#####################################################################'#010+ + '# Units'#010+ + '#####################################################################'#010, + #010+ + '.PHONY: fpc_units'#010+ + #010+ + 'ifdef TARGET_UNITS'#010+ + 'override ALLTARGET+=fpc_units'#010+ + #010+ + 'override UNITPPUFILES=$(addsuffix $(PPUEXT),$(TARGET_UNITS))'#010+ + 'override INSTALLPPUFILES+=$(UNITPPUFILES)'#010+ + 'override CLEANPPUFILES+=$(UNITPPUFILES)'#010+ + 'endif'#010+ + #010+ + 'fpc_units: $(UNITPPU','FILES)'#010+ + #010+ + #010+ + '[exerules]'#010+ + '#####################################################################'#010+ + '# Exes'#010+ + '#####################################################################'#010+ + #010+ + '.PHONY: fpc_exes'#010+ + #010+ + 'ifdef TARGET_PROGRAMS'#010+ + 'override EXEFILES=$(addsuffix $(','EXEEXT),$(TARGET_PROGRAMS))'#010+ + 'override EXEOFILES:=$(addsuffix $(OEXT),$(TARGET_PROGRAMS)) $(addprefi'+ + 'x $(LIBPREFIX),$(addsuffix $(STATICLIBEXT),$(TARGET_PROGRAMS)))'#010+ + #010+ + 'override ALLTARGET+=fpc_exes'#010+ + 'override INSTALLEXEFILES+=$(EXEFILES)'#010+ + 'override C','LEANEXEFILES+=$(EXEFILES) $(EXEOFILES)'#010+ + 'endif'#010+ + #010+ + 'fpc_exes: $(EXEFILES)'#010+ + #010+ + #010+ + '[rstrules]'#010+ + '#####################################################################'#010+ + '# Resource strings'#010+ + '#####################################################################'#010, + #010+ + 'ifdef TARGET_RSTS'#010+ + 'override RSTFILES=$(addsuffix $(RSTEXT),$(TARGET_RSTS))'#010+ + #010+ + 'override CLEANRSTFILES+=$(RSTFILES)'#010+ + 'endif'#010+ + #010+ + #010+ + '[examplerules]'#010+ + '#####################################################################'#010+ + '# Examples'#010+ + '########################','############################################'+ + '#'#010+ + #010+ + '.PHONY: fpc_examples fpc_test'#010+ + #010+ + 'ifdef TARGET_EXAMPLES'#010+ + 'override EXAMPLESOURCEFILES:=$(wildcard $(addsuffix .pp,$(TARGET_EXAMP'+ + 'LES)) $(addsuffix .pas,$(TARGET_EXAMPLES)))'#010+ + 'override EXAMPLEFILES:=$(a','ddsuffix $(EXEEXT),$(TARGET_EXAMPLES))'#010+ + 'override EXAMPLEOFILES:=$(addsuffix $(OEXT),$(TARGET_EXAMPLES)) $(addp'+ + 'refix $(LIBPREFIX),$(addsuffix $(STATICLIBEXT),$(TARGET_EXAMPLES)))'#010+ + #010+ + 'override CLEANEXEFILES+=$(EXAMPLEFILES) $(EXAMPLEOFILES)'#010+ + 'endif',#010+ + #010+ + 'fpc_examples: all $(EXAMPLEFILES) $(addsuffix _all,$(TARGET_EXAMPLEDIR'+ + 'S))'#010+ + #010+ + #010+ + '[compilerules]'#010+ + '#####################################################################'#010+ + '# General compile rules'#010+ + '#####################################################','###############'+ + '#'#010+ + #010+ + '.PHONY: fpc_packages fpc_all fpc_debug'#010+ + #010+ + '$(FPCMADE): $(ALLTARGET)'#010+ + ' @$(ECHO) Compiled > $(FPCMADE)'#010+ + #010+ + 'fpc_packages: $(COMPILEPACKAGES)'#010+ + #010+ + 'fpc_all: fpc_packages $(FPCMADE)'#010+ + #010+ + 'fpc_debug:'#010+ + ' $(MAKE) all DEBUG=1'#010+ + #010+ + '# General',' compile rules, available for both possible .pp and .pas ex'+ + 'tensions'#010+ + #010+ + '.SUFFIXES: $(EXEEXT) $(PPUEXT) $(OEXT) .pas .pp'#010+ + #010+ + '%$(PPUEXT): %.pp'#010+ + ' $(COMPILER) $<'#010+ + ' $(EXECPPAS)'#010+ + #010+ + '%$(PPUEXT): %.pas'#010+ + ' $(COMPILER) $<'#010+ + ' $(EXECPPAS)'#010, + #010+ + '%$(EXEEXT): %.pp'#010+ + ' $(COMPILER) $<'#010+ + ' $(EXECPPAS)'#010+ + #010+ + '%$(EXEEXT): %.pas'#010+ + ' $(COMPILER) $<'#010+ + ' $(EXECPPAS)'#010+ + #010+ + '# Search paths for .ppu and .pp and .pas'#010+ + 'vpath %.pp $(COMPILER_SOURCEDIR) $(COMPILER_INCDIR)'#010+ + 'vpath %.pas $(COMPILER_','SOURCEDIR) $(COMPILER_INCDIR)'#010+ + 'vpath %$(PPUEXT) $(COMPILER_UNITTARGETDIR)'#010+ + #010+ + #010+ + '[libraryrules]'#010+ + '#####################################################################'#010+ + '# Library'#010+ + '#####################################################################'#010, + #010+ + '.PHONY: fpc_smart fpc_shared'#010+ + #010+ + 'ifndef LIB_FULLNAME'#010+ + 'ifdef LIB_VERSION'#010+ + 'LIB_FULLNAME=$(LIB_NAME).$(LIB_VERSION)'#010+ + 'else'#010+ + 'LIB_FULLNAME=$(LIB_NAME)'#010+ + 'endif'#010+ + 'endif'#010+ + #010+ + '# Default sharedlib units are all unit objects'#010+ + 'ifndef LIB_SHAREDUNITS'#010+ + 'LIB_SHAREDUNITS:=$','(TARGET_UNITS)'#010+ + 'endif'#010+ + #010+ + 'fpc_smart:'#010+ + ' $(MAKE) all LINKSMART=1 CREATESMART=1'#010+ + #010+ + 'fpc_shared: all'#010+ + 'ifdef HASSHAREDLIB'#010+ + ' $(PPUMOVE) $(LIB_SHAREDUNITS) -o$(LIB_FULLNAME)'#010+ + 'else'#010+ + ' @$(ECHO) Shared Libraries not supported'#010+ + 'endif'#010+ + #010+ + #010+ + '[install','rules]'#010+ + '#####################################################################'#010+ + '# Install rules'#010+ + '#####################################################################'#010+ + #010+ + '.PHONY: fpc_install fpc_sourceinstall'#010+ + #010+ + 'ifdef INSTALL_UNITS'#010+ + 'override INSTALLP','PUFILES+=$(addsuffix $(PPUEXT),$(INSTALL_UNITS))'#010+ + 'endif'#010+ + #010+ + 'ifdef INSTALLPPUFILES'#010+ + 'override INSTALLPPUFILES:=$(addprefix $(UNITTARGETDIRPREFIX),$(INSTALL'+ + 'PPUFILES))'#010+ + 'ifdef PPUFILES'#010+ + 'INSTALLPPULINKFILES:=$(shell $(PPUFILES) -S -O $(INSTALLPPUFILES))',#010+ + 'else'#010+ + 'INSTALLPPULINKFILES:=$(wildcard $(subst $(PPUEXT),$(OEXT),$(INSTALLPPU'+ + 'FILES)) $(addprefix $(LIBPREFIX),$(subst $(PPUEXT),$(STATICLIBEXT),$(I'+ + 'NSTALLPPUFILES))))'#010+ + 'endif'#010+ + 'override INSTALLPPULINKFILES:=$(addprefix $(UNITTARGETDIRPREFIX),$(IN', + 'STALLPPULINKFILES))'#010+ + 'endif'#010+ + #010+ + 'ifdef INSTALLEXEFILES'#010+ + 'override INSTALLEXEFILES:=$(addprefix $(TARGETDIRPREFIX),$(INSTALLEXEF'+ + 'ILES))'#010+ + 'endif'#010+ + #010+ + #010+ + 'fpc_install: $(INSTALLTARGET)'#010+ + '# Create UnitInstallFiles'#010+ + 'ifdef INSTALLEXEFILES'#010+ + ' $(MKDIR) $(INSTALL_B','INDIR)'#010+ + '# Compress the exes if upx is defined'#010+ + 'ifdef UPXPROG'#010+ + ' -$(UPXPROG) $(INSTALLEXEFILES)'#010+ + 'endif'#010+ + ' $(INSTALLEXE) $(INSTALLEXEFILES) $(INSTALL_BINDIR)'#010+ + 'endif'#010+ + 'ifdef INSTALLPPUFILES'#010+ + ' $(MKDIR) $(INSTALL_UNITDIR)'#010+ + ' $(INS','TALL) $(INSTALLPPUFILES) $(INSTALL_UNITDIR)'#010+ + 'ifneq ($(INSTALLPPULINKFILES),)'#010+ + ' $(INSTALL) $(INSTALLPPULINKFILES) $(INSTALL_UNITDIR)'#010+ + 'endif'#010+ + 'ifneq ($(wildcard $(LIB_FULLNAME)),)'#010+ + ' $(MKDIR) $(INSTALL_LIBDIR)'#010+ + ' $(INSTALL) $(LIB_','FULLNAME) $(INSTALL_LIBDIR)'#010+ + 'ifdef inUnix'#010+ + ' ln -sf $(LIB_FULLNAME) $(INSTALL_LIBDIR)/$(LIB_NAME)'#010+ + 'endif'#010+ + 'endif'#010+ + 'endif'#010+ + 'ifdef EXTRAINSTALLFILES'#010+ + ' $(MKDIR) $(INSTALL_DATADIR)'#010+ + ' $(INSTALL) $(EXTRAINSTALLFILES) $(INSTALL_DATADIR)'#010+ + 'e','ndif'#010+ + #010+ + 'fpc_sourceinstall: distclean'#010+ + ' $(MKDIR) $(INSTALL_SOURCEDIR)'#010+ + ' $(COPYTREE) $(BASEDIR) $(INSTALL_SOURCEDIR)'#010+ + #010+ + #010+ + '[exampleinstallrules]'#010+ + '#####################################################################'#010+ + '# exampleinstall rule','s'#010+ + '#####################################################################'#010+ + #010+ + '.PHONY: fpc_exampleinstall'#010+ + #010+ + 'fpc_exampleinstall: $(addsuffix _distclean,$(TARGET_EXAMPLEDIRS))'#010+ + 'ifdef EXAMPLESOURCEFILES'#010+ + ' $(MKDIR) $(INSTALL_EXAMPLEDIR)'#010+ + ' $','(COPY) $(EXAMPLESOURCEFILES) $(INSTALL_EXAMPLEDIR)'#010+ + 'endif'#010+ + 'ifdef TARGET_EXAMPLEDIRS'#010+ + 'ifndef EXAMPLESOURCEFILES'#010+ + ' $(MKDIR) $(INSTALL_EXAMPLEDIR)'#010+ + 'endif'#010+ + ' $(COPYTREE) $(addsuffix /*,$(TARGET_EXAMPLEDIRS)) $(INSTALL_EX'+ + 'AMPLEDIR)'#010+ + 'endif'#010+ + #010, + #010+ + '[zipinstallrules]'#010+ + '#####################################################################'#010+ + '# Zip'#010+ + '#####################################################################'#010+ + #010+ + '.PHONY: fpc_zipinstall fpc_zipsourceinstall fpc_zipexampleinstall'#010+ + #010+ + '# Tempo','rary path to pack a file'#010+ + 'ifndef PACKDIR'#010+ + 'ifndef inUnix'#010+ + 'PACKDIR=$(BASEDIR)/../pack_tmp'#010+ + 'else'#010+ + 'PACKDIR=/tmp/fpc-pack'#010+ + 'endif'#010+ + 'endif'#010+ + #010+ + '# Maybe create default zipname from packagename'#010+ + 'ifndef DIST_ZIPNAME'#010+ + 'ifdef PACKAGE_NAME'#010+ + 'DIST_ZIPNAME=$(ZIPPREFIX)$(P','ACKAGE_NAME)$(ZIPSUFFIX)'#010+ + 'endif'#010+ + 'endif'#010+ + #010+ + '# Use tar by default under linux'#010+ + 'ifndef USEZIP'#010+ + 'ifdef inUnix'#010+ + 'USETAR=1'#010+ + 'endif'#010+ + 'endif'#010+ + #010+ + '# Use a wrapper script by default for Os/2'#010+ + 'ifdef inOS2'#010+ + 'USEZIPWRAPPER=1'#010+ + 'endif'#010+ + #010+ + '# Create commands to create the zip/tar fi','le'#010+ + 'ZIPWRAPPER=$(DIST_DESTDIR)/fpczip$(BATCHEXT)'#010+ + 'ZIPCMD_CDPACK:=cd $(subst /,$(PATHSEP),$(PACKDIR))'#010+ + 'ZIPCMD_CDBASE:=cd $(subst /,$(PATHSEP),$(BASEDIR))'#010+ + 'ifdef USETAR'#010+ + 'ZIPDESTFILE:=$(DIST_DESTDIR)/$(DIST_ZIPNAME)$(TAREXT)'#010+ + 'ZIPCMD_ZIP:=$(TARPROG) ','cf$(TAROPT) $(ZIPDESTFILE) *'#010+ + 'else'#010+ + 'ZIPDESTFILE:=$(DIST_DESTDIR)/$(DIST_ZIPNAME)$(ZIPEXT)'#010+ + 'ZIPCMD_ZIP:=$(subst /,$(PATHSEP),$(ZIPPROG)) -Dr $(ZIPOPT) $(ZIPDESTFI'+ + 'LE) *'#010+ + 'endif'#010+ + #010+ + 'fpc_zipinstall:'#010+ + ' $(MAKE) $(ZIPTARGET) INSTALL_PREFIX=$(PACKDIR',')'#010+ + ' $(DEL) $(ZIPDESTFILE)'#010+ + 'ifdef USEZIPWRAPPER'#010+ + 'ifneq ($(ECHO),echo)'#010+ + ' $(ECHO) "$(ZIPCMD_CDPACK)" > $(ZIPWRAPPER)'#010+ + ' $(ECHO) "$(ZIPCMD_ZIP)" >> $(ZIPWRAPPER)'#010+ + ' $(ECHO) "$(ZIPCMD_CDBASE)" >> $(ZIPWRAPPER)'#010+ + 'else'#010+ + ' $(','ECHO) $(ZIPCMD_CDPACK) > $(ZIPWRAPPER)'#010+ + ' $(ECHO) $(ZIPCMD_ZIP) >> $(ZIPWRAPPER)'#010+ + ' $(ECHO) $(ZIPCMD_CDBASE) >> $(ZIPWRAPPER)'#010+ + 'endif'#010+ + 'ifdef inUnix'#010+ + ' /bin/sh $(ZIPWRAPPER)'#010+ + 'else'#010+ + ' $(ZIPWRAPPER)'#010+ + 'endif'#010+ + ' $(DEL) $(ZIPWR','APPER)'#010+ + 'else'#010+ + ' $(ZIPCMD_CDPACK) ; $(ZIPCMD_ZIP) ; $(ZIPCMD_CDBASE)'#010+ + 'endif'#010+ + ' $(DELTREE) $(PACKDIR)'#010+ + #010+ + 'fpc_zipsourceinstall:'#010+ + ' $(MAKE) fpc_zipinstall ZIPTARGET=sourceinstall ZIPSUFFIX=src'#010+ + #010+ + 'fpc_zipexampleinstall:'#010+ + ' $(MAKE) ','fpc_zipinstall ZIPTARGET=exampleinstall ZIPSUFFIX=ex'+ + 'm'#010+ + #010+ + #010+ + '[cleanrules]'#010+ + '#####################################################################'#010+ + '# Clean rules'#010+ + '#####################################################################'#010+ + #010+ + '.PHONY: fpc_clea','n fpc_cleanall fpc_distclean'#010+ + #010+ + 'ifdef EXEFILES'#010+ + 'override CLEANEXEFILES:=$(addprefix $(TARGETDIRPREFIX),$(CLEANEXEFILES'+ + '))'#010+ + 'endif'#010+ + #010+ + 'ifdef EXTRACLEANUNITS'#010+ + 'override CLEANPPUFILES+=$(addsuffix $(PPUEXT),$(EXTRACLEANUNITS))'#010+ + 'endif'#010+ + #010+ + 'ifdef CLEANPPUFILES'#010, + 'override CLEANPPUFILES:=$(addprefix $(UNITTARGETDIRPREFIX),$(CLEANPPUF'+ + 'ILES))'#010+ + '# Get the .o and .a files created for the units'#010+ + 'ifdef PPUFILES'#010+ + 'CLEANPPULINKFILES:=$(shell $(PPUFILES) $(CLEANPPUFILES))'#010+ + 'else'#010+ + 'CLEANPPULINKFILES:=$(wildcard $(subst ','$(PPUEXT),$(OEXT),$(CLEANPPUFI'+ + 'LES)) $(addprefix $(LIBPREFIX),$(subst $(PPUEXT),$(STATICLIBEXT),$(CLE'+ + 'ANPPUFILES))))'#010+ + 'endif'#010+ + 'override CLEANPPULINKFILES:=$(addprefix $(UNITTARGETDIRPREFIX),$(CLEAN'+ + 'PPULINKFILES))'#010+ + 'endif'#010+ + #010+ + 'fpc_clean: $(CLEANTARGET)'#010+ + 'i','fdef CLEANEXEFILES'#010+ + ' -$(DEL) $(CLEANEXEFILES)'#010+ + 'endif'#010+ + 'ifdef CLEANPPUFILES'#010+ + ' -$(DEL) $(CLEANPPUFILES)'#010+ + 'endif'#010+ + 'ifneq ($(CLEANPPULINKFILES),)'#010+ + ' -$(DEL) $(CLEANPPULINKFILES)'#010+ + 'endif'#010+ + 'ifdef CLEANRSTFILES'#010+ + ' -$(DEL) $(addprefix $(','UNITTARGETDIRPREFIX),$(CLEANRSTFILES))'+ + #010+ + 'endif'#010+ + 'ifdef EXTRACLEANFILES'#010+ + ' -$(DEL) $(EXTRACLEANFILES)'#010+ + 'endif'#010+ + 'ifdef LIB_NAME'#010+ + ' -$(DEL) $(LIB_NAME) $(LIB_FULLNAME)'#010+ + 'endif'#010+ + ' -$(DEL) $(FPCMADE) $(PPAS) link.res $(FPCEXTFILE) $(REDIRFI','L'+ + 'E)'#010+ + #010+ + 'fpc_distclean: fpc_clean'#010+ + #010+ + '# Also run clean first if targetdir is set. Unittargetdir is always'#010+ + '# set if targetdir or unittargetdir is specified'#010+ + 'ifdef COMPILER_UNITTARGETDIR'#010+ + 'TARGETDIRCLEAN=fpc_clean'#010+ + 'endif'#010+ + #010+ + 'fpc_cleanall: $(CLEANTARGET) $(','TARGETDIRCLEAN)'#010+ + 'ifdef CLEANEXEFILES'#010+ + ' -$(DEL) $(CLEANEXEFILES)'#010+ + 'endif'#010+ + ' -$(DEL) *$(OEXT) *$(PPUEXT) *$(RSTEXT) *$(ASMEXT) *$(STATICLIB'+ + 'EXT) *$(SHAREDLIBEXT) *$(PPLEXT)'#010+ + ' -$(DELTREE) *$(SMARTEXT)'#010+ + ' -$(DEL) $(FPCMADE) $(','PPAS) link.res $(FPCEXTFILE) $(REDIRFIL'+ + 'E)'#010+ + #010+ + #010+ + '[inforules]'#010+ + '#####################################################################'#010+ + '# Info rules'#010+ + '#####################################################################'#010+ + #010+ + '.PHONY: fpc_info'#010+ + #010+ + 'fpc_info:'#010+ + ' ',' @$(ECHO)'#010+ + ' @$(ECHO) == Package info =='#010+ + ' @$(ECHO) Package Name..... $(PACKAGE_NAME)'#010+ + ' @$(ECHO) Package Version.. $(PACKAGE_VERSION)'#010+ + ' @$(ECHO)'#010+ + ' @$(ECHO) == Configuration info =='#010+ + ' @$(ECHO)'#010+ + ' ',' @$(ECHO) FPC.......... $(FPC)'#010+ + ' @$(ECHO) FPC Version.. $(FPC_VERSION)'#010+ + ' @$(ECHO) Source CPU... $(CPU_SOURCE)'#010+ + ' @$(ECHO) Target CPU... $(CPU_TARGET)'#010+ + ' @$(ECHO) Source OS.... $(OS_SOURCE)'#010+ + ' @$(ECHO) Tar','get OS.... $(OS_TARGET)'#010+ + ' @$(ECHO)'#010+ + ' @$(ECHO) == Directory info =='#010+ + ' @$(ECHO)'#010+ + ' @$(ECHO) Basedir......... $(BASEDIR)'#010+ + ' @$(ECHO) FPCDir.......... $(FPCDIR)'#010+ + ' @$(ECHO) UnitsDir........ $(UNITSDIR)'#010+ + ' ',' @$(ECHO) PackagesDir..... $(PACKAGESDIR)'#010+ + ' @$(ECHO)'#010+ + ' @$(ECHO) GCC library..... $(GCCLIBDIR)'#010+ + ' @$(ECHO) Other library... $(OTHERLIBDIR)'#010+ + ' @$(ECHO)'#010+ + ' @$(ECHO) == Tools info =='#010+ + ' @$(ECHO)'#010+ + ' @$(','ECHO) Pwd....... $(PWD)'#010+ + ' @$(ECHO) Echo...... $(ECHO)'#010+ + ' @$(ECHO) PPUMove... $(PPUMOVE)'#010+ + ' @$(ECHO) PPUFiles.. $(PPUFILES)'#010+ + ' @$(ECHO) Date...... $(DATE)'#010+ + ' @$(ECHO) Upx....... $(UPXPROG)'#010+ + ' @$(ECHO) Zi','p....... $(ZIPPROG)'#010+ + ' @$(ECHO)'#010+ + ' @$(ECHO) == Object info =='#010+ + ' @$(ECHO)'#010+ + ' @$(ECHO) Target Loaders...... $(TARGET_LOADERS)'#010+ + ' @$(ECHO) Target Units........ $(TARGET_UNITS)'#010+ + ' @$(ECHO) Target Programs.....',' $(TARGET_PROGRAMS)'#010+ + ' @$(ECHO) Target Dirs......... $(TARGET_DIRS)'#010+ + ' @$(ECHO) Target Examples..... $(TARGET_EXAMPLES)'#010+ + ' @$(ECHO) Target ExampleDirs.. $(TARGET_EXAMPLEDIRS)'#010+ + ' @$(ECHO)'#010+ + ' @$(ECHO) ExtraCleanUn','its... $(CLEAN_UNITS)'#010+ + ' @$(ECHO) ExtraCleanFiles... $(CLEAN_FILES)'#010+ + ' @$(ECHO)'#010+ + ' @$(ECHO) ExtraInstallUnits. $(INSTALL_UNITS)'#010+ + ' @$(ECHO) ExtraInstallFiles. $(INSTALL_FILES)'#010+ + ' @$(ECHO)'#010+ + ' @$(ECHO) == Ins','tall info =='#010+ + ' @$(ECHO)'#010+ + ' @$(ECHO) DateStr.............. $(DATESTR)'#010+ + ' @$(ECHO) ZipPrefix............ $(ZIPPREFIX)'#010+ + ' @$(ECHO) ZipSuffix............ $(ZIPSUFFIX)'#010+ + ' @$(ECHO)'#010+ + ' @$(ECHO) INSTALL_BASEDIR...','... $(INSTALL_BASEDIR)'#010+ + ' @$(ECHO) INSTALL_BINDIR....... $(INSTALL_BINDIR)'#010+ + ' @$(ECHO) INSTALL_LIBDIR....... $(INSTALL_LIBDIR)'#010+ + ' @$(ECHO) INSTALL_UNITDIR...... $(INSTALL_UNITDIR)'#010+ + ' @$(ECHO) INSTALL_SOURCEDIR.... $(','INSTALL_SOURCEDIR)'#010+ + ' @$(ECHO) INSTALL_DOCDIR....... $(INSTALL_DOCDIR)'#010+ + ' @$(ECHO) INSTALL_DATADIR...... $(INSTALL_DATADIR)'#010+ + ' @$(ECHO)'#010+ + ' @$(ECHO) DIST_DESTDIR......... $(DIST_DESTDIR)'#010+ + ' @$(ECHO) DIST_ZIPNAME.','........ $(DIST_ZIPNAME)'#010+ + ' @$(ECHO)'#010+ + #010+ + '[localmakefile]'#010+ + '#####################################################################'#010+ + '# Local Makefile'#010+ + '#####################################################################'#010+ + #010+ + 'ifneq ($(wildcard fpcma','ke.loc),)'#010+ + 'include fpcmake.loc'#010+ + 'endif'#010+ + #010+ + '[userrules]'#010+ + '#####################################################################'#010+ + '# Users rules'#010+ + '#####################################################################'#010 +); diff --git a/utils/fpcm/fpcmake.ini b/utils/fpcm/fpcmake.ini new file mode 100644 index 0000000000..662496d5cf --- /dev/null +++ b/utils/fpcm/fpcmake.ini @@ -0,0 +1,1235 @@ +; +; Templates used by fpcmake to create a Makefile from Makefile.fpc +; + +[osdetect] +##################################################################### +# Autodetect OS (Linux or Dos or Windows NT or OS/2) +# define inUnix when running under Unix (Linux,FreeBSD) +# define inWinNT when running under WinNT +# define inOS2 when running under OS/2 +##################################################################### + +# 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 +inUnix=1 +PWD:=$(firstword $(PWD)) +endif +else +PWD:=$(firstword $(PWD)) +endif + +# Detect NT - NT sets OS to Windows_NT +# Detect OS/2 - OS/2 has OS2_SHELL defined +ifndef inUnix +ifeq ($(OS),Windows_NT) +inWinNT=1 +else +ifdef OS2_SHELL +inOS2=1 +endif +endif +endif + +# The extension of executables +ifdef inUnix +SRCEXEEXT= +else +SRCEXEEXT=.exe +endif + +# The extension of batch files / scripts +ifdef inUnix +BATCHEXT=.sh +else +ifdef inOS2 +BATCHEXT=.cmd +else +BATCHEXT=.bat +endif +endif + +# Path Separator, the subst trick is necessary for the \ that can't exists +# at the end of a line +ifdef inUnix +PATHSEP=/ +else +PATHSEP=$(subst /,\,/) +endif + +# The path which is searched separated by spaces +ifdef inUnix +SEARCHPATH=$(subst :, ,$(PATH)) +else +SEARCHPATH=$(subst ;, ,$(PATH)) +endif + +# Base dir +ifdef PWD +BASEDIR:=$(shell $(PWD)) +else +BASEDIR=. +endif + +[fpcdetect] +##################################################################### +# FPC version/target Detection +##################################################################### + +# What compiler to use ? +ifndef FPC +# Compatibility with old makefiles +ifdef PP +FPC=$(PP) +else +FPC=ppc386 +endif +endif +override FPC:=$(subst $(SRCEXEEXT),,$(FPC)) +override FPC:=$(subst \,/,$(FPC))$(SRCEXEEXT) + +# Target OS +ifndef OS_TARGET +OS_TARGET:=$(shell $(FPC) -iTO) +endif + +# Source OS +ifndef OS_SOURCE +OS_SOURCE:=$(shell $(FPC) -iSO) +endif + +# Target CPU +ifndef CPU_TARGET +CPU_TARGET:=$(shell $(FPC) -iTP) +endif + +# Source CPU +ifndef CPU_SOURCE +CPU_SOURCE:=$(shell $(FPC) -iSP) +endif + +# FPC version +ifndef FPC_VERSION +FPC_VERSION:=$(shell $(FPC) -iV) +endif + +export FPC OS_TARGET OS_SOURCE CPU_TARGET CPU_SOURCE FPC_VERSION + + +[fpcdirdetect] +##################################################################### +# FPCDIR Setting +##################################################################### + +# Test FPCDIR to look if the RTL dir exists +ifdef FPCDIR +override FPCDIR:=$(subst \,/,$(FPCDIR)) +ifeq ($(wildcard $(FPCDIR)/rtl),) +ifeq ($(wildcard $(FPCDIR)/units),) +override FPCDIR=wrong +endif +endif +else +override FPCDIR=wrong +endif + +# Detect FPCDIR +ifeq ($(FPCDIR),wrong) +ifdef inUnix +override FPCDIR=/usr/local/lib/fpc/$(FPC_VERSION) +ifeq ($(wildcard $(FPCDIR)/units),) +override FPCDIR=/usr/lib/fpc/$(FPC_VERSION) +endif +else +override FPCDIR:=$(subst /$(FPC),,$(firstword $(strip $(wildcard $(addsuffix /$(FPC),$(SEARCHPATH)))))) +override FPCDIR:=$(FPCDIR)/.. +ifeq ($(wildcard $(FPCDIR)/rtl),) +ifeq ($(wildcard $(FPCDIR)/units),) +override FPCDIR:=$(FPCDIR)/.. +ifeq ($(wildcard $(FPCDIR)/rtl),) +ifeq ($(wildcard $(FPCDIR)/units),) +override FPCDIR=c:/pp +endif +endif +endif +endif +endif +endif +override FPCDIR:=$(wildcard $(FPCDIR)) + +# Units dir +UNITSDIR=$(wildcard $(FPCDIR)/units/$(OS_TARGET)) + +# Packages dir +PACKAGESDIR=$(wildcard $(FPCDIR) $(FPCDIR)/packages) + + +[shelltools] +##################################################################### +# Shell tools +##################################################################### + +# echo +ifndef ECHO +ECHO:=$(strip $(wildcard $(addsuffix /gecho$(EXEEXT),$(SEARCHPATH)))) +ifeq ($(ECHO),) +ECHO:=$(strip $(wildcard $(addsuffix /echo$(SRCEXEEXT),$(SEARCHPATH)))) +ifeq ($(ECHO),) +ECHO:=echo +else +ECHO:=$(firstword $(ECHO)) +endif +else +ECHO:=$(firstword $(ECHO)) +endif +endif + +# To copy pograms +ifndef COPY +COPY:=cp -fp +endif + +# Copy a whole tree +ifndef COPYTREE +COPYTREE:=cp -rfp +endif + +# To move pograms +ifndef MOVE +MOVE:=mv -f +endif + +# Check delete program +ifndef DEL +DEL:=rm -f +endif + +# Check deltree program +ifndef DELTREE +DELTREE:=rm -rf +endif + +# To install files +ifndef INSTALL +ifdef inUnix +INSTALL:=install -c -m 644 +else +INSTALL:=$(COPY) +endif +endif + +# To install programs +ifndef INSTALLEXE +ifdef inUnix +INSTALLEXE:=install -c -m 755 +else +INSTALLEXE:=$(COPY) +endif +endif + +# To make a directory. +ifndef MKDIR +ifdef inUnix +MKDIR:=install -m 755 -d +else +MKDIR:=ginstall -m 755 -d +endif +endif + +export ECHO COPY COPYTREE MOVE DEL DELTREE INSTALL INSTALLEXE MKDIR + + +[defaulttools] +##################################################################### +# Default Tools +##################################################################### + +# assembler, redefine it if cross compiling +ifndef AS +AS=as +endif + +# linker, but probably not used +ifndef LD +LD=ld +endif + +# ppas.bat / ppas.sh +PPAS=$(BATCHEXT) + +# ldconfig to rebuild .so cache +ifdef inUnix +LDCONFIG=ldconfig +else +LDCONFIG= +endif + +# ppumove +ifndef PPUMOVE +PPUMOVE:=$(strip $(wildcard $(addsuffix /ppumove$(SRCEXEEXT),$(SEARCHPATH)))) +ifeq ($(PPUMOVE),) +PPUMOVE= +else +PPUMOVE:=$(firstword $(PPUMOVE)) +endif +endif +export PPUMOVE + +# ppufiles +ifndef PPUFILES +PPUFILES:=$(strip $(wildcard $(addsuffix /ppufiles$(SRCEXEEXT),$(SEARCHPATH)))) +ifeq ($(PPUFILES),) +PPUFILES= +else +PPUFILES:=$(firstword $(PPUFILES)) +endif +endif +export PPUFILES + +# gdate/date +ifndef DATE +DATE:=$(strip $(wildcard $(addsuffix /date$(SRCEXEEXT),$(SEARCHPATH)))) +ifeq ($(DATE),) +DATE:=$(strip $(wildcard $(addsuffix /gdate$(SRCEXEEXT),$(SEACHPATH)))) +ifeq ($(DATE),) +DATE= +else +DATE:=$(firstword $(DATE)) +endif +else +DATE:=$(firstword $(DATE)) +endif +endif +export DATE + +ifdef DATE +DATESTR:=$(shell $(DATE) +%Y%m%d) +else +DATESTR= +endif + +# 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$(SRCEXEEXT),$(SEARCHPATH)))) +ifeq ($(UPXPROG),) +UPXPROG= +else +UPXPROG:=$(firstword $(UPXPROG)) +endif +else +UPXPROG= +endif +endif +export UPXPROG + +# ZipProg, you can't use Zip as the var name (PFV) +ifndef ZIPPROG +ZIPPROG:=$(strip $(wildcard $(addsuffix /zip$(SRCEXEEXT),$(SEARCHPATH)))) +ifeq ($(ZIPPROG),) +ZIPPROG= +else +ZIPPROG:=$(firstword $(ZIPPROG)) +endif +endif +export ZIPPROG + +ZIPOPT=-9 +ZIPEXT=.zip + +# Tar +ifndef TARPROG +TARPROG:=$(strip $(wildcard $(addsuffix /tar$(SRCEXEEXT),$(SEARCHPATH)))) +ifeq ($(TARPROG),) +TARPROG= +else +TARPROG:=$(firstword $(TARPROG)) +endif +endif +export TARPROG + +ifeq ($(USETAR),bz2) +TAROPT=vI +TAREXT=.tar.bz2 +else +TAROPT=vz +TAREXT=.tar.gz +endif + + +[extensions] +##################################################################### +# Default extensions +##################################################################### + +# Default needed extensions (Go32v2,Linux) +LOADEREXT=.as +EXEEXT=.exe +PPLEXT=.ppl +PPUEXT=.ppu +OEXT=.o +ASMEXT=.s +SMARTEXT=.sl +STATICLIBEXT=.a +SHAREDLIBEXT=.so +LIBPREFIX=lib +RSTEXT=.rst +FPCMADE=fpcmade + + +# Go32v1 +ifeq ($(OS_TARGET),go32v1) +PPUEXT=.pp1 +OEXT=.o1 +ASMEXT=.s1 +SMARTEXT=.sl1 +STATICLIBEXT=.a1 +SHAREDLIBEXT=.so1 +LIBPREFIX= +FPCMADE=fpcmade.v1 +PACKAGESUFFIX=v1 +endif + +# Go32v2 +ifeq ($(OS_TARGET),go32v2) +LIBPREFIX= +FPCMADE=fpcmade.dos +ZIPSUFFIX=go32 +endif + +# Linux +ifeq ($(OS_TARGET),linux) +EXEEXT= +HASSHAREDLIB=1 +FPCMADE=fpcmade.lnx +ZIPSUFFIX=linux +endif + +# Linux +ifeq ($(OS_TARGET),freebsd) +EXEEXT= +HASSHAREDLIB=1 +FPCMADE=fpcmade.freebsd +ZIPSUFFIX=freebsd +endif + +# Win32 +ifeq ($(OS_TARGET),win32) +PPUEXT=.ppw +OEXT=.ow +ASMEXT=.sw +SMARTEXT=.slw +STATICLIBEXT=.aw +SHAREDLIBEXT=.dll +FPCMADE=fpcmade.w32 +ZIPSUFFIX=w32 +endif + +# OS/2 +ifeq ($(OS_TARGET),os2) +PPUEXT=.ppo +ASMEXT=.so2 +OEXT=.oo2 +SMARTEXT=.so +STATICLIBEXT=.ao2 +SHAREDLIBEXT=.dll +FPCMADE=fpcmade.os2 +ZIPSUFFIX=emx +endif + +[defaultdirs] +##################################################################### +# Default Directories +##################################################################### + +# Units dir +ifdef REQUIRE_UNITSDIR +override UNITSDIR+=$(REQUIRE_UNITSDIR) +endif + +# Units dir +ifdef REQUIRE_PACKAGESDIR +override PACKAGESDIR+=$(REQUIRE_PACKAGESDIR) +endif + + +# Linux and freebsd use unix dirs with /usr/bin, /usr/lib +# When zipping use the target as default, when normal install then +# use the source os as default +ifdef ZIPTARGET +# Zipinstall +ifeq ($(OS_TARGET),linux) +UNIXINSTALLDIR=1 +endif +ifeq ($(OS_TARGET),freebsd) +UNIXINSTALLDIR=1 +endif +else +# Normal install +ifeq ($(OS_SOURCE),linux) +UNIXINSTALLDIR=1 +endif +ifeq ($(OS_SOURCE),freebsd) +UNIXINSTALLDIR=1 +endif +endif + +# set the prefix directory where to install everything +ifndef INSTALL_PREFIX +ifdef UNIXINSTALLDIR +INSTALL_PREFIX=/usr +else +INSTALL_PREFIX=/pp +endif +endif +export INSTALL_PREFIX + +# Where to place the resulting zip files +ifndef DIST_DESTDIR +DIST_DESTDIR:=$(BASEDIR) +endif +export DIST_DESTDIR + + +##################################################################### +# Install Directories +##################################################################### + +# set the base directory where to install everything +ifndef INSTALL_BASEDIR +ifdef UNIXINSTALLDIR +INSTALL_BASEDIR=$(INSTALL_PREFIX)/lib/fpc/$(FPC_VERSION) +else +INSTALL_BASEDIR=$(INSTALL_PREFIX) +endif +endif + +# set the directory where to install the binaries +ifndef INSTALL_BINDIR +ifdef UNIXINSTALLDIR +INSTALL_BINDIR=$(INSTALL_PREFIX)/bin +else +INSTALL_BINDIR=$(INSTALL_BASEDIR)/bin/$(OS_TARGET) +endif +endif + +# set the directory where to install the units. +ifndef INSTALL_UNITDIR +INSTALL_UNITDIR=$(INSTALL_BASEDIR)/units/$(OS_TARGET) +ifdef PACKAGE_NAME +INSTALL_UNITDIR:=$(INSTALL_UNITDIR)/$(PACKAGE_NAME) +endif +endif + +# Where to install shared libraries +ifndef INSTALL_LIBDIR +ifdef UNIXINSTALLDIR +INSTALL_LIBDIR=$(INSTALL_PREFIX)/lib +else +INSTALL_LIBDIR=$(INSTALL_UNITDIR) +endif +endif + +# Where the source files will be stored +ifndef INSTALL_SOURCEDIR +ifdef UNIXINSTALLDIR +INSTALL_SOURCEDIR=$(INSTALL_PREFIX)/src/fpc-$(FPC_VERSION) +else +INSTALL_SOURCEDIR=$(INSTALL_BASEDIR)/source +endif +ifdef PACKAGE_NAME +INSTALL_SOURCEDIR:=$(INSTALL_SOURCEDIR)/$(PACKAGE_NAME) +endif +endif + +# Where the doc files will be stored +ifndef INSTALL_DOCDIR +ifdef UNIXINSTALLDIR +INSTALL_DOCDIR=$(INSTALL_PREFIX)/doc/fpc-$(FPC_VERSION) +else +INSTALL_DOCDIR=$(INSTALL_BASEDIR)/doc +endif +endif + +# Where to install the examples, under linux we use the doc dir +# because the copytree command will create a subdir itself +ifndef INSTALL_EXAMPLEDIR +ifdef UNIXINSTALLDIR +INSTALL_EXAMPLEDIR=$(INSTALL_DOCDIR)/examples +else +INSTALL_EXAMPLEDIR=$(INSTALL_BASEDIR)/examples +endif +ifdef EXAMPLESUBDIR +INSTALL_EXAMPLEDIR:=$(INSTALL_EXAMPLEDIR)/$(EXAMPLESUBDIR) +endif +endif + +# Where the some extra (data)files will be stored +ifndef INSTALL_DATADIR +INSTALL_DATADIR=$(INSTALL_BASEDIR) +endif + + +[dirlibc] +# On linux, try to find where libgcc.a is. +ifdef inUnix +ifndef GCCLIBDIR +GCCLIBDIR:=$(shell dirname `(gcc -v 2>&1)| head -n 1| awk '{ print $$4 } '`) +endif +ifndef OTHERLIBDIR +OTHERLIBDIR:=$(shell grep -v "^\#" /etc/ld.so.conf | awk '{ ORS=" "; print $1 }') +endif +export GCCLIBDIR OTHERLIB +endif + + +[command_begin] +##################################################################### +# Compiler Command Line +##################################################################### + +# Load commandline OPTDEF and add FPC_CPU define +override FPCOPTDEF=$(CPU_TARGET) + +# Load commandline OPT and add target and unit dir to be sure +ifneq ($(OS_TARGET),$(OS_SOURCE)) +override FPCOPT+=-T$(OS_TARGET) +endif + +# User dirs should be first, so they are looked at first +ifdef UNITDIR +override FPCOPT+=$(addprefix -Fu,$(UNITDIR)) +endif +ifdef LIBDIR +override FPCOPT+=$(addprefix -Fl,$(LIBDIR)) +endif +ifdef OBJDIR +override FPCOPT+=$(addprefix -Fo,$(OBJDIR)) +endif +ifdef INCDIR +override FPCOPT+=$(addprefix -Fi,$(INCDIR)) +endif + +# Smartlinking +ifdef LINKSMART +override FPCOPT+=-XX +endif + +# Smartlinking creation +ifdef CREATESMART +override FPCOPT+=-CX +endif + +# Debug +ifdef DEBUG +override FPCOPT+=-gl +override FPCOPTDEF+=DEBUG +endif + +# Release mode (strip, optimize and don't load ppc386.cfg) +ifdef RELEASE +override FPCOPT+=-Xs -OG2p3 -n +override FPCOPTDEF+=RELEASE +endif + +# Strip +ifdef STRIP +override FPCOPT+=-Xs +endif + +# Optimizer +ifdef OPTIMIZE +override FPCOPT+=-OG2p3 +endif + +# Verbose settings (warning,note,info) +ifdef VERBOSE +override FPCOPT+=-vwni +endif + +# Needed compiler options +ifdef COMPILER_OPTIONS +override FPCOPT+=$(COMPILER_OPTIONS) +endif +ifdef COMPILER_UNITDIR +override FPCOPT+=$(addprefix -Fu,$(COMPILER_UNITDIR)) +endif +ifdef COMPILER_LIBRARYDIR +override FPCOPT+=$(addprefix -Fl,$(COMPILER_LIBRARYDIR)) +endif +ifdef COMPILER_OBJECTDIR +override FPCOPT+=$(addprefix -Fo,$(COMPILER_OBJECTDIR)) +endif +ifdef COMPILER_INCLUDEDIR +override FPCOPT+=$(addprefix -Fi,$(COMPILER_INCLUDEDIR)) +endif + +# Target dirs and the prefix to use for clean/install +ifdef COMPILER_TARGETDIR +override FPCOPT+=-FE$(COMPILER_TARGETDIR) +ifeq ($(COMPILER_TARGETDIR),.) +override TARGETDIRPREFIX= +else +override TARGETDIRPREFIX=$(COMPILER_TARGETDIR)/ +endif +endif + +# Unit target dir +ifdef COMPILER_UNITTARGETDIR +override FPCOPT+=-FU$(COMPILER_UNITTARGETDIR) +ifeq ($(COMPILER_UNITTARGETDIR),.) +override UNITTARGETDIRPREFIX= +else +override UNITTARGETDIRPREFIX=$(COMPILER_TARGETDIR)/ +endif +else +ifdef COMPILER_TARGETDIR +override COMPILER_UNITTARGETDIR=$(COMPILER_TARGETDIR) +override UNITTARGETDIRPREFIX=$(TARGETDIRPREFIX) +endif +endif + +[command_libc] +# Add GCC lib path if asked +ifdef GCCLIBDIR +override FPCOPT+=-Fl$(GCCLIBDIR) +endif +ifdef OTHERLIBDIR +override FPCOPT+=$(addprefix -Fl,$(OTHERLIBDIR)) +endif + + +[command_end] +# Add commandline options last so they can override +ifdef OPT +override FPCOPT+=$(OPT) +endif + +# Add defines from FPCOPTDEF to FPCOPT +ifdef FPCOPTDEF +override FPCOPT+=$(addprefix -d,$(FPCOPTDEF)) +endif + +# Was a config file specified ? +ifdef CFGFILE +override FPCOPT+=@$(CFGFILE) +endif + +# For win32 the options are passed using the environment FPCEXTCMD +ifeq ($(OS_SOURCE),win32) +override FPCEXTCMD:=$(FPCOPT) +override FPCOPT:=!FPCEXTCMD +export FPCEXTCMD +endif + +# Compiler commandline +override COMPILER:=$(FPC) $(FPCOPT) + +# also call ppas if with command option -s +# but only if the OS_SOURCE and OS_TARGET are equal +ifeq (,$(findstring -s ,$(COMPILER))) +EXECPPAS= +else +ifeq ($(OS_SOURCE),$(OS_TARGET)) +EXECPPAS:=@$(PPAS) +endif +endif + + +[loaderrules] +##################################################################### +# Loaders +##################################################################### + +.PHONY: fpc_loaders + +ifdef TARGET_LOADERS +override ALLTARGET+=fpc_loaders +override CLEANTARGET+=fpc_loaders_clean +override INSTALLTARGET+=fpc_loaders_install + +override LOADEROFILES:=$(addsuffix $(OEXT),$(TARGET_LOADERS)) +endif + +%$(OEXT): %$(LOADEREXT) + $(AS) -o $*$(OEXT) $< + +fpc_loaders: $(LOADEROFILES) + +fpc_loaders_clean: + -$(DEL) $(LOADEROFILES) + +fpc_loaders_install: + $(MKDIR) $(INSTALL_UNITDIR) + $(INSTALL) $(LOADEROFILES) $(INSTALL_UNITDIR) + + +[unitrules] +##################################################################### +# Units +##################################################################### + +.PHONY: fpc_units + +ifdef TARGET_UNITS +override ALLTARGET+=fpc_units + +override UNITPPUFILES=$(addsuffix $(PPUEXT),$(TARGET_UNITS)) +override INSTALLPPUFILES+=$(UNITPPUFILES) +override CLEANPPUFILES+=$(UNITPPUFILES) +endif + +fpc_units: $(UNITPPUFILES) + + +[exerules] +##################################################################### +# Exes +##################################################################### + +.PHONY: fpc_exes + +ifdef TARGET_PROGRAMS +override EXEFILES=$(addsuffix $(EXEEXT),$(TARGET_PROGRAMS)) +override EXEOFILES:=$(addsuffix $(OEXT),$(TARGET_PROGRAMS)) $(addprefix $(LIBPREFIX),$(addsuffix $(STATICLIBEXT),$(TARGET_PROGRAMS))) + +override ALLTARGET+=fpc_exes +override INSTALLEXEFILES+=$(EXEFILES) +override CLEANEXEFILES+=$(EXEFILES) $(EXEOFILES) +endif + +fpc_exes: $(EXEFILES) + + +[rstrules] +##################################################################### +# Resource strings +##################################################################### + +ifdef TARGET_RSTS +override RSTFILES=$(addsuffix $(RSTEXT),$(TARGET_RSTS)) + +override CLEANRSTFILES+=$(RSTFILES) +endif + + +[examplerules] +##################################################################### +# Examples +##################################################################### + +.PHONY: fpc_examples fpc_test + +ifdef TARGET_EXAMPLES +override EXAMPLESOURCEFILES:=$(wildcard $(addsuffix .pp,$(TARGET_EXAMPLES)) $(addsuffix .pas,$(TARGET_EXAMPLES))) +override EXAMPLEFILES:=$(addsuffix $(EXEEXT),$(TARGET_EXAMPLES)) +override EXAMPLEOFILES:=$(addsuffix $(OEXT),$(TARGET_EXAMPLES)) $(addprefix $(LIBPREFIX),$(addsuffix $(STATICLIBEXT),$(TARGET_EXAMPLES))) + +override CLEANEXEFILES+=$(EXAMPLEFILES) $(EXAMPLEOFILES) +endif + +fpc_examples: all $(EXAMPLEFILES) $(addsuffix _all,$(TARGET_EXAMPLEDIRS)) + + +[compilerules] +##################################################################### +# General compile rules +##################################################################### + +.PHONY: fpc_packages fpc_all fpc_debug + +$(FPCMADE): $(ALLTARGET) + @$(ECHO) Compiled > $(FPCMADE) + +fpc_packages: $(COMPILEPACKAGES) + +fpc_all: fpc_packages $(FPCMADE) + +fpc_debug: + $(MAKE) all DEBUG=1 + +# General compile rules, available for both possible .pp and .pas extensions + +.SUFFIXES: $(EXEEXT) $(PPUEXT) $(OEXT) .pas .pp + +%$(PPUEXT): %.pp + $(COMPILER) $< + $(EXECPPAS) + +%$(PPUEXT): %.pas + $(COMPILER) $< + $(EXECPPAS) + +%$(EXEEXT): %.pp + $(COMPILER) $< + $(EXECPPAS) + +%$(EXEEXT): %.pas + $(COMPILER) $< + $(EXECPPAS) + +# Search paths for .ppu and .pp and .pas +vpath %.pp $(COMPILER_SOURCEDIR) $(COMPILER_INCDIR) +vpath %.pas $(COMPILER_SOURCEDIR) $(COMPILER_INCDIR) +vpath %$(PPUEXT) $(COMPILER_UNITTARGETDIR) + + +[libraryrules] +##################################################################### +# Library +##################################################################### + +.PHONY: fpc_smart fpc_shared + +ifndef LIB_FULLNAME +ifdef LIB_VERSION +LIB_FULLNAME=$(LIB_NAME).$(LIB_VERSION) +else +LIB_FULLNAME=$(LIB_NAME) +endif +endif + +# Default sharedlib units are all unit objects +ifndef LIB_SHAREDUNITS +LIB_SHAREDUNITS:=$(TARGET_UNITS) +endif + +fpc_smart: + $(MAKE) all LINKSMART=1 CREATESMART=1 + +fpc_shared: all +ifdef HASSHAREDLIB + $(PPUMOVE) $(LIB_SHAREDUNITS) -o$(LIB_FULLNAME) +else + @$(ECHO) Shared Libraries not supported +endif + + +[installrules] +##################################################################### +# Install rules +##################################################################### + +.PHONY: fpc_install fpc_sourceinstall + +ifdef INSTALL_UNITS +override INSTALLPPUFILES+=$(addsuffix $(PPUEXT),$(INSTALL_UNITS)) +endif + +ifdef INSTALLPPUFILES +override INSTALLPPUFILES:=$(addprefix $(UNITTARGETDIRPREFIX),$(INSTALLPPUFILES)) +ifdef PPUFILES +INSTALLPPULINKFILES:=$(shell $(PPUFILES) -S -O $(INSTALLPPUFILES)) +else +INSTALLPPULINKFILES:=$(wildcard $(subst $(PPUEXT),$(OEXT),$(INSTALLPPUFILES)) $(addprefix $(LIBPREFIX),$(subst $(PPUEXT),$(STATICLIBEXT),$(INSTALLPPUFILES)))) +endif +override INSTALLPPULINKFILES:=$(addprefix $(UNITTARGETDIRPREFIX),$(INSTALLPPULINKFILES)) +endif + +ifdef INSTALLEXEFILES +override INSTALLEXEFILES:=$(addprefix $(TARGETDIRPREFIX),$(INSTALLEXEFILES)) +endif + + +fpc_install: $(INSTALLTARGET) +# Create UnitInstallFiles +ifdef INSTALLEXEFILES + $(MKDIR) $(INSTALL_BINDIR) +# Compress the exes if upx is defined +ifdef UPXPROG + -$(UPXPROG) $(INSTALLEXEFILES) +endif + $(INSTALLEXE) $(INSTALLEXEFILES) $(INSTALL_BINDIR) +endif +ifdef INSTALLPPUFILES + $(MKDIR) $(INSTALL_UNITDIR) + $(INSTALL) $(INSTALLPPUFILES) $(INSTALL_UNITDIR) +ifneq ($(INSTALLPPULINKFILES),) + $(INSTALL) $(INSTALLPPULINKFILES) $(INSTALL_UNITDIR) +endif +ifneq ($(wildcard $(LIB_FULLNAME)),) + $(MKDIR) $(INSTALL_LIBDIR) + $(INSTALL) $(LIB_FULLNAME) $(INSTALL_LIBDIR) +ifdef inUnix + ln -sf $(LIB_FULLNAME) $(INSTALL_LIBDIR)/$(LIB_NAME) +endif +endif +endif +ifdef EXTRAINSTALLFILES + $(MKDIR) $(INSTALL_DATADIR) + $(INSTALL) $(EXTRAINSTALLFILES) $(INSTALL_DATADIR) +endif + +fpc_sourceinstall: distclean + $(MKDIR) $(INSTALL_SOURCEDIR) + $(COPYTREE) $(BASEDIR) $(INSTALL_SOURCEDIR) + + +[exampleinstallrules] +##################################################################### +# exampleinstall rules +##################################################################### + +.PHONY: fpc_exampleinstall + +fpc_exampleinstall: $(addsuffix _distclean,$(TARGET_EXAMPLEDIRS)) +ifdef EXAMPLESOURCEFILES + $(MKDIR) $(INSTALL_EXAMPLEDIR) + $(COPY) $(EXAMPLESOURCEFILES) $(INSTALL_EXAMPLEDIR) +endif +ifdef TARGET_EXAMPLEDIRS +ifndef EXAMPLESOURCEFILES + $(MKDIR) $(INSTALL_EXAMPLEDIR) +endif + $(COPYTREE) $(addsuffix /*,$(TARGET_EXAMPLEDIRS)) $(INSTALL_EXAMPLEDIR) +endif + + +[zipinstallrules] +##################################################################### +# Zip +##################################################################### + +.PHONY: fpc_zipinstall fpc_zipsourceinstall fpc_zipexampleinstall + +# Temporary path to pack a file +ifndef PACKDIR +ifndef inUnix +PACKDIR=$(BASEDIR)/../pack_tmp +else +PACKDIR=/tmp/fpc-pack +endif +endif + +# Maybe create default zipname from packagename +ifndef DIST_ZIPNAME +ifdef PACKAGE_NAME +DIST_ZIPNAME=$(ZIPPREFIX)$(PACKAGE_NAME)$(ZIPSUFFIX) +endif +endif + +# Use tar by default under linux +ifndef USEZIP +ifdef inUnix +USETAR=1 +endif +endif + +# Use a wrapper script by default for Os/2 +ifdef inOS2 +USEZIPWRAPPER=1 +endif + +# Create commands to create the zip/tar file +ZIPWRAPPER=$(DIST_DESTDIR)/fpczip$(BATCHEXT) +ZIPCMD_CDPACK:=cd $(subst /,$(PATHSEP),$(PACKDIR)) +ZIPCMD_CDBASE:=cd $(subst /,$(PATHSEP),$(BASEDIR)) +ifdef USETAR +ZIPDESTFILE:=$(DIST_DESTDIR)/$(DIST_ZIPNAME)$(TAREXT) +ZIPCMD_ZIP:=$(TARPROG) cf$(TAROPT) $(ZIPDESTFILE) * +else +ZIPDESTFILE:=$(DIST_DESTDIR)/$(DIST_ZIPNAME)$(ZIPEXT) +ZIPCMD_ZIP:=$(subst /,$(PATHSEP),$(ZIPPROG)) -Dr $(ZIPOPT) $(ZIPDESTFILE) * +endif + +fpc_zipinstall: + $(MAKE) $(ZIPTARGET) INSTALL_PREFIX=$(PACKDIR) + $(DEL) $(ZIPDESTFILE) +ifdef USEZIPWRAPPER +ifneq ($(ECHO),echo) + $(ECHO) "$(ZIPCMD_CDPACK)" > $(ZIPWRAPPER) + $(ECHO) "$(ZIPCMD_ZIP)" >> $(ZIPWRAPPER) + $(ECHO) "$(ZIPCMD_CDBASE)" >> $(ZIPWRAPPER) +else + $(ECHO) $(ZIPCMD_CDPACK) > $(ZIPWRAPPER) + $(ECHO) $(ZIPCMD_ZIP) >> $(ZIPWRAPPER) + $(ECHO) $(ZIPCMD_CDBASE) >> $(ZIPWRAPPER) +endif +ifdef inUnix + /bin/sh $(ZIPWRAPPER) +else + $(ZIPWRAPPER) +endif + $(DEL) $(ZIPWRAPPER) +else + $(ZIPCMD_CDPACK) ; $(ZIPCMD_ZIP) ; $(ZIPCMD_CDBASE) +endif + $(DELTREE) $(PACKDIR) + +fpc_zipsourceinstall: + $(MAKE) fpc_zipinstall ZIPTARGET=sourceinstall ZIPSUFFIX=src + +fpc_zipexampleinstall: + $(MAKE) fpc_zipinstall ZIPTARGET=exampleinstall ZIPSUFFIX=exm + + +[cleanrules] +##################################################################### +# Clean rules +##################################################################### + +.PHONY: fpc_clean fpc_cleanall fpc_distclean + +ifdef EXEFILES +override CLEANEXEFILES:=$(addprefix $(TARGETDIRPREFIX),$(CLEANEXEFILES)) +endif + +ifdef EXTRACLEANUNITS +override CLEANPPUFILES+=$(addsuffix $(PPUEXT),$(EXTRACLEANUNITS)) +endif + +ifdef CLEANPPUFILES +override CLEANPPUFILES:=$(addprefix $(UNITTARGETDIRPREFIX),$(CLEANPPUFILES)) +# Get the .o and .a files created for the units +ifdef PPUFILES +CLEANPPULINKFILES:=$(shell $(PPUFILES) $(CLEANPPUFILES)) +else +CLEANPPULINKFILES:=$(wildcard $(subst $(PPUEXT),$(OEXT),$(CLEANPPUFILES)) $(addprefix $(LIBPREFIX),$(subst $(PPUEXT),$(STATICLIBEXT),$(CLEANPPUFILES)))) +endif +override CLEANPPULINKFILES:=$(addprefix $(UNITTARGETDIRPREFIX),$(CLEANPPULINKFILES)) +endif + +fpc_clean: $(CLEANTARGET) +ifdef CLEANEXEFILES + -$(DEL) $(CLEANEXEFILES) +endif +ifdef CLEANPPUFILES + -$(DEL) $(CLEANPPUFILES) +endif +ifneq ($(CLEANPPULINKFILES),) + -$(DEL) $(CLEANPPULINKFILES) +endif +ifdef CLEANRSTFILES + -$(DEL) $(addprefix $(UNITTARGETDIRPREFIX),$(CLEANRSTFILES)) +endif +ifdef EXTRACLEANFILES + -$(DEL) $(EXTRACLEANFILES) +endif +ifdef LIB_NAME + -$(DEL) $(LIB_NAME) $(LIB_FULLNAME) +endif + -$(DEL) $(FPCMADE) $(PPAS) link.res $(FPCEXTFILE) $(REDIRFILE) + +fpc_distclean: fpc_clean + +# Also run clean first if targetdir is set. Unittargetdir is always +# set if targetdir or unittargetdir is specified +ifdef COMPILER_UNITTARGETDIR +TARGETDIRCLEAN=fpc_clean +endif + +fpc_cleanall: $(CLEANTARGET) $(TARGETDIRCLEAN) +ifdef CLEANEXEFILES + -$(DEL) $(CLEANEXEFILES) +endif + -$(DEL) *$(OEXT) *$(PPUEXT) *$(RSTEXT) *$(ASMEXT) *$(STATICLIBEXT) *$(SHAREDLIBEXT) *$(PPLEXT) + -$(DELTREE) *$(SMARTEXT) + -$(DEL) $(FPCMADE) $(PPAS) link.res $(FPCEXTFILE) $(REDIRFILE) + + +[inforules] +##################################################################### +# Info rules +##################################################################### + +.PHONY: fpc_info + +fpc_info: + @$(ECHO) + @$(ECHO) == Package info == + @$(ECHO) Package Name..... $(PACKAGE_NAME) + @$(ECHO) Package Version.. $(PACKAGE_VERSION) + @$(ECHO) + @$(ECHO) == Configuration info == + @$(ECHO) + @$(ECHO) FPC.......... $(FPC) + @$(ECHO) FPC Version.. $(FPC_VERSION) + @$(ECHO) Source CPU... $(CPU_SOURCE) + @$(ECHO) Target CPU... $(CPU_TARGET) + @$(ECHO) Source OS.... $(OS_SOURCE) + @$(ECHO) Target OS.... $(OS_TARGET) + @$(ECHO) + @$(ECHO) == Directory info == + @$(ECHO) + @$(ECHO) Basedir......... $(BASEDIR) + @$(ECHO) FPCDir.......... $(FPCDIR) + @$(ECHO) UnitsDir........ $(UNITSDIR) + @$(ECHO) PackagesDir..... $(PACKAGESDIR) + @$(ECHO) + @$(ECHO) GCC library..... $(GCCLIBDIR) + @$(ECHO) Other library... $(OTHERLIBDIR) + @$(ECHO) + @$(ECHO) == Tools info == + @$(ECHO) + @$(ECHO) Pwd....... $(PWD) + @$(ECHO) Echo...... $(ECHO) + @$(ECHO) PPUMove... $(PPUMOVE) + @$(ECHO) PPUFiles.. $(PPUFILES) + @$(ECHO) Date...... $(DATE) + @$(ECHO) Upx....... $(UPXPROG) + @$(ECHO) Zip....... $(ZIPPROG) + @$(ECHO) + @$(ECHO) == Object info == + @$(ECHO) + @$(ECHO) Target Loaders...... $(TARGET_LOADERS) + @$(ECHO) Target Units........ $(TARGET_UNITS) + @$(ECHO) Target Programs..... $(TARGET_PROGRAMS) + @$(ECHO) Target Dirs......... $(TARGET_DIRS) + @$(ECHO) Target Examples..... $(TARGET_EXAMPLES) + @$(ECHO) Target ExampleDirs.. $(TARGET_EXAMPLEDIRS) + @$(ECHO) + @$(ECHO) ExtraCleanUnits... $(CLEAN_UNITS) + @$(ECHO) ExtraCleanFiles... $(CLEAN_FILES) + @$(ECHO) + @$(ECHO) ExtraInstallUnits. $(INSTALL_UNITS) + @$(ECHO) ExtraInstallFiles. $(INSTALL_FILES) + @$(ECHO) + @$(ECHO) == Install info == + @$(ECHO) + @$(ECHO) DateStr.............. $(DATESTR) + @$(ECHO) ZipPrefix............ $(ZIPPREFIX) + @$(ECHO) ZipSuffix............ $(ZIPSUFFIX) + @$(ECHO) + @$(ECHO) INSTALL_BASEDIR...... $(INSTALL_BASEDIR) + @$(ECHO) INSTALL_BINDIR....... $(INSTALL_BINDIR) + @$(ECHO) INSTALL_LIBDIR....... $(INSTALL_LIBDIR) + @$(ECHO) INSTALL_UNITDIR...... $(INSTALL_UNITDIR) + @$(ECHO) INSTALL_SOURCEDIR.... $(INSTALL_SOURCEDIR) + @$(ECHO) INSTALL_DOCDIR....... $(INSTALL_DOCDIR) + @$(ECHO) INSTALL_DATADIR...... $(INSTALL_DATADIR) + @$(ECHO) + @$(ECHO) DIST_DESTDIR......... $(DIST_DESTDIR) + @$(ECHO) DIST_ZIPNAME......... $(DIST_ZIPNAME) + @$(ECHO) + +[localmakefile] +##################################################################### +# Local Makefile +##################################################################### + +ifneq ($(wildcard fpcmake.loc),) +include fpcmake.loc +endif + +[userrules] +##################################################################### +# Users rules +##################################################################### diff --git a/utils/fpcm/fpcmake.pp b/utils/fpcm/fpcmake.pp new file mode 100644 index 0000000000..f9dd088de1 --- /dev/null +++ b/utils/fpcm/fpcmake.pp @@ -0,0 +1,63 @@ +{ + $Id$ + Copyright (c) 2001 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 + dos,sysutils, + fpcmmain,fpcmwr; + + procedure ProcessFile(const fn:string); + var + CurrFPCMake : TFPCMake; + CurrMakefile : TMakefileWriter; + s : string; + begin + CurrFPCMake:=nil; +// try + CurrFPCMake:=TFPCMake.Create(fn); + s:=GetEnv('FPCDIR'); + if s<>'' then + CurrFPCMake.Variables.Add('FPCDIR',s) + else + CurrFPCMake.Variables.Add('FPCDIR','c:/pp'); + CurrFPCMake.Variables.Add('UNITSDIR','$(FPCDIR)/units'); + CurrFPCMake.Variables.Add('PACKAGESDIR','$(FPCDIR)/packages'); + CurrFPCMake.LoadMakefileFPC; + CurrFPCMake.LoadPackageSection; + CurrFPCMake.LoadRequires(CurrFPCMake); +// CurrFPCMake.Print; + + CurrMakefile:=TMakefileWriter.Create(CurrFPCMake,'Makefile'); + CurrMakefile.WriteGenericMakefile; + CurrMakefile.Free; + +// except +// on e : exception do +// writeln('Error: ',e.message); +// end; + CurrFPCMake.Free; + end; + +begin + ProcessFile('Makefile.fpc'); +end. +{ + $Log$ + Revision 1.1 2001-01-24 21:59:36 peter + * first commit of new fpcmake + +} diff --git a/utils/fpcm/fpcmdic.pp b/utils/fpcm/fpcmdic.pp new file mode 100644 index 0000000000..a7c20a7fe4 --- /dev/null +++ b/utils/fpcm/fpcmdic.pp @@ -0,0 +1,544 @@ +{ + $Id$ + Copyright (c) 2001 by Peter Vreman + + TDictionary class + + 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+} +unit fpcmdic; +interface + + const { the real size will be [-hasharray..hasharray] ! } + hasharraysize = 2047; + + type + { namedindexobect for use with dictionary and indexarray } + TDictionaryItem=class + private + Fname : string; + FSpeedValue : cardinal; + protected + procedure SetName(const n:string); + public + left, + right : TDictionaryItem; + constructor create(const n:string); + property Name:string read FName write SetName; + property SpeedValue:cardinal read FSpeedValue; + end; + + Pdictionaryhasharray=^Tdictionaryhasharray; + Tdictionaryhasharray=array[-hasharraysize..hasharraysize] of TDictionaryItem; + + Tnamedindexcallback = procedure(p:TDictionaryItem) of object; + + Tdictionary=class + private + FRoot : TDictionaryItem; + FHashArray : Pdictionaryhasharray; + procedure cleartree(obj:TDictionaryItem); + function insertNode(NewNode:TDictionaryItem;var currNode:TDictionaryItem):TDictionaryItem; + procedure inserttree(currtree,currroot:TDictionaryItem); + public + noclear : boolean; + replace_existing : boolean; + constructor Create; + destructor Destroy;override; + procedure usehash; + procedure clear; + function delete(const s:string):TDictionaryItem; + function empty:boolean; + procedure foreach(proc2call:Tnamedindexcallback); + function insert(obj:TDictionaryItem):TDictionaryItem; + function rename(const olds,News : string):TDictionaryItem; + function search(const s:string):TDictionaryItem; + function speedsearch(const s:string;SpeedValue:integer):TDictionaryItem; + property Items[const s:string]:TDictionaryItem read Search;default; + end; + + { Speed/Hash value } + Function GetSpeedValue(Const s:String):cardinal; + + +implementation + + +{***************************************************************************** + GetSpeedValue +*****************************************************************************} + +var + Crc32Tbl : array[0..255] of cardinal; + +procedure MakeCRC32Tbl; +var + crc : cardinal; + i,n : integer; +begin + for i:=0 to 255 do + begin + crc:=i; + for n:=1 to 8 do + if odd(crc) then + crc:=(crc shr 1) xor $edb88320 + else + crc:=crc shr 1; + Crc32Tbl[i]:=crc; + end; +end; + + +Function GetSpeedValue(Const s:String):cardinal; +var + i : integer; + InitCrc : cardinal; +begin + if Crc32Tbl[1]=0 then + MakeCrc32Tbl; + InitCrc:=$ffffffff; + for i:=1 to Length(s) do + InitCrc:=Crc32Tbl[byte(InitCrc) xor ord(s[i])] xor (InitCrc shr 8); + GetSpeedValue:=InitCrc; +end; + + +{**************************************************************************** + TDictionaryItem + ****************************************************************************} + +constructor TDictionaryItem.Create(const n:string); +begin + left:=nil; + right:=nil; + FSpeedValue:=-1; + FName:=n; +end; + + +procedure TDictionaryItem.Setname(const n:string); +begin + if FSpeedValue=-1 then + FName:=n; +end; + + +{**************************************************************************** + TDICTIONARY +****************************************************************************} + + constructor Tdictionary.Create; + begin + FRoot:=nil; + FHashArray:=nil; + noclear:=false; + replace_existing:=false; + end; + + + procedure Tdictionary.usehash; + begin + if not(assigned(FRoot)) and + not(assigned(FHashArray)) then + begin + New(FHashArray); + fillchar(FHashArray^,sizeof(FHashArray^),0); + end; + end; + + + destructor Tdictionary.destroy; + begin + if not noclear then + clear; + if assigned(FHashArray) then + dispose(FHashArray); + end; + + + procedure Tdictionary.cleartree(obj:TDictionaryItem); + begin + if assigned(obj.left) then + cleartree(obj.left); + if assigned(obj.right) then + cleartree(obj.right); + obj.free; + obj:=nil; + end; + + + procedure Tdictionary.clear; + var + w : integer; + begin + if assigned(FRoot) then + cleartree(FRoot); + if assigned(FHashArray) then + for w:=-hasharraysize to hasharraysize do + if assigned(FHashArray^[w]) then + cleartree(FHashArray^[w]); + end; + + + function Tdictionary.delete(const s:string):TDictionaryItem; + var + p,SpeedValue : cardinal; + n : TDictionaryItem; + + procedure insert_right_bottom(var root,Atree:TDictionaryItem); + begin + while root.right<>nil do + root:=root.right; + root.right:=Atree; + end; + + function delete_from_tree(root:TDictionaryItem):TDictionaryItem; + type + leftright=(left,right); + var + lr : leftright; + oldroot : TDictionaryItem; + begin + oldroot:=nil; + while (root<>nil) and (root.SpeedValue<>SpeedValue) do + begin + oldroot:=root; + if SpeedValuenil) and (root.name<>s) do + begin + oldroot:=root; + if snil then + begin + { Now the Node pointing to root must point to the left + subtree of root. The right subtree of root must be + connected to the right bottom of the left subtree.} + if lr=left then + oldroot.left:=root.left + else + oldroot.right:=root.left; + if root.right<>nil then + insert_right_bottom(root.left,root.right); + end + else + begin + { There is no left subtree. So we can just replace the Node to + delete with the right subtree.} + if lr=left then + oldroot.left:=root.right + else + oldroot.right:=root.right; + end; + delete_from_tree:=root; + end; + + begin + SpeedValue:=GetSpeedValue(s); + n:=FRoot; + if assigned(FHashArray) then + begin + { First, check if the Node to delete directly located under + the hasharray.} + p:=SpeedValue mod hasharraysize; + n:=FHashArray^[p]; + if (n<>nil) and (n.SpeedValue=SpeedValue) and + (n.name=s) then + begin + { The Node to delete is directly located under the + hasharray. Make the hasharray point to the left + subtree of the Node and place the right subtree on + the right-bottom of the left subtree.} + if n.left<>nil then + begin + FHashArray^[p]:=n.left; + if n.right<>nil then + insert_right_bottom(n.left,n.right); + end + else + FHashArray^[p]:=n.right; + delete:=n; + exit; + end; + end + else + begin + { First check if the Node to delete is the root.} + if (FRoot<>nil) and (n.SpeedValue=SpeedValue) and + (n.name=s) then + begin + if n.left<>nil then + begin + FRoot:=n.left; + if n.right<>nil then + insert_right_bottom(n.left,n.right); + end + else + FRoot:=n.right; + delete:=n; + exit; + end; + end; + delete:=delete_from_tree(n); + end; + + function Tdictionary.empty:boolean; + var + w : integer; + begin + if assigned(FHashArray) then + begin + empty:=false; + for w:=-hasharraysize to hasharraysize do + if assigned(FHashArray^[w]) then + exit; + empty:=true; + end + else + empty:=(FRoot=nil); + end; + + + procedure Tdictionary.foreach(proc2call:Tnamedindexcallback); + + procedure a(p:TDictionaryItem); + begin + proc2call(p); + if assigned(p.left) then + a(p.left); + if assigned(p.right) then + a(p.right); + end; + + var + i : integer; + begin + if assigned(FHashArray) then + begin + for i:=-hasharraysize to hasharraysize do + if assigned(FHashArray^[i]) then + a(FHashArray^[i]); + end + else + if assigned(FRoot) then + a(FRoot); + end; + + + function Tdictionary.insert(obj:TDictionaryItem):TDictionaryItem; + begin + obj.FSpeedValue:=GetSpeedValue(obj.name); + if assigned(FHashArray) then + insert:=insertNode(obj,FHashArray^[obj.SpeedValue mod hasharraysize]) + else + insert:=insertNode(obj,FRoot); + end; + + + function tdictionary.insertNode(NewNode:TDictionaryItem;var currNode:TDictionaryItem):TDictionaryItem; + begin + if currNode=nil then + begin + currNode:=NewNode; + insertNode:=NewNode; + end + { First check SpeedValue, to allow a fast insert } + else + if currNode.SpeedValue>NewNode.SpeedValue then + insertNode:=insertNode(NewNode,currNode.right) + else + if currNode.SpeedValueNewNode.name then + insertNode:=insertNode(NewNode,currNode.right) + else + if currNode.namehp.SpeedValue then + begin + lasthp:=hp; + hp:=hp.left + end + else + if spdvalhp.name then + begin + lasthp:=hp; + hp:=hp.left + end + else + begin + lasthp:=hp; + hp:=hp.right; + end; + end; + end; + end; + + + function Tdictionary.search(const s:string):TDictionaryItem; + begin + search:=speedsearch(s,GetSpeedValue(s)); + end; + + + function Tdictionary.speedsearch(const s:string;SpeedValue:integer):TDictionaryItem; + var + NewNode:TDictionaryItem; + begin + if assigned(FHashArray) then + NewNode:=FHashArray^[SpeedValue mod hasharraysize] + else + NewNode:=FRoot; + while assigned(NewNode) do + begin + if SpeedValue>NewNode.SpeedValue then + NewNode:=NewNode.left + else + if SpeedValueNewNode.name then + NewNode:=NewNode.left + else + NewNode:=NewNode.right; + end; + end; + speedsearch:=nil; + end; + + + +end. +{ + $Log$ + Revision 1.1 2001-01-24 21:59:36 peter + * first commit of new fpcmake + +} diff --git a/utils/fpcm/fpcmmain.pp b/utils/fpcm/fpcmmain.pp new file mode 100644 index 0000000000..bdd6f7ace6 --- /dev/null +++ b/utils/fpcm/fpcmmain.pp @@ -0,0 +1,828 @@ +{ + $Id$ + Copyright (c) 2001 by Peter Vreman + + FPCMake - Main module + + 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+} +unit fpcmmain; +interface + + uses + sysutils,classes, + fpcmdic; + + const + Version='v1.99.0'; + Title='fpcmake '+Version; + TitleDate=Title+' ['+{$ifdef fpc}{$i %DATE}{$else}'n/a'{$endif}+']'; + type + TTarget=(t_all, + t_linux,t_go32v2,t_win32,t_os2,t_freebsd + ); + + const + TargetStr : array[TTarget] of string=('all', + 'linux','go32v2','win32','os2','freebsd' + ); + + TargetSuffix : array[TTarget] of string=('', + '_linux','_go32v2','_win32','_os2','_freebsd' + ); + + + type + TKeyValueItem = class(TDictionaryItem) + private + FValue : string; + public + constructor Create(const k,v:string); + property Value:string read FValue write FValue; + end; + + TKeyValue = class(TDictionary) + private + function GetKey(const k:string):string; + public + procedure Add(const k,v:String); + property Key[const s:string]:string read GetKey;default; + end; + + TFPCMakeSection = class(TDictionaryItem) + private + FList : TStringList; + FDictionary : TKeyValue; + procedure PrintDic(p:TDictionaryItem); + procedure BuildIniDic(p:TDictionaryItem); + procedure BuildMakefileDic(p:TDictionaryItem); + function GetKey(const k:string):string; + public + constructor Create(const n:string); + constructor CreateKeyValue(const n:string); + destructor Destroy;override; + procedure AddLine(const s:string); + procedure AddKey(const k,v:string); + procedure ParseIni; + procedure BuildIni; + procedure BuildMakefile; + procedure Print; + property Key[const s:string]:string read GetKey;default; + property List:TStringList read FList; + property Dictionary:TKeyValue read FDictionary; + end; + + TFPCMake = class + private + FStream : TStream; + FFileName : string; + FCommentChars : TSysCharSet; + FEmptyLines : boolean; + FSections : TDictionary; + FPackageSec, + FExportSec : TFPCMakeSection; + FPackageName, + FPackageVersion : string; + FRequireList : TStringList; + FVariables : TKeyValue; + procedure Init; + procedure ParseSec(p:TDictionaryItem); + procedure PrintSec(p:TDictionaryItem); + function GetSec(const AName:string):TDictionaryItem; + public + constructor Create(const AFileName:string); + constructor CreateFromStream(s:TStream;const AFileName:string); + destructor Destroy;override; + procedure LoadSections; + procedure LoadMakefileFPC; + procedure LoadPackageSection; + procedure LoadRequiredPackage(const ReqName,ReqVersion:string); + procedure LoadRequires(FromFPCMake:TFPCMake); + function GetTargetRequires(t:TTarget):TStringList; + procedure CreateExportSection; + procedure SubstVariables(var s:string); + function GetVariable(const inivar:string):string; + procedure Print; + property Section[const s:string]:TDictionaryItem read GetSec;default; + property RequireList:TStringList read FRequireList; + property Variables:TKeyValue read FVariables; + property PackageName:string read FPackageName; + property PackageVersion:string read FPackageVersion; + property PackageSec:TFPCMakeSection read FPackageSec; + property ExportSec:TFPCMakeSection read FExportSec; + property CommentChars:TSysCharSet read FCommentChars write FCommentChars; + property EmptyLines:Boolean read FEmptyLines write FEmptyLines; + end; + + function posidx(const substr,s : string;idx:integer):integer; + + +implementation + + resourcestring + s_not_list_sec='Not a list section "%s"'; + s_not_key_value_sec='Not a key-value section "%s"'; + s_err_section_start='%s:%d: Wrong section start'; + s_err_not_key_value='Parse error key=value excepted: "%s"'; + s_err_no_section='%s:%d: Entries without section'; + s_no_package_section='No package section found'; + s_no_package_name='No package name set'; + s_no_package_version='No package version set'; + s_err_require_format='Wrong require format "%s"'; + + type + tspecialdir=record + dir,unitdir,packdir : string; + end; + + const + specialdirs = 4; + specialdir : array[1..specialdirs] of tspecialdir=( + (dir: 'rtl'; unitdir: '$(UNITSDIR)/rtl'; packdir: '$(FPCDIR)/rtl'), + (dir: 'fcl'; unitdir: '$(UNITSDIR)/fcl'; packdir: '$(FPCDIR)/fcl'), + (dir: 'api'; unitdir: '$(UNITSDIR)/api'; packdir: '$(FPCDIR)/api'), + (dir: 'fv'; unitdir: '$(UNITSDIR)/fv'; packdir: '$(FPCDIR)/fv') + ); + +{**************************************************************************** + Helpers +****************************************************************************} + + Function PathExists ( F : String) : Boolean; + Var + Info : TSearchRec; + begin + if F[Length(f)] in ['/','\'] then + Delete(f,length(f),1); + PathExists:=(findfirst(F,fareadonly+faarchive+fahidden+fadirectory,info)=0) and + ((info.attr and fadirectory)=fadirectory); + findclose(Info); + end; + + + function posidx(const substr,s : string;idx:integer):integer; + var + i,j : integer; + e : boolean; + begin + i:=idx; + j:=0; + e:=(length(SubStr)>0); + while e and (i<=Length(s)-Length(SubStr)) do + begin + inc(i); + if (SubStr[1]=s[i]) and (Substr=Copy(s,i,Length(SubStr))) then + begin + j:=i; + e:=false; + end; + end; + PosIdx:=j; + end; + + + +{**************************************************************************** + TKeyValueItem +****************************************************************************} + + constructor TKeyValueItem.Create(const k,v:string); + begin + inherited Create(k); + value:=v; + end; + + +{**************************************************************************** + TKeyValue +****************************************************************************} + + function TKeyValue.GetKey(const k:string):string; + var + p : TKeyValueItem; + begin + p:=TKeyValueItem(Search(k)); + if p=nil then + GetKey:='' + else + GetKey:=p.Value; + end; + + + procedure TKeyValue.Add(const k,v:string); + begin + Insert(TKeyValueItem.Create(k,v)); + end; + + +{**************************************************************************** + TFPCMakeSection +****************************************************************************} + + constructor TFPCMakeSection.Create(const n:string); + begin + inherited Create(n); + FList:=TStringList.Create; + FDictionary:=nil; + end; + + + constructor TFPCMakeSection.CreateKeyValue(const n:string); + begin + inherited Create(n); + FList:=nil; + FDictionary:=TKeyValue.Create; + end; + + + destructor TFPCMakeSection.Destroy; + begin + inherited Destroy; + FList.Free; + FDictionary.Free; + end; + + + procedure TFPCMakeSection.AddLine(const s:string); + begin + if FList=nil then + raise Exception.Create(Format(s_not_list_sec,[Name])); + FList.Add(s); + end; + + + procedure TFPCMakeSection.AddKey(const k,v:string); + begin + if FDictionary=nil then + raise Exception.Create(Format(s_not_key_value_sec,[Name])); + { Don't add empty values } + if v<>'' then + FDictionary.Add(k,v); + end; + + + procedure TFPCMakeSection.PrintDic(p:TDictionaryItem); + begin + with TKeyValueItem(p) do + begin + writeln(' ',name,' = "',value,'"'); + end; + end; + + + function TFPCMakeSection.GetKey(const k:string):string; + begin + if FDictionary=nil then + raise Exception.Create(Format(s_not_key_value_sec,[Name])); + GetKey:=FDictionary[k]; + end; + + + procedure TFPCMakeSection.Print; + var + i : integer; + begin + writeln('[',Name,']'); + if assigned(FList) then + begin + writeln(' List:'); + for i:=0 to FList.Count-1 do + Writeln(' "'+FList[i],'"'); + if assigned(FDictionary) then + writeln(''); + end; + if assigned(FDictionary) then + begin + writeln(' Dictionary:'); + FDictionary.Foreach(@PrintDic); + end; + end; + + + procedure TFPCMakeSection.ParseIni; + var + p : TKeyValueItem; + i,j,len,maxi : integer; + s,newkey,value : string; + begin + { If already processed skip } + if assigned(FDictionary) then + exit; + { Don't process rules section } + if (Name='rules') then + exit; + { Parse the section } + FDictionary:=TKeyValue.Create; + { Parse the list } + maxi:=FList.Count; + i:=0; + while (i'=' then + Raise Exception.Create(Format(s_err_not_key_value,[s])); + While (j'') and not(s[1] in FCommentChars)) then + begin + { section start? } + if (s<>'') and (s[1]='[') then + begin + j:=pos(']',s); + if j=0 then + raise Exception.Create(Format(s_err_section_start,[FFileName,i])); + SecName:=Copy(s,2,j-2); + CurrSec:=TFPCMakeSection(FSections[SecName]); + if CurrSec=nil then + CurrSec:=TFPCMakeSection(FSections.Insert(TFPCMakeSection.Create(SecName))); + end + else + begin + if CurrSec=nil then + raise Exception.Create(Format(s_err_no_section,[FFileName,i])); + { Insert string without spaces stripped } + CurrSec.AddLine(SLInput[i]); + end; + end; + inc(i); + end; + finally + SLInput.Free; + end; + end; + + + procedure TFPCMake.LoadMakefileFPC; + begin + LoadSections; + { Parse all sections } + FSections.Foreach(@ParseSec); + end; + + + procedure TFPCMake.LoadPackageSection; + begin + { Get package info from package section } + FPackageSec:=TFPCMakeSection(FSections['package']); + if FPackageSec=nil then + begin + Writeln('Note: no package section'); + exit; + end; + { Parse the section to key=value pairs } + FPackageSec.ParseIni; + { mandatory name } + FPackageName:=FPackageSec['name']; + if FPackageName='' then + Raise Exception.Create(s_no_package_name); + { mandatory version } + FPackageVersion:=FPackageSec['version']; + if FPackageVersion='' then + Raise Exception.Create(s_no_package_version); + { Set the ExportSec } + FExportSec:=TFPCMakeSection(FSections[Lowercase(FPackageName)]); + end; + + + procedure TFPCMake.CreateExportSection; + var + t : TTarget; + begin + { Don't create a section twice } + if FExportSec<>nil then + exit; + { Look if we've already an own section, else create a new + key-value section } + FExportSec:=TFPCMakeSection(FSections[LowerCase(FPackageName)]); + if FExportSec=nil then + FExportSec:=TFPCMakeSection(FSections.Insert(TFPCMakeSection.CreateKeyValue(LowerCase(FPackageName)))); + { Add default the values to the export section } + FExportSec.AddKey('name',FPackageName); + FExportSec.AddKey('version',FPackageVersion); + { Add required packages } + for t:=low(TTarget) to high(TTarget) do + FExportSec.AddKey('require'+TargetSuffix[t],FPackageSec['require'+TargetSuffix[t]]); + { Unit dir } + {FExportSec.AddKey('unitdir','$(UNITSDIR)/'+Lowercase(PackageName));} + end; + + + procedure TFPCMake.LoadRequiredPackage(const ReqName,ReqVersion:string); + + function TryFile(const fn:string):boolean; + var + ReqFPCMake : TFPCMake; + HList : TStringList; + NewSec,ReqSec,Sec : TFPCMakeSection; + begin + TryFile:=false; + if FileExists(fn) then + begin + writeln('Package ',ReqName,': ',fn); + + ReqFPCMake:=TFPCMake.Create(fn); + ReqFPCMake.LoadMakefileFPC; + ReqFPCMake.LoadPackageSection; + { Check package name and version } + if LowerCase(ReqFPCMake.PackageName)<>ReqName then + raise Exception.Create('s_wrong_package_name'); + if (ReqVersion<>'') and (ReqFPCMake.PackageVersion'' then + begin + i:=Pos('(',ReqName); + if i>0 then + begin + j:=Pos(')',ReqName); + if (i=1) or (j=0) then + Raise Exception.Create(Format(s_err_require_format,[ReqName])); + ReqVersion:=Copy(ReqName,i+1,j-i-1); + ReqName:=Copy(ReqName,1,i-1); + end + else + ReqVersion:=''; + { We only use lowercase names } + ReqName:=Lowercase(ReqName); + { Already loaded ? } + if not RequireList.Find(ReqName,i) then + begin + LoadRequiredPackage(ReqName,ReqVersion); + RequireList.Add(ReqName); + end; + end; + until s=''; + end; + { Force an rtl dependency } + if not RequireList.Find('rtl',i) then + begin + LoadRequiredPackage('rtl',''); + RequireList.Add('rtl'); + end; + end; + + + function TFPCMake.GetTargetRequires(t:TTarget):TStringList; + var + ReqSec : TFPCMakeSection; + ReqList : TStringList; + + procedure AddReqSec(t:TTarget;Sec:TFPCMakeSection); + var + s, + ReqName : string; + RSec : TFPCMakeSection; + i,j : integer; + begin + s:=Sec['packages'+TargetSuffix[t]]; + while s<>'' do + begin + i:=pos(' ',s); + if i=0 then + begin + ReqName:=Trim(s); + s:=''; + end + else + begin + ReqName:=Trim(Copy(s,1,i)); + Delete(s,1,i); + s:=TrimLeft(s); + end; + if ReqName<>'' then + begin + i:=Pos('(',ReqName); + if i>0 then + ReqName:=Copy(ReqName,1,i-1); + { We only use lowercase names } + ReqName:=Lowercase(ReqName); + { Already loaded ? } + if not ReqList.Find(ReqName,i) then + begin + RSec:=TFPCMakeSection(FSections[ReqName+'_require']); + if assigned(RSec) then + begin + { for packages we depend on always include the + target and all keys } + if t<>t_all then + AddReqSec(t_all,RSec); + AddReqSec(t,RSec); + end; + ReqList.Add(ReqName); + end; + end; + end; + end; + + begin + ReqList:=TStringList.Create; + ReqSec:=TFPCMakeSection(FSections['require']); + if assigned(ReqSec) then + AddReqSec(t,ReqSec); + GetTargetRequires:=ReqList; + end; + + + procedure TFPCMake.SubstVariables(var s:string); + var + i,j,k : integer; + s2,s3 : string; + Sec : TFPCMakeSection; + begin + repeat + i:=Pos('$(',s); + if i=0 then + break; + j:=PosIdx(')',s,i+2); + s2:=Copy(s,i+2,j-i-2); + k:=pos('.',s2); + if k>0 then + begin + s3:=Copy(s2,k+1,Length(s2)-k); + s2:=Copy(s2,1,k-1); + Sec:=TFPCMakeSection(Section[s2]); + if assigned(Sec) then + s2:=Sec[s3] + else + s2:=''; + end + else + s2:=Variables[s2]; + Delete(s,i,j-i+1); + Insert(s2,s,i); + until false; + end; + + + function TFPCMake.GetVariable(const inivar:string):string; + var + Sec : TFPCMakeSection; + Dic : TKeyValue; + i : integer; + begin + Result:=''; + i:=Pos('.',inivar); + if i<>0 then + begin + Sec:=TFPCMakeSection(FSections[Copy(Inivar,1,i-1)]); + if assigned(Sec) then + begin + Dic:=TKeyValue(Sec.Dictionary); + Result:=Dic[Copy(IniVar,i+1,Length(IniVar)-i)]; + end + else + exit; + end + else + Result:=Variables[IniVar]; + end; + + + procedure TFPCMake.ParseSec(p:TDictionaryItem); + begin + TFPCMakeSection(p).ParseIni; + end; + + + procedure TFPCMake.PrintSec(p:TDictionaryItem); + begin + TFPCMakeSection(p).Print; + end; + + + procedure TFPCMake.Print; + begin + FSections.Foreach(@PrintSec); + end; + + + function TFPCMake.GetSec(const AName:string):TDictionaryItem; + begin + GetSec:=FSections.Search(AName); + end; + +end. +{ + $Log$ + Revision 1.1 2001-01-24 21:59:36 peter + * first commit of new fpcmake + +} diff --git a/utils/fpcm/fpcmwr.pp b/utils/fpcm/fpcmwr.pp new file mode 100644 index 0000000000..2dde10589d --- /dev/null +++ b/utils/fpcm/fpcmwr.pp @@ -0,0 +1,713 @@ +{ + $Id$ + Copyright (c) 2001 by Peter Vreman + + FPCMake - Makefile writer + + 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+} +unit fpcmwr; +interface + + uses + sysutils,classes, + fpcmmain; + + type + tsections=(sec_none, + sec_units,sec_exes,sec_loaders,sec_examples, + sec_compile,sec_install,sec_exampleinstall, + sec_zipinstall,sec_clean,sec_libs, + sec_command,sec_exts,sec_dirs,sec_tools,sec_info + ); + + tRules=( + r_all,r_debug, + r_examples, + r_smart,r_shared, + r_install,r_sourceinstall,r_exampleinstall, + r_zipinstall,r_zipsourceinstall,r_zipexampleinstall, + r_clean,r_distclean,r_cleanall, + r_info + ); + + + const + rule2str : array[trules] of string=( + 'all','debug', + 'examples', + 'smart','shared', + 'install','sourceinstall','exampleinstall', + 'zipinstall','zipsourceinstall','zipexampleinstall', + 'clean','distclean','cleanall', + 'info' + ); + + rule2sec : array[trules] of tsections=( + sec_compile,sec_compile, + sec_examples, + sec_libs,sec_libs, + sec_install,sec_install,sec_exampleinstall, + sec_zipinstall,sec_zipinstall,sec_zipinstall, + sec_clean,sec_clean,sec_clean, + sec_info + ); + + + + type + TMakefileWriter=class + private + FFileName : string; + FIni : TFPCMake; + FInput : TFPCMake; + FOutput : TStringList; + FPhony : string; + FHasSection : array[tsections] of boolean; + procedure LoadFPCMakeIni; + procedure AddIniSection(const s:string); + procedure AddCustomSection(const s:string); + procedure AddTargetVariable(const inivar:string); + procedure AddVariable(const inivar:string); + function AddTargetDefines(const inivar,prefix:string):string; + procedure AddRequiredPackages; + procedure AddTool(const exename:string); + procedure AddRules; + procedure AddPhony(const s:string); + procedure WritePhony; + procedure AddTargetDirs(const inivar:string); + function CheckTargetVariable(const inivar:string):boolean; + function CheckVariable(const inivar:string):boolean; + public + constructor Create(AFPCMake:TFPCMake;const AFileName:string); + destructor Destroy;override; + procedure WriteGenericMakefile; + end; + + +implementation + +{$i fpcmake.inc} + + type + TMyMemoryStream=class(TMemoryStream) + public + constructor Create(p:pointer;mysize:integer); + end; + + +{***************************************************************************** + Helpers +*****************************************************************************} + + function FixVariable(s:string):string; + var + i : integer; + begin + Result:=UpperCase(s); + i:=pos('.',Result); + if i>0 then + Result[i]:='_'; + end; + + + function VarName(const s:string):string; + var + i,j : longint; + begin + i:=0; + result:=s; + while i0 then + Delete(result,i,j-i+1) + else + Delete(result,i,1); + dec(i); + end; + '$','(',')' : + begin + Delete(result,i,1); + dec(i); + end; + 'a'..'z' : + result[i]:=chr(ord(result[i])-32); + end; + end; + end; + + + procedure AddStrNoDup(var s:string;const s2:string); + var + i,idx : longint; + again,add : boolean; + begin + add:=false; + idx:=0; + repeat + again:=false; + i:=posidx(s2,s,idx); + if (i=0) then + add:=true + else + if (i=1) then + begin + if (length(s)>length(s2)) and + (s[length(s2)+1]<>' ') then + add:=true; + end + else + if (i>1) and + ((s[i-1]<>' ') or + ((length(s)>=i+length(s2)) and (s[i+length(s2)]<>' '))) then + begin + idx:=i+length(s2); + again:=true; + end; + until not again; + if add then + begin + if s='' then + s:=s2 + else + s:=s+' '+s2; + end; + end; + procedure FixTab(sl:TStringList); + var + i,j,k : integer; + s,s2 : string; + begin + i:=0; + while (i'') and (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; + + +{***************************************************************************** + TMyMemoryStream +*****************************************************************************} + + constructor TMyMemoryStream.Create(p:pointer;mysize:integer); + begin + inherited Create; + SetPointer(p,mysize); + end; + + +{***************************************************************************** + TMyMemoryStream +*****************************************************************************} + + constructor TMakefileWriter.Create(AFPCMake:TFPCMake;const AFileName:string); + begin + FInput:=AFPCMake; + FFileName:=AFileName; + FOutput:=TStringList.Create; + FPhony:=''; + FillChar(FHasSection,sizeof(FHasSection),1); + LoadFPCMakeIni; + end; + + + destructor TMakefileWriter.Destroy; + begin + FOutput.Free; + FIni.Free; + end; + + + procedure TMakefileWriter.LoadFPCMakeIni; + var + IniStream : TStream; + begin + try + IniStream:=TMyMemoryStream.Create(@fpcmakeini,sizeof(fpcmakeini)); + FIni:=TFPCMake.CreateFromStream(IniStream,'fpcmake.ini'); + { Leave the '#' comments in the output } +// FIni.CommentChars:=[';']; + FIni.LoadSections; + finally + IniStream.Destroy; + end; + end; + + + procedure TMakefileWriter.AddIniSection(const s:string); + var + Sec : TFPCMakeSection; + begin + Sec:=TFPCMakeSection(FIni[s]); + if assigned(Sec) then + FOutput.AddStrings(Sec.List) + else + Raise Exception.Create(Format('Section "%s" doesn''t exists in fpcmake.ini',[s])); + end; + + + procedure TMakefileWriter.AddCustomSection(const s:string); + var + Sec : TFPCMakeSection; + begin + Sec:=TFPCMakeSection(FInput[s]); + if assigned(Sec) then + begin + Sec.BuildMakefile; + FOutput.AddStrings(Sec.List); + end; + end; + + + function TMakefileWriter.CheckTargetVariable(const inivar:string):boolean; + var + t : TTarget; + begin + result:=false; + for t:=low(TTarget) to high(TTarget) do + if FInput.GetVariable(IniVar+TargetSuffix[t])<>'' then + begin + result:=true; + exit; + end; + end; + + + function TMakefileWriter.CheckVariable(const inivar:string):boolean; + begin + Result:=(FInput.GetVariable(IniVar)<>''); + end; + + + procedure TMakefileWriter.AddTargetVariable(const inivar:string); + var + s : string; + T : TTarget; + begin + for t:=low(TTarget) to high(TTarget) do + begin + s:=FInput.GetVariable(IniVar+TargetSuffix[t]); + if s<>'' then + begin + if t<>t_all then + FOutput.Add('ifeq ($(OS_TARGET),'+TargetStr[t]+')'); + FOutput.Add('override '+FixVariable(IniVar)+'+='+s); + if t<>t_all then + FOutput.Add('endif'); + end; + end; + end; + + + procedure TMakefileWriter.AddVariable(const inivar:string); + var + s : string; + begin + s:=FInput.GetVariable(IniVar); + if s<>'' then + FOutput.Add('override '+FixVariable(IniVar)+'='+s) + end; + + + function TMakefileWriter.AddTargetDefines(const inivar,prefix:string):string; + var + s : string; + T : TTarget; + name : string; + i,k1,k2 : integer; + begin + result:=''; + for t:=low(TTarget) to high(TTarget) do + begin + s:=FInput.GetVariable(IniVar+TargetSuffix[t]); + while (s<>'') do + begin + i:=pos(' ',s); + if i=0 then + i:=length(s)+1; + name:=Copy(s,1,i-1); + s:=TrimLeft(Copy(s,i+1,Length(s)-i)); + { Remove (..) } + k1:=pos('(',name); + if k1>0 then + begin + k2:=PosIdx(')',name,k1); + if k2=0 then + k2:=length(name)+1; + Delete(Name,k1,k2); + end; + FOutput.Add(prefix+VarName(name)+'=1'); + { add to the list of dirs without duplicates } + AddStrNoDup(result,name); + end; + end; + end; + + + procedure TMakefileWriter.AddTool(const exename:string); + var + varname : string; + begin + with FOutput do + begin + varname:=FixVariable(exename); + Add('ifndef '+varname); + Add(varname+':=$(strip $(wildcard $(addsuffix /'+exename+'$(SRCEXEEXT),$(SEARCHPATH))))'); + Add('ifeq ($('+varname+'),)'); + Add(varname+'='); + Add('else'); + Add(varname+':=$(firstword $('+varname+'))'); + Add('endif'); + Add('endif'); + Add('export '+varname); + end; + end; + + + procedure TMakefileWriter.AddRules; + + procedure AddRule(rule:trules); + var + i : integer; + hs : string; + Sec : TFPCMakeSection; + Rules : TStringList; + begin + Sec:=TFPCMakeSection(FInput['rules']); + if assigned(Sec) then + begin + Rules:=Sec.List; + for i:=0 to Rules.Count-1 do + begin + if (length(rules[i])>length(rule2str[rule])) and + (rules[i][1]=rule2str[rule][1]) and + ((rules[i][length(rule2str[rule])+1]=':') or + ((length(rules[i])>length(rule2str[rule])+1) and + (rules[i][length(rule2str[rule])+2]=':'))) and + (Copy(rules[i],1,length(rule2str[rule]))=rule2str[rule]) then + exit; + end; + end; + hs:=''; + if FHasSection[Rule2Sec[rule]] then + hs:=hs+' fpc_'+rule2str[rule]; + { include target dirs } + if CheckTargetVariable('target.dirs') then + begin + if not(rule in [r_sourceinstall,r_zipinstall,r_zipsourceinstall]) or + not(CheckVariable('package.name')) then + hs:=hs+' $(addsuffix _'+rule2str[rule]+',$(TARGET_DIRS))'; + end; + { include cleaning of example dirs } + if (rule=r_clean) and + CheckTargetVariable('target.exampledirs') then + hs:=hs+' $(addsuffix _'+rule2str[rule]+',$(TARGET_EXAMPLEDIRS))'; + if hs<>'' then + begin + AddPhony(Rule2Str[Rule]); + FOutput.Add(rule2str[rule]+':'+hs); + end; + end; + + var + rule : trules; + begin + for rule:=low(trules) to high(trules) do + AddRule(rule); + WritePhony; + end; + + procedure TMakefileWriter.AddPhony(const s:string); + begin + FPhony:=FPhony+' '+s; + end; + + + procedure TMakefileWriter.WritePhony; + begin + if FPhony<>'' then + begin + FOutput.Add('.PHONY:'+FPhony); + FPhony:=''; + end; + end; + + + procedure TMakefileWriter.AddTargetDirs(const inivar:string); + + procedure AddTargetDir(const s,defpref:string); + var + j : trules; + begin + FOutput.Add('ifdef '+defpref+VarName(s)); + for j:=low(trules) to high(trules) do + begin + FOutput.Add(s+'_'+rule2str[j]+':'); + FOutput.Add(#9+'$(MAKE) -C '+s+' '+rule2str[j]); + AddPhony(rule2str[j]); + end; + WritePhony; + FOutput.Add('endif'); + end; + + var + i : integer; + hs : string; + prefix : string; + begin + prefix:=FixVariable(inivar)+'_'; + hs:=AddTargetDefines(inivar,prefix); + while hs<>'' do + begin + i:=pos(' ',hs); + if i=0 then + i:=length(hs)+1; + AddTargetDir(Copy(hs,1,i-1),prefix); + delete(hs,1,i); + end; + end; + + + procedure TMakefileWriter.AddRequiredPackages; + + procedure AddPackage(const pack,prefix:string); + var + packdirvar,unitdirvar : string; + begin + FOutput.Add('ifdef '+Prefix+VarName(pack)); + { create needed variables } + packdirvar:='PACKAGEDIR_'+VarName(pack); + unitdirvar:='UNITDIR_'+VarName(pack); + { Search packagedir by looking for Makefile.fpc } + FOutput.Add(packdirvar+':=$(subst /Makefile.fpc,,$(strip $(wildcard $(addsuffix /'+pack+'/$(OS_TARGET)/Makefile.fpc,$(PACKAGESDIR)))))'); + FOutput.Add('ifeq ($('+packdirvar+'),)'); + FOutput.Add(packdirvar+':=$(subst /Makefile.fpc,,$(strip $(wildcard $(addsuffix /'+pack+'/Makefile.fpc,$(PACKAGESDIR)))))'); + FOutput.Add('ifeq ($('+packdirvar+'),)'); + FOutput.Add(packdirvar+'='); + FOutput.Add('else'); + FOutput.Add(packdirvar+':=$(firstword $('+packdirvar+'))'); + FOutput.Add('endif'); + FOutput.Add('else'); + FOutput.Add(packdirvar+':=$(firstword $('+packdirvar+'))'); + FOutput.Add('endif'); + { If Packagedir found look for FPCMade } + FOutput.Add('ifdef '+packdirvar); + FOutput.Add('ifeq ($(wildcard $('+packdirvar+')/$(FPCMADE)),)'); + FOutput.Add('override COMPILEPACKAGES+=package_'+pack); + AddPhony('package_'+pack); + FOutput.Add('package_'+pack+':'); + FOutput.Add(#9'$(MAKE) -C $('+packdirvar+') all'); + FOutput.Add('endif'); + FOutput.Add(unitdirvar+'=$('+packdirvar+')'); + { Package dir doesn''t exists, use unit dir } + FOutput.Add('else'); + FOutput.Add(packdirvar+'='); + FOutput.Add(unitdirvar+':=$(subst /Package.fpc,,$(strip $(wildcard $(addsuffix /'+pack+'/Package.fpc,$(UNITSDIR)))))'); + FOutput.Add('ifeq ($('+unitdirvar+'),)'); + FOutput.Add(unitdirvar+'='); + FOutput.Add('else'); + FOutput.Add(unitdirvar+':=$(firstword $('+unitdirvar+'))'); + FOutput.Add('endif'); + FOutput.Add('endif'); + { Add Unit dir to the command line -Fu } + FOutput.Add('ifdef '+unitdirvar); + FOutput.Add('override COMPILER_UNITDIR+=$('+unitdirvar+')'); + FOutput.Add('endif'); + { endif for package } + FOutput.Add('endif'); + end; + + var + i : integer; + hs : string; + prefix : string; + t : Ttarget; + sl : TStringList; + begin + prefix:='REQUIRE_PACKAGES_'; + { Add target defines } + for t:=low(ttarget) to high(ttarget) do + begin + sl:=FInput.GetTargetRequires(t); + if sl.count>0 then + begin + writeln(TargetStr[t]+' requires:'); + if t<>t_all then + FOutput.Add('ifeq ($(OS_TARGET),'+TargetStr[t]+')'); + for i:=0 to sl.count-1 do + begin + FOutput.Add(prefix+VarName(sl[i])+'=1'); + writeln(sl[i]); + end; + if t<>t_all then + FOutput.Add('endif'); + end; + sl.Free; + end; + { Add all require packages } + for i:=0 to FInput.RequireList.Count-1 do + AddPackage(FInput.RequireList[i],prefix); + WritePhony; + end; + + procedure TMakefileWriter.WriteGenericMakefile; + var + i : integer; + rule : trules; + begin + with FOutput do + begin + { Header } + Add('#'); + Add('# Don''t edit, this file is generated by '+TitleDate); + Add('#'); + Add('default: all'); + { Add automatic detect sections } + AddIniSection('osdetect'); + AddIniSection('fpcdetect'); + AddIniSection('fpcdirdetect'); + { Package } + AddVariable('package.name'); + AddVariable('package.version'); + { First add the required packages sections } + for i:=0 to FInput.RequireList.Count-1 do + AddCustomSection(FInput.Requirelist[i]); + { Targets } + AddTargetVariable('target.dirs'); + AddTargetVariable('target.programs'); + AddTargetVariable('target.units'); + AddTargetVariable('target.rsts'); + AddTargetVariable('target.examples'); + AddTargetVariable('target.exampledirs'); + { Clean } + AddTargetVariable('clean.units'); + AddTargetVariable('clean.files'); + { Install } + AddTargetVariable('install.units'); + AddTargetVariable('install.files'); + AddVariable('install.prefixdir'); + AddVariable('install.basedir'); + AddVariable('install.datadir'); + { Dist } + AddVariable('dist.zipname'); + AddVariable('dist.ziptarget'); + { Compiler } + AddVariable('compiler.options'); + AddVariable('compiler.version'); + AddVariable('compiler.includedir'); + AddVariable('compiler.sourcedir'); + AddVariable('compiler.objectdir'); + AddVariable('compiler.librarydir'); + AddVariable('compiler.targetdir'); + AddVariable('compiler.unittargetdir'); + { Require packages } + AddRequiredPackages; + { default dirs/tools/extensions } + AddIniSection('shelltools'); + AddIniSection('defaulttools'); + AddIniSection('extensions'); + AddIniSection('defaultdirs'); + if CheckVariable('require.libc') then + AddIniSection('dirlibc'); + { commandline } + AddIniSection('command_begin'); + if CheckVariable('require.libc') then + AddIniSection('command_libc'); + AddIniSection('command_end'); + { compile } + if CheckTargetVariable('target.loaders') then + AddIniSection('loaderrules'); + if CheckTargetVariable('target.units') then + AddIniSection('unitrules'); + if CheckTargetVariable('target.programs') then + AddIniSection('exerules'); + if CheckTargetVariable('target.rsts') then + AddIniSection('rstrules'); + if CheckTargetVariable('target.examples') or + CheckTargetVariable('target.exampledirs') then + AddIniSection('examplerules'); + AddIniSection('compilerules'); + if CheckVariable('lib.name') then + AddIniSection('libraryrules'); + { install } + AddIniSection('installrules'); + if CheckTargetVariable('target.examples') or + CheckTargetVariable('target.exampledirs') then + AddIniSection('exampleinstallrules'); + if CheckVariable('package.name') then + AddIniSection('zipinstallrules'); + { clean } + AddIniSection('cleanrules'); + { info } + AddIniSection('inforules'); + { Subdirs } + AddTargetDirs('target.dirs'); + AddTargetDirs('target.exampledirs'); + { Rules } + AddRules; + { Users own rules } + AddIniSection('localmakefile'); + AddIniSection('userrules'); + if assigned(FInput['rules']) then + AddStrings(TFPCMakeSection(FInput['rules']).List); + end; + { write to disk } + Fixtab(FOutput); + FOutput.SaveToFile(FFileName); + end; + +end. +{ + $Log$ + Revision 1.1 2001-01-24 21:59:36 peter + * first commit of new fpcmake + +}