File: create_linux_cross_win32_deb.sh

package info (click to toggle)
lazarus 2.0.0%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 214,460 kB
  • sloc: pascal: 1,862,622; xml: 265,709; cpp: 56,595; sh: 3,008; java: 609; makefile: 535; perl: 297; sql: 222; ansic: 137
file content (250 lines) | stat: -rwxr-xr-x 7,690 bytes parent folder | download | duplicates (10)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
#!/usr/bin/env bash
# Author: Mattias Gaertner
# License: LGPL
# Abstract: Download, compile binutils and FPC

set -e
#set -x

# This is the root for all download and building directories
if [ ! -d "$BuildRoot" ]; then
  BuildRoot=~/freepascal
fi

#===============================================================================
# parse command line parameters
echo "parsing parameters ..."
DownloadBinutils=no
DownloadFPC=no
BuildBinutils=no
BuildCrossFPC=no
BuildNormalFPC=no
BuildCrossWin32DEB=no

Params=$@
for p in $Params; do
  case "$p" in
  all)
    DownloadBinutils=yes
    DownloadFPC=yes
    BuildBinutils=yes
    BuildLinWin32DEB=no
    BuildNormalDEB=no
    ;;
  downloadbinutils)
    DownloadBinutils=yes
    ;;
  downloadfpc)
    DownloadFPC=yes
    ;;
  buildbinutils)
    BuildBinutils=yes
    ;;
  buildnormalfpc)
    BuildNormalFPC=yes
    ;;
  buildcrossfpc)
    BuildCrossFPC=yes
    ;;
  buildcrosswin32deb)
    BuildCrossWin32DEB=yes
    ;;
  *)
    echo "Unknown option: $p"
    echo
    echo "Usage:"
    echo "  $0 [all] [downloadbinutils] [downloadfpc] [buildbinutils] [buildcrossfpc] [buildcrosswin32deb]"
    exit -1
    ;;
  esac
done

# expand paths
BuildRoot=$(echo $BuildRoot | sed -e 's#//#/#g' -e 's#/$##')
Targets='i386-win32'

#===============================================================================
# download and build binutils and fpc
set -x
Params=""
if [ $DownloadBinutils = "yes" ]; then
  Params="$Params downloadbinutils"
fi
if [ $DownloadFPC = "yes" ]; then
  Params="$Params downloadfpc"
fi
if [ $BuildBinutils = "yes" ]; then
  Params="$Params buildbinutils"
fi
if [ $BuildNormalFPC = "yes" ]; then
  Params="$Params buildnormalfpc"
fi
if [ $BuildCrossFPC = "yes" ]; then
  Params="$Params buildcrossfpc"
fi

if [ "x$Params" != "x" ]; then
  Params="$Params targets=$Targets"
  echo "calling update_cross_fpc.sh $Params ..."
  ./update_cross_fpc.sh $Params || exit
fi


