configure
changeset 5475 2e6990a8c7c4
parent 5305 fab86bb654da
child 5480 0933c2bd8279
equal deleted inserted replaced
5474:ac55aefc54f3 5475:2e6990a8c7c4
     1 #!/bin/sh
     1 #!/bin/sh
     2 
     2 
     3 # This 'configure' script is a very easy wrapper around 'make updateconf'
     3 # Find out where configure is (in what dir)
     4 #  It allows cross-compilers to do their job much more easy.
     4 ROOT_DIR="`dirname $0`"
       
     5 ROOT_DIR="`cd $ROOT_DIR && pwd`"
     5 
     6 
     6 function showhelp() {
     7 PWD="`pwd`"
     7 	echo "Configure for OpenTTD"
     8 PREFIX="`pwd`/bin"
     8 	echo ""
       
     9 	echo "Usage:"
       
    10 	echo " $0 --your_options"
       
    11 	echo ""
       
    12 	echo "Params:"
       
    13 	echo " --debug             Create debug-release                [no]"
       
    14 	echo " --profile           Create profile-release              [no]"
       
    15 	echo " --dedicated         Make a dedicated build              [no]"
       
    16 	echo " --revision          Set the revision of the compilation [detected]"
       
    17 	echo " --target-cc         Sets the target-compiler            [\$CC]"
       
    18 	echo " --target-cxx        Sets the C++ target-compiler        []"
       
    19 	echo " --host-cc           Sets the host-compiler              [\$CC]"
       
    20 	echo " --host-cxx          Sets the C++ host-compiler          []"
       
    21 	echo " --os                Sets the OS. Listens to:            [detected]"
       
    22 	echo "                        UNIX, OSX, FREEBSD, MORPHOS"
       
    23 	echo "                        BEOS, SUNOS, CYGWIN, MINGW, OS2"
       
    24 	echo " --windres           Sets the windres (Windows)          [windres]"
       
    25 	echo " --force-le          Force LE platform                   [no]"
       
    26 	echo " --force-be          Force BE platform                   [no]"
       
    27 	echo ""
       
    28 	echo "Params that can be used with --with or --without"
       
    29 	echo "   (e.g.: --without-static disables static (default))"
       
    30 	echo " static              Do you want a static build?         [no]"
       
    31 	echo " directmusic         Do you want direct-music?           [no]"
       
    32 	echo " zlib                Do you want zlib-support?           [yes]"
       
    33 	echo " sdl                 Do you want SDL-support?            [yes]"
       
    34 	echo " png                 Do you want PNG-support?            [yes]"
       
    35 	echo " iconv               Do you want iconv-support?          [no]"
       
    36 	echo " network             Do you want network-support?        [yes]"
       
    37 	echo " cocoa               Do you want cocoa-support? (MacOSX) [no]"
       
    38 	echo " freetype            Do you want freetype-support?       [yes]"
       
    39 	echo " fontconfig          Do you want fontconfig-support?     [yes]"
       
    40 	echo ""
       
    41 	echo "Params used to configure external libs:"
       
    42 	echo " --static-zlib-path  Set the path to your static zlib    []"
       
    43 	echo " --sdl-config        Where is your sdl-config            [sdl-config]"
       
    44 	echo " --libpng-config     Where is your libpng-config         [libpng-config]"
       
    45 	echo " --freetype-config   Where is your freetype-config       [freetype-config]"
       
    46 	echo " --fontconfig-config Where is your fontconfig-config     [pkg-config fontconfig]"
       
    47 	echo " --with-iconv        Set the path to your iconv headers  []"
       
    48 	echo " "
       
    49 }
       
    50 
     9 
    51 function handle() {
    10 . $ROOT_DIR/config.lib
    52 	PARAM="$PARAM \"$1=`awk 'BEGIN { FS="="; $0="'"$2"'"; print $2;}'`\""
       
    53 }
       
    54 
    11 
    55 # The things you can use inside this case:
    12 # Set default dirs
    56 #  handle NAME VALUE - Sets the value to give the 'make upgradeconf'
    13 OBJS_DIR="$PWD/objs"
    57 #                         Value is in form: tag=REAL_VALUE
    14 BASE_SRC_OBJS_DIR="$OBJS_DIR"
    58 #  ITEM="NAME"       - Will set the value as above, only with the next param
    15 LANG_OBJS_DIR="$OBJS_DIR/lang"
    59 #  SITEM="NAME"      - Will set the var $NAME to the next param
    16 BIN_DIR="$PREFIX"
    60 for n in "$@"
    17 SRC_DIR="$ROOT_DIR/src"
    61 do
    18 LANG_DIR="$SRC_DIR/lang"
    62 	case "$n" in
    19 MEDIA_DIR="$ROOT_DIR/media"
    63 		--help | -h)
    20 SOURCE_LIST="$ROOT_DIR/source.list"
    64 			showhelp
       
    65 			exit 0
       
    66 			;;
       
    67 
    21 
    68 		--debug)
    22 if [ "$1" = "--reconfig" ]
    69 			DEBUG_SET=1
       
    70 			ITEM="DEBUG"
       
    71 			;;
       
    72 		--debug=*)
       
    73 			handle "DEBUG" "$n"
       
    74 			;;
       
    75 		--profile)
       
    76 			PARAM="$PARAM PROFILE=1"
       
    77 			;;
       
    78 		--dedicated)
       
    79 			PARAM="$PARAM DEDICATED=1"
       
    80 			;;
       
    81 		--revision=*)
       
    82 			RELEASE=`awk 'BEGIN { FS="="; $0="'"$n"'"; print $2;}'`
       
    83 			;;
       
    84 		--revision)
       
    85 			SITEM="RELEASE"
       
    86 			;;
       
    87 		--target-cc=*)
       
    88 			handle "CC_TARGET" "$n"
       
    89 			;;
       
    90 		--target-cc)
       
    91 			ITEM="CC_TARGET"
       
    92 			;;
       
    93 		--target-cxx=*)
       
    94 			handle "CXX_TARGET" "$n"
       
    95 			;;
       
    96 		--target-cxx)
       
    97 			SITEM="CXX_TARGET"
       
    98 			;;
       
    99 		--host-cc=*)
       
   100 			handle "CC_HOST" "$n"
       
   101 			;;
       
   102 		--host-cc)
       
   103 			ITEM="CC_HOST"
       
   104 			;;
       
   105 		--host-cxx=*)
       
   106 			handle "CXX_HOST" "$n"
       
   107 			;;
       
   108 		--host-cxx)
       
   109 			ITEM="CXX_HOST"
       
   110 			;;
       
   111 		--host-cflags=*)
       
   112 			handle CFLAGS_HOST "$n"
       
   113 			;;
       
   114 		--host-cflags)
       
   115 			ITEM="CFLAGS_HOST"
       
   116 			;;
       
   117 		--os=*)
       
   118 			TARGET_OS=`awk 'BEGIN { FS="="; $0="'"$n"'"; print $2;}'`
       
   119 			;;
       
   120 		--os)
       
   121 			SITEM="TARGET_OS"
       
   122 			;;
       
   123 		--windres=*)
       
   124 			handle WINDRES "$n"
       
   125 			;;
       
   126 		--windres)
       
   127 			ITEM="WINDRES"
       
   128 			;;
       
   129 		--force-le)
       
   130 			PARAM="$PARAM ENDIAN_FORCE=LE"
       
   131 			;;
       
   132 		--force-be)
       
   133 			PARAM="$PARAM ENDIAN_FORCE=BE"
       
   134 			;;
       
   135 
       
   136 		--with-static)
       
   137 			PARAM="$PARAM STATIC=1"
       
   138 			;;
       
   139 		--without-static)
       
   140 			PARAM="$PARAM STATIC="
       
   141 			;;
       
   142 		--with-directmusic)
       
   143 			PARAM="$PARAM WITH_DIRECTMUSIC=1"
       
   144 			;;
       
   145 		--without-directmusic)
       
   146 			PARAM="$PARAM WITH_DIRECTMUSIC="
       
   147 			;;
       
   148 		--with-zlib)
       
   149 			PARAM="$PARAM WITH_ZLIB=1"
       
   150 			;;
       
   151 		--without-zlib)
       
   152 			PARAM="$PARAM WITH_ZLIB="
       
   153 			;;
       
   154 		--with-sdl)
       
   155 			PARAM="$PARAM WITH_SDL=1"
       
   156 			;;
       
   157 		--without-sdl)
       
   158 			PARAM="$PARAM WITH_SDL="
       
   159 			;;
       
   160 		--with-png)
       
   161 			PARAM="$PARAM WITH_PNG=1"
       
   162 			;;
       
   163 		--without-png)
       
   164 			PARAM="$PARAM WITH_PNG="
       
   165 			;;
       
   166 		--with-iconv)
       
   167 			PARAM="$PARAM WITH_ICONV=1"
       
   168 			;;
       
   169 		--with-iconv=*)
       
   170 			PARAM="$PARAM WITH_ICONV=1"
       
   171 			handle WITH_ICONV_PATH "$n"
       
   172 			;;
       
   173 		--without-iconv)
       
   174 			PARAM="$PARAM WITH_ICONV="
       
   175 			;;
       
   176 		--with-cocoa)
       
   177 			PARAM="$PARAM WITH_COCOA=1"
       
   178 			;;
       
   179 		--with-network)
       
   180 			PARAM="$PARAM WITH_NETWORK=1"
       
   181 			;;
       
   182 		--without-network)
       
   183 			PARAM="$PARAM WITH_NETWORK="
       
   184 			;;
       
   185 		--without-cocoa)
       
   186 			PARAM="$PARAM WITH_COCOA="
       
   187 			;;
       
   188 		--with-freetype)
       
   189 			PARAM="$PARAM WITH_FREETYPE=1"
       
   190 			;;
       
   191 		--without-freetype)
       
   192 			PARAM="$PARAM WITH_FREETYPE="
       
   193 			;;
       
   194 		--with-fontconfig)
       
   195 			PARAM="$PARAM WITH_FONTCONFIG=1"
       
   196 			;;
       
   197 		--without-fontconfig)
       
   198 			PARAM="$PARAM WITH_FONTCONFIG="
       
   199 			;;
       
   200 		--static-zlib-path=*)
       
   201 			handle STATIC_ZLIB_PATH "$n"
       
   202 			;;
       
   203 		--static-zlib-path)
       
   204 			ITEM="STATIC_ZLIB_PATH"
       
   205 			;;
       
   206 		--sdl-config=*)
       
   207 			handle SDL_CONFIG "$n"
       
   208 			;;
       
   209 		--sdl-config)
       
   210 			ITEM="SDL_CONFIG"
       
   211 			;;
       
   212 		--libpng-config=*)
       
   213 			handle LIBPNG_CONFIG "$n"
       
   214 			;;
       
   215 		--libpng-config)
       
   216 			ITEM="LIBPNG_CONFIG"
       
   217 			;;
       
   218 		--freetype-config=*)
       
   219 			handle FREETYPE_CONFIG "$n"
       
   220 			;;
       
   221 		--freetype-config)
       
   222 			ITEM="FREETYPE_CONFIG"
       
   223 			;;
       
   224 		--fontconfig-config=*)
       
   225 			handle FONTCONFIG_CONFIG "$n"
       
   226 			;;
       
   227 		--fontconfig-config)
       
   228 			ITEM="FONTCONFIG_CONFIG"
       
   229 			;;
       
   230 
       
   231 		--*=*)
       
   232 			echo -n "Unknown switch "
       
   233 			echo `awk 'BEGIN { FS="="; $0="'"$n"'"; print $1;}'`
       
   234 			exit 1
       
   235 			;;
       
   236 		-*)
       
   237 			echo "Unknown switch $n"
       
   238 			exit 1
       
   239 			;;
       
   240 
       
   241 		*)
       
   242 			if ! test -z "$ITEM"
       
   243 			then
       
   244 				PARAM="$PARAM $ITEM=\"$n\""
       
   245 				ITEM="";
       
   246 			elif ! test -z "$SITEM"
       
   247 			then
       
   248 				export $SITEM="$n"
       
   249 				SITEM=""
       
   250 			else
       
   251 				echo "Unknown switch $n"
       
   252 				exit 1
       
   253 			fi
       
   254 			;;
       
   255 	esac
       
   256 done
       
   257 
       
   258 if ! test -z "$TARGET_OS"
       
   259 then
    23 then
   260 	TARGET_OS=`echo $TARGET_OS | tr '[:lower:]' '[:upper:]'`
    24 	if ! [ -f "config.cache" ]
   261 	case "$TARGET_OS" in
    25 	then
   262 		WIN32)
    26 		echo "can't reconfigure, because never configured before"
   263 			PARAM="$PARAM WIN32=1"
    27 		exit 1
   264 			;;
    28 	fi
   265 		UNIX)
    29 	# Make sure we don't lock config.cache
   266 			PARAM="$PARAM UNIX=1"
    30 	configure=`cat config.cache`
   267 			;;
    31 	$configure
   268 		OSX)
    32 	exit $?
   269 			PARAM="$PARAM OSX=1 UNIX=1"
       
   270 			;;
       
   271 		FREEBSD)
       
   272 			PARAM="$PARAM FREEBSD=1"
       
   273 			;;
       
   274 		MORPHOS)
       
   275 			PARAM="$PARAM MORPHOS=1 UNIX=1"
       
   276 			;;
       
   277 		BEOS)
       
   278 			PARAM="$PARAM BEOS=1 UNIX=1"
       
   279 			;;
       
   280 		OS2)
       
   281 			PARAM="$PARAM OS2=1 UNIX=1"
       
   282 			;;
       
   283 		SUNOS)
       
   284 			PARAM="$PARAM SUNOS=1 UNIX=1"
       
   285 			;;
       
   286 		CYGWIN)
       
   287 			PARAM="$PARAM CYGWIN=1 WIN32=1"
       
   288 			;;
       
   289 		MINGW)
       
   290 			PARAM="$PARAM MINGW=1 WIN32=1"
       
   291 			;;
       
   292 		*)
       
   293 			echo "Unknown OS: $TARGET_OS"
       
   294 			exit 1
       
   295 			;;
       
   296 	esac
       
   297 	PARAM="$PARAM BYPASS_OS_DETECT=1"
       
   298 fi
    33 fi
   299 
    34 
   300 if ! test -z "$DEBUG_SET"
    35 set_default
       
    36 detect_params $@
       
    37 save_params
       
    38 check_params
       
    39 make_cflags_and_ldflags
       
    40 
       
    41 EXE=""
       
    42 if [ "$os" = "MINGW" ] || [ "$os" = "CYGWIN" ] || [ "$os" = "OS2" ]
   301 then
    43 then
   302 	if test -z "`echo $PARAM | grep "DEBUG="`"
    44 	EXE=".exe"
   303 	then
       
   304 		# Someone did --debug, without assigning a value, assume 1
       
   305 		PARAM="$PARAM DEBUG=1"
       
   306 	fi
       
   307 fi
    45 fi
   308 
    46 
   309 # First remove the Makefile.config, else you can have double entries
    47 TTD="openttd$EXE"
   310 rm -f Makefile.config
    48 STRGEN="strgen$EXE"
       
    49 ENDIAN_CHECK="endian_check$EXE"
   311 
    50 
   312 echo "make upgradeconf $PARAM" > Makefile.run
    51 if [ -z "$sort" ]
   313 . Makefile.run
       
   314 rm -f Makefile.run
       
   315 
       
   316 # Makefile.config currently doesn't support custom RELEASE (revision), so, we add the line
       
   317 # yourself!
       
   318 
       
   319 if ! test -z "$RELEASE"
       
   320 then
    52 then
   321 	echo "RELEASE=$RELEASE" >> Makefile.config
    53 	PIPE_SORT="sed s/a/a/"
       
    54 else
       
    55 	PIPE_SORT="$sort"
   322 fi
    56 fi
   323 
    57 
       
    58 if ! [ -f "$LANG_DIR/english.txt" ]
       
    59 then
       
    60 	echo "Languages not found in $LANG_DIR. Can't continue without it."
       
    61 	echo "Please make sure the dir exists and contains at least english.txt"
       
    62 fi
       
    63 
       
    64 # Read the source.list and process it
       
    65 SRCS="`cat $ROOT_DIR/source.list | tr '\r' '\n' | awk '
       
    66 	{  }
       
    67 	/^(	*)#end/  { if (deep == skip) { skip -= 1; } deep -= 1; next; }
       
    68 	/^(	*)#else/ { if (deep == skip) { skip -= 1; } else if (deep - 1 == skip) { skip += 1; } next; }
       
    69 	/^(	*)#if/   {
       
    70 		gsub("	", "", $0);
       
    71 		gsub("^#if ", "", $0);
       
    72 
       
    73 		if (deep != skip) { deep += 1; next; }
       
    74 
       
    75 		deep += 1;
       
    76 
       
    77 		if ($0 == "SDL"         && "'$sdl_config'" == "")          { next; }
       
    78 		if ($0 == "OSX"         && "'$os'" != "OSX")               { next; }
       
    79 		if ($0 == "DEDICATED"   && "'$enable_dedicated'" != "1")   { next; }
       
    80 		if ($0 == "COCOA"       && "'$with_cocoa'" == "0")         { next; }
       
    81 		if ($0 == "BEOS"        && "'$os'" != "BEOS")              { next; }
       
    82 		if ($0 == "WIN32"       && "'$os'" != "MINGW" &&
       
    83 		                "'$os'" != "CYGWIN" && "'$os'" != "MSVC" ) { next; }
       
    84 		if ($0 == "MSVC"        && "'$os'" != "MSVC")              { next; }
       
    85 		if ($0 == "DIRECTMUSIC" && "'$with_direct_music'" != "1")  { next; }
       
    86 
       
    87 		skip += 1;
       
    88 
       
    89 		next;
       
    90 	}
       
    91 	/^(	*)#/ { next }
       
    92 	/^$/ { next }
       
    93 	/\.h$/ { next }
       
    94 	/\.hpp$/ { next }
       
    95 	{
       
    96 		if (deep == skip) {
       
    97 			gsub("	", "", $0);
       
    98 			print $0;
       
    99 		}
       
   100 	}
       
   101 ' | $PIPE_SORT`"
       
   102 
       
   103 OBJS_C="`  echo \"$SRCS\" | awk ' { ORS = " " } /\.c$/   { gsub(".c$",   ".o", $0); print $0; }'`"
       
   104 OBJS_CPP="`echo \"$SRCS\" | awk ' { ORS = " " } /\.cpp$/ { gsub(".cpp$", ".o", $0); print $0; }'`"
       
   105 OBJS_M="`  echo \"$SRCS\" | awk ' { ORS = " " } /\.m$/   { gsub(".m$",   ".o", $0); print $0; }'`"
       
   106 OBJS_RC="` echo \"$SRCS\" | awk ' { ORS = " " } /\.rc$/  { gsub(".rc$",  ".o", $0); print $0; }'`"
       
   107 SRCS="`    echo \"$SRCS\" | awk ' { ORS = " " } { print $0; }'`"
       
   108 
       
   109 # In makefiles, we always use -u for sort
       
   110 if [ -z "$sort" ]
       
   111 then
       
   112 	sort="sed s/a/a/"
       
   113 else
       
   114 	sort="$sort -u"
       
   115 fi
       
   116 
       
   117 CONFIGURE_FILES="$ROOT_DIR/configure $ROOT_DIR/config.lib $ROOT_DIR/Makefile.in $ROOT_DIR/Makefile.lang.in $ROOT_DIR/Makefile.src.in"
       
   118 
       
   119 generate_main
       
   120 generate_lang
       
   121 generate_src