~widelands-dev/widelands/bug-1656671

5179 by Victor Pelt
.bzrignore shouldn't be in bzr
1
#!/bin/sh
5013 by Nasenbaer
Add script for compilation, to ease the use of cmake for beginners
2
echo " "
7851.1.29 by GunChleoc
Added CMake option to omit building website-related stuff and rescued the English language.
3
echo "###########################################################"
4
echo "#     Script to simplify the compilation of Widelands     #"
5
echo "###########################################################"
5477 by Nasenbaer
Move build_and_run.sh to compile.sh and rework it, to be much more intuitive for users.
6
echo " "
7
echo "  Because of the many different systems Widelands"
8
echo "  might be compiled on, we unfortunally can not"
9
echo "  provide a simple way to prepare your system for"
10
echo "  compilation. To ensure your system is ready, best"
11
echo "  check http://wl.widelands.org/wiki/BuildingWidelands"
12
echo " "
7851.1.29 by GunChleoc
Added CMake option to omit building website-related stuff and rescued the English language.
13
echo "  You will often find helpful hands at our"
5477 by Nasenbaer
Move build_and_run.sh to compile.sh and rework it, to be much more intuitive for users.
14
echo "  * IRC Chat: http://wl.widelands.org/webchat/"
15
echo "  * Forums: http://wl.widelands.org/forum/"
16
echo "  * Mailinglist: http://wl.widelands.org/wiki/MailLists/"
17
echo " "
7851.1.29 by GunChleoc
Added CMake option to omit building website-related stuff and rescued the English language.
18
echo "  Please post your bug reports and feature requests at:"
5477 by Nasenbaer
Move build_and_run.sh to compile.sh and rework it, to be much more intuitive for users.
19
echo "  https://bugs.launchpad.net/widelands"
20
echo " "
7851.1.29 by GunChleoc
Added CMake option to omit building website-related stuff and rescued the English language.
21
echo "###########################################################"
22
echo " "
23
24
25
## Option to avoid building and linking website-related executables.
8075.1.2 by GunChleoc
Streamlined code for no website.
26
BUILD_WEBSITE="ON"
8075.1.3 by GunChleoc
Added commandline switch for translations.
27
BUILD_TRANSLATIONS="ON"
8075.1.1 by GunChleoc
Added switch to compile.sh for release builds.
28
BUILDTYPE="Debug"
7851.1.29 by GunChleoc
Added CMake option to omit building website-related stuff and rescued the English language.
29
while [ "$1" != "" ]; do
8075.1.3 by GunChleoc
Added commandline switch for translations.
30
  if [ "$1" = "--no-website" -o "$1" = "-w" ]; then
8075.1.2 by GunChleoc
Streamlined code for no website.
31
    BUILD_WEBSITE="OFF"
8075.1.1 by GunChleoc
Added switch to compile.sh for release builds.
32
  elif [ "$1" = "--release" -o "$1" = "-r" ]; then
33
    BUILDTYPE="Release"
8075.1.3 by GunChleoc
Added commandline switch for translations.
34
  elif [ "$1" = "--no-translations" -o "$1" = "-t" ]; then
35
    BUILD_TRANSLATIONS="OFF"
7851.1.29 by GunChleoc
Added CMake option to omit building website-related stuff and rescued the English language.
36
  fi
37
  shift
38
done
8075.1.2 by GunChleoc
Streamlined code for no website.
39
if [ $BUILD_WEBSITE = "ON" ]; then
7851.1.30 by GunChleoc
Typo.
40
  echo "A complete build will be created."
8075.1.3 by GunChleoc
Added commandline switch for translations.
41
  echo "You can use -w or --no-website to omit building and"
7851.1.29 by GunChleoc
Added CMake option to omit building website-related stuff and rescued the English language.
42
  echo "linking website-related executables."
43
else
44
  echo "Any website-related code will be OMITTED in the build."
45
  echo "Make sure that you have created and tested a full"
46
  echo "build before submitting code to the repository!"
47
fi
48
echo " "
8075.1.3 by GunChleoc
Added commandline switch for translations.
49
if [ $BUILD_TRANSLATIONS = "ON" ]; then
50
  echo "Translations will be built."
51
  echo "You can use -t or --no-translations to omit building them."
52
else
53
echo "Translations will not be built."
54
fi
55
echo " "
8110.5.3 by GunChleoc
clang-format.
56
echo "###########################################################"
57
echo " "
8075.1.1 by GunChleoc
Added switch to compile.sh for release builds.
58
if [ $BUILDTYPE = "Release" ]; then
59
  echo "Creating a Release build."
60
else
61
  echo "Creating a Debug build. Use -r to create a Release build."
