1#!/bin/sh 2# 3# Configuration script for Services. 4# 5# Anope (c) 2003-2020 Anope Team 6# Contact us at team@anope.org 7# 8# This program is free but copyrighted software; see the file COPYING for 9# details. 10# 11# Based on the original code of Epona by PegSoft. 12# Based on the original code of Services by Andy Church. 13# 14########################################################################### 15 16echo2 () { 17 $ECHO2 "$*$ECHO2SUF" # these are defined later 18} 19 20exists () { # because some shells don't have test -e 21 if [ -f $1 -o -d $1 -o -p $1 -o -c $1 -o -b $1 ] ; then 22 return 0 23 else 24 return 1 25 fi 26} 27 28Load_Cache () { 29 if [ -f $SOURCE_DIR/config.cache -a -r $SOURCE_DIR/config.cache -a ! "$IGNORE_CACHE" ] ; then 30 echo "Using defaults from config.cache. To ignore, $SOURCE_DIR/Config -nocache" 31 echo "" 32 . $SOURCE_DIR/config.cache 33 CAN_QUICK="yes" 34 else 35 CAN_QUICK="no" 36 fi 37} 38 39Run_Build_System () { 40 WITH_INST="" 41 WITH_RUN="" 42 WITH_PERM="" 43 EXTRA_INCLUDE="" 44 EXTRA_LIBS="" 45 GEN_TYPE="" 46 47 if [ "$INSTDIR" != "" ] ; then 48 WITH_INST="-DINSTDIR:STRING=$INSTDIR" 49 fi 50 51 if [ "$RUNGROUP" != "" ] ; then 52 WITH_RUN="-DRUNGROUP:STRING=$RUNGROUP" 53 fi 54 55 if [ "$UMASK" != "" ] ; then 56 WITH_PERM="-DDEFUMASK:STRING=$UMASK" 57 fi 58 59 if [ "$DEBUG" = "yes" ] ; then 60 BUILD_TYPE="-DCMAKE_BUILD_TYPE:STRING=DEBUG" 61 else 62 BUILD_TYPE="-DCMAKE_BUILD_TYPE:STRING=RELEASE" 63 fi 64 65 if [ "$USE_PCH" = "yes" ] ; then 66 PCH="-DUSE_PCH:BOOLEAN=ON" 67 else 68 PCH="-DUSE_PCH:BOOLEAN=OFF" 69 fi 70 71 if [ "$EXTRA_INCLUDE_DIRS" != "" ] ; then 72 EXTRA_INCLUDE="-DEXTRA_INCLUDE:STRING=$EXTRA_INCLUDE_DIRS" 73 fi 74 75 if [ "$EXTRA_LIB_DIRS" != "" ] ; then 76 EXTRA_LIBS="-DEXTRA_LIBS:STRING=$EXTRA_LIB_DIRS" 77 fi 78 79 case `uname -s` in 80 MINGW*) 81 GEN_TYPE="-G\"MSYS Makefiles\"" 82 ;; 83 esac 84 85 if [ "$SOURCE_DIR" = "." ] ; then 86 pwdsave=`pwd` 87 test -d build || mkdir build 88 cd "build" 89 REAL_SOURCE_DIR=".." 90 else 91 REAL_SOURCE_DIR="$SOURCE_DIR" 92 fi 93 94 echo "cmake $GEN_TYPE $WITH_INST $WITH_RUN $WITH_PERM $BUILD_TYPE $PCH $EXTRA_INCLUDE $EXTRA_LIBS $EXTRA_CONFIG_ARGS $REAL_SOURCE_DIR" 95 96 cmake $GEN_TYPE $WITH_INST $WITH_RUN $WITH_PERM $BUILD_TYPE $PCH $EXTRA_INCLUDE $EXTRA_LIBS $EXTRA_CONFIG_ARGS $REAL_SOURCE_DIR 97 if [ $? -ne 0 ]; then 98 echo "You should fix these issues and then run ./Config -quick to rerun CMake." 99 exit 1 100 fi 101 102 echo "" 103 if [ "$SOURCE_DIR" = "." ] ; then 104 echo "Now cd build, then run make to build Anope." 105 cd "$pwdsave" 106 else 107 echo "Now run make to build Anope." 108 fi 109} 110 111ECHO2SUF='' 112if [ "`echo -n a ; echo -n b`" = "ab" ] ; then 113 ECHO2='echo -n' 114elif [ "`echo 'a\c' ; echo 'b\c'`" = "ab" ] ; then 115 ECHO2='echo' ; ECHO2SUF='\c' 116elif [ "`printf 'a' 2>&1 ; printf 'b' 2>&1`" = "ab" ] ; then 117 ECHO2='printf "%s"' 118else 119 # oh well... 120 ECHO2='echo' 121fi 122export ECHO2 ECHO2SUF 123 124########################################################################### 125# Init values 126########################################################################### 127 128INSTDIR=$HOME/services 129RUNGROUP= 130UMASK= 131DEBUG="no" 132USE_PCH="no" 133EXTRA_INCLUDE_DIRS= 134EXTRA_LIB_DIRS= 135EXTRA_CONFIG_ARGS= 136CAN_QUICK="no" 137SOURCE_DIR=`dirname $0` 138 139########################################################################### 140# Check out the options 141########################################################################### 142 143while [ $# -ge 1 ] ; do 144 if [ $1 = "--help" ] ; then 145 echo "Config utility for Anope" 146 echo "------------------------" 147 echo "Syntax: ./Config [options]" 148 echo "-nocache Ignore settings saved in config.cache" 149 echo "-nointro Skip intro (disclaimer, etc)" 150 echo "-quick Skip questions, go straight to cmake" 151 exit 0 152 elif [ $1 = "-nocache" ] ; then 153 IGNORE_CACHE="1" 154 elif [ $1 = "-nointro" ] ; then 155 NO_INTRO="1" 156 elif [ $1 = "-quick" -o $1 = "-q" ] ; then 157 Load_Cache 158 if [ "$CAN_QUICK" = "yes" ] ; then 159 Run_Build_System 160 else 161 echo "" 162 echo "Can't find cache file (config.cache), aborting..." 163 fi 164 exit 0 165 fi 166 shift 1 167done 168 169########################################################################### 170# Check for CMake and (optionally) install it 171########################################################################### 172 173cmake --version 2>&1 > /dev/null 174if [ $? -ne 0 ] ; then 175 clear 176 echo "Anope requires CMake 2.4 or newer, which can be downloaded at https://cmake.org/ or through your system's package manager." 177 echo "If you have installed CMake already, ensure it is in your PATH environment variable." 178 exit 0 179fi 180 181########################################################################### 182 183if [ ! "$NO_INTRO" ] ; then 184 case `uname -s` in 185 MINGW*) 186 PAGER=less 187 ;; 188 *) 189 PAGER=more 190 clear 191 ;; 192 esac 193 . $SOURCE_DIR/src/version.sh 194 cat $SOURCE_DIR/.BANNER | sed "s/CURVER/$VERSION_MAJOR.$VERSION_MINOR.$VERSION_PATCH$VERSION_EXTRA/" | sed "s@SOURCE_DIR@$SOURCE_DIR@" | $PAGER 195 echo "" 196else 197 echo "" 198fi 199 200echo "Beginning Services configuration." 201echo "" 202 203########################################################################### 204# Load the cache 205########################################################################### 206 207if [ ! "$IGNORE_CACHE" ] ; then 208 Load_Cache 209fi 210 211# Ask the user anything we need to know ahead of time. 212 213export ok INPUT 214 215#### 216 217ok=0 218echo "In what directory should Anope be installed?" 219while [ $ok -eq 0 ] ; do 220 echo2 "[$INSTDIR] " 221 if read INPUT ; then : ; else echo "" ; exit 1 ; fi 222 if [ ! "$INPUT" ] ; then 223 INPUT=$INSTDIR 224 fi 225 if [ ! -d "$INPUT" ] ; then 226 if exists "$INPUT" ; then 227 echo "$INPUT exists, but is not a directory!" 228 else 229 echo "$INPUT does not exist. Create it?" 230 echo2 "[y] " 231 read YN 232 if [ "$YN" != "n" ] ; then 233 if mkdir -p $INPUT ; then 234 ok=1 235 fi 236 fi 237 fi 238 elif exists "$INPUT/include/services.h" ; then 239 echo "You cannot use the Services source directory as a target directory." 240 else 241 ok=1 242 fi 243done 244INSTDIR=$INPUT 245echo "" 246 247#### 248 249OLD_RUNGROUP="$RUNGROUP" 250if [ "$RUNGROUP" ] ; then 251 echo "Which group should all Services data files be owned by? (If Services" 252 echo "should not force files to be owned by a particular group, type \"none\"" 253 echo "(without the quotes) and press Return.)" 254else 255 echo "Which group should all Services data files be owned by? (If Services" 256 echo "should not force files to be owned by a particular group, just press" 257 echo "Return.)" 258fi 259echo2 "[$RUNGROUP] " 260if read INPUT ; then : ; else echo "" ; exit 1 ; fi 261if [ "$INPUT" ] ; then 262 if [ "$INPUT" = "none" ] ; then 263 RUNGROUP="" 264 else 265 RUNGROUP="$INPUT" 266 fi 267fi 268echo "" 269 270#### 271 272if [ ! "$UMASK" -o "$RUNGROUP" != "$OLD_RUNGROUP" ] ; then 273 if [ "$RUNGROUP" ] ; then 274 UMASK=007 275 else 276 UMASK=077 277 fi 278fi 279 280ok=0 281echo "What should the default umask for data files be (in octal)?" 282echo "(077 = only accessible by owner; 007 = accessible by owner and group)" 283while [ $ok -eq 0 ] ; do 284 echo2 "[$UMASK] " 285 if read INPUT ; then : ; else echo "" ; exit 1 ; fi 286 if [ ! "$INPUT" ] ; then 287 INPUT=$UMASK 288 fi 289 if [ `echo "$INPUT" | grep -c '[^0-7]'` -gt 0 ] ; then 290 echo "$UMASK is not a valid octal number!" 291 else 292 if [ "`echo $INPUT | cut -c1`" != "0" ] ; then 293 INPUT=0$INPUT 294 fi 295 ok=1 296 fi 297done 298UMASK=$INPUT 299echo "" 300 301#### 302 303TEMP_YN="n" 304if [ "$DEBUG" = "yes" ] ; then 305 TEMP_YN="y" 306fi 307echo "Would you like to build a debug version of Anope?" 308echo2 "[$TEMP_YN] " 309read YN 310if [ "$YN" ] ; then 311 if [ "$YN" = "y" ] ; then 312 DEBUG="yes" 313 else 314 DEBUG="no" 315 fi 316fi 317echo "" 318 319#### 320 321TEMP_YN="n" 322if [ "$USE_PCH" = "yes" ] ; then 323 TEMP_YN="y" 324fi 325echo "Do you want to build using precompiled headers? This can speed up" 326echo "the build, but uses more disk space." 327echo2 "[$TEMP_YN] " 328read YN 329if [ "$YN" ] ; then 330 if [ "$YN" = "y" ] ; then 331 USE_PCH="yes" 332 else 333 USE_PCH="no" 334 fi 335fi 336echo "" 337 338#### 339 340echo "Are there any extra include directories you wish to use?" 341echo "You may only need to do this if CMake is unable to locate" 342echo "missing dependencies without hints." 343echo "Separate directories with semicolons." 344echo "If you need no extra include directories, enter NONE in all caps." 345echo2 "[$EXTRA_INCLUDE_DIRS] " 346if read INPUT ; then : ; else echo "" ; exit 1 ; fi 347if [ "$INPUT" ] ; then 348 if [ "$INPUT" = "NONE" ] ; then 349 EXTRA_INCLUDE_DIRS="" 350 else 351 EXTRA_INCLUDE_DIRS=$INPUT 352 fi 353fi 354echo "" 355 356#### 357 358echo "Are there any extra library directories you wish to use?" 359echo "You may only need to do this if CMake is unable to locate" 360echo "missing dependencies without hints." 361echo "Separate directories with semicolons." 362echo "If you need no extra library directories, enter NONE in all caps." 363echo2 "[$EXTRA_LIB_DIRS] " 364if read INPUT ; then : ; else echo "" ; exit 1 ; fi 365if [ "$INPUT" ] ; then 366 if [ "$INPUT" = "NONE" ] ; then 367 EXTRA_LIB_DIRS="" 368 else 369 EXTRA_LIB_DIRS=$INPUT 370 fi 371fi 372echo "" 373 374#### 375 376echo "Are there any extra arguments you wish to pass to CMake?" 377echo "If you need no extra arguments to CMake, enter NONE in all caps." 378echo2 "[$EXTRA_CONFIG_ARGS] " 379if read INPUT ; then : ; else echo "" ; exit 1 ; fi 380if [ "$INPUT" ] ; then 381 if [ "$INPUT" = "NONE" ] ; then 382 EXTRA_CONFIG_ARGS="" 383 else 384 EXTRA_CONFIG_ARGS=$INPUT 385 fi 386fi 387echo "" 388 389#### 390 391################################################################################ 392# Store values 393################################################################################ 394 395echo2 "Saving configuration results in config.cache... " 396 397cat <<EOT >$SOURCE_DIR/config.cache 398INSTDIR="$INSTDIR" 399RUNGROUP="$RUNGROUP" 400UMASK=$UMASK 401DEBUG="$DEBUG" 402USE_PCH="$USE_PCH" 403EXTRA_INCLUDE_DIRS="$EXTRA_INCLUDE_DIRS" 404EXTRA_LIB_DIRS="$EXTRA_LIB_DIRS" 405EXTRA_CONFIG_ARGS="$EXTRA_CONFIG_ARGS" 406EOT 407echo "done." 408 409 410################################################################################ 411# Build the build system string 412################################################################################ 413 414Run_Build_System 415