#===============================================================================
# build fpc_crosswin32 deb
if [ $BuildCrossWin32DEB = "yes" ]; then

  # check if bison is there
  fakeroot -v

  #----------------------------------------------------------------------------
  # retrieve the version information
  #----------------------------------------------------------------------------
  echo -n "retrieving the FPC version ..."
  VersionFile="$BuildRoot/fpc/compiler/version.pas"
  CompilerVersion=`cat $VersionFile | grep ' *version_nr *=.*;' | sed -e 's/[^0-9]//g'`
  CompilerRelease=`cat $VersionFile | grep ' *release_nr *=.*;' | sed -e 's/[^0-9]//g'`
  CompilerPatch=`cat $VersionFile | grep ' *patch_nr *=.*;' | sed -e 's/[^0-9]//g'`
  CompilerVersionStr="$CompilerVersion.$CompilerRelease.$CompilerPatch"
  FPCVersion="$CompilerVersion.$CompilerRelease"
  if [ "$CompilerPatch" != "0" ]; then
    FPCVersion="$FPCVersion.$CompilerPatch"
  fi
  echo " $CompilerVersionStr-$FPCRelease"

  FPCRelease=$(date +%y%m%d)
  echo " $CompilerVersionStr-$FPCRelease"

  #------------------------------------------------------------------------------
  # setup variables

  CurDir=`pwd`
  Arch=i386
  PackageName=fpc_crosswin32
  ResourceDir=$CurDir/debian_crosswin32
  FPCBuildDir=~/tmp/fpc_build
  FPCDeb=$CurDir/${PackageName}_${FPCVersion}-${FPCRelease}_$Arch.deb
  DebianInstallDir=$FPCBuildDir/usr
  DebianRulezDir=$FPCBuildDir/DEBIAN/
  DebianDocDir=$FPCBuildDir/usr/share/doc/$PackageName
  Date=`date --rfc-822`

  #----------------------------------------------------------------------------
  # create temporary directory
  #----------------------------------------------------------------------------
  echo "create temporary directory $TmpSrcDir ..."
  rm -rf $FPCBuildDir
  mkdir -p $FPCBuildDir
  
  #----------------------------------------------------------------------------
  # collect binutils
  #----------------------------------------------------------------------------
  echo "collecting binutils from $BuildRoot/binutils/cross/bin/ ..."
  BinDir=$FPCBuildDir/usr/bin/
  mkdir -p $BinDir
  MyIntel=i686
  for Target in $Targets; do
    TargetCPU=$(echo $Target | sed -e 's#^\(.*\)-.*$#\1#')
    TargetOS=$(echo $Target | sed -e 's#^.*-\(.*\)$#\1#')
    BinUtilsCPU=$TargetCPU
    BinUtilsOS=$TargetOS

    if [ $TargetOS = "win32" ]; then
      BinUtilsOS="mingw32"
      BinUtilsCPU=$MyIntel
    fi

    BinUtilsDir=$BuildRoot/binutils/cross/bin/
    BinUtilsPrefix="$BinUtilsCPU-$BinUtilsOS-"

    cd ${BinUtilsDir}
    for binutility in $(ls -B ${BinUtilsPrefix}*); do
      NewName=$(echo $binutility | sed -e "s#^$BinUtilsPrefix##")
      NewFileName="${TargetCPU}-${TargetOS}-$NewName"
      if [ $NewName = "windres" ]; then
        # windres needs two names:
        # - the Makefiles expects without prefix fpc-
        # - the compiler expects 'windres' with prefix fpc-
        ln -s /usr/bin/${NewFileName} ${BinDir}windres
      fi
      cp ${BinUtilsDir}${binutility} ${BinDir}${NewFileName}
    done
    cd -
  done

  #----------------------------------------------------------------------------
  # collect fpc libs (e.g. .ppu/.o)
  #----------------------------------------------------------------------------
  echo "collecting fpc libs (e.g. .ppu/.o) from $BuildRoot/binutils/cross/destination/ ..."
  for Target in $Targets; do
    FPCLibDir=lib/fpc/$CompilerVersionStr/units # !!! no / at end
    
    DestDir=$FPCBuildDir/usr/$FPCLibDir
    mkdir -p $DestDir
    cp -av $BuildRoot/binutils/cross/destination/$FPCLibDir/$Target $DestDir
  done
  
  #----------------------------------------------------------------------------
  # create default /usr/lib/fpc/fpc-cross.cfg
  #----------------------------------------------------------------------------
  touch $FPCBuildDir/usr/lib/fpc/fpc-cross.cfg
  
  #------------------------------------------------------------------------------
  # create rulez and files

  # change debian files
  mkdir -p $DebianDocDir
  mkdir -p $DebianRulezDir

  # create debian control file, which contains the package description
  echo "creating DEBIAN/control file"
  cat $ResourceDir/control | sed -e "s/FPCVERSION/$FPCVersion/g" > $DebianRulezDir/control

  # create debian changelog file, needed for version
  echo "creating usr/share/doc/fpc/changelog file ..."
  File=$DebianDocDir/changelog
  echo "$PackageName ($FPCVersion-$FPCRelease) unstable; urgency=low" > $File
  echo " -- Mattias Gaertner <mattias@freepascal.org>  $Date" >> $File
  echo "" >> $File
  cat $ResourceDir/changelog >> $File
  gzip --best $File

  # create postinst if needed
  if [ -f "$ResourceDir/postinst" ]; then
    echo "creating DEBIAN/postinst file"
    cat $ResourceDir/postinst | sed -e "s/FPCVERSION/$FPCVersion/g" > $DebianRulezDir/postinst
    chmod a+x $DebianRulezDir/postinst
  fi

  # create postrm if needed
  if [ -f "$ResourceDir/postrm" ]; then
    echo "creating DEBIAN/postrm file"
    cat $ResourceDir/postrm | sed -e "s/FPCVERSION/$FPCVersion/g" > $DebianRulezDir/postrm
    chmod a+x $DebianRulezDir/postrm
  fi

  # create changelog.Debian file
  echo "creating changelog.Debian file ..."
  File=$DebianDocDir/changelog.Debian
  cp $ResourceDir/changelog.Debian $File
  gzip --best $File

  # create debian copyright file
  echo "creating copyright file ..."
  cp $ResourceDir/copyright $DebianDocDir/

  #------------------------------------------------------------------------------
  # creating deb

  cd $FPCBuildDir
  fakeroot dpkg-deb --build $FPCBuildDir
  mv $FPCBuildDir.deb $FPCDeb

  echo "The new deb can be found at $FPCDeb"
  echo "You can test it with lintian."
else
  echo "To build the deb call this script with parameter all or buildcrosswin32deb"
fi

# end.