62
fi
63
echo " "
64
echo "For instructions on how to adjust options and build with"
65
echo "CMake, please take a look at"
66
echo "https://wl.widelands.org/wiki/BuildingWidelands/."
67
echo " "
68
echo "###########################################################"
69
echo " "
5477 by Nasenbaer
Move build_and_run.sh to compile.sh and rework it, to be much more intuitive for users.
70
71
######################################
7119.6.12 by Hans Joachim Desserud
Made a fallback solution if ninja is not available.
72
# Definition of some local variables #
73
######################################
7119.6.15 by Hans Joachim Desserud
Reorganize the buildtool check, leaving a gap for variation
74
buildtool="" #Use ninja by default, fall back to make if that is not available.
7119.6.12 by Hans Joachim Desserud
Made a fallback solution if ninja is not available.
75
######################################
76
77
78
######################################
5477 by Nasenbaer
Move build_and_run.sh to compile.sh and rework it, to be much more intuitive for users.
79
#    Definition of some functions    #
80
######################################
81
  # Check basic stuff
82
  basic_check () {
83
    # Check whether the script is run in a widelands main directory
84
    if ! [ -f src/wlapplication.cc ] ; then
85
      echo "  This script must be run from the main directory of the widelands"
86
      echo "  source code."
87
      exit 1
88
    fi
89
    return 0
90
  }
91
7119.6.14 by Hans Joachim Desserud
Check whether ninja is available and set buildtool up front
92
  set_buildtool () {
7119.6.19 by Hans Joachim Desserud
Catch alternative binary name for ninja
93
    #Defaults to ninja, but if that is not found, we use make instead
7119.6.16 by Hans Joachim Desserud
Make check whether ninja is installed work properly
94
    if [ `command -v ninja` ] ; then
7119.6.15 by Hans Joachim Desserud
Reorganize the buildtool check, leaving a gap for variation
95
      buildtool="ninja"
7119.6.19 by Hans Joachim Desserud
Catch alternative binary name for ninja
96
    #On some systems (most notably Fedora), the binary is called ninja-build
97
    elif [ `command -v ninja-build` ] ; then
98
      buildtool="ninja-build"
7119.6.22 by Hans Joachim Desserud
Case for systems refering to GNU make as gmake
99
    #... and some systems refer to GNU make as gmake
100
    elif [ `command -v gmake` ] ; then
101
      buildtool="gmake"
7119.6.15 by Hans Joachim Desserud
Reorganize the buildtool check, leaving a gap for variation
102
    else
7119.6.14 by Hans Joachim Desserud
Check whether ninja is available and set buildtool up front
103
      buildtool="make"
104
    fi
105
  }
106
5477 by Nasenbaer
Move build_and_run.sh to compile.sh and rework it, to be much more intuitive for users.
107
  # Check if directories / links already exists and create / update them if needed.
108
  prepare_directories_and_links () {
5669 by Jens Beyer (Qcumber-some)
remove old locale symlink in case of moving to new compile directory in compile.sh
109
    test -d build/locale || mkdir -p build/locale
7293.1.54 by fios at foramnagaidhlig
Fixed localedir.
110
    test -e data/locale || ln -s ../build/locale data/locale
5477 by Nasenbaer
Move build_and_run.sh to compile.sh and rework it, to be much more intuitive for users.
111
    return 0
112
  }
113
114
  # Compile Widelands
115
  compile_widelands () {
7119.6.19 by Hans Joachim Desserud
Catch alternative binary name for ninja
116
    if [ $buildtool = "ninja" ] || [ $buildtool = "ninja-build" ] ; then
8075.1.3 by GunChleoc
Added commandline switch for translations.
117
      cmake -G Ninja .. -DCMAKE_BUILD_TYPE=$BUILDTYPE -DOPTION_BUILD_WEBSITE_TOOLS=$BUILD_WEBSITE -DOPTION_BUILD_TRANSLATIONS=$BUILD_TRANSLATIONS
7119.6.12 by Hans Joachim Desserud
Made a fallback solution if ninja is not available.
118
    else
8075.1.3 by GunChleoc
Added commandline switch for translations.
119
      cmake .. -DCMAKE_BUILD_TYPE=$BUILDTYPE -DOPTION_BUILD_WEBSITE_TOOLS=$BUILD_WEBSITE -DOPTION_BUILD_TRANSLATIONS=$BUILD_TRANSLATIONS
7119.6.12 by Hans Joachim Desserud
Made a fallback solution if ninja is not available.
120
    fi
7119.6.20 by Hans Joachim Desserud
Indentation
121
7119.6.24 by Hans Joachim Desserud
No longer apply MAKEOPTS. Probably not set by the target audience for this script
122
    $buildtool
5477 by Nasenbaer
Move build_and_run.sh to compile.sh and rework it, to be much more intuitive for users.
123
    return 0
124
  }
125
126
  # Remove old and move newly compiled files
127
  move_built_files () {
5665 by Jens Beyer (Qcumber-some)
Since build dir is empty, we can use it for compilation in compile.sh
128
    rm  -f ../VERSION || true
129
    rm  -f ../widelands || true
5477 by Nasenbaer
Move build_and_run.sh to compile.sh and rework it, to be much more intuitive for users.
130
5665 by Jens Beyer (Qcumber-some)
Since build dir is empty, we can use it for compilation in compile.sh
131
    mv VERSION ../VERSION
132
    mv src/widelands ../widelands
5477 by Nasenbaer
Move build_and_run.sh to compile.sh and rework it, to be much more intuitive for users.
133
    return 0
134
  }
