Changeset 2051
- Timestamp:
- 04/15/07 14:00:25 (2 years ago)
- Files:
-
- trunk/install/dmd-posix/mkinstaller.sh (modified) (5 diffs)
- trunk/lib/install-dmd.sh (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/install/dmd-posix/mkinstaller.sh
r2050 r2051 1 1 #!/bin/bash -x 2 # Copyright (C) 2007 Gregor Richards 3 # Permission is granted to do anything you please with this software. 4 # This software is provided with no warranty, express or implied, within the 5 # bounds of applicable law. 2 6 3 7 die() { … … 23 27 fi 24 28 29 30 31 25 32 # 1) The core 26 33 if [ ! -e lib/libphobos.a ] … … 43 50 mkdir -p libtango_objs 44 51 cd libtango_objs || die 1 "Failed to cd to libtango_objs" 45 for i in ../libSD G-*.a52 for i in ../libSDD-*.a 46 53 do 47 54 ar x $i … … 51 58 cd .. || die 1 "Failed to cd out of libtango_objs" 52 59 fi 53 54 60 mkdir -p tmp 55 61 cd tmp || die 1 "Failed to cd to temporary Tango install" … … 59 65 60 66 mkdir -p import 61 cp -pR ../tango i nclude|| die 1 "Failed to copy in the tango .d files"67 cp -pR ../tango import || die 1 "Failed to copy in the tango .d files" 62 68 63 69 mkdir -p lib trunk/lib/install-dmd.sh
r1962 r2051 1 1 #!/bin/bash 2 2 3 # A simple script to install Tango for DMD 4 # Copyright (C) 2006 Gregor Richards 5 # Permission is granted to do anything you please with this software. 6 # This software is provided with no warranty, express or implied, within the 7 # bounds of applicable law. 3 8 # 4 # Copyright (c) 2006 Alexander Panek 5 # 6 # This software is provided 'as-is', without any express or implied warranty. 7 # In no event will the authors be held liable for any damages arising from the 8 # use of this software. 9 # 10 # Permission is granted to anyone to use this software for any purpose, 11 # including commercial applications, and to alter it and redistribute it 12 # freely, subject to the following restrictions: 13 # 14 # 1. The origin of this software must not be misrepresented; you must not claim 15 # that you wrote the original software. If you use this software in a 16 # product, an acknowledgment in the product documentation would be 17 # appreciated but is not required. 18 # 19 # 2. Altered source versions must be plainly marked as such, and must not 20 # be misrepresented as being the original software. 21 # 22 # 3. This notice may not be removed or altered from any source distribution. 23 # 9 # Modifications by Alexander Panek 24 10 25 # local directories26 PREFIX=/usr/local27 MAN_DIR=/usr/share/man/man128 29 # mirrors & filename30 DMD_MIRROR=http://ftp.digitalmars.com31 DMD_FILENAME=dmd.zip32 DMD_CONF=/etc/dmd.conf33 TANGO_REPOSITORY='http://svn.dsource.org/projects/tango/trunk/'34 DSSS_ARCHIVE='http://svn.dsource.org/projects/dsss/downloads/0.9/dsss-0.9-dmd-gnuWlinux.tar.gz'35 36 # state variables (changable through --flags)37 ROOT=138 DMD_DOWNLOAD=039 TANGO_DOWNLOAD=040 DMD_INSTALL=041 DSSS_INSTALL=042 # 42.43 #44 CLEANALL=145 #DEBUG=046 #47 #SIMULATE=048 #49 50 ## HELPER FUNCTIONS51 52 # 'exception', prints first parameter and exits script totally.53 11 die() { 54 CLEANALL=0 55 RET=$1 56 shift 57 echo "$@" 58 exit $1 12 echo "$1" 13 exit $2 59 14 } 60 15 61 # prints usage62 16 usage() { 63 cat <<EOF 64 Usage: $0 <install prefix> [OPTIONS] 17 echo 'Usage: install-dmd.sh [--inplace] [--prefix <install prefix>] 18 Options: 19 --inplace: Don'\''t install anywhere, just keep the installation in-place. 20 (Not recommended, doesn'\''t work without -I) 21 --prefix: Install to the specified prefix. 22 --uninstall: Uninstall tango, switch back to standard phobos.' 23 exit 0 24 } 65 25 66 Options: 67 --with-dmd: install DMD too (requires a dmd.zip in the current directory; use --download to get a fresh copy) 68 If you want to download DMD yourself, please go to http://digitalmars.com/d/ . 69 --version=[x[.]]xxx : Use a specific version of DMD 70 Examples: 71 --version=0.176 72 --version=.176 73 --version=0176 26 cd "`dirname $0`" 74 27 75 --v1: use version 1.00 of DMD (implies that another file name is used [dmd.1.00.zip]) 28 # 0) Parse arguments 29 INPLACE=0 30 SETPREFIX=0 31 UNINSTALL=0 76 32 77 # --with-dsss: install DSSS (D Shared Software System) too. Requires an internet connection, for now. 78 # See http://dsource.org/projects/dsss/ for more information on DSSS! 33 while [ "$#" != "0" ] 34 do 35 if [ "$1" = "--inplace" ] 36 then 37 INPLACE=1 38 elif [ "$1" = "--prefix" ] 39 then 40 SETPREFIX=1 41 shift 79 42 80 --no-root: Do not install a global dmd.conf (default: /etc/dmd.conf) 81 --no-clean: Do not remove DMD archive or Tango copy 82 83 --download: checkout a fresh copy of Tango (subversion required) 84 --download-dmd: Download a fresh copy of DMD (implies --with-dmd) 85 --download-all: Download DMD and checkout a fresh copy of Tango (implies --with-dmd) 86 87 # --uninstall: Uninstall Tango 88 # --uninstall-dmd: Uninstall Tango and DMD 89 # --uninstall-dsss: Uninstall DSSS only 90 # --uninstall-all: Uninstall Tango, DMD and DSSS 91 92 --help: Display this text 43 PREFIX="$1" 44 elif [ "$1" = "--uninstall" ] 45 then 46 UNINSTALL=1 47 else 48 usage 49 fi 50 shift 51 done 93 52 94 53 95 # => not yet implemented96 EOF97 98 }99 100 # gets printed after installation is finished successfully101 finished() {102 cat <<EOF103 54 104 55 105 -----------------------------------------------------------------106 Tango has been installed successfully.107 You can find documentation at http://dsource.org/projects/tango,108 or locally in ${PREFIX}/include/tango/doc/.109 56 110 General D documentation can be found at: 111 o http://digitalmars.com/d/ 112 o http://dsource.org/projects/tutorials/wiki 113 o http://dprogramming.com/ 114 o http://www.prowiki.org/wiki4d/wiki.cgi?FrontPage" 57 dmd --help >& /dev/null || die "dmd not found on your \$PATH!" 1 115 58 116 Enjoy your stay in the Tango dancing club! \\\\o \\o/ o// 59 PHOBOS_DIR="`whereis libphobos.a | sed -e 's/libphobos:[ ]*\([^ ]*\)[ ]*.*/\1/' -`" 60 PHOBOS_DIR="`dirname $PHOBOS_DIR`" 117 61 118 EOF 119 } 62 which --version >& /dev/null 63 if [ "$?" = "0" ] 64 then 65 PREFIX="`which dmd`" 66 PREFIX="`dirname $PREFIX`/.." 67 else 68 PREFIX="$PHOBOS_DIR/.." 69 fi 70 DMD_VER="`dmd | head -n 1 | awk '{print $5}'`" 71 DMD_MCH="x86" 120 72 121 download_dmd() { 122 echo "Downloading dmd.zip from ${DMD_MIRROR}..." 123 wget -c ${DMD_MIRROR}/${DMD_FILENAME} || die 1 "Error downloading DMD. Aborting." 124 } 73 if [ "$INPLACE" = "1" -a \ 74 "$SETPREFIX" = "1" ] 75 then 76 die "Cannot both set a prefix and do an in-place install." 2 77 fi 125 78 126 download_tango() { 127 echo "Downloading Tango from ${TANGO_MIRROR} (subversion required)..." 128 129 echo "..creating temporary directory tango/..." 130 mkdir -p tango || die 1 "Error while creating temporary directory." 131 132 echo "..changing directory to tango/..." 133 cd tango || die 1 "Error while changing directory (tango/)." 134 135 echo "..checking out tango/trunk (quietly). This may take some time..." 136 svn checkout -q ${TANGO_REPOSITORY} || die 1 "Error while checking out." 137 138 echo "..changing directory to tango/trunk/..." 139 cd trunk || die 1 "Error while changing directory (tango/trunk/)." 140 141 echo "..moving dmd archive to current directory..." 142 mv ../../${DMD_FILENAME} . || die 1 "Error moving dmd archive to tango/trunk/." 143 } 144 145 install_dmd() { 146 unzip_dmd 147 copy_dmd 148 copy_dmd_include 149 copy_dmd_lib 150 copy_dmd_doc 151 cleanup_dmd 152 } 153 154 unzip_dmd() { 155 if [ ! -f ${DMD_FILENAME} ] 156 then 157 die 1 "Could not find dmd archive. Please use --download-dmd or manually download the file from ${DMD_MIRROR}. Aborting." 158 fi 159 160 echo "Extracting zip file..." 161 unzip -q -d . ${DMD_FILENAME} || die 1 'Could not extract zip file. Aborting.' 162 } 163 164 copy_dmd() { 165 echo "Copying compiler binaries..." 166 167 echo "..creating ${PREFIX}/bin" 168 mkdir -p ${PREFIX}/bin || die 1 "Error creating directory (${PREFIX}/bin)." 169 170 echo "..settin executable flag for dmd, objasm, dumpobj and rdmd..." 171 chmod +x dmd/bin/{dmd,obj2asm,dumpobj,rdmd} || die 1 "Error chmod-ing (dmd, objasm, dumpobj, rdmd)." 172 173 echo "..copying executable files to ${PREFIX}/bin..." 174 cp dmd/bin/dmd ${PREFIX}/bin || die 1 "Error copying dmd/bin/dmd." 175 cp dmd/bin/obj2asm ${PREFIX}/bin || die 1 "Error copying dmd/bin/objasm." 176 cp dmd/bin/dumpobj ${PREFIX}/bin || die 1 "Error copying dmd/bin/dumpobj." 177 cp dmd/bin/rdmd ${PREFIX}/bin || die 1 "Error copying dmd/bin/rdmd." 178 } 179 180 copy_dmd_include() { 181 echo "Copying runtime library sources..." 182 183 echo "..creating ${PREFIX}/include" 184 mkdir -p ${PREFIX}/include || die 1 "Error creating ${PREFIX}/include." 185 186 echo "..copying files" 187 cp -r dmd/src/phobos ${PREFIX}/include || die 1 "Error copying library sources to ${PREFIX}/include." 188 } 189 190 copy_dmd_doc() { 191 echo "Copying D documentation and samples (Phobos)..." 192 193 echo "..creating directories ${PREFIX}/doc/dmd/{src,samples}..." 194 mkdir -p {${PREFIX}/doc/dmd/samples,${PREFIX}/doc/dmd/src} || die 1 "Error creating documentation directories." 195 196 cp -r dmd/html/d/* ${PREFIX}/doc/dmd/ || die 1 "Error copying documentation." 197 cp -r dmd/samples/d/* ${PREFIX}/doc/dmd/samples/ || die 1 "Error copying samples." 198 cp -r dmd/src/dmd/* ${PREFIX}/doc/dmd/src/ || die 1 "Error copying source." 199 } 200 201 copy_dmd_lib() { 202 echo "Copying runtime library..." 203 204 echo "..creating ${PREFIX}/lib..." 205 mkdir -p ${PREFIX}/lib || die 1 "Error creating directory for runtime library (${PREFIX}/lib)." 206 207 echo "..copying original libphobos.a" 208 cp dmd/lib/libphobos.a ${PREFIX}/lib/ || die 1 "Error copying libphobos.a." 209 # cp dmd/lib/phobos.lib ${PREFIX}/lib/ || die 1 "Error copying phobos.lib." 210 } 211 212 copy_dmd_man() { 213 echo "Copying manpages to ${MAN_DIR}" 214 cp dmd/man/man1/* ${MAN_DIR} || die 1 "Error copying manpages." 215 } 216 217 install_tango() { 218 echo "Installing Tango..." 219 220 echo "..checking if we have a local copy of the repository or an extracted package..." 221 if [ `find . -name .svn | grep '' -c` -gt 0 ] 222 then 223 echo "...svn files found, using svn export to copy (avoiding recreation of .svn* files)..." 224 225 echo "...checking if directory already exists (svn export will fail, if so)..." 226 if [ -f ${PREFIX}/include/tango ] 227 then 228 die 1 "Error, destination does already exist; please delete it or change prefix." 229 else 230 echo "....everything fine; doing svn export..." 231 mkdir -p ${PREFIX}/include 232 svn export --force . ${PREFIX}/include/tango || die 1 "Error exporting Tango via svn export." 233 fi 234 else 235 echo "...no subversion files found, using normal copy method..." 236 echo "...creating directory ${PREFIX}/include..." 237 238 mkdir -p ${PREFIX}/include/tango || die 1 "Error creating Tango directory." 239 cp -r ./* ${PREFIX}/include/tango || die 1 "Error copying Tango to new directory." 240 fi 241 242 if [ ! -f "lib/libphobos.a" ] 243 then 244 echo "...changing directory: lib/" 245 cd lib/ 246 247 echo "...building base runtime library" 248 ./build-dmd.sh || die 1 "Error building library." 249 250 echo "...changing directory: ../" 251 cd ../ 252 fi 253 254 if [ -f "${PREFIX}/lib/libphobos.a" ] 255 then 256 echo "...making a backup of the original phobos library" 257 mv ${PREFIX}/lib/libphobos.a ${PREFIX}/lib/original_libphobos.a || die 1 "Error renaming original libphobos.a" 258 fi 259 260 if [ -f "lib/libphobos.a" ] 261 then 262 cp lib/libphobos.a ${PREFIX}/lib/libphobos.a || die 1 "Error copying Tango's libphobos.a replacement to ${PREFIX}/lib/libphobos.a" 263 else 264 die 1 "Library has not been built, yet the build script itself did not throw an error. Please report this to a developer." 265 fi 266 } 267 268 dmd_conf_install() { 269 echo "Modifying or creating dmd.conf file (first found by whereis command)..." 270 271 echo "..trying to find dmd.conf..." 272 if [ `whereis dmd | tr ' ' '\n' | grep dmd.conf -c` -lt 1 ] 273 then 274 echo "..no dmd.conf found, installing default one to /etc/dmd.conf..." 275 276 # no dmd.conf installed yet, install a fresh one! 277 echo "[Environment]" > ${DMD_CONF} || die 1 "Error writing to ${DMD_CONF}." 278 # echo ";DFLAGS=-I\"${PREFIX}/include/phobos -L-L${PREFIX}/lib\"" >> ${DMD_CONF} || die 1 "Error writing to ${DMD_CONF}." 279 echo "DFLAGS=-I${PREFIX}/include/tango -L-L${PREFIX}/lib/ -version=Posix -version=Tango" >> ${DMD_CONF} || die 1 "Error writing to ${DMD_CONF}." 280 else 281 echo -n "..dmd.conf found: `whereis dmd | tr ' ' '\n' | grep dmd.conf -m 1` -- doing sed magic." 282 283 sed -e 's/DFLAGS=-I.*phobos.*/;&\nDFLAGS=-I"\${PREFIX}\/include\/tango\/ -L-L\${PREFIX}\/lib\/ -version=Posix -version=Tango"/g' `whereis dmd | tr ' ' '\n' | grep -v X | grep -m 1 dmd.conf` > _dmd.conf || die 284 mv _dmd.conf `whereis dmd | tr ' ' '\n' | grep -v X | grep -m 1 dmd.conf` || die 1 # replace old dmd.conf with changed dmd.conf 285 fi 286 } 287 288 cleanup_tango() { 289 echo "Cleaning up (removing) tango/trunk/..." 79 # If uninstalling, do that now 80 if [ "$UNINSTALL" = "1" ] 81 then 82 if [ ! -e "$PHOBOS_DIR/libphobos.a.phobos" ] 83 then 84 die "tango does not appear to be installed!" 3 85 fi 86 if [ "$INPLACE" = "0" ] 87 then 88 rm -rf $PHOBOS_DIR/libphobos.a $PREFIX/import/$DMD_VER/object.d 89 mv $PREFIX/import/$DMD_VER/object.d.phobos $PREFIX/import/$DMD_VER/object.d 90 mv $PHOBOS_DIR/libphobos.a.phobos $PHOBOS_DIR/libphobos.a 91 fi 92 die "Done!" 0 93 fi 290 94 291 95 292 if [ ${TANGO_DOWNLOAD} = 1 ] 293 then 294 if [ ${DMD_INSTALL} = 1 ] 295 then 296 if [ ${ROOT} = 0 ] 297 then 298 mv ${PREFIX} ../../ 299 fi 300 fi 301 fi 302 303 cd ../../ || die 1 "Error while cleaning up." 304 rm -rf tango || die 1 "Error while cleaning up." 305 } 306 307 cleanup_dmd() { 308 echo "Cleaning up tango/trunk/dmd/..." 309 310 rm -rf dmd/ || die 1 "Error while cleaning up." 311 312 if [ ${CLEANALL} = 1 ] 313 then 314 echo "Removing dmd archive..." 315 rm -r ${DMD_FILENAME} || die 1 "Error while removing dmd.zip." 316 fi 317 } 318 319 install_dsss() { 320 echo "Installing DSSS to ${PREFIX}..." 321 322 echo "..trying to download archive (this may take a while)..." 323 wget -c ${DSSS_ARCHIVE} || die 1 "Error downloading DSSS binary archive." 324 325 echo "..extracting archive..." 326 unzip -d dsss/ ${DSSS_ARCHIVE##*/} || die 1 "Error extracting DSSS binary archive." 327 328 echo "..copying files over to ${PREFIX}/..." 329 cp -r dsss/dsss-0.9-dmd-gnuWlinux/* ${PREFIX}/ || die 1 "Error copying DSSS to ${PREFIX}." 330 331 echo "..cleaning up..." 332 rm -rf dsss/ || die 1 "Error while cleaning up DSSS temporaries." 333 334 echo "DSSS installed." 335 echo "" 336 } 337 338 ## TO BE DONE ## 339 #uninstall_tango() { 340 341 #} 342 343 ## TO BE DONE ## 344 #uninstall_dmd() { 345 346 #} 347 348 ############################################################################################ 349 ############################################################################################ 350 # ACTUAL START OF THE SCRIPT (or end of functions, depends on your pessimism/optimism ;) ) 351 ############################################################################################ 352 ############################################################################################ 353 354 if [ -n "$1" ] 96 # Sanity check 97 if [ ! -e libphobos.a ] 355 98 then 356 PREFIX="$1" 357 else 358 usage 359 die 1 99 die "You must run build-dmd.sh before running install-dmd.sh" 4 360 100 fi 361 101 362 if [ -z "`echo ${PREFIX} | grep '^/'`" ] 102 # Back up the original files 103 if [ -e "$PHOBOS_DIR/libphobos.a.phobos" ] 363 104 then 364 PREFIX="`pwd`${PREFIX}" 105 die "You must uninstall your old copy of Tango before installing a new one." 4 106 fi 107 mv -f $PHOBOS_DIR/libphobos.a $PHOBOS_DIR/libphobos.a.phobos 108 mv $PREFIX/import/$DMD_VER/object.d $PREFIX/import/$DMD_VER/object.d.phobos || 109 die "Failed to move Phobos' object.d" 8 110 111 # Install ... 112 if [ "$INPLACE" = "0" ] 113 then 114 echo 'Copying files...' 115 mkdir -p $PREFIX/import/$DMD_VER || die "Failed to create import/$DMD_VER (maybe you need root privileges?)" 5 116 cp -pRvf libphobos.a $PHOBOS_DIR || die "Failed to copy libraries" 7 117 cp -pRvf ../object.di $PREFIX/import/$DMD_VER/object.d || die "Failed to copy source" 8 365 118 fi 366 119 367 # Check for flags 368 for i in $*; 369 do 370 case "$i" in 371 --with-dmd) 372 DMD_INSTALL=1 373 ;; 374 --with-dsss) 375 DSSS_INSTALL=1 376 ;; 377 --download) 378 TANGO_DOWNLOAD=1 379 ;; 380 --download-dmd) 381 DMD_DOWNLOAD=1 382 DMD_INSTALL=1 383 ;; 384 --download-all) 385 DMD_DOWNLOAD=1 386 DMD_INSTALL=1 387 TANGO_DOWNLOAD=1 388 ;; 389 --no-root) 390 ROOT=0 391 ;; 392 --no-clean) 393 CLEANALL=0 394 ;; 395 --version=1.00) 396 VERSION="1.00" 397 398 DMD_FILENAME="dmd.1.00.zip" 399 ;; 400 --version=*) 401 # This version is /not/ 1.0 ready (only supporting 0.123 thingies) 402 VERSION=`echo -n "${i}" | sed -n 's/^--version=[0-9]\?\.\?\([0-9]\{3\}\)/\1/p'` 403 404 # Don't use this one yet - it isn't tested... 405 #VERSION=`echo -n "${i}" | sed -n 's/^--version=\(\([1-9]\{1\}\)\.\{1\}\([0-9]\{1,3\}\)|\([0-9]\?\.\?\([0-9]\{3\}\)\)\)/\1/p'` 406 407 if [ -n "${VERSION}" ] 408 then 409 DMD_FILENAME="dmd.${VERSION}.zip" 410 else 411 DMD_FILENAME="dmd.zip" 412 fi 413 ;; 414 -v1) 415 VERSION="1.00" 416 417 DMD_FILENAME="dmd.1.00.zip" 418 ;; 419 --help) 420 usage 421 die 422 ;; 423 --debug) 424 DEBUG=1 425 ;; 426 --simulate) 427 SIMULATE=1 428 ;; 429 esac 430 done 431 432 if [ ${DMD_DOWNLOAD} = 1 ] 433 then 434 download_dmd 435 fi 436 437 if [ ${TANGO_DOWNLOAD} = 1 ] 438 then 439 download_tango 440 fi 441 442 if [ ${DMD_INSTALL} = 1 ] 443 then 444 install_dmd 445 fi 446 447 install_tango 448 449 if [ ${ROOT} = 1 ] 450 then 451 dmd_conf_install 452 fi 453 454 if [ ${TANGO_DOWNLOAD} = 1 ] 455 then 456 cleanup_tango 457 fi 458 459 finished 120 die "Done!" 0












