File: create_linux_cross_win32_rpm.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 (201 lines) | stat: -rwxr-xr-x 6,212 bytes parent folder | download | duplicates (12)
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
#!/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
BuildCrossWin32RPM=no

Params=$@
for p in $Params; do
  case "$p" in
  all)
    DownloadBinutils=yes
    DownloadFPC=yes
    BuildBinutils=yes
    BuildLinWin32RPM=no
    BuildNormalRPM=no
    ;;
  downloadbinutils)
    DownloadBinutils=yes
    ;;
  downloadfpc)
    DownloadFPC=yes
    ;;
  buildbinutils)
    BuildBinutils=yes
    ;;
  buildnormalfpc)
    BuildNormalFPC=yes
    ;;
  buildcrossfpc)
    BuildCrossFPC=yes
    ;;
  buildcrosswin32rpm)
    BuildCrossWin32RPM=yes
    ;;
  *)
    echo "Unknown option: $p"
    echo
    echo "Usage:"
    echo "  $0 [all] [downloadbinutils] [downloadfpc] [buildbinutils] [buildcrossfpc] [buildcrosswin32rpm]"
    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=i386-win32"
  echo "calling update_cross_fpc.sh $Params ..."
  ./update_cross_fpc.sh $Params || exit
fi


#===============================================================================
# build fpc_crosswin32 rpm
if [ $BuildCrossWin32RPM = "yes" ]; then

  #----------------------------------------------------------------------------
  # 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"

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

  #----------------------------------------------------------------------------
  # create temporary directory
  #----------------------------------------------------------------------------
  TmpSrcDir=$HOME/tmp/fpc_crosswin32
  echo "create temporary directory $TmpSrcDir ..."
  rm -rf $TmpSrcDir
  mkdir -p $TmpSrcDir
  
  #----------------------------------------------------------------------------
  # collect binutils
  #----------------------------------------------------------------------------
  echo "collecting binutils from $BuildRoot/binutils/cross/bin/ ..."
  BinDir=$TmpSrcDir/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##")
      NewName="fpc-${TargetCPU}-${TargetOS}-$NewName"
      cp ${BinUtilsDir}${binutility} ${BinDir}${NewName}
    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
    
    mkdir -p $TmpSrcDir/$FPCLibDir
    cp -a $BuildRoot/binutils/cross/destination/$FPCLibDir/$Target $TmpSrcDir/$FPCLibDir/
  done

  #----------------------------------------------------------------------------
  # create default /usr/lib/fpc/fpc-cross.cfg
  #----------------------------------------------------------------------------
  touch $TmpSrcDir/lib/fpc/fpc-cross.cfg

  #----------------------------------------------------------------------------
  # copy tools (windres)
  #----------------------------------------------------------------------------
  FPCLibDir=lib/fpc/$CompilerVersionStr # !!! no / at end
  DestDir=$TmpSrcDir/$FPCLibDir
  cp -p $BuildRoot/bin/* $DestDir/

  #----------------------------------------------------------------------------
  # create tgz
  #----------------------------------------------------------------------------
  echo "creating tgz ..."
  SrcTGZ=$(../rpm/get_rpm_source_dir.sh)/SOURCES/fpc_crosswin32-$CompilerVersionStr-$Release.tar.gz

  cd $TmpSrcDir
  tar czf $SrcTGZ .
  cd -

  #----------------------------------------------------------------------------
  # change spec file
  #----------------------------------------------------------------------------
  echo "creating spec file ..."
  SpecFileTemplate=../rpm/fpc_crosswin32.spec.template
  SpecFile=fpc_crosswin32.spec
  cat $SpecFileTemplate | \
    sed -e 's/FPCVERSION/'"$CompilerVersionStr/" \
        -e 's/FPCRELEASE/'"$Release/" \
    > $SpecFile
    

  rpmbuild --nodeps -ba $SpecFile

  echo "The new rpm can be found at $(../rpm/get_rpm_source_dir.sh)/RPMS/i386/fpc_crosswin32-$CompilerVersionStr-$Release.i386.rpm"
else
  echo "To build the rpm call this script with parameter all or buildcrosswin32rpm"
fi

# end.