135
7119.6.1 by Hans Joachim Desserud
Always create update script
136
  create_update_script () {
5477 by Nasenbaer
Move build_and_run.sh to compile.sh and rework it, to be much more intuitive for users.
137
    # First check if this is an bzr checkout at all - only in that case,
138
    # creation of a script makes any sense.
6810.2.68 by GunChleoc
Some merging cleanup - needs testing:
139
    if ! [ -f .bzr/branch-format ] ; then
7119.6.6 by Hans Joachim Desserud
Warn if you don't get an update script
140
      echo "You don't appear to be using Bazaar. An update script will not be created"
5477 by Nasenbaer
Move build_and_run.sh to compile.sh and rework it, to be much more intuitive for users.
141
      return 0
6810.2.68 by GunChleoc
Some merging cleanup - needs testing:
142
    fi
7119.6.26 by Hans Joachim Desserud
Create update script using cat. Not superhappy about breaking indentation that way though...
143
      rm -f update.sh || true
144
      cat > update.sh << END_SCRIPT
145
#!/bin/sh
146
echo "################################################"
147
echo "#            Widelands update script.          #"
148
echo "################################################"
149
echo " "
150
151
set -e
152
if ! [ -f src/wlapplication.cc ] ; then
153
  echo "  This script must be run from the main directory of the widelands"
154
  echo "  source code."
155
  exit 1
156
fi
157
158
bzr pull
159
cd build
160
$buildtool
161
rm  ../VERSION || true
162
rm  ../widelands || true
163
mv VERSION ../VERSION
164
mv src/widelands ../widelands
165
cd ..
166
167
echo " "
168
echo "################################################"
169
echo "#      Widelands was updated successfully.     #"
170
echo "# You should be able to run it via ./widelands #"
171
echo "################################################"
172
END_SCRIPT
173
      chmod +x ./update.sh
174
      echo "  -> The update script has successfully been created."
5477 by Nasenbaer
Move build_and_run.sh to compile.sh and rework it, to be much more intuitive for users.
175
  }
176
######################################
177
178
179
180
######################################
181
#    Here is the "main" function     #
182
######################################
5179 by Victor Pelt
.bzrignore shouldn't be in bzr
183
set -e
5477 by Nasenbaer
Move build_and_run.sh to compile.sh and rework it, to be much more intuitive for users.
184
basic_check
7119.6.14 by Hans Joachim Desserud
Check whether ninja is available and set buildtool up front
185
set_buildtool
5477 by Nasenbaer
Move build_and_run.sh to compile.sh and rework it, to be much more intuitive for users.
186
prepare_directories_and_links
7143 by Holger Rapp
Remove empty build dir and instead let compile.sh create it when needed.
187
mkdir -p build
7119.6.18 by Hans Joachim Desserud
Let directory preparation do one thing and one thing only
188
cd build
5477 by Nasenbaer
Move build_and_run.sh to compile.sh and rework it, to be much more intuitive for users.
189
compile_widelands
190
move_built_files
5665 by Jens Beyer (Qcumber-some)
Since build dir is empty, we can use it for compilation in compile.sh
191
cd ..
7119.6.1 by Hans Joachim Desserud
Always create update script
192
create_update_script
5477 by Nasenbaer
Move build_and_run.sh to compile.sh and rework it, to be much more intuitive for users.
193
echo " "
7851.1.29 by GunChleoc
Added CMake option to omit building website-related stuff and rescued the English language.
194
echo "###########################################################"
8075.1.4 by GunChleoc
Print settings summary at end of script.
195
echo "# Congratulations! Widelands has been built successfully  #"
196
echo "# with the following settings:                            #"
197
echo "#                                                         #"
198
if [ $BUILDTYPE = "Release" ]; then
199
  echo "# - Release build                                         #"
200
else
201
  echo "# - Debug build                                           #"
202
fi
203
if [ $BUILD_TRANSLATIONS = "ON" ]; then
204
  echo "# - Translations                                          #"
205
else
206
  echo "# - No translations                                       #"
207
fi
208
209
if [ $BUILD_WEBSITE = "ON" ]; then
210
  echo "# - Website-related executables                           #"
211
else
212
  echo "# - No website-related executables                        #"
213
fi
214
echo "#                                                         #"
7851.1.29 by GunChleoc
Added CMake option to omit building website-related stuff and rescued the English language.
215
echo "# You should now be able to run Widelands via             #"
216
echo "# typing ./widelands + ENTER in your terminal             #"
217
echo "#                                                         #"
218
echo "# You can update Widelands via running ./update.sh        #"
219
echo "# in the same directory that you ran this script in.      #"
220
echo "###########################################################"
5477 by Nasenbaer
Move build_and_run.sh to compile.sh and rework it, to be much more intuitive for users.
221
######################################