| 1 |
#!/bin/sh |
| 2 |
# ---------------------------------------------------------------------------- |
| 3 |
# - afnix-setup - |
| 4 |
# - afnix build tree configuration installer - |
| 5 |
# ---------------------------------------------------------------------------- |
| 6 |
# - This program is free software; you can redistribute it and/or modify - |
| 7 |
# - it provided that this copyright notice is kept intact. - |
| 8 |
# - - |
| 9 |
# - This program is distributed in the hope that it will be useful, but - |
| 10 |
# - without any warranty; without even the implied warranty of - |
| 11 |
# - merchantability or fitness for a particular purpose. In not event shall - |
| 12 |
# - the copyright holder be liable for any direct, indirect, incidental or - |
| 13 |
# - special damages arising in any way out of the use of this software. - |
| 14 |
# ---------------------------------------------------------------------------- |
| 15 |
# - copyright (c) 1999-2023 amaury darsch - |
| 16 |
# ---------------------------------------------------------------------------- |
| 17 |
|
| 18 |
# ---------------------------------------------------------------------------- |
| 19 |
# - set default variables - |
| 20 |
# ---------------------------------------------------------------------------- |
| 21 |
|
| 22 |
# the program name we are running |
| 23 |
prgnam="$0" |
| 24 |
# the platform source name |
| 25 |
pltnam="unknown" |
| 26 |
# the top directory of the distribution |
| 27 |
topdir= |
| 28 |
# the cnf directory |
| 29 |
cnfdir= |
| 30 |
# the build directory |
| 31 |
blddir= |
| 32 |
# the source directory |
| 33 |
srcdir= |
| 34 |
# the installation directory prefix |
| 35 |
prefix="/opt/afnix" |
| 36 |
# the shared directory |
| 37 |
shrdir="$prefix/share" |
| 38 |
# the alternate directory (for etc) |
| 39 |
altdir="$prefix" |
| 40 |
# the sdk name |
| 41 |
sdknam= |
| 42 |
# the sdk directory |
| 43 |
sdkdir= |
| 44 |
# whether or not we report the option |
| 45 |
shwopt="no" |
| 46 |
# the default compiler |
| 47 |
ccname= |
| 48 |
# the platform os version |
| 49 |
pltvrs= |
| 50 |
pltmaj="0" |
| 51 |
pltmin="0" |
| 52 |
# the processor name |
| 53 |
cpunam= |
| 54 |
# the processor bits |
| 55 |
cpubit= |
| 56 |
# the process native |
| 57 |
cpuntv= |
| 58 |
# the machine configuration |
| 59 |
mchcnf= |
| 60 |
# default compilation mode |
| 61 |
ccmode="debug" |
| 62 |
# linking type |
| 63 |
lktype= |
| 64 |
# linking mode |
| 65 |
lkmode= |
| 66 |
# the openmp mode |
| 67 |
openmp="no" |
| 68 |
# the distribution package |
| 69 |
pkgnam= |
| 70 |
# the optional package bin directory |
| 71 |
pkgbin= |
| 72 |
# the optional package lib directory |
| 73 |
pkglib= |
| 74 |
# the optional package project directory |
| 75 |
pkgprj= |
| 76 |
# the optional package header directory |
| 77 |
pkghdr= |
| 78 |
# the optional package etc directory |
| 79 |
pkgetc= |
| 80 |
# the optional package man directory |
| 81 |
pkgman= |
| 82 |
# the optional package doc directory |
| 83 |
pkgdoc= |
| 84 |
# the optional package www directory |
| 85 |
pkgwww= |
| 86 |
# the optional package srv directory |
| 87 |
pkgsrv= |
| 88 |
|
| 89 |
# ---------------------------------------------------------------------------- |
| 90 |
# - local function always make life easier - |
| 91 |
# ---------------------------------------------------------------------------- |
| 92 |
|
| 93 |
# print a usage message |
| 94 |
usage () { |
| 95 |
echo "usage: afnix-setup [options]" |
| 96 |
echo " -h print this help message" |
| 97 |
echo " -v be verbose" |
| 98 |
echo " -g set debug mode" |
| 99 |
echo " -o set optimized mode" |
| 100 |
echo " -p set profiled mode (internal)" |
| 101 |
echo |
| 102 |
echo " --prefix set target directory to install" |
| 103 |
echo " --shrdir set shared directory to install" |
| 104 |
echo " --altdir set alternate directory to install" |
| 105 |
echo " --sdknam set the target sdk by name" |
| 106 |
echo " --sdkdir set the target sdk directory" |
| 107 |
echo " --ccname set default compiler" |
| 108 |
echo " --shared compile and link dynamically" |
| 109 |
echo " --static compile and link statically" |
| 110 |
echo " --openmp enable openmp compilation" |
| 111 |
echo " --pkgnam set the distribution package" |
| 112 |
echo " --pkgbin set the optional package bin directory" |
| 113 |
echo " --pkglib set the optional package lib directory" |
| 114 |
echo " --pkgprj set the optional package prj directory" |
| 115 |
echo " --pkghdr set the optional package hdr directory" |
| 116 |
echo " --pkgetc set the optional package etc directory" |
| 117 |
echo " --pkgman set the optional package man directory" |
| 118 |
echo " --pkgdoc set the optional package doc directory" |
| 119 |
echo " --pkgwww set the optional package www directory" |
| 120 |
echo " --pkgsrv set the optional package srv directory" |
| 121 |
exit 0 |
| 122 |
} |
| 123 |
|
| 124 |
# print an error message |
| 125 |
error () { |
| 126 |
echo "afnix-setup: $1" |
| 127 |
exit 1 |
| 128 |
} |
| 129 |
|
| 130 |
# report options |
| 131 |
report () { |
| 132 |
echo "top directory = $topdir" |
| 133 |
echo "config directory = $cnfdir" |
| 134 |
echo "source directory = $srcdir" |
| 135 |
echo "prefix = $prefix" |
| 136 |
echo "shared directory = $shrdir" |
| 137 |
echo "alternate directory = $altdir" |
| 138 |
echo "sdk name = $sdknam" |
| 139 |
echo "sdk directory = $sdkdir" |
| 140 |
echo "platform name = $pltnam" |
| 141 |
echo "platform version = $pltvrs" |
| 142 |
echo "processor name = $cpunam" |
| 143 |
echo "processor size = $cpubit" |
| 144 |
echo "processor native = $cpuntv" |
| 145 |
echo "compiler = $ccname" |
| 146 |
echo "compilation mode = $ccmode" |
| 147 |
echo "linking type = $lktype" |
| 148 |
echo "linking mode = $lkmode" |
| 149 |
echo "openmp mode = $openmp" |
| 150 |
echo "package name = $pkgnam" |
| 151 |
echo "package binary = $pkgbin" |
| 152 |
echo "package library = $pkglib" |
| 153 |
echo "package project = $pkgprj" |
| 154 |
echo "package header = $pkghdr" |
| 155 |
echo "package etc = $pkgetc" |
| 156 |
echo "package manual = $pkgman" |
| 157 |
echo "package doc = $pkgdoc" |
| 158 |
echo "package www = $pkgwww" |
| 159 |
echo "package srv = $pkgsrv" |
| 160 |
} |
| 161 |
|
| 162 |
# this function computes the various directories |
| 163 |
getdir () { |
| 164 |
# compute top directory path |
| 165 |
if test -z "$prgnam"; then |
| 166 |
topdir="../.." |
| 167 |
else |
| 168 |
topdir=`dirname $prgnam`/../.. |
| 169 |
fi |
| 170 |
# get the directory fixer |
| 171 |
fixexe="$topdir/cnf/bin/afnix-fxdir" |
| 172 |
# fix the top directory |
| 173 |
topdir=`$fixexe $topdir` |
| 174 |
# compute the cnf directory |
| 175 |
cnfdir="$topdir/cnf" |
| 176 |
if test ! -d "$cnfdir"; then |
| 177 |
error "cannot find cnf directory" $cnfdir |
| 178 |
fi |
| 179 |
# compute the build directory |
| 180 |
blddir="$topdir/bld" |
| 181 |
# compute the source directory |
| 182 |
srcdir="$topdir/src" |
| 183 |
if test ! -d "$srcdir"; then |
| 184 |
error "cannot find source directory $srcdir" |
| 185 |
fi |
| 186 |
} |
| 187 |
|
| 188 |
# compute the compiler and linker |
| 189 |
getccl () { |
| 190 |
# get the query script |
| 191 |
qryexe="$topdir/cnf/bin/afnix-query --pltname=$pltnam" |
| 192 |
if test -z "$ccname"; then |
| 193 |
# get the compiler name |
| 194 |
ccname=`$qryexe ccname` |
| 195 |
if test "$?" != "0"; then |
| 196 |
error "cannot determine compiler name" |
| 197 |
fi |
| 198 |
fi |
| 199 |
# get the linking type |
| 200 |
if test -z "$lktype"; then |
| 201 |
lktype=`$qryexe lktype` |
| 202 |
if test "$?" != "0"; then |
| 203 |
error "cannot determine linking type" |
| 204 |
fi |
| 205 |
fi |
| 206 |
# get the linking mode |
| 207 |
lkmode=`$qryexe --default=generic lkmode` |
| 208 |
if test "$?" != "0"; then |
| 209 |
error "cannot determine linking mode" |
| 210 |
fi |
| 211 |
if test "$lktype" = "static"; then |
| 212 |
lkmode= |
| 213 |
fi |
| 214 |
} |
| 215 |
|
| 216 |
# fix the configuration |
| 217 |
fixcnf () { |
| 218 |
# get the compiler version script |
| 219 |
vccexe="$topdir/cnf/bin/afnix-vcomp" |
| 220 |
# update with the compiler version |
| 221 |
ccname=`$vccexe --ccname=$ccname` |
| 222 |
# force directory with darwin |
| 223 |
if test "$pltnam" = "darwin"; then |
| 224 |
pkgdir="$blddir/pkg" |
| 225 |
prefix="$pkgdir/usr" |
| 226 |
shrdir="$prefix/share" |
| 227 |
altdir="$shrdir" |
| 228 |
if test -z "$sdkdir"; then |
| 229 |
sdkdir="/Developer/SDKs/MacOSX10.5.sdk" |
| 230 |
fi |
| 231 |
if test ! -d "$sdkdir"; then |
| 232 |
error "cannot find sdk directory $sdkdir" |
| 233 |
fi |
| 234 |
fi |
| 235 |
} |
| 236 |
|
| 237 |
# this function creates the build configuration directory |
| 238 |
gendef () { |
| 239 |
# precompute guess option |
| 240 |
if test -n "$sdknam"; then |
| 241 |
pltopt="--sdknam=$sdknam" |
| 242 |
if test -z "$sdkdir"; then |
| 243 |
sdkdir=$AFNIX_SDK |
| 244 |
fi |
| 245 |
if test -n "$sdkdir"; then |
| 246 |
pltopt="$pltopt --sdkdir=$sdkdir" |
| 247 |
fi |
| 248 |
fi |
| 249 |
# get the guess script |
| 250 |
pltexe="$topdir/cnf/bin/afnix-guess $pltopt" |
| 251 |
# create the target cnf directory |
| 252 |
trgdir="$topdir/bld/cnf" |
| 253 |
/bin/mkdir -p $trgdir |
| 254 |
# compute platform information |
| 255 |
pltnam=`$pltexe -n` |
| 256 |
if test "$?" != "0"; then |
| 257 |
error "cannot determine platform name" |
| 258 |
fi |
| •259 |
pltvrs=0.0 |
| 260 |
if test "$?" != "0"; then |
| 261 |
error "cannot determine platform version" |
| 262 |
fi |
| •263 |
pltmaj=0 |
| 264 |
if test "$?" != "0"; then |
| 265 |
error "cannot determine platform major number" |
| 266 |
fi |
| •267 |
pltmin=0 |
| 268 |
if test "$?" != "0"; then |
| 269 |
error "cannot determine platform minor number" |
| 270 |
fi |
| 271 |
cpuntv=`$pltexe -p` |
| 272 |
if test "$?" != "0"; then |
| 273 |
error "cannot determine native processor" |
| 274 |
fi |
| 275 |
# cross compilation special cases |
| 276 |
if test -z "$cpunam"; then |
| 277 |
cpunam=`$pltexe -p` |
| 278 |
fi |
| 279 |
if test "$?" != "0"; then |
| 280 |
error "cannot determine processor" |
| 281 |
fi |
| 282 |
cpubit=`$pltexe -s --cpunam=$cpunam` |
| 283 |
# set the machine configuration |
| 284 |
mchcnf=$pltnam-$cpunam |
| 285 |
} |
| 286 |
|
| 287 |
gencnf () { |
| 288 |
# install afnix-plat.mak file |
| 289 |
trgmak="$trgdir/afnix-plat.mak" |
| 290 |
# make file generation |
| 291 |
echo "# afnix-plat.mak" > $trgmak |
| 292 |
echo "# afnix makefile configuration" >> $trgmak |
| 293 |
echo >> $trgmak |
| 294 |
echo "# platform configuration" >> $trgmak |
| 295 |
echo "PLATNAME = $pltnam" >> $trgmak |
| 296 |
echo "PLATVERS = $pltvrs" >> $trgmak |
| 297 |
echo "PLATVMAJ = $pltmaj" >> $trgmak |
| 298 |
echo "PLATVMIN = $pltmin" >> $trgmak |
| 299 |
echo "PROCNAME = $cpunam" >> $trgmak |
| 300 |
echo "PROCNATV = $cpuntv" >> $trgmak |
| 301 |
echo "PROCBITS = $cpubit" >> $trgmak |
| 302 |
echo "MACHCONF = $mchcnf" >> $trgmak |
| 303 |
echo >> $trgmak |
| 304 |
echo "# installation options" >> $trgmak |
| 305 |
echo "PREFIX = $prefix" >> $trgmak |
| 306 |
echo "SHRDIR = $shrdir" >> $trgmak |
| 307 |
echo "ALTDIR = $altdir" >> $trgmak |
| 308 |
echo "SDKDIR = $sdkdir" >> $trgmak |
| 309 |
echo "PKGNAM = $pkgnam" >> $trgmak |
| 310 |
echo "PKGBIN = $pkgbin" >> $trgmak |
| 311 |
echo "PKGLIB = $pkglib" >> $trgmak |
| 312 |
echo "PKGPRJ = $pkgprj" >> $trgmak |
| 313 |
echo "PKGHDR = $pkghdr" >> $trgmak |
| 314 |
echo "PKGETC = $pkgetc" >> $trgmak |
| 315 |
echo "PKGMAN = $pkgman" >> $trgmak |
| 316 |
echo "PKGDOC = $pkgdoc" >> $trgmak |
| 317 |
echo "PKGWWW = $pkgwww" >> $trgmak |
| 318 |
echo "PKGSRV = $pkgsrv" >> $trgmak |
| 319 |
echo >> $trgmak |
| 320 |
echo "# compilation mode" >> $trgmak |
| 321 |
echo "CCMODE = $ccmode" >> $trgmak |
| 322 |
echo >> $trgmak |
| 323 |
echo "# linking options" >> $trgmak |
| 324 |
echo "LKTYPE = $lktype" >> $trgmak |
| 325 |
echo "LKMODE = $lkmode" >> $trgmak |
| 326 |
echo >> $trgmak |
| 327 |
echo "# openmp options" >> $trgmak |
| 328 |
echo "OPENMP = $openmp" >> $trgmak |
| 329 |
|
| 330 |
# get the appropriate compiler config |
| 331 |
ccmake="$cnfdir/mak/afnix-${ccname}.mak" |
| 332 |
if test ! -f "$ccmake"; then |
| 333 |
error "cannot find compiler definitions $ccname" |
| 334 |
fi |
| 335 |
ccfile="$trgdir/afnix-comp.mak" |
| 336 |
if test ! -f "$ccfile"; then |
| 337 |
ln -s $ccmake $ccfile |
| 338 |
fi |
| 339 |
} |
| 340 |
|
| 341 |
# ---------------------------------------------------------------------------- |
| 342 |
# - parse options - this is where we really start - |
| 343 |
# ---------------------------------------------------------------------------- |
| 344 |
|
| 345 |
# compute various directories |
| 346 |
getdir |
| 347 |
|
| 348 |
# parse the options |
| 349 |
preopt= |
| 350 |
for nxtopt |
| 351 |
do |
| 352 |
# assign the previous option argument |
| 353 |
if test -n "$preopt"; then |
| 354 |
eval "$preopt=\$nxtopt" |
| 355 |
preopt= |
| 356 |
continue |
| 357 |
fi |
| 358 |
|
| 359 |
# extract options |
| 360 |
case "$nxtopt" in |
| 361 |
-*=*) argopt=`echo "$nxtopt" | sed 's/[-_a-zA-Z0-9]*=//'`;; |
| 362 |
*) argopt=;; |
| 363 |
esac |
| 364 |
|
| 365 |
# process options now |
| 366 |
case "$nxtopt" in |
| 367 |
-h) usage;; |
| 368 |
-v) shwopt="yes";; |
| 369 |
-g) ccmode="debug";; |
| 370 |
-o) ccmode="optimized";; |
| 371 |
-p) ccmode="profiled";; |
| 372 |
|
| 373 |
--prefix) preopt=prefix ;; |
| 374 |
--prefix=*) oldfix="$prefix" ; |
| 375 |
prefix="$argopt" ; |
| 376 |
if test "$shrdir" = "$oldfix/share"; then |
| 377 |
shrdir="$prefix/share"; |
| 378 |
fi;; |
| 379 |
--static) lktype="static";; |
| 380 |
--shared) lktype="dynamic";; |
| 381 |
--openmp) openmp="yes";; |
| 382 |
--shrdir) preopt=shrdir;; |
| 383 |
--shrdir=*) shrdir="$argopt";; |
| 384 |
--altdir) preopt=altdir;; |
| 385 |
--altdir=*) altdir="$argopt";; |
| 386 |
--cpunam) preopt=cpunam;; |
| 387 |
--cpunam=*) cpunam="$argopt";; |
| 388 |
--sdknam) preopt=sdknam;; |
| 389 |
--sdknam=*) sdknam="$argopt";; |
| 390 |
--sdkdir) preopt=sdkdir;; |
| 391 |
--sdkdir=*) sdkdir="$argopt";; |
| 392 |
--pkgnam) preopt=pkgnam;; |
| 393 |
--pkgnam=*) pkgnam="$argopt";; |
| 394 |
--pkgbin) preopt=pkgbin;; |
| 395 |
--pkgbin=*) pkgbin="$argopt";; |
| 396 |
--pkglib) preopt=pkglib;; |
| 397 |
--pkglib=*) pkglib="$argopt";; |
| 398 |
--pkgprj) preopt=pkgprj;; |
| 399 |
--pkgprj=*) pkgprj="$argopt";; |
| 400 |
--pkghdr) preopt=pkghdr;; |
| 401 |
--pkghdr=*) pkghdr="$argopt";; |
| 402 |
--pkgetc) preopt=pkgetc;; |
| 403 |
--pkgetc=*) pkgetc="$argopt";; |
| 404 |
--pkgman) preopt=pkgman;; |
| 405 |
--pkgman=*) pkgman="$argopt";; |
| 406 |
--pkgdoc) preopt=pkgdoc;; |
| 407 |
--pkgdoc=*) pkgdoc="$argopt";; |
| 408 |
--pkgwww) preopt=pkgwww;; |
| 409 |
--pkgwww=*) pkgwww="$argopt";; |
| 410 |
--pkgsrv) preopt=pkgsrv;; |
| 411 |
--pkgsrv=*) pkgsrv="$argopt";; |
| 412 |
--ccname) preopt=ccname;; |
| 413 |
--ccname=*) ccname="$argopt";; |
| 414 |
*) error "illegal option $nxtopt";; |
| 415 |
esac |
| 416 |
done |
| 417 |
|
| 418 |
# create the definitions |
| 419 |
gendef |
| 420 |
# compute the compiler & linker |
| 421 |
getccl |
| 422 |
# fix the definitions |
| 423 |
fixcnf |
| 424 |
# create the configuration |
| 425 |
gencnf |
| 426 |
|
| 427 |
# check if we report the user option |
| 428 |
if test "$shwopt" = "yes"; then |
| 429 |
report |
| 430 |
fi |
| 431 |
|
| 432 |
# success |
| 433 |
exit 0 |