From 407aee486da3afd67f48689f7aaa5732e755bb6c Mon Sep 17 00:00:00 2001 From: Pawel Kolodziejski Date: Thu, 12 Jun 2008 12:08:15 +0000 Subject: [PATCH] - initial support for configure based on scummvm tree (tested mac os x leopard, linux(ubuntu), cygwin with mingwin gcc) - adopted more common dir code from scummvm for easier multi platform support - synced some changes from scummvm code --- COPYING.GPL | 340 +++++ Makefile | 78 +- Makefile.common | 222 ++-- Makefile.cross | 11 - Makefile.mingw | 26 - README | 2 +- common/algorithm.h | 154 +++ common/array.h | 180 +++ common/debug.cpp | 4 +- common/debug.h | 2 +- common/endian.h | 217 ++++ common/func.h | 303 +++++ common/hash-str.h | 86 ++ common/hashmap.cpp | 90 ++ common/hashmap.h | 541 ++++++++ common/list.h | 82 +- common/matrix3.cpp | 5 +- common/memorypool.cpp | 118 ++ common/memorypool.h | 54 + common/module.mk | 14 + common/platform.h | 388 ------ common/str.cpp | 484 +++++++ common/str.h | 224 ++++ common/sys.h | 301 +++-- common/util.h | 60 + common/vector3d.h | 41 +- common/zlib.cpp | 41 + common/zlib.h | 48 + config.guess | 1516 ++++++++++++++++++++++ config.sub | 1626 ++++++++++++++++++++++++ configure | 1238 ++++++++++++++++++ dists/residual.rc | 4 +- engine/actor.cpp | 12 +- engine/backend/dc/driver_ronin_gfx.cpp | 2 +- engine/backend/driver.h | 2 +- engine/backend/module.mk | 7 + engine/backend/sdl/driver_gl.cpp | 3 +- engine/backend/sdl/driver_gl.h | 2 +- engine/backend/sdl/driver_sdl.cpp | 18 + engine/backend/sdl/driver_tinygl.cpp | 4 +- engine/backend/sdl/driver_tinygl.h | 2 +- engine/backend/sdl/module.mk | 12 + engine/bitmap.cpp | 2 +- engine/color.h | 2 +- engine/costume.cpp | 25 +- engine/engine.cpp | 2 + engine/engine.h | 13 - engine/font.cpp | 2 +- engine/font.h | 2 +- engine/imuse/imuse.cpp | 1 - engine/imuse/imuse.h | 1 - engine/imuse/imuse_mcmp_mgr.cpp | 2 +- engine/imuse/imuse_mcmp_mgr.h | 1 - engine/imuse/imuse_music.cpp | 1 - engine/imuse/imuse_script.cpp | 1 - engine/imuse/imuse_sndmgr.cpp | 6 +- engine/imuse/imuse_sndmgr.h | 1 - engine/imuse/imuse_tables.cpp | 1 - engine/imuse/imuse_tables.h | 1 - engine/imuse/imuse_track.cpp | 1 - engine/imuse/imuse_track.h | 1 - engine/imuse/module.mk | 13 + engine/keyframe.cpp | 2 +- engine/lab.cpp | 2 +- engine/lipsynch.cpp | 2 +- engine/lipsynch.h | 3 +- engine/lua.cpp | 91 +- engine/lua.h | 2 + engine/lua/lmathlib.cpp | 14 +- engine/lua/module.mk | 30 + engine/main.cpp | 14 +- engine/material.cpp | 2 +- engine/model.cpp | 2 +- engine/module.mk | 28 + engine/resource.cpp | 4 + engine/smush/blocky16.cpp | 2 +- engine/smush/blocky16.h | 2 +- engine/smush/module.mk | 9 + engine/smush/smush.cpp | 2 +- engine/smush/smush.h | 1 - engine/smush/vima.cpp | 2 +- engine/textobject.cpp | 1 + engine/tinygl/light.cpp | 2 +- engine/tinygl/matrix.cpp | 2 +- engine/tinygl/module.mk | 28 + engine/tinygl/zgl.h | 8 +- mixer/audiostream.cpp | 36 +- mixer/audiostream.h | 5 +- mixer/mixer.cpp | 2 +- mixer/mixer.h | 1 - mixer/module.mk | 18 + mixer/rate.cpp | 1 + mixer/rate.h | 2 +- ports.mk | 177 +++ rules.mk | 67 + 95 files changed, 8389 insertions(+), 818 deletions(-) create mode 100644 COPYING.GPL delete mode 100644 Makefile.cross delete mode 100644 Makefile.mingw create mode 100644 common/algorithm.h create mode 100644 common/array.h create mode 100644 common/endian.h create mode 100644 common/func.h create mode 100644 common/hash-str.h create mode 100644 common/hashmap.cpp create mode 100644 common/hashmap.h create mode 100644 common/memorypool.cpp create mode 100644 common/memorypool.h create mode 100644 common/module.mk delete mode 100644 common/platform.h create mode 100644 common/str.cpp create mode 100644 common/str.h create mode 100644 common/util.h create mode 100644 common/zlib.cpp create mode 100644 common/zlib.h create mode 100755 config.guess create mode 100755 config.sub create mode 100755 configure create mode 100644 engine/backend/module.mk create mode 100644 engine/backend/sdl/module.mk create mode 100644 engine/imuse/module.mk create mode 100644 engine/lua/module.mk create mode 100644 engine/module.mk create mode 100644 engine/smush/module.mk create mode 100644 engine/tinygl/module.mk create mode 100644 mixer/module.mk create mode 100644 ports.mk create mode 100644 rules.mk diff --git a/COPYING.GPL b/COPYING.GPL new file mode 100644 index 00000000000..b6f92f3dbfa --- /dev/null +++ b/COPYING.GPL @@ -0,0 +1,340 @@ + GNU GENERAL PUBLIC LICENSE + Version 2, June 1991 + + Copyright (C) 1989, 1991 Free Software Foundation, Inc. + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The licenses for most software are designed to take away your +freedom to share and change it. By contrast, the GNU General Public +License is intended to guarantee your freedom to share and change free +software--to make sure the software is free for all its users. This +General Public License applies to most of the Free Software +Foundation's software and to any other program whose authors commit to +using it. (Some other Free Software Foundation software is covered by +the GNU Library General Public License instead.) You can apply it to +your programs, too. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +this service if you wish), that you receive source code or can get it +if you want it, that you can change the software or use pieces of it +in new free programs; and that you know you can do these things. + + To protect your rights, we need to make restrictions that forbid +anyone to deny you these rights or to ask you to surrender the rights. +These restrictions translate to certain responsibilities for you if you +distribute copies of the software, or if you modify it. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must give the recipients all the rights that +you have. You must make sure that they, too, receive or can get the +source code. And you must show them these terms so they know their +rights. + + We protect your rights with two steps: (1) copyright the software, and +(2) offer you this license which gives you legal permission to copy, +distribute and/or modify the software. + + Also, for each author's protection and ours, we want to make certain +that everyone understands that there is no warranty for this free +software. If the software is modified by someone else and passed on, we +want its recipients to know that what they have is not the original, so +that any problems introduced by others will not reflect on the original +authors' reputations. + + Finally, any free program is threatened constantly by software +patents. We wish to avoid the danger that redistributors of a free +program will individually obtain patent licenses, in effect making the +program proprietary. To prevent this, we have made it clear that any +patent must be licensed for everyone's free use or not licensed at all. + + The precise terms and conditions for copying, distribution and +modification follow. + + GNU GENERAL PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. This License applies to any program or other work which contains +a notice placed by the copyright holder saying it may be distributed +under the terms of this General Public License. The "Program", below, +refers to any such program or work, and a "work based on the Program" +means either the Program or any derivative work under copyright law: +that is to say, a work containing the Program or a portion of it, +either verbatim or with modifications and/or translated into another +language. (Hereinafter, translation is included without limitation in +the term "modification".) Each licensee is addressed as "you". + +Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope. The act of +running the Program is not restricted, and the output from the Program +is covered only if its contents constitute a work based on the +Program (independent of having been made by running the Program). +Whether that is true depends on what the Program does. + + 1. You may copy and distribute verbatim copies of the Program's +source code as you receive it, in any medium, provided that you +conspicuously and appropriately publish on each copy an appropriate +copyright notice and disclaimer of warranty; keep intact all the +notices that refer to this License and to the absence of any warranty; +and give any other recipients of the Program a copy of this License +along with the Program. + +You may charge a fee for the physical act of transferring a copy, and +you may at your option offer warranty protection in exchange for a fee. + + 2. You may modify your copy or copies of the Program or any portion +of it, thus forming a work based on the Program, and copy and +distribute such modifications or work under the terms of Section 1 +above, provided that you also meet all of these conditions: + + a) You must cause the modified files to carry prominent notices + stating that you changed the files and the date of any change. + + b) You must cause any work that you distribute or publish, that in + whole or in part contains or is derived from the Program or any + part thereof, to be licensed as a whole at no charge to all third + parties under the terms of this License. + + c) If the modified program normally reads commands interactively + when run, you must cause it, when started running for such + interactive use in the most ordinary way, to print or display an + announcement including an appropriate copyright notice and a + notice that there is no warranty (or else, saying that you provide + a warranty) and that users may redistribute the program under + these conditions, and telling the user how to view a copy of this + License. (Exception: if the Program itself is interactive but + does not normally print such an announcement, your work based on + the Program is not required to print an announcement.) + +These requirements apply to the modified work as a whole. If +identifiable sections of that work are not derived from the Program, +and can be reasonably considered independent and separate works in +themselves, then this License, and its terms, do not apply to those +sections when you distribute them as separate works. But when you +distribute the same sections as part of a whole which is a work based +on the Program, the distribution of the whole must be on the terms of +this License, whose permissions for other licensees extend to the +entire whole, and thus to each and every part regardless of who wrote it. + +Thus, it is not the intent of this section to claim rights or contest +your rights to work written entirely by you; rather, the intent is to +exercise the right to control the distribution of derivative or +collective works based on the Program. + +In addition, mere aggregation of another work not based on the Program +with the Program (or with a work based on the Program) on a volume of +a storage or distribution medium does not bring the other work under +the scope of this License. + + 3. You may copy and distribute the Program (or a work based on it, +under Section 2) in object code or executable form under the terms of +Sections 1 and 2 above provided that you also do one of the following: + + a) Accompany it with the complete corresponding machine-readable + source code, which must be distributed under the terms of Sections + 1 and 2 above on a medium customarily used for software interchange; or, + + b) Accompany it with a written offer, valid for at least three + years, to give any third party, for a charge no more than your + cost of physically performing source distribution, a complete + machine-readable copy of the corresponding source code, to be + distributed under the terms of Sections 1 and 2 above on a medium + customarily used for software interchange; or, + + c) Accompany it with the information you received as to the offer + to distribute corresponding source code. (This alternative is + allowed only for noncommercial distribution and only if you + received the program in object code or executable form with such + an offer, in accord with Subsection b above.) + +The source code for a work means the preferred form of the work for +making modifications to it. For an executable work, complete source +code means all the source code for all modules it contains, plus any +associated interface definition files, plus the scripts used to +control compilation and installation of the executable. However, as a +special exception, the source code distributed need not include +anything that is normally distributed (in either source or binary +form) with the major components (compiler, kernel, and so on) of the +operating system on which the executable runs, unless that component +itself accompanies the executable. + +If distribution of executable or object code is made by offering +access to copy from a designated place, then offering equivalent +access to copy the source code from the same place counts as +distribution of the source code, even though third parties are not +compelled to copy the source along with the object code. + + 4. You may not copy, modify, sublicense, or distribute the Program +except as expressly provided under this License. Any attempt +otherwise to copy, modify, sublicense or distribute the Program is +void, and will automatically terminate your rights under this License. +However, parties who have received copies, or rights, from you under +this License will not have their licenses terminated so long as such +parties remain in full compliance. + + 5. You are not required to accept this License, since you have not +signed it. However, nothing else grants you permission to modify or +distribute the Program or its derivative works. These actions are +prohibited by law if you do not accept this License. Therefore, by +modifying or distributing the Program (or any work based on the +Program), you indicate your acceptance of this License to do so, and +all its terms and conditions for copying, distributing or modifying +the Program or works based on it. + + 6. Each time you redistribute the Program (or any work based on the +Program), the recipient automatically receives a license from the +original licensor to copy, distribute or modify the Program subject to +these terms and conditions. You may not impose any further +restrictions on the recipients' exercise of the rights granted herein. +You are not responsible for enforcing compliance by third parties to +this License. + + 7. If, as a consequence of a court judgment or allegation of patent +infringement or for any other reason (not limited to patent issues), +conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot +distribute so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you +may not distribute the Program at all. For example, if a patent +license would not permit royalty-free redistribution of the Program by +all those who receive copies directly or indirectly through you, then +the only way you could satisfy both it and this License would be to +refrain entirely from distribution of the Program. + +If any portion of this section is held invalid or unenforceable under +any particular circumstance, the balance of the section is intended to +apply and the section as a whole is intended to apply in other +circumstances. + +It is not the purpose of this section to induce you to infringe any +patents or other property right claims or to contest validity of any +such claims; this section has the sole purpose of protecting the +integrity of the free software distribution system, which is +implemented by public license practices. Many people have made +generous contributions to the wide range of software distributed +through that system in reliance on consistent application of that +system; it is up to the author/donor to decide if he or she is willing +to distribute software through any other system and a licensee cannot +impose that choice. + +This section is intended to make thoroughly clear what is believed to +be a consequence of the rest of this License. + + 8. If the distribution and/or use of the Program is restricted in +certain countries either by patents or by copyrighted interfaces, the +original copyright holder who places the Program under this License +may add an explicit geographical distribution limitation excluding +those countries, so that distribution is permitted only in or among +countries not thus excluded. In such case, this License incorporates +the limitation as if written in the body of this License. + + 9. The Free Software Foundation may publish revised and/or new versions +of the General Public License from time to time. Such new versions will +be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + +Each version is given a distinguishing version number. If the Program +specifies a version number of this License which applies to it and "any +later version", you have the option of following the terms and conditions +either of that version or of any later version published by the Free +Software Foundation. If the Program does not specify a version number of +this License, you may choose any version ever published by the Free Software +Foundation. + + 10. If you wish to incorporate parts of the Program into other free +programs whose distribution conditions are different, write to the author +to ask for permission. For software which is copyrighted by the Free +Software Foundation, write to the Free Software Foundation; we sometimes +make exceptions for this. Our decision will be guided by the two goals +of preserving the free status of all derivatives of our free software and +of promoting the sharing and reuse of software generally. + + NO WARRANTY + + 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY +FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN +OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES +PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED +OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS +TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE +PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, +REPAIR OR CORRECTION. + + 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR +REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, +INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING +OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED +TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY +YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER +PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE +POSSIBILITY OF SUCH DAMAGES. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + + To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +convey the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + + Copyright (C) + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA + + +Also add information on how to contact you by electronic and paper mail. + +If the program is interactive, make it output a short notice like this +when it starts in an interactive mode: + + Gnomovision version 69, Copyright (C) year name of author + Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. + This is free software, and you are welcome to redistribute it + under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the appropriate +parts of the General Public License. Of course, the commands you use may +be called something other than `show w' and `show c'; they could even be +mouse-clicks or menu items--whatever suits your program. + +You should also get your employer (if you work as a programmer) or your +school, if any, to sign a "copyright disclaimer" for the program, if +necessary. Here is a sample; alter the names: + + Yoyodyne, Inc., hereby disclaims all copyright interest in the program + `Gnomovision' (which makes passes at compilers) written by James Hacker. + + , 1 April 1989 + Ty Coon, President of Vice + +This General Public License does not permit incorporating your program into +proprietary programs. If your program is a subroutine library, you may +consider it more useful to permit linking proprietary applications with the +library. If this is what you want to do, use the GNU Library General +Public License instead of this License. diff --git a/Makefile b/Makefile index 8797eb36721..ff8cf30b77d 100644 --- a/Makefile +++ b/Makefile @@ -1,11 +1,71 @@ -CXX = g++ -CC = gcc -AR = ar rcu -CXXFLAGS = -g -W -Wall `sdl-config --cflags` -I. -DUNIX -Wno-multichar -Wno-unknown-pragmas -Wno-unused-parameter # -O2 -LDFLAGS = -g -W -Wall -LIBS = `sdl-config --libs` -lz +# $URL$ +# $Id$ -# Comment this out for Mac OS X ... -LIBS += -lGL -lGLU +####################################################################### +# Default compilation parameters. Normally don't edit these # +####################################################################### -include Makefile.common +srcdir ?= . + +DEFINES := -DHAVE_CONFIG_H +LDFLAGS := +INCLUDES := -I. -I$(srcdir) +LIBS := +OBJS := +DEPDIR := .deps + +MODULES := +MODULE_DIRS := + +# Load the make rules generated by configure +-include config.mk + +CXXFLAGS:= -Wall $(CXXFLAGS) +# Turn off some annoying and not-so-useful warnings +CXXFLAGS+= -Wno-long-long -Wno-multichar -Wno-unknown-pragmas -Wno-reorder -Wno-unused-parameter +# Enable even more warnings... +#CXXFLAGS+= -pedantic -Wpointer-arith -Wcast-qual -Wcast-align +#CXXFLAGS+= -Wimplicit -Wundef -Wnon-virtual-dtor -Wwrite-strings + +# Disable RTTI and exceptions, and enabled checking of pointers returned by "new" +#CXXFLAGS+= -fno-rtti -fno-exceptions -fcheck-new + +# There is a nice extra warning that flags variables that are potentially +# used before being initialized. Very handy to catch a certain kind of +# bugs. Unfortunately, it only works when optimizations are turned on, +# which is why we normally don't use it. +#CXXFLAGS+= -O -Wuninitialized + +####################################################################### +# Default commands - put the necessary replacements in config.mk # +####################################################################### + +CAT ?= cat +CP ?= cp +ECHO ?= printf +INSTALL ?= install +MKDIR ?= mkdir -p +RM ?= rm -f +RM_REC ?= $(RM) -r +ZIP ?= zip -q + +####################################################################### +# Misc stuff - you should never have to edit this # +####################################################################### + +EXECUTABLE := residual$(EXEEXT) + +include $(srcdir)/Makefile.common + +# check if configure has been run or has been changed since last run +config.h config.mk: $(srcdir)/configure +ifeq "$(findstring config.mk,$(MAKEFILE_LIST))" "config.mk" + @echo "Running $(srcdir)/configure with the last specified parameters" + @sleep 2s + LDFLAGS="$(SAVED_LDFLAGS)" CXX="$(SAVED_CXX)" CXXFLAGS="$(SAVED_CXXFLAGS)" CPPFLAGS="$(SAVED_CPPFLAGS)" \ + $(srcdir)/configure $(SAVED_CONFIGFLAGS) +else + $(error You need to run $(srcdir)/configure before you can run make. Check $(srcdir)/configure --help for a list of parameters) +endif + +include $(srcdir)/ports.mk diff --git a/Makefile.common b/Makefile.common index 6add8f6641e..f11fccb46cc 100644 --- a/Makefile.common +++ b/Makefile.common @@ -1,110 +1,126 @@ -OBJS =\ - common/debug.o \ - common/matrix3.o \ - common/matrix4.o \ - common/mutex.o \ - mixer/audiostream.o \ - mixer/mixer.o \ - mixer/rate.o \ - engine/lua/lapi.o \ - engine/lua/lauxlib.o \ - engine/lua/lbuffer.o \ - engine/lua/lbuiltin.o \ - engine/lua/ldo.o \ - engine/lua/lfunc.o \ - engine/lua/lgc.o \ - engine/lua/liolib.o \ - engine/lua/llex.o \ - engine/lua/lmathlib.o \ - engine/lua/lmem.o \ - engine/lua/lobject.o \ - engine/lua/lparser.o \ - engine/lua/lrestore.o \ - engine/lua/lsave.o \ - engine/lua/lstate.o \ - engine/lua/lstring.o \ - engine/lua/lstrlib.o \ - engine/lua/ltable.o \ - engine/lua/ltask.o \ - engine/lua/ltm.o \ - engine/lua/lundump.o \ - engine/lua/lvm.o \ - engine/lua/lzio.o \ - engine/imuse/imuse.o \ - engine/imuse/imuse_mcmp_mgr.o \ - engine/imuse/imuse_music.o \ - engine/imuse/imuse_script.o \ - engine/imuse/imuse_sndmgr.o \ - engine/imuse/imuse_tables.o \ - engine/imuse/imuse_track.o \ - engine/smush/blocky16.o \ - engine/smush/smush.o \ - engine/smush/vima.o \ - engine/actor.o \ - engine/bitmap.o \ - engine/costume.o \ - engine/engine.o \ - engine/savegame.o \ - engine/font.o \ - engine/keyframe.o \ - engine/lab.o \ - engine/lipsynch.o \ - engine/localize.o \ - engine/lua.o \ - engine/main.o \ - engine/material.o \ - engine/model.o \ - engine/objectstate.o \ - engine/primitives.o \ - engine/registry.o \ - engine/resource.o \ - engine/scene.o \ - engine/textobject.o \ - engine/textsplit.o \ - engine/walkplane.o \ - $(DRIVER_OBJS) +# This file is used by Makefile and declares common build rules, +# a list of common object files etc. +# +# $URL$ +# $Id$ -DRIVER_OBJS ?=\ - engine/backend/default-timer.o \ - engine/backend/sdl/driver_sdl.o \ - engine/backend/sdl/driver_gl.o \ - engine/backend/sdl/driver_tinygl.o \ - $(TINYGL_OBJS) +###################################################################### +# The default build target: just build the scummvm executable +###################################################################### -TINYGL_OBJS =\ - engine/tinygl/api.o \ - engine/tinygl/arrays.o \ - engine/tinygl/clear.o \ - engine/tinygl/clip.o \ - engine/tinygl/error.o \ - engine/tinygl/get.o \ - engine/tinygl/image_util.o \ - engine/tinygl/init.o \ - engine/tinygl/light.o \ - engine/tinygl/list.o \ - engine/tinygl/matrix.o \ - engine/tinygl/memory.o \ - engine/tinygl/misc.o \ - engine/tinygl/msghandling.o \ - engine/tinygl/select.o \ - engine/tinygl/specbuf.o \ - engine/tinygl/texture.o \ - engine/tinygl/vertex.o \ - engine/tinygl/zbuffer.o \ - engine/tinygl/zline.o \ - engine/tinygl/zmath.o \ - engine/tinygl/ztriangle.o +all: $(EXECUTABLE) -DEPS = $(OBJS:.o=.d) -residual: $(OBJS) - $(CXX) $(LDFLAGS) -o $@ $(OBJS) $(LIBS) +###################################################################### +# Module settings +###################################################################### -.cpp.o: - @test -d $(*D) || mkdir -p $(*D) - $(CXX) $(CXXFLAGS) -Wp,-MMD,"$*.d",-MQ,"$*.o",-MP -c $(<) -o $*.o +MODULES := $(MODULES) -clean: - -rm -f residual$(EXEEXT) *.o *.d common/*.[od] engine/*.[od] engine/backend/sdl/*.[od] engine/imuse/*.[od] engine/lua/*.[od] engine/smush/*.[od] engine/tinygl/*.[od] mixer/*.[od] +# After the game specific modules follow the shared modules +MODULES += \ + engine \ + engine/backend \ + engine/imuse \ + engine/lua \ + engine/smush \ + engine/tinygl \ + common \ + mixer --include $(DEPS) + +###################################################################### +# The build rules follow - normally you should have no need to +# touch whatever comes after here. +###################################################################### + +# Concat DEFINES and INCLUDES to form the CPPFLAGS +CPPFLAGS := $(DEFINES) $(INCLUDES) + +# Include the build instructions for all modules +-include $(addprefix $(srcdir)/, $(addsuffix /module.mk,$(MODULES))) + +# Depdir information +DEPDIRS = $(addsuffix $(DEPDIR),$(MODULE_DIRS)) +DEPFILES = + +# The build rule for the Residual executable +$(EXECUTABLE): $(OBJS) + $(CXX) $(LDFLAGS) $(PRE_OBJS_FLAGS) $+ $(POST_OBJS_FLAGS) $(LIBS) -o $@ + +distclean: clean + $(RM) config.h config.mk config.log + +clean: + $(RM_REC) $(DEPDIRS) + $(RM) $(OBJS) $(EXECUTABLE) + +ifndef HAVE_GCC3 +# If you use GCC, disable the above and enable this for intelligent +# dependency tracking. +%.o: %.cpp + $(MKDIR) $(*D)/$(DEPDIR) + $(CXX) -Wp,-MMD,"$(*D)/$(DEPDIR)/$(*F).d2" $(CXXFLAGS) $(CPPFLAGS) -c $(<) -o $*.o + $(ECHO) "$(*D)/" > $(*D)/$(DEPDIR)/$(*F).d + $(CAT) "$(*D)/$(DEPDIR)/$(*F).d2" >> "$(*D)/$(DEPDIR)/$(*F).d" + $(RM) "$(*D)/$(DEPDIR)/$(*F).d2" +else +# If you even have GCC 3.x, you can use this build rule, which is safer; the above +# rule can get you into a bad state if you Ctrl-C at the wrong moment. +# Also, with this GCC inserts additional dummy rules for the involved headers, +# which ensures a smooth compilation even if said headers become obsolete. +%.o: %.cpp + $(MKDIR) $(*D)/$(DEPDIR) + $(CXX) -Wp,-MMD,"$(*D)/$(DEPDIR)/$(*F).d",-MQ,"$@",-MP $(CXXFLAGS) $(CPPFLAGS) -c $(<) -o $*.o +%.o: %.m + $(MKDIR) $(*D)/$(DEPDIR) + $(CXX) -Wp,-MMD,"$(*D)/$(DEPDIR)/$(*F).d",-MQ,"$@",-MP $(OBJCFLAGS) -c $(<) -o $*.o +endif + +# Include the dependency tracking files. +-include $(wildcard $(addsuffix /*.d,$(DEPDIRS))) + + +###################################################################### +# Create the files that depend on the version +###################################################################### + + +###################################################################### +# Distribution settings +###################################################################### + +ifeq ($(VER_EXTRA),svn) +DISTVERSION = $(shell date '+%Y-%m-%d') +else +DISTVERSION = $(VERSION) +endif + +DISTNAME := residual-$(DISTVERSION) +DISTDIR := dist + +ifeq ($(shell svn stat $(srcdir) 2>&1 | grep "is not a working copy"),) +SVNROOT := $(srcdir) +else +SVNROOT := https://scummvm.svn.sourceforge.net/svnroot/scummvm/residual/trunk/ +endif + + +$(DISTDIR)/$(DISTNAME).tar.gz: + cd $(DISTDIR); tar zcf $(DISTNAME).tar.gz $(DISTNAME) + +$(DISTDIR)/$(DISTNAME).tar.bz2: + cd $(DISTDIR); tar jcf $(DISTNAME).tar.bz2 $(DISTNAME) + +$(DISTDIR)/$(DISTNAME).zip: + cd $(DISTDIR); zip -qr9 $(DISTNAME).zip $(DISTNAME) + +dist-src: \ + $(DISTDIR)/$(DISTNAME).tar.gz \ + $(DISTDIR)/$(DISTNAME).tar.bz2 \ + $(DISTDIR)/$(DISTNAME).zip + @#RPM-src? + @#DEB-src? + + +.PHONY: all clean distclean dist-src diff --git a/Makefile.cross b/Makefile.cross deleted file mode 100644 index 70ee387dcff..00000000000 --- a/Makefile.cross +++ /dev/null @@ -1,11 +0,0 @@ -### Modify these paths if needed -SDL_CFLAGS=-I/usr/i586-mingw32msvc/include/SDL -SDL_LIBS=-L/usr/i586-mingw32msvc/lib -lSDL - -CXX = i586-mingw32msvc-g++ -CXXFLAGS = -W -Wall -Wno-multichar -I. $(SDL_CFLAGS) # -O2 -LDFLAGS = -W -Wall # -O2 -LIBS = -lmingw32 -lopengl32 -lglu32 -lgdi32 $(SDL_LIBS) -lz -EXEEXT =.exe - -include Makefile.common diff --git a/Makefile.mingw b/Makefile.mingw deleted file mode 100644 index c31133e80fb..00000000000 --- a/Makefile.mingw +++ /dev/null @@ -1,26 +0,0 @@ -# Where residual will be installed -RESIDUALPATH=C:/residual - -### Modify these paths -SDL_CFLAGS=`sdl-config --cflags` -SDL_LIBS=`sdl-config --libs` - -CXX = g++ -CXXFLAGS = -g -W -Wall -Wno-multichar -I. $(SDL_CFLAGS) # -O2 -LDFLAGS = -g -W -Wall # -O2 -LIBS = -lmingw32 -lopengl32 -lglu32 -lgdi32 $(SDL_LIBS) -lz -EXEEXT =.exe - -include Makefile.common - -# Some additional targets -install: residual - mkdir -p $(RESIDUALPATH) - strip residual$(EXEEXT) -o $(RESIDUALPATH)/residual$(EXEEXT) - -dist: install - cp COPYING $(RESIDUALPATH)/copying.txt - cp README $(RESIDUALPATH)/readme.txt - cp /usr/local/README-SDL.txt $(RESIDUALPATH) - cp /usr/local/bin/SDL.dll $(RESIDUALPATH) - u2d $(RESIDUALPATH)/*.txt diff --git a/README b/README index 1d085b2ba73..a7dd1424da8 100644 --- a/README +++ b/README @@ -1,5 +1,5 @@ Residual: A LucasArts 3D game interpreter Version: 0.06a-CVS -(C) 2003-2006 The ScummVM-Residual team Last Updated: 14 May 2006 +(C) 2003-2008 The ScummVM-Residual team Last Updated: 14 May 2006 ------------------------------------------------------------------------------ What is Residual? diff --git a/common/algorithm.h b/common/algorithm.h new file mode 100644 index 00000000000..6341145531b --- /dev/null +++ b/common/algorithm.h @@ -0,0 +1,154 @@ +/* Residual - Virtual machine to run LucasArts' 3D adventure games + * Copyright (C) 2003-2006 The ScummVM-Residual Team (www.scummvm.org) + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * $URL$ + * $Id$ + */ + +#ifndef COMMON_ALGORITHM_H +#define COMMON_ALGORITHM_H + +#include "common/sys.h" + +namespace Common { + +template +Out copy(In first, In last, Out dst) { + while (first != last) + *dst++ = *first++; + return dst; +} + +template +Out copy_backward(In first, In last, Out dst) { + while (first != last) + *--dst = *--last; + return dst; +} + +template +Out copy_if(In first, In last, Out dst, Op op) { + while (first != last) { + if (op(*first)) + *dst++ = *first; + ++first; + } + return dst; +} + +// Our 'specialized' 'set_to' template for char, signed char and unsigned char arrays. +// Since C++ doesn't support partial specialized template functions (currently) we +// are going this way... +// With this we assure the usage of memset for those, which should be +// faster than a simple loop like for the generic 'set_to'. +template +signed char *set_to(signed char *first, signed char *last, Value val) { + memset(first, (val & 0xFF), last - first); + return last; +} + +template +unsigned char *set_to(unsigned char *first, unsigned char *last, Value val) { + memset(first, (val & 0xFF), last - first); + return last; +} + +template +char *set_to(char *first, char *last, Value val) { + memset(first, (val & 0xFF), last - first); + return last; +} + +template +In set_to(In first, In last, Value val) { + while (first != last) + *first++ = val; + return first; +} + +template +In find(In first, In last, const T &v) { + while (first != last) { + if (*first == v) + return first; + ++first; + } + return last; +} + +template +In find_if(In first, In last, Pred p) { + while (first != last) { + if (p(*first)) + return first; + ++first; + } + return last; +} + +template +Op for_each(In first, In last, Op f) { + while (first != last) f(*first++); + return f; +} + +// Simple sort function, modeled after std::sort. +// Use it like this: sort(container.begin(), container.end()). +// Also work on plain old int arrays etc. +template +void sort(T first, T last) { + if (first == last) + return; + + // Simple selection sort + T i(first); + for (; i != last; ++i) { + T minElem(i); + T j(i); + ++j; + for (; j != last; ++j) + if (*j < *minElem) + minElem = j; + if (minElem != i) + SWAP(*minElem, *i); + } +} + +// Using this with: Common::Less from common/func.h +// will give the same results as the function above. +template +void sort(T first, T last, StrictWeakOrdering comp) { + if (first == last) + return; + + // Simple selection sort + T i(first); + for (; i != last; ++i) { + T minElem(i); + T j(i); + ++j; + for (; j != last; ++j) + if (comp(*j, *minElem)) + minElem = j; + if (minElem != i) + SWAP(*minElem, *i); + } +} + +} // end of namespace Common +#endif + diff --git a/common/array.h b/common/array.h new file mode 100644 index 00000000000..abeb277d5d8 --- /dev/null +++ b/common/array.h @@ -0,0 +1,180 @@ +/* Residual - Virtual machine to run LucasArts' 3D adventure games + * Copyright (C) 2003-2006 The ScummVM-Residual Team (www.scummvm.org) + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * $URL$ + * $Id$ + */ + +#ifndef COMMON_ARRAY_H +#define COMMON_ARRAY_H + +#include "common/sys.h" +#include "common/algorithm.h" + +namespace Common { + +template +class Array { +protected: + uint _capacity; + uint _size; + T *_data; + +public: + typedef T *iterator; + typedef const T *const_iterator; + + typedef T value_type; + +public: + Array() : _capacity(0), _size(0), _data(0) {} + Array(const Array &array) : _capacity(0), _size(0), _data(0) { + _size = array._size; + _capacity = _size + 32; + _data = new T[_capacity]; + copy(array._data, array._data + _size, _data); + } + + ~Array() { + delete[] _data; + } + + void push_back(const T &element) { + ensureCapacity(_size + 1); + _data[_size++] = element; + } + + void push_back(const Array &array) { + ensureCapacity(_size + array._size); + copy(array._data, array._data + array._size, _data + _size); + _size += array._size; + } + + void insert_at(int idx, const T &element) { + assert(idx >= 0 && (uint)idx <= _size); + ensureCapacity(_size + 1); + copy_backward(_data + idx, _data + _size, _data + _size + 1); + _data[idx] = element; + _size++; + } + + T remove_at(int idx) { + assert(idx >= 0 && (uint)idx < _size); + T tmp = _data[idx]; + copy(_data + idx + 1, _data + _size, _data + idx); + _size--; + return tmp; + } + + // TODO: insert, remove, ... + + T& operator[](int idx) { + assert(idx >= 0 && (uint)idx < _size); + return _data[idx]; + } + + const T& operator[](int idx) const { + assert(idx >= 0 && (uint)idx < _size); + return _data[idx]; + } + + Array& operator=(const Array &array) { + if (this == &array) + return *this; + + delete[] _data; + _size = array._size; + _capacity = _size + 32; + _data = new T[_capacity]; + copy(array._data, array._data + _size, _data); + + return *this; + } + + uint size() const { + return _size; + } + + void clear() { + delete[] _data; + _data = 0; + _size = 0; + _capacity = 0; + } + + bool empty() const { + return (_size == 0); + } + + + iterator begin() { + return _data; + } + + iterator end() { + return _data + _size; + } + + const_iterator begin() const { + return _data; + } + + const_iterator end() const { + return _data + _size; + } + + void reserve(uint newCapacity) { + if (newCapacity <= _capacity) + return; + + T *old_data = _data; + _capacity = newCapacity; + _data = new T[newCapacity]; + + if (old_data) { + // Copy old data + copy(old_data, old_data + _size, _data); + delete[] old_data; + } + } + + void resize(uint newSize) { + if (newSize == _size) + return; + + T *old_data = _data; + _capacity = newSize; + _data = new T[newSize]; + if (old_data) { + // Copy old data + int cnt = (_size < newSize ? _size : newSize); + copy(old_data, old_data + cnt, _data); + delete[] old_data; + } + _size = newSize; + } + +protected: + void ensureCapacity(uint len) { + if (len >= _capacity) + reserve(len + 32); + } +}; + +} // End of namespace Common + +#endif diff --git a/common/debug.cpp b/common/debug.cpp index 292f5439593..cc115dd163b 100644 --- a/common/debug.cpp +++ b/common/debug.cpp @@ -87,7 +87,7 @@ void hexdump(const byte * data, int len, int bytesPerLine) { printf("|\n"); } -void warning(const char *fmt, ...) { +void CDECL warning(const char *fmt, ...) { std::fprintf(stderr, "WARNING: "); std::va_list va; @@ -98,7 +98,7 @@ void warning(const char *fmt, ...) { std::fprintf(stderr, "\n"); } -void error(const char *fmt, ...) { +void CDECL error(const char *fmt, ...) { std::fprintf(stderr, "ERROR: "); std::va_list va; diff --git a/common/debug.h b/common/debug.h index 2963d9c2d0f..8b6e5da1672 100644 --- a/common/debug.h +++ b/common/debug.h @@ -20,7 +20,7 @@ * */ -#include "common/platform.h" +#include "common/sys.h" #ifndef COMMON_DEBUG_H #define COMMON_DEBUG_H diff --git a/common/endian.h b/common/endian.h new file mode 100644 index 00000000000..a7eb3b7ed18 --- /dev/null +++ b/common/endian.h @@ -0,0 +1,217 @@ +/* Residual - Virtual machine to run LucasArts' 3D adventure games + * Copyright (C) 2003-2008 The ScummVM-Residual Team (www.scummvm.org) + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * $URL$ + * $Id$ + * + */ + +#ifndef COMMON_ENDIAN_H +#define COMMON_ENDIAN_H + +#include "common/sys.h" + +// +// Endian conversion functions, macros etc., follow from here! +// + +/** + * Swap the bytes in a 32 bit word in order to convert LE encoded data to BE + * and vice versa. + */ +FORCEINLINE uint32 SWAP_BYTES_32(uint32 a) { + return ((a >> 24) & 0x000000FF) | + ((a >> 8) & 0x0000FF00) | + ((a << 8) & 0x00FF0000) | + ((a << 24) & 0xFF000000); +} + +/** + * Swap the bytes in a 16 bit word in order to convert LE encoded data to BE + * and vice versa. + */ +FORCEINLINE uint16 SWAP_BYTES_16(uint16 a) { + return ((a >> 8) & 0x00FF) + ((a << 8) & 0xFF00); +} + + +/** + * A wrapper macro used around four character constants, like 'DATA', to + * ensure portability. Typical usage: MKID_BE('DATA'). + * + * Why is this necessary? The C/C++ standard does not define the endianess to + * be used for character constants. Hence if one uses multi-byte character + * constants, a potential portability problem opens up. + * + * Fortunately, a semi-standard has been established: On almost all systems + * and compilers, multi-byte character constants are encoded using the big + * endian convention (probably in analogy to the encoding of string constants). + * Still some systems differ. This is why we provide the MKID_BE macro. If + * you wrap your four character constants with it, the result will always be + * BE encoded, even on systems which differ from the default BE encoding. + * + * For the latter systems we provide the INVERSE_MKID override. + */ +#if defined(INVERSE_MKID) +#define MKID_BE(a) ((uint32) \ + (((a) >> 24) & 0x000000FF) | \ + (((a) >> 8) & 0x0000FF00) | \ + (((a) << 8) & 0x00FF0000) | \ + (((a) << 24) & 0xFF000000)) + +#else +# define MKID_BE(a) ((uint32)(a)) +#endif + + + +#if defined(SYSTEM_LITTLE_ENDIAN) + + #define READ_UINT16(a) READ_LE_UINT16(a) + #define READ_UINT32(a) READ_LE_UINT32(a) + + #define WRITE_UINT16(a, v) WRITE_LE_UINT16(a, v) + #define WRITE_UINT32(a, v) WRITE_LE_UINT32(a, v) + + #define FROM_LE_32(a) ((uint32)(a)) + #define FROM_LE_16(a) ((uint16)(a)) + + #define FROM_BE_32(a) SWAP_BYTES_32(a) + #define FROM_BE_16(a) SWAP_BYTES_16(a) + + #define TO_LE_32(a) ((uint32)(a)) + #define TO_LE_16(a) ((uint16)(a)) + + #define TO_BE_32(a) SWAP_BYTES_32(a) + #define TO_BE_16(a) SWAP_BYTES_16(a) + +#elif defined(SYSTEM_BIG_ENDIAN) + + #define MKID(a) ((uint32)(a)) + #define MKID_BE(a) ((uint32)(a)) + + #define READ_UINT16(a) READ_BE_UINT16(a) + #define READ_UINT32(a) READ_BE_UINT32(a) + + #define WRITE_UINT16(a, v) WRITE_BE_UINT16(a, v) + #define WRITE_UINT32(a, v) WRITE_BE_UINT32(a, v) + + #define FROM_LE_32(a) SWAP_BYTES_32(a) + #define FROM_LE_16(a) SWAP_BYTES_16(a) + + #define FROM_BE_32(a) ((uint32)(a)) + #define FROM_BE_16(a) ((uint16)(a)) + + #define TO_LE_32(a) SWAP_BYTES_32(a) + #define TO_LE_16(a) SWAP_BYTES_16(a) + + #define TO_BE_32(a) ((uint32)(a)) + #define TO_BE_16(a) ((uint16)(a)) + +#else + + #error No endianness defined + + +#endif + + +#if defined(SYSTEM_NEED_ALIGNMENT) || !defined(SYSTEM_LITTLE_ENDIAN) + FORCEINLINE uint16 READ_LE_UINT16(const void *ptr) { + const byte *b = (const byte *)ptr; + return (b[1] << 8) + b[0]; + } + FORCEINLINE uint32 READ_LE_UINT32(const void *ptr) { + const byte *b = (const byte *)ptr; + return (b[3] << 24) + (b[2] << 16) + (b[1] << 8) + (b[0]); + } + FORCEINLINE void WRITE_LE_UINT16(void *ptr, uint16 value) { + byte *b = (byte *)ptr; + b[0] = (byte)(value >> 0); + b[1] = (byte)(value >> 8); + } + FORCEINLINE void WRITE_LE_UINT32(void *ptr, uint32 value) { + byte *b = (byte *)ptr; + b[0] = (byte)(value >> 0); + b[1] = (byte)(value >> 8); + b[2] = (byte)(value >> 16); + b[3] = (byte)(value >> 24); + } +#else + FORCEINLINE uint16 READ_LE_UINT16(const void *ptr) { + return *(const uint16 *)(ptr); + } + FORCEINLINE uint32 READ_LE_UINT32(const void *ptr) { + return *(const uint32 *)(ptr); + } + FORCEINLINE void WRITE_LE_UINT16(void *ptr, uint16 value) { + *(uint16 *)(ptr) = value; + } + FORCEINLINE void WRITE_LE_UINT32(void *ptr, uint32 value) { + *(uint32 *)(ptr) = value; + } +#endif + + +#if defined(SYSTEM_NEED_ALIGNMENT) || !defined(SYSTEM_BIG_ENDIAN) + FORCEINLINE uint16 READ_BE_UINT16(const void *ptr) { + const byte *b = (const byte *)ptr; + return (b[0] << 8) + b[1]; + } + FORCEINLINE uint32 READ_BE_UINT32(const void *ptr) { + const byte *b = (const byte*)ptr; + return (b[0] << 24) + (b[1] << 16) + (b[2] << 8) + (b[3]); + } + FORCEINLINE void WRITE_BE_UINT16(void *ptr, uint16 value) { + byte *b = (byte *)ptr; + b[0] = (byte)(value >> 8); + b[1] = (byte)(value >> 0); + } + FORCEINLINE void WRITE_BE_UINT32(void *ptr, uint32 value) { + byte *b = (byte *)ptr; + b[0] = (byte)(value >> 24); + b[1] = (byte)(value >> 16); + b[2] = (byte)(value >> 8); + b[3] = (byte)(value >> 0); + } +#else + FORCEINLINE uint16 READ_BE_UINT16(const void *ptr) { + return *(const uint16 *)(ptr); + } + FORCEINLINE uint32 READ_BE_UINT32(const void *ptr) { + return *(const uint32 *)(ptr); + } + FORCEINLINE void WRITE_BE_UINT16(void *ptr, uint16 value) { + *(uint16 *)(ptr) = value; + } + FORCEINLINE void WRITE_BE_UINT32(void *ptr, uint32 value) { + *(uint32 *)(ptr) = value; + } +#endif + +FORCEINLINE uint32 READ_LE_UINT24(const void *ptr) { + const byte *b = (const byte *)ptr; + return (b[2] << 16) + (b[1] << 8) + (b[0]); +} + +FORCEINLINE uint32 READ_BE_UINT24(const void *ptr) { + const byte *b = (const byte*)ptr; + return (b[0] << 16) + (b[1] << 8) + (b[2]); +} + + +#endif diff --git a/common/func.h b/common/func.h new file mode 100644 index 00000000000..25e10dd3099 --- /dev/null +++ b/common/func.h @@ -0,0 +1,303 @@ +/* Residual - Virtual machine to run LucasArts' 3D adventure games + * Copyright (C) 2003-2008 The ScummVM-Residual Team (www.scummvm.org) + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * $URL$ + * $Id$ + */ + +#ifndef COMMON_FUNC_H +#define COMMON_FUNC_H + +#include "common/sys.h" + +namespace Common { + +template +struct UnaryFunction { + typedef Arg ArgumenType; + typedef Result ResultType; +}; + +template +struct BinaryFunction { + typedef Arg1 FirstArgumentType; + typedef Arg2 SecondArgumentType; + typedef Result ResultType; +}; + +template +struct EqualTo : public BinaryFunction { + bool operator()(const T &x, const T &y) const { return x == y; } +}; + +template +struct Less : public BinaryFunction { + bool operator()(const T &x, const T &y) const { return x < y; } +}; + +template +struct Greater : public BinaryFunction { + bool operator()(const T &x, const T &y) const { return x > y; } +}; + +template +class Binder1st : public UnaryFunction { +private: + Op _op; + typename Op::FirstArgumentType _arg1; +public: + Binder1st(const Op &op, const typename Op::FirstArgumentType &arg1) : _op(op), _arg1(arg1) {} + + typename Op::ResultType operator()(typename Op::SecondArgumentType v) const { + return _op(_arg1, v); + } +}; + +template +inline Binder1st bind1st(const Op &op, const T &t) { + return Binder1st(op, t); +} + +template +class Binder2nd : public UnaryFunction { +private: + Op _op; + typename Op::SecondArgumentType _arg2; +public: + Binder2nd(const Op &op, const typename Op::SecondArgumentType &arg2) : _op(op), _arg2(arg2) {} + + typename Op::ResultType operator()(typename Op::FirstArgumentType v) const { + return _op(v, _arg2); + } +}; + +template +inline Binder2nd bind2nd(const Op &op, const T &t) { + return Binder2nd(op, t); +} + +template +class PointerToUnaryFunc : public UnaryFunction { +private: + Result (*_func)(Arg); +public: + typedef Result (*FuncType)(Arg); + + PointerToUnaryFunc(const FuncType &func) : _func(func) {} + Result operator()(Arg v) const { + return _func(v); + } +}; + +template +class PointerToBinaryFunc : public BinaryFunction { +private: + Result (*_func)(Arg1, Arg2); +public: + typedef Result (*FuncType)(Arg1, Arg2); + + PointerToBinaryFunc(const FuncType &func) : _func(func) {} + Result operator()(Arg1 v1, Arg2 v2) const { + return _func(v1, v2); + } +}; + +template +inline PointerToUnaryFunc ptr_fun(Result (*func)(Arg)) { + return PointerToUnaryFunc(func); +} + +template +inline PointerToBinaryFunc ptr_fun(Result (*func)(Arg1, Arg2)) { + return PointerToBinaryFunc(func); +} + +template +class MemFunc0 : public UnaryFunction { +private: + Result (T::*_func)(); +public: + typedef Result (T::*FuncType)(); + + MemFunc0(const FuncType &func) : _func(func) {} + Result operator()(T *v) const { + return (v->*_func)(); + } +}; + +template +class ConstMemFunc0 : public UnaryFunction { +private: + Result (T::*_func)() const; +public: + typedef Result (T::*FuncType)() const; + + ConstMemFunc0(const FuncType &func) : _func(func) {} + Result operator()(T *v) const { + return (v->*_func)(); + } +}; + +template +class MemFunc1 : public BinaryFunction { +private: + Result (T::*_func)(Arg); +public: + typedef Result (T::*FuncType)(Arg); + + MemFunc1(const FuncType &func) : _func(func) {} + Result operator()(T *v1, Arg v2) const { + return (v1->*_func)(v2); + } +}; + +template +class ConstMemFunc1 : public BinaryFunction { +private: + Result (T::*_func)(Arg) const; +public: + typedef Result (T::*FuncType)(Arg) const; + + ConstMemFunc1(const FuncType &func) : _func(func) {} + Result operator()(T *v1, Arg v2) const { + return (v1->*_func)(v2); + } +}; + +template +inline MemFunc0 mem_fun(Result (T::*f)()) { + return MemFunc0(f); +} + +template +inline ConstMemFunc0 mem_fun(Result (T::*f)() const) { + return ConstMemFunc0(f); +} + +template +inline MemFunc1 mem_fun(Result (T::*f)(Arg)) { + return MemFunc1(f); +} + +template +inline ConstMemFunc1 mem_fun(Result (T::*f)(Arg) const) { + return ConstMemFunc1(f); +} + +// functor code + +template +struct Functor0 { + virtual ~Functor0() {} + + virtual bool isValid() const = 0; + virtual Res operator()() const = 0; +}; + +template +class Functor0Mem : public Functor0 { +public: + typedef Res (T::*FuncType)(); + + Functor0Mem(T *t, const FuncType &func) : _t(t), _func(func) {} + + bool isValid() const { return _func != 0; } + Res operator()() const { + return (_t->*_func)(); + } +private: + mutable T *_t; + const FuncType _func; +}; + +template +struct Functor1 : public Common::UnaryFunction { + virtual ~Functor1() {} + + virtual bool isValid() const = 0; + virtual Res operator()(Arg) const = 0; +}; + +template +class Functor1Mem : public Functor1 { +public: + typedef Res (T::*FuncType)(Arg); + + Functor1Mem(T *t, const FuncType &func) : _t(t), _func(func) {} + + bool isValid() const { return _func != 0; } + Res operator()(Arg v1) const { + return (_t->*_func)(v1); + } +private: + mutable T *_t; + const FuncType _func; +}; + +template +struct Functor2 : public Common::BinaryFunction { + virtual ~Functor2() {} + + virtual bool isValid() const = 0; + virtual Res operator()(Arg1, Arg2) const = 0; +}; + +template +class Functor2Mem : public Functor2 { +public: + typedef Res (T::*FuncType)(Arg1, Arg2); + + Functor2Mem(T *t, const FuncType &func) : _t(t), _func(func) {} + + bool isValid() const { return _func != 0; } + Res operator()(Arg1 v1, Arg2 v2) const { + return (_t->*_func)(v1, v2); + } +private: + mutable T *_t; + const FuncType _func; +}; + +/** + * Base template for hash functor objects, used by HashMap. + * This needs to be specialized for every type that you need to hash. + */ +template struct Hash; + + +#define GENERATE_TRIVIAL_HASH_FUNCTOR(T) \ + template<> struct Hash : public UnaryFunction { \ + uint operator()(T val) const { return (uint)val; } \ + } + +GENERATE_TRIVIAL_HASH_FUNCTOR(bool); +GENERATE_TRIVIAL_HASH_FUNCTOR(char); +GENERATE_TRIVIAL_HASH_FUNCTOR(signed char); +GENERATE_TRIVIAL_HASH_FUNCTOR(unsigned char); +GENERATE_TRIVIAL_HASH_FUNCTOR(short); +GENERATE_TRIVIAL_HASH_FUNCTOR(int); +GENERATE_TRIVIAL_HASH_FUNCTOR(long); +GENERATE_TRIVIAL_HASH_FUNCTOR(unsigned short); +GENERATE_TRIVIAL_HASH_FUNCTOR(unsigned int); +GENERATE_TRIVIAL_HASH_FUNCTOR(unsigned long); + +#undef GENERATE_TRIVIAL_HASH_FUNCTOR + +} // End of namespace Common + +#endif + diff --git a/common/hash-str.h b/common/hash-str.h new file mode 100644 index 00000000000..a19d83f85ca --- /dev/null +++ b/common/hash-str.h @@ -0,0 +1,86 @@ +/* Residual - Virtual machine to run LucasArts' 3D adventure games + * Copyright (C) 2003-2008 The ScummVM-Residual Team (www.scummvm.org) + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * $URL$ + * $Id$ + */ + +#ifndef COMMON_HASH_STR_H +#define COMMON_HASH_STR_H + +#include "common/hashmap.h" +#include "common/str.h" + +namespace Common { + +uint hashit(const char *str); +uint hashit_lower(const char *str); // Generate a hash based on the lowercase version of the string +inline uint hashit(const String &str) { return hashit(str.c_str()); } +inline uint hashit_lower(const String &str) { return hashit_lower(str.c_str()); } + + +// FIXME: The following functors obviously are not consistently named + +struct CaseSensitiveString_EqualTo { + bool operator()(const String& x, const String& y) const { return strcmp(x.c_str(), y.c_str()) == 0; } +}; + +struct CaseSensitiveString_Hash { + uint operator()(const String& x) const { return hashit(x.c_str()); } +}; + + +struct IgnoreCase_EqualTo { + bool operator()(const String& x, const String& y) const { return strcasecmp(x.c_str(), y.c_str()) == 0; } +}; + +struct IgnoreCase_Hash { + uint operator()(const String& x) const { return hashit_lower(x.c_str()); } +}; + + + +// Specalization of the Hash functor for String objects. +// We do case sensitve hashing here, because that is what +// the default EqualTo is compatible with. If one wants to use +// case insensitve hashing, then only because one wants to use +// IgnoreCase_EqualTo, and then one has to specify a custom +// hash anyway. +template <> +struct Hash { + uint operator()(const String& s) const { + return hashit(s.c_str()); + } +}; + +template <> +struct Hash { + uint operator()(const char *s) const { + return hashit(s); + } +}; + + +// String map -- by default case insensitive +typedef HashMap StringMap; + + + +} // End of namespace Common + + +#endif diff --git a/common/hashmap.cpp b/common/hashmap.cpp new file mode 100644 index 00000000000..b0e9e17f7da --- /dev/null +++ b/common/hashmap.cpp @@ -0,0 +1,90 @@ +/* Residual - Virtual machine to run LucasArts' 3D adventure games + * Copyright (C) 2003-2008 The ScummVM-Residual Team (www.scummvm.org) + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * $URL$ + * $Id$ + * + */ + +// The hash map (associative array) implementation in this file is +// based on code by Andrew Y. Ng, 1996: + +/* + * Copyright (c) 1998-2003 Massachusetts Institute of Technology. + * This code was developed as part of the Haystack research project + * (http://haystack.lcs.mit.edu/). Permission is hereby granted, + * free of charge, to any person obtaining a copy of this software + * and associated documentation files (the "Software"), to deal in + * the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, + * sublicense, and/or sell copies of the Software, and to permit + * persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES + * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT + * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + */ + +#include "common/hashmap.h" + +namespace Common { + +// const char *: +uint hashit(const char *p) { + uint hash = 0; + byte c; + while ((c = *p++)) + hash = (hash * 31 + c); + return hash; +} + +uint hashit_lower(const char *p) { + uint hash = 0; + byte c; + while ((c = *p++)) + hash = (hash * 31 + tolower(c)); + return hash; +} + +// The following table is taken from the GNU ISO C++ Library's hashtable.h file. +static const uint primes[] = { + 53ul, 97ul, 193ul, 389ul, 769ul, + 1543ul, 3079ul, 6151ul, 12289ul, 24593ul, + 49157ul, 98317ul, 196613ul, 393241ul, 786433ul, + 1572869ul, 3145739ul, 6291469ul, 12582917ul, 25165843ul, + 50331653ul, 100663319ul, 201326611ul, 402653189ul, 805306457ul, + 1610612741ul, 3221225473ul, 4294967291ul +}; + +uint nextTableSize(uint x) { + int i = 0; + while (x >= primes[i]) + i++; + return primes[i]; +} + + +} // End of namespace Common diff --git a/common/hashmap.h b/common/hashmap.h new file mode 100644 index 00000000000..55fc63f4e9b --- /dev/null +++ b/common/hashmap.h @@ -0,0 +1,541 @@ +/* Residual - Virtual machine to run LucasArts' 3D adventure games + * Copyright (C) 2003-2008 The ScummVM-Residual Team (www.scummvm.org) + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * $URL$ + * $Id$ + * + */ + +// The hash map (associative array) implementation in this file is +// based on code by Andrew Y. Ng, 1996: + +/* + * Copyright (c) 1998-2003 Massachusetts Institute of Technology. + * This code was developed as part of the Haystack research project + * (http://haystack.lcs.mit.edu/). Permission is hereby granted, + * free of charge, to any person obtaining a copy of this software + * and associated documentation files (the "Software"), to deal in + * the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, + * sublicense, and/or sell copies of the Software, and to permit + * persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES + * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT + * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + */ + +#ifndef COMMON_HASHMAP_H +#define COMMON_HASHMAP_H + +#include "common/func.h" +#include "common/str.h" +#include "common/util.h" + +#define USE_HASHMAP_MEMORY_POOL +#ifdef USE_HASHMAP_MEMORY_POOL +#include "common/memorypool.h" +// FIXME: we sadly can't assume standard C++ to be present +// on every system we support, so we should get rid of this. +// The solution should be to write a simple placement new +// on our own. +#include +#endif + +namespace Common { + +// The table sizes ideally are primes. We use a helper function to find +// suitable table sizes. +uint nextTableSize(uint x); + + +// Enable the following #define if you want to check how many collisions the +// code produces (many collisions indicate either a bad hash function, or a +// hash table that is too small). +//#define DEBUG_HASH_COLLISIONS + + +/** + * HashMap maps objects of type Key to objects of type Val. + * For each used Key type, we need an "uint hashit(Key,uint)" function + * that computes a hash for the given Key object and returns it as an + * an integer from 0 to hashsize-1, and also an "equality functor". + * that returns true if if its two arguments are to be considered + * equal. Also, we assume that "=" works on Val objects for assignment. + * + * If aa is an HashMap, then space is allocated each time aa[key] is + * referenced, for a new key. If the object is const, then an assertion is + * triggered instead. Hence if you are not sure whether a key is contained in + * the map, use contains() first to check for its presence. + */ +template, class EqualFunc = EqualTo > +class HashMap { +private: +#if defined (PALMOS_MODE) +public: +#endif + + typedef HashMap HM_t; + + struct Node { + const Key _key; + Val _value; + Node(const Key &key) : _key(key), _value() {} + }; + + +#ifdef USE_HASHMAP_MEMORY_POOL + MemoryPool _nodePool; + + Node *allocNode(const Key &key) { + void* mem = _nodePool.malloc(); + return new (mem) Node(key); + } + + void freeNode(Node *node) { + node->~Node(); + _nodePool.free(node); + } +#else + Node* allocNode(const Key &key) { + return new Node(key); + } + + void freeNode(Node *node) { + delete node; + } +#endif + + Node **_arr; // hashtable of size arrsize. + uint _arrsize, _nele; + + HashFunc _hash; + EqualFunc _equal; + + // Default value, returned by the const getVal. + const Val _defaultVal; + +#ifdef DEBUG_HASH_COLLISIONS + mutable int _collisions, _lookups; +#endif + + void assign(const HM_t &map); + int lookup(const Key &key) const; + int lookupAndCreateIfMissing(const Key &key); + void expand_array(uint newsize); + + template friend class IteratorImpl; + + /** + * Simple HashMap iterator implementation. + */ + template + class IteratorImpl { + friend class HashMap; + template friend class IteratorImpl; + protected: + typedef const HashMap hashmap_t; + + uint _idx; + hashmap_t *_hashmap; + + protected: + IteratorImpl(uint idx, hashmap_t *hashmap) : _idx(idx), _hashmap(hashmap) {} + + NodeType *deref() const { + assert(_hashmap != 0); + assert(_idx < _hashmap->_arrsize); + Node *node = _hashmap->_arr[_idx]; + assert(node != 0); + return node; + } + + public: + IteratorImpl() : _idx(0), _hashmap(0) {} + template + IteratorImpl(const IteratorImpl &c) : _idx(c._idx), _hashmap(c._hashmap) {} + + NodeType &operator*() const { return *deref(); } + NodeType *operator->() const { return deref(); } + + bool operator==(const IteratorImpl &iter) const { return _idx == iter._idx && _hashmap == iter._hashmap; } + bool operator!=(const IteratorImpl &iter) const { return !(*this == iter); } + + IteratorImpl &operator++() { + assert(_hashmap); + do { + _idx++; + } while (_idx < _hashmap->_arrsize && _hashmap->_arr[_idx] == 0); + if (_idx >= _hashmap->_arrsize) + _idx = (uint)-1; + + return *this; + } + + IteratorImpl operator++(int) { + IteratorImpl old = *this; + operator ++(); + return old; + } + }; + +public: + typedef IteratorImpl iterator; + typedef IteratorImpl const_iterator; + + HashMap(); + HashMap(const HM_t &map); + ~HashMap(); + + HM_t &operator=(const HM_t &map) { + if (this == &map) + return *this; + + // Remove the previous content and ... + clear(); + delete[] _arr; + // ... copy the new stuff. + assign(map); + return *this; + } + + bool contains(const Key &key) const; + + Val &operator[](const Key &key); + const Val &operator[](const Key &key) const; + + Val &getVal(const Key &key); + const Val &getVal(const Key &key) const; + void setVal(const Key &key, const Val &val); + + void clear(bool shrinkArray = 0); + + void erase(const Key &key); + + uint size() const { return _nele; } + + iterator begin() { + // Find and return the _key non-empty entry + for (uint ctr = 0; ctr < _arrsize; ++ctr) { + if (_arr[ctr]) + return iterator(ctr, this); + } + return end(); + } + iterator end() { + return iterator((uint)-1, this); + } + + const_iterator begin() const { + // Find and return the first non-empty entry + for (uint ctr = 0; ctr < _arrsize; ++ctr) { + if (_arr[ctr]) + return const_iterator(ctr, this); + } + return end(); + } + const_iterator end() const { + return const_iterator((uint)-1, this); + } + + iterator find(const Key &key) { + uint ctr = lookup(key); + if (_arr[ctr]) + return iterator(ctr, this); + return end(); + } + + const_iterator find(const Key &key) const { + uint ctr = lookup(key); + if (_arr[ctr]) + return const_iterator(ctr, this); + return end(); + } + + // TODO: insert() method? + + bool empty() const { + return (_nele == 0); + } +}; + +//------------------------------------------------------- +// HashMap functions + +/** + * Base constructor, creates an empty hashmap. + */ +template +HashMap::HashMap() : +#ifdef USE_HASHMAP_MEMORY_POOL + _nodePool(sizeof(Node)), +#endif + _defaultVal() { + _arrsize = nextTableSize(0); + _arr = new Node *[_arrsize]; + assert(_arr != NULL); + memset(_arr, 0, _arrsize * sizeof(Node *)); + + _nele = 0; + +#ifdef DEBUG_HASH_COLLISIONS + _collisions = 0; + _lookups = 0; +#endif +} + +/** + * Copy constructor, creates a full copy of the given hashmap. + * We must provide a custom copy constructor as we use pointers + * to heap buffers for the internal storage. + */ +template +HashMap::HashMap(const HM_t &map) : +#ifdef USE_HASHMAP_MEMORY_POOL + _nodePool(sizeof(Node)), +#endif + _defaultVal() { + assign(map); +} + +/** + * Destructor, frees all used memory. + */ +template +HashMap::~HashMap() { + for (uint ctr = 0; ctr < _arrsize; ++ctr) + if (_arr[ctr] != NULL) + freeNode(_arr[ctr]); + + delete[] _arr; +} + +/** + * Internal method for assigning the content of another HashMap + * to this one. + * + * @note We do *not* deallocate the previous storage here -- the caller is + * responsible for doing that! + */ +template +void HashMap::assign(const HM_t &map) { + _arrsize = map._arrsize; + _arr = new Node *[_arrsize]; + assert(_arr != NULL); + memset(_arr, 0, _arrsize * sizeof(Node *)); + + // Simply clone the map given to us, one by one. + _nele = 0; + for (uint ctr = 0; ctr < _arrsize; ++ctr) { + if (map._arr[ctr] != NULL) { + _arr[ctr] = allocNode(map._arr[ctr]->_key); + _arr[ctr]->_value = map._arr[ctr]->_value; + _nele++; + } + } + // Perform a sanity check (to help track down hashmap corruption) + assert(_nele == map._nele); +} + + +template +void HashMap::clear(bool shrinkArray) { + for (uint ctr = 0; ctr < _arrsize; ++ctr) { + if (_arr[ctr] != NULL) { + freeNode(_arr[ctr]); + _arr[ctr] = NULL; + } + } + + if (shrinkArray && _arrsize > nextTableSize(0)) { + delete[] _arr; + + _arrsize = nextTableSize(0); + _arr = new Node *[_arrsize]; + assert(_arr != NULL); + memset(_arr, 0, _arrsize * sizeof(Node *)); + } + + _nele = 0; +} + +template +void HashMap::expand_array(uint newsize) { + assert(newsize > _arrsize); + uint ctr, dex; + + const uint old_nele = _nele; + const uint old_arrsize = _arrsize; + Node **old_arr = _arr; + + // allocate a new array + _nele = 0; + _arrsize = newsize; + _arr = new Node *[_arrsize]; + assert(_arr != NULL); + memset(_arr, 0, _arrsize * sizeof(Node *)); + + // rehash all the old elements + for (ctr = 0; ctr < old_arrsize; ++ctr) { + if (old_arr[ctr] == NULL) + continue; + + // Insert the element from the old table into the new table. + // Since we know that no key exists twice in the old table, we + // can do this slightly better than by calling lookup, since we + // don't have to call _equal(). + dex = _hash(old_arr[ctr]->_key) % _arrsize; + while (_arr[dex] != NULL) { + dex = (dex + 1) % _arrsize; + } + + _arr[dex] = old_arr[ctr]; + _nele++; + } + + // Perform a sanity check: Old number of elements should match the new one! + // This check will fail if some previous operation corrupted this hashmap. + assert(_nele == old_nele); + + delete[] old_arr; + + return; +} + +template +int HashMap::lookup(const Key &key) const { + uint ctr = _hash(key) % _arrsize; + + while (_arr[ctr] != NULL && !_equal(_arr[ctr]->_key, key)) { + ctr = (ctr + 1) % _arrsize; + +#ifdef DEBUG_HASH_COLLISIONS + _collisions++; +#endif + } + +#ifdef DEBUG_HASH_COLLISIONS + _lookups++; + fprintf(stderr, "collisions %d, lookups %d, ratio %f in HashMap %p; size %d num elements %d\n", + _collisions, _lookups, ((double) _collisions / (double)_lookups), + (const void *)this, _arrsize, _nele); +#endif + + return ctr; +} + +template +int HashMap::lookupAndCreateIfMissing(const Key &key) { + uint ctr = lookup(key); + + if (_arr[ctr] == NULL) { + _arr[ctr] = allocNode(key); + _nele++; + + // Keep the load factor below 75%. + if (_nele > _arrsize * 75 / 100) { + expand_array(nextTableSize(_arrsize)); + ctr = lookup(key); + } + } + + return ctr; +} + + +template +bool HashMap::contains(const Key &key) const { + uint ctr = lookup(key); + return (_arr[ctr] != NULL); +} + +template +Val &HashMap::operator[](const Key &key) { + return getVal(key); +} + +template +const Val &HashMap::operator[](const Key &key) const { + return getVal(key); +} + +template +Val &HashMap::getVal(const Key &key) { + uint ctr = lookupAndCreateIfMissing(key); + assert(_arr[ctr] != NULL); + return _arr[ctr]->_value; +} + +template +const Val &HashMap::getVal(const Key &key) const { + uint ctr = lookup(key); + if (_arr[ctr] != NULL) + return _arr[ctr]->_value; + else + return _defaultVal; +} + +template +void HashMap::setVal(const Key &key, const Val &val) { + uint ctr = lookupAndCreateIfMissing(key); + assert(_arr[ctr] != NULL); + _arr[ctr]->_value = val; +} + +template +void HashMap::erase(const Key &key) { + // This is based on code in the Wikipedia article on Hash tables. + uint i = lookup(key); + if (_arr[i] == NULL) + return; // key wasn't present, so no work has to be done + // If we remove a key, we must check all subsequent keys and possibly + // reinsert them. + uint j = i; + freeNode(_arr[i]); + _arr[i] = NULL; + while (true) { + // Look at the next table slot + j = (j + 1) % _arrsize; + // If the next slot is empty, we are done + if (_arr[j] == NULL) + break; + // Compute the slot where the content of the next slot should normally be, + // assuming an empty table, and check whether we have to move it. + uint k = _hash(_arr[j]->_key) % _arrsize; + if ((j > i && (k <= i || k > j)) || + (j < i && (k <= i && k > j)) ) { + _arr[i] = _arr[j]; + i = j; + } + } + _arr[i] = NULL; + _nele--; + return; +} + +} // End of namespace Common + +#endif diff --git a/common/list.h b/common/list.h index df744a71f85..9e719cf1713 100644 --- a/common/list.h +++ b/common/list.h @@ -29,9 +29,9 @@ namespace Common { /** * Simple double linked list, modeled after the list template of the standard - * C++ library. + * C++ library. */ -template +template class List { protected: #if defined (_WIN32_WCE) || defined (_MSC_VER) @@ -42,16 +42,17 @@ public: NodeBase *_prev; NodeBase *_next; }; - + template struct Node : public NodeBase { t_T2 _data; - + Node(const t_T2 &x) : _data(x) {} }; - template + template class Iterator { + template friend class Iterator; friend class List; NodeBase *_node; @@ -63,6 +64,14 @@ public: public: Iterator() : _node(0) {} + template + Iterator(const Iterator &c) : _node(c._node) {} + + template + Iterator &operator=(const Iterator &c) { + _node = c._node; + return *this; + } // Prefix inc Iterator &operator++() { @@ -88,28 +97,30 @@ public: --(*this); return tmp; } - t_T2& operator*() const { + t_T2 &operator*() const { assert(_node); #if (__GNUC__ == 2) && (__GNUC_MINOR__ >= 95) return static_cast::Node *>(_node)->_data; #else - return static_cast*>(_node)->_data; + return static_cast *>(_node)->_data; #endif } - t_T2* operator->() const { + t_T2 *operator->() const { return &(operator*()); } - - bool operator==(const Iterator& x) const { + + template + bool operator==(const Iterator &x) const { return _node == x._node; } - - bool operator!=(const Iterator& x) const { + + template + bool operator!=(const Iterator &x) const { return _node != x._node; } }; - NodeBase *_anchor; + NodeBase _anchor; public: typedef Iterator iterator; @@ -119,41 +130,38 @@ public: public: List() { - _anchor = new NodeBase; - _anchor->_prev = _anchor; - _anchor->_next = _anchor; + _anchor._prev = &_anchor; + _anchor._next = &_anchor; } - List(const List& list) { - _anchor = new NodeBase; - _anchor->_prev = _anchor; - _anchor->_next = _anchor; + List(const List &list) { + _anchor._prev = &_anchor; + _anchor._next = &_anchor; insert(begin(), list.begin(), list.end()); } ~List() { clear(); - delete _anchor; } - void push_front(const t_T& element) { + void push_front(const t_T &element) { insert(begin(), element); } - void push_back(const t_T& element) { + void push_back(const t_T &element) { insert(end(), element); } - void insert(iterator pos, const t_T& element) { + void insert(iterator pos, const t_T &element) { NodeBase *newNode = new Node(element); - + newNode->_next = pos._node; newNode->_prev = pos._node->_prev; newNode->_prev->_next = newNode; newNode->_next->_prev = newNode; } - template + template void insert(iterator pos, iterator2 first, iterator2 last) { for (; first != last; ++first) insert(pos, *first); @@ -200,7 +208,7 @@ public: } - List& operator =(const List& list) { + List &operator=(const List &list) { if (this != &list) { iterator i; const_iterator j; @@ -214,7 +222,7 @@ public: else erase(i, end()); } - + return *this; } @@ -228,34 +236,34 @@ public: void clear() { erase(begin(), end()); } - - bool empty() const { - return (_anchor == _anchor->_next); + + bool empty() const { + return (&_anchor == _anchor._next); } iterator begin() { - return iterator(_anchor->_next); + return iterator(_anchor._next); } iterator reverse_begin() { - return iterator(_anchor->_prev); + return iterator(_anchor._prev); } iterator end() { - return iterator(_anchor); + return iterator(&_anchor); } const_iterator begin() const { - return const_iterator(_anchor->_next); + return const_iterator(_anchor._next); } const_iterator reverse_begin() const { - return const_iterator(_anchor->_prev); + return const_iterator(_anchor._prev); } const_iterator end() const { - return const_iterator(_anchor); + return const_iterator(const_cast(&_anchor)); } }; diff --git a/common/matrix3.cpp b/common/matrix3.cpp index 642088fe1b2..c18da0eca5b 100644 --- a/common/matrix3.cpp +++ b/common/matrix3.cpp @@ -43,9 +43,8 @@ void Matrix3::buildFromPitchYawRoll(float pitch, float yaw, float roll) { (*this) *= temp2; } -#define MYPI 3.14159265358979323846 -#define DEGTORAD(a) (a * MYPI / 180.0) -#define RADTODEG(a) (a * 180.0 / MYPI) +#define DEGTORAD(a) (a * LOCAL_PI / 180.0) +#define RADTODEG(a) (a * 180.0 / LOCAL_PI) float RadianToDegree(float rad) { return (float)RADTODEG(rad); diff --git a/common/memorypool.cpp b/common/memorypool.cpp new file mode 100644 index 00000000000..d13b8d558c5 --- /dev/null +++ b/common/memorypool.cpp @@ -0,0 +1,118 @@ +/* Residual - Virtual machine to run LucasArts' 3D adventure games + * Copyright (C) 2003-2008 The ScummVM-Residual Team (www.scummvm.org) + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * $URL$ + * $Id$ + * + */ + +#include "common/memorypool.h" +#include "common/util.h" + +namespace Common { + +static const size_t CHUNK_PAGE_SIZE = 32; + +void* MemoryPool::allocPage() { + void* result = ::malloc(CHUNK_PAGE_SIZE * _chunkSize); + _pages.push_back(result); + void* current = result; + for (size_t i = 1; i < CHUNK_PAGE_SIZE; ++i) { + void* next = ((char*)current + _chunkSize); + *(void**)current = next; + + current = next; + } + *(void**)current = NULL; + return result; +} + +MemoryPool::MemoryPool(size_t chunkSize) { + // You must at least fit the pointer in the node (technically unneeded considering the next rounding statement) + _chunkSize = MAX(chunkSize, sizeof(void*)); + // There might be an alignment problem on some platforms when trying to load a void* on a non natural boundary + // so we round to the next sizeof(void*) + _chunkSize = (_chunkSize + sizeof(void*) - 1) & (~(sizeof(void*) - 1)); + + _next = NULL; +} + +MemoryPool::~MemoryPool() { + for (size_t i = 0; i<_pages.size(); ++i) + ::free(_pages[i]); +} + +void* MemoryPool::malloc() { +#if 1 + if (!_next) + _next = allocPage(); + + void* result = _next; + _next = *(void**)result; + return result; +#else + return ::malloc(_chunkSize); +#endif +} + +void MemoryPool::free(void* ptr) { +#if 1 + *(void**)ptr = _next; + _next = ptr; +#else + ::free(ptr); +#endif +} + +// Technically not compliant C++ to compare unrelated pointers. In practice... +bool MemoryPool::isPointerInPage(void* ptr, void* page) { + return (ptr >= page) && (ptr < (char*)page + CHUNK_PAGE_SIZE * _chunkSize); +} + +void MemoryPool::freeUnusedPages() { + //std::sort(_pages.begin(), _pages.end()); + Array numberOfFreeChunksPerPage; + numberOfFreeChunksPerPage.resize(_pages.size()); + for (size_t i = 0; i < numberOfFreeChunksPerPage.size(); ++i) { + numberOfFreeChunksPerPage[i] = 0; + } + + void* iterator = _next; + while (iterator) { + // This should be a binary search + for (size_t i = 0; i < _pages.size(); ++i) { + if (isPointerInPage(iterator, _pages[i])) { + ++numberOfFreeChunksPerPage[i]; + break; + } + } + iterator = *(void**)iterator; + } + + size_t freedPagesCount = 0; + for (size_t i = 0; i < _pages.size(); ++i) { + if (numberOfFreeChunksPerPage[i] == CHUNK_PAGE_SIZE) { + ::free(_pages[i]); + _pages[i] = NULL; // TODO : Remove NULL values + ++freedPagesCount; + } + } + + //printf("%d freed pages\n", freedPagesCount); +} + +} // End of namespace Common diff --git a/common/memorypool.h b/common/memorypool.h new file mode 100644 index 00000000000..ecc3908c602 --- /dev/null +++ b/common/memorypool.h @@ -0,0 +1,54 @@ +/* Residual - Virtual machine to run LucasArts' 3D adventure games + * Copyright (C) 2003-2008 The ScummVM-Residual Team (www.scummvm.org) + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * $URL$ + * $Id$ + * + */ + +#ifndef COMMON_MEMORYPOOL_H +#define COMMON_MEMORYPOOL_H + +#include "common/sys.h" +#include "common/array.h" + +namespace Common { + +class MemoryPool { +private: + MemoryPool(const MemoryPool&); + MemoryPool& operator=(const MemoryPool&); + + size_t _chunkSize; + Array _pages; + void* _next; + + void* allocPage(); + bool isPointerInPage(void* ptr, void* page); +public: + MemoryPool(size_t chunkSize); + ~MemoryPool(); + + void* malloc(); + void free(void* ptr); + + void freeUnusedPages(); +}; + +} // End of namespace Common + +#endif diff --git a/common/module.mk b/common/module.mk new file mode 100644 index 00000000000..3395c7b1977 --- /dev/null +++ b/common/module.mk @@ -0,0 +1,14 @@ +MODULE := common + +MODULE_OBJS := \ + debug.o \ + hashmap.o \ + matrix3.o \ + matrix4.o \ + memorypool.o \ + str.o \ + mutex.o \ + zlib.o + +# Include common rules +include $(srcdir)/rules.mk diff --git a/common/platform.h b/common/platform.h deleted file mode 100644 index ea0c48c0130..00000000000 --- a/common/platform.h +++ /dev/null @@ -1,388 +0,0 @@ -/* Residual - Virtual machine to run LucasArts' 3D adventure games - * Copyright (C) 2003-2006 The ScummVM-Residual Team (www.scummvm.org) - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA - * - * $URL$ - * $Id$ - * - */ - -#ifndef COMMON_PLATFORM_H -#define COMMON_PLATFORM_H - -#include "common/sys.h" -#include "common/vector3d.h" - -#include -#include -#ifndef __DC__ -#include -#endif - -// Use config.h, generated by configure -#if defined(HAVE_CONFIG_H) -#include "config.h" -#endif - -#ifndef PI -#define PI 3.14159265358979323846 -#endif - -#define ARRAYSIZE(x) ((int)(sizeof(x) / sizeof(x[0]))) - -template inline T ABS (T x) { return (x>=0) ? x : -x; } -template inline T MIN (T a, T b) { return (a inline T MAX (T a, T b) { return (a>b) ? a : b; } - -#ifndef round -#define round(x) ((x > 0.0) ? floor((x) + 0.5) : ceil((x) - 0.5)) -#endif - -#if defined(_MSC_VER) - - #define snprintf _snprintf - - #if defined(CHECK_HEAP) - #undef CHECK_HEAP - #define CHECK_HEAP checkHeap(); - #else - #define CHECK_HEAP - #endif - - #define SYSTEM_LITTLE_ENDIAN - - #define FORCEINLINE __forceinline - #define NORETURN _declspec(noreturn) - - typedef unsigned char byte; - typedef unsigned char uint8; - typedef unsigned short uint16; - typedef unsigned long uint32; - typedef unsigned int uint; - typedef signed char int8; - typedef signed short int16; - typedef signed long int32; - - #define START_PACK_STRUCTS pack(push, 1) - #define END_PACK_STRUCTS pack(pop) - #define GCC_PACK - -#elif defined(__MINGW32__) - - #define CHECK_HEAP - #define SYSTEM_LITTLE_ENDIAN - - #define NORETURN __attribute__((__noreturn__)) - #define GCC_PACK __attribute__((packed)) - #define _HEAPOK 0 - - typedef unsigned char byte; - typedef unsigned char uint8; - typedef unsigned short uint16; - typedef unsigned int uint32; - typedef unsigned int uint; - typedef signed char int8; - typedef signed short int16; - typedef signed int int32; - - #define START_PACK_STRUCTS pack (push, 1) - #define END_PACK_STRUCTS pack(pop) - -#elif defined(UNIX) - - #define CHECK_HEAP - - #ifdef X11_BACKEND - - // You need to set this manually if necessary -// #define SYSTEM_LITTLE_ENDIAN - - #else - /* need this for the SDL_BYTEORDER define */ - #include - - #if SDL_BYTEORDER == SDL_LIL_ENDIAN - #define SYSTEM_LITTLE_ENDIAN - #elif SDL_BYTEORDER == SDL_BIG_ENDIAN - #define SYSTEM_BIG_ENDIAN - #else - #error Neither SDL_BIG_ENDIAN nor SDL_LIL_ENDIAN is set. - #endif - #endif - - // You need to set this manually if necessary -// #define SYSTEM_NEED_ALIGNMENT - - #define FORCEINLINE inline - #define CDECL - - #ifndef HAVE_CONFIG_H - typedef unsigned char byte; - typedef unsigned char uint8; - typedef unsigned short uint16; - typedef unsigned int uint; - typedef unsigned int uint32; - typedef signed char int8; - typedef signed short int16; - typedef signed int int32; - #endif - - #if defined(__DECCXX) // Assume alpha architecture - #define INVERSE_MKID - #define SYSTEM_NEED_ALIGNMENT - #endif - - #if defined(__GNUC__) - #define START_PACK_STRUCTS - #define END_PACK_STRUCTS - #define GCC_PACK __attribute__((packed)) - #define NORETURN __attribute__((__noreturn__)) - #else - #define START_PACK_STRUCTS pack (1) - #define END_PACK_STRUCTS pack () - #define GCC_PACK - #define NORETURN - #endif - - #ifdef __FreeBSD__ - #undef ROUND - #define ROUND(x) rint(x) - #endif - - #if defined(__APPLE__) && defined(__MACH__) - #define MACOSX - #endif - -#elif defined(__MORPHOS__) - #define scumm_stricmp stricmp - #define scumm_strnicmp strnicmp - #define CHECK_HEAP - - #define SYSTEM_BIG_ENDIAN - #define SYSTEM_NEED_ALIGNMENT - - #define FORCEINLINE inline - #define CDECL - - typedef unsigned char byte; - typedef unsigned char uint8; - typedef unsigned short uint16; - typedef unsigned long uint32; - typedef unsigned int uint; - typedef signed char int8; - typedef signed short int16; - typedef signed long int32; - - #if defined(__GNUC__) - #define START_PACK_STRUCTS - #define END_PACK_STRUCTS - #define GCC_PACK __attribute__((packed)) - #define NORETURN __attribute__((__noreturn__)) - #else - #define START_PACK_STRUCTS pack (1) - #define END_PACK_STRUCTS pack () - #define GCC_PACK - #define NORETURN - #endif - #define main morphos_main - -#elif defined(__DC__) - - #define CHECK_HEAP - #define SYSTEM_LITTLE_ENDIAN - #define SYSTEM_NEED_ALIGNMENT - - #define FORCEINLINE inline - #define NORETURN __attribute__((__noreturn__)) - #define GCC_PACK __attribute__((packed)) - #define CDECL - - typedef unsigned char byte; - typedef unsigned char uint8; - typedef unsigned short uint16; - typedef unsigned long uint32; - typedef unsigned int uint; - typedef signed char int8; - typedef signed short int16; - typedef signed long int32; - - #define START_PACK_STRUCTS pack (push, 1) - #define END_PACK_STRUCTS pack(pop) - -#else - #error No system type defined -#endif - -FORCEINLINE uint32 SWAP_BYTES_32(uint32 a) { - return ((a >> 24) & 0x000000FF) | - ((a >> 8) & 0x0000FF00) | - ((a << 8) & 0x00FF0000) | - ((a << 24) & 0xFF000000); -} - -FORCEINLINE uint16 SWAP_BYTES_16(uint16 a) { - return ((a >> 8) & 0x00FF) + ((a << 8) & 0xFF00); -} - - -#if defined(SYSTEM_LITTLE_ENDIAN) - - #define PROTO_MKID(a) ((uint32) \ - (((a) >> 24) & 0x000000FF) | \ - (((a) >> 8) & 0x0000FF00) | \ - (((a) << 8) & 0x00FF0000) | \ - (((a) << 24) & 0xFF000000)) - #define PROTO_MKID_BE(a) ((uint32)(a)) - - #if defined(INVERSE_MKID) - # define MKID(a) PROTO_MKID_BE(a) - # define MKID_BE(a) PROTO_MKID(a) - #else - # define MKID(a) PROTO_MKID(a) - # define MKID_BE(a) PROTO_MKID_BE(a) - #endif - - #define READ_UINT32(a) READ_LE_UINT32(a) - - #define FROM_LE_32(a) ((uint32)(a)) - #define FROM_LE_16(a) ((uint16)(a)) - - #define TO_LE_32(a) ((uint32)(a)) - #define TO_LE_16(a) ((uint16)(a)) - - #define TO_BE_32(a) SWAP_BYTES_32(a) - #define TO_BE_16(a) SWAP_BYTES_16(a) - -#elif defined(SYSTEM_BIG_ENDIAN) - - #define MKID(a) ((uint32)(a)) - #define MKID_BE(a) ((uint32)(a)) - - #define READ_UINT32(a) READ_BE_UINT32(a) - - #define FROM_LE_32(a) SWAP_BYTES_32(a) - #define FROM_LE_16(a) SWAP_BYTES_16(a) - - #define TO_LE_32(a) SWAP_BYTES_32(a) - #define TO_LE_16(a) SWAP_BYTES_16(a) - - #define TO_BE_32(a) ((uint32)(a)) - #define TO_BE_16(a) ((uint16)(a)) - -#else - - #error No endianness defined - -#endif - - -#if defined(SYSTEM_NEED_ALIGNMENT) || defined(SYSTEM_BIG_ENDIAN) - FORCEINLINE uint16 READ_LE_UINT16(const void *ptr) { - const byte *b = (const byte *)ptr; - return (b[1] << 8) + b[0]; - } - FORCEINLINE uint32 READ_LE_UINT32(const void *ptr) { - const byte *b = (const byte *)ptr; - return (b[3] << 24) + (b[2] << 16) + (b[1] << 8) + (b[0]); - } - FORCEINLINE void WRITE_LE_UINT16(void *ptr, uint16 value) { - byte *b = (byte *)ptr; - b[0] = (byte)(value >> 0); - b[1] = (byte)(value >> 8); - } - FORCEINLINE void WRITE_LE_UINT32(void *ptr, uint32 value) { - byte *b = (byte *)ptr; - b[0] = (byte)(value >> 0); - b[1] = (byte)(value >> 8); - b[2] = (byte)(value >> 16); - b[3] = (byte)(value >> 24); - } -#else - FORCEINLINE uint16 READ_LE_UINT16(const void *ptr) { - return *(const uint16 *)(ptr); - } - FORCEINLINE uint32 READ_LE_UINT32(const void *ptr) { - return *(const uint32 *)(ptr); - } - FORCEINLINE void WRITE_LE_UINT16(void *ptr, uint16 value) { - *(uint16 *)(ptr) = value; - } - FORCEINLINE void WRITE_LE_UINT32(void *ptr, uint32 value) { - *(uint32 *)(ptr) = value; - } -#endif - - -#if defined(SYSTEM_NEED_ALIGNMENT) || defined(SYSTEM_LITTLE_ENDIAN) - FORCEINLINE uint16 READ_BE_UINT16(const void *ptr) { - const byte *b = (const byte *)ptr; - return (b[0] << 8) + b[1]; - } - FORCEINLINE uint32 READ_BE_UINT32(const void *ptr) { - const byte *b = (const byte*)ptr; - return (b[0] << 24) + (b[1] << 16) + (b[2] << 8) + (b[3]); - } - FORCEINLINE void WRITE_BE_UINT16(void *ptr, uint16 value) { - byte *b = (byte *)ptr; - b[0] = (byte)(value >> 8); - b[1] = (byte)(value >> 0); - } - FORCEINLINE void WRITE_BE_UINT32(void *ptr, uint32 value) { - byte *b = (byte *)ptr; - b[0] = (byte)(value >> 24); - b[1] = (byte)(value >> 16); - b[2] = (byte)(value >> 8); - b[3] = (byte)(value >> 0); - } -#else - FORCEINLINE uint16 READ_BE_UINT16(const void *ptr) { - return *(const uint16 *)(ptr); - } - FORCEINLINE uint32 READ_BE_UINT32(const void *ptr) { - return *(const uint32 *)(ptr); - } - FORCEINLINE void WRITE_BE_UINT16(void *ptr, uint16 value) { - *(uint16 *)(ptr) = value; - } - FORCEINLINE void WRITE_BE_UINT32(void *ptr, uint32 value) { - *(uint32 *)(ptr) = value; - } -#endif - -#if defined(SYSTEM_BIG_ENDIAN) - -inline float get_float(const char *data) { - const unsigned char *udata = reinterpret_cast(data); - unsigned char fdata[4]; - fdata[0] = udata[3]; - fdata[1] = udata[2]; - fdata[2] = udata[1]; - fdata[3] = udata[0]; - return *(reinterpret_cast(fdata)); -} - -#else - -inline float get_float(const char *data) { - return *(reinterpret_cast(data)); -} -#endif - -inline Vector3d get_vector3d(const char *data) { - return Vector3d(get_float(data), get_float(data + 4), get_float(data + 8)); -} - -#endif diff --git a/common/str.cpp b/common/str.cpp new file mode 100644 index 00000000000..894b5862f1e --- /dev/null +++ b/common/str.cpp @@ -0,0 +1,484 @@ +/* Residual - Virtual machine to run LucasArts' 3D adventure games + * Copyright (C) 2003-2008 The ScummVM-Residual Team (www.scummvm.org) + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * $URL$ + * $Id$ + */ + +#include "common/str.h" +#include "common/hash-str.h" +#include "common/util.h" + +namespace Common { + +#if !(defined(PALMOS_ARM) || defined(PALMOS_DEBUG) || defined(__GP32__)) +const String String::emptyString; +#else +const char *String::emptyString = ""; +#endif + +static int computeCapacity(int len) { + // By default, for the capacity we use the nearest multiple of 32 + // that leaves at least 16 chars of extra space (in case the string + // grows a bit). + // Finally, we subtract 1 to compensate for the trailing zero byte. + len += 16; + return ((len + 32 - 1) & ~0x1F) - 1; +} + +String::String(const char *str, uint32 len) +: _len(0), _str(_storage) { + + // Init _storage member explicitly (ie. without calling its constructor) + // for GCC 2.95.x compatibility (see also tracker item #1602879). + _storage[0] = 0; + + if (str && *str) { + const uint32 tmp = strlen(str); + assert(len <= tmp); + if (len <= 0) + len = tmp; + _len = len; + + if (len >= _builtinCapacity) { + // Not enough internal storage, so allocate more + _extern._capacity = computeCapacity(len); + _extern._refCount = 0; + _str = (char *)malloc(_extern._capacity+1); + assert(_str != 0); + } + + // Copy the string into the storage area + memcpy(_str, str, len); + _str[len] = 0; + } +} + +String::String(const String &str) + : _len(str._len), _str(str.isStorageIntern() ? _storage : str._str) { + if (str.isStorageIntern()) { + // String in internal storage: just copy it + memcpy(_storage, str._storage, _builtinCapacity); + } else { + // String in external storage: use refcount mechanism + str.incRefCount(); + _extern._refCount = str._extern._refCount; + _extern._capacity = str._extern._capacity; + } + assert(_str != 0); +} + +String::String(char c) +: _len(0), _str(_storage) { + + _storage[0] = c; + _storage[1] = 0; + + _len = (c == 0) ? 0 : 1; +} + +String::~String() { + decRefCount(_extern._refCount); +} + +void String::incRefCount() const { + assert(!isStorageIntern()); + if (_extern._refCount == 0) { + _extern._refCount = new int(2); + } else { + ++(*_extern._refCount); + } +} + +void String::decRefCount(int *oldRefCount) { + if (isStorageIntern()) + return; + + if (oldRefCount) { + --(*oldRefCount); + } + if (!oldRefCount || *oldRefCount <= 0) { + // The ref count reached zero, so we free the string storage + // and the ref count storage. + delete oldRefCount; + free(_str); + + // Even though _str points to a freed memory block now, + // we do not change its value, because any code that calls + // decRefCount will have to do this afterwards anyway. + } +} + +String& String::operator =(const char *str) { + uint32 len = strlen(str); + ensureCapacity(len, false); + _len = len; + memcpy(_str, str, len + 1); + return *this; +} + +String &String::operator =(const String &str) { + if (str.isStorageIntern()) { + decRefCount(_extern._refCount); + _len = str._len; + _str = _storage; + memcpy(_str, str._str, _len + 1); + } else { + str.incRefCount(); + decRefCount(_extern._refCount); + + _extern._refCount = str._extern._refCount; + _extern._capacity = str._extern._capacity; + _len = str._len; + _str = str._str; + } + + return *this; +} + +String& String::operator =(char c) { + ensureCapacity(1, false); + _len = 1; + _str[0] = c; + _str[1] = 0; + return *this; +} + +String &String::operator +=(const char *str) { + int len = strlen(str); + if (len > 0) { + ensureCapacity(_len + len, true); + + memcpy(_str + _len, str, len + 1); + _len += len; + } + return *this; +} + +String &String::operator +=(const String &str) { + int len = str._len; + if (len > 0) { + ensureCapacity(_len + len, true); + + memcpy(_str + _len, str._str, len + 1); + _len += len; + } + return *this; +} + +String &String::operator +=(char c) { + ensureCapacity(_len + 1, true); + + _str[_len++] = c; + _str[_len] = 0; + + return *this; +} + +bool String::hasPrefix(const char *x) const { + assert(x != 0); + // Compare x with the start of _str. + const char *y = c_str(); + while (*x && *x == *y) { + ++x; + ++y; + } + // It's a prefix, if and only if all letters in x are 'used up' before + // _str ends. + return *x == 0; +} + +bool String::hasSuffix(const char *x) const { + assert(x != 0); + // Compare x with the end of _str. + const uint32 x_len = strlen(x); + if (x_len > _len) + return false; + const char *y = c_str() + _len - x_len; + while (*x && *x == *y) { + ++x; + ++y; + } + // It's a suffix, if and only if all letters in x are 'used up' before + // _str ends. + return *x == 0; +} + +bool String::contains(const char *x) const { + assert(x != 0); + return strstr(c_str(), x) != NULL; +} + +bool String::contains(char x) const { + return strchr(c_str(), x) != NULL; +} + +void String::deleteLastChar() { + deleteChar(_len - 1); +} + +void String::deleteChar(uint32 p) { + assert(p < _len); + + // Call ensureCapacity to make sure we actually *own* the storage + // to which _str points to -- we wouldn't want to modify a storage + // which other string objects are sharing, after all. + ensureCapacity(_len, true); + while (p++ < _len) + _str[p-1] = _str[p]; + _len--; +} + +void String::clear() { + decRefCount(_extern._refCount); + + _len = 0; + _str = _storage; + _storage[0] = 0; +} + +void String::setChar(char c, uint32 p) { + assert(p <= _len); + + ensureCapacity(_len, true); + _str[p] = c; +} + +void String::insertChar(char c, uint32 p) { + assert(p <= _len); + + ensureCapacity(_len + 1, true); + _len++; + for (uint32 i = _len; i > p; --i) + _str[i] = _str[i-1]; + _str[p] = c; +} + +void String::toLowercase() { + ensureCapacity(_len, true); + for (uint32 i = 0; i < _len; ++i) + _str[i] = tolower(_str[i]); +} + +void String::toUppercase() { + ensureCapacity(_len, true); + for (uint32 i = 0; i < _len; ++i) + _str[i] = toupper(_str[i]); +} + +/** + * Ensure that enough storage is available to store at least new_len + * characters plus a null byte. In addition, if we currently share + * the storage with another string, unshare it, so that we can safely + * write to the storage. + */ +void String::ensureCapacity(uint32 new_len, bool keep_old) { + bool isShared; + uint32 curCapacity, newCapacity; + char *newStorage; + int *oldRefCount = _extern._refCount; + + if (isStorageIntern()) { + isShared = false; + curCapacity = _builtinCapacity - 1; + } else { + isShared = (oldRefCount && *oldRefCount > 1); + curCapacity = _extern._capacity; + } + + // Special case: If there is enough space, and we do not share + // the storage, then there is nothing to do. + if (!isShared && new_len <= curCapacity) + return; + + if (isShared && new_len <= _builtinCapacity - 1) { + // We share the storage, but there is enough internal storage: Use that. + newStorage = _storage; + newCapacity = _builtinCapacity - 1; + } else { + // We need to allocate storage on the heap! + + // Compute a suitable new capacity limit + newCapacity = computeCapacity(new_len); + + // Allocate new storage + newStorage = (char *)malloc(newCapacity+1); + assert(newStorage); + } + + // Copy old data if needed, elsewise reset the new storage. + if (keep_old) { + assert(_len <= newCapacity); + memcpy(newStorage, _str, _len + 1); + } else { + _len = 0; + newStorage[0] = 0; + } + + // Release hold on the old storage ... + decRefCount(oldRefCount); + + // ... in favor of the new storage + _str = newStorage; + + if (!isStorageIntern()) { + // Set the ref count & capacity if we use an external storage. + // It is important to do this *after* copying any old content, + // else we would override data that has not yet been copied! + _extern._refCount = 0; + _extern._capacity = newCapacity; + } +} + +uint String::hash() const { + return hashit(c_str()); +} + +#pragma mark - + +bool String::operator ==(const String &x) const { + return equals(x); +} + +bool String::operator ==(const char *x) const { + assert(x != 0); + return equals(x); +} + +bool String::operator !=(const String &x) const { + return !equals(x); +} + +bool String::operator !=(const char *x) const { + assert(x != 0); + return !equals(x); +} + +bool String::operator < (const String &x) const { + return compareTo(x) < 0; +} + +bool String::operator <= (const String &x) const { + return compareTo(x) <= 0; +} + +bool String::operator > (const String &x) const { + return compareTo(x) > 0; +} + +bool String::operator >= (const String &x) const { + return compareTo(x) >= 0; +} + +#pragma mark - + +bool operator == (const char* y, const String &x) { + return (x == y); +} + +bool operator != (const char* y, const String &x) { + return x != y; +} + +#pragma mark - + +bool String::equals(const String &x) const { + return (0 == compareTo(x)); +} + +bool String::equals(const char *x) const { + assert(x != 0); + return (0 == compareTo(x)); +} + +bool String::equalsIgnoreCase(const String &x) const { + return (0 == compareToIgnoreCase(x)); +} + +bool String::equalsIgnoreCase(const char *x) const { + assert(x != 0); + return (0 == compareToIgnoreCase(x)); +} + +int String::compareTo(const String &x) const { + return compareTo(x.c_str()); +} + +int String::compareTo(const char *x) const { + assert(x != 0); + return strcmp(c_str(), x); +} + +int String::compareToIgnoreCase(const String &x) const { + return compareToIgnoreCase(x.c_str()); +} + +int String::compareToIgnoreCase(const char *x) const { + assert(x != 0); + return strcasecmp(c_str(), x); +} + +#pragma mark - + +String operator +(const String &x, const String &y) { + String temp(x); + temp += y; + return temp; +} + +String operator +(const char *x, const String &y) { + String temp(x); + temp += y; + return temp; +} + +String operator +(const String &x, const char *y) { + String temp(x); + temp += y; + return temp; +} + +String operator +(char x, const String &y) { + String temp(x); + temp += y; + return temp; +} + +String operator +(const String &x, char y) { + String temp(x); + temp += y; + return temp; +} + +char *ltrim(char *t) { + while (isspace(*t)) + t++; + return t; +} + +char *rtrim(char *t) { + int l = strlen(t) - 1; + while (l >= 0 && isspace(t[l])) + t[l--] = 0; + return t; +} + +char *trim(char *t) { + return rtrim(ltrim(t)); +} + +} // End of namespace Common diff --git a/common/str.h b/common/str.h new file mode 100644 index 00000000000..4fcb76fce40 --- /dev/null +++ b/common/str.h @@ -0,0 +1,224 @@ +/* Residual - Virtual machine to run LucasArts' 3D adventure games + * Copyright (C) 2003-2008 The ScummVM-Residual Team (www.scummvm.org) + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * $URL$ + * $Id$ + */ + +#ifndef COMMON_STRING_H +#define COMMON_STRING_H + +#include "common/sys.h" +#include "common/array.h" + +namespace Common { + +/** + * Simple string class for ScummVM. Provides automatic storage managment, + * and overloads several operators in a 'natural' fashion, mimicking + * the std::string class. Even provides simple iterators. + * + * This class tries to avoid allocating lots of small blocks on the heap, + * since that is inefficient on several platforms supported by ScummVM. + * Instead, small strings are stored 'inside' the string object (i.e. on + * the stack, for stack allocated objects), and only for strings exceeding + * a certain length do we allocate a buffer on the heap. + */ +class String { +protected: + /** + * The size of the internal storage. Increasing this means less heap + * allocations are needed, at the cost of more stack memory usage, + * and of course lots of wasted memory. Empirically, 90% or more of + * all String instances are less than 32 chars long. If a platform + * is very short on stack space, it would be possible to lower this. + * A value of 24 still seems acceptable, though considerably worse, + * while 16 seems to be the lowest you want to go... Anything lower + * than 8 makes no sense, since that's the size of member _extern + * (on 32 bit machines; 12 bytes on systems with 64bit pointers). + */ + static const uint32 _builtinCapacity = 32; + + /** + * Length of the string. Stored to avoid having to call strlen + * a lot. Yes, we limit ourselves to strings shorter than 4GB -- + * on purpose :-). + */ + uint32 _len; + + /** + * Pointer to the actual string storage. Either points to _storage, + * or to a block allocated on the heap via malloc. + */ + char *_str; + + + union { + /** + * Internal string storage. + */ + char _storage[_builtinCapacity]; + /** + * External string storage data -- the refcounter, and the + * capacity of the string _str points to. + */ + struct { + mutable int *_refCount; + uint32 _capacity; + } _extern; + }; + + inline bool isStorageIntern() const { + return _str == _storage; + } + +public: +#if !(defined(PALMOS_ARM) || defined(PALMOS_DEBUG) || defined(__GP32__)) + static const String emptyString; +#else + static const char *emptyString; +#endif + + String() : _len(0), _str(_storage) { _storage[0] = 0; } + String(const char *str, uint32 len = 0); + String(const String &str); + String(char c); + ~String(); + + String &operator =(const char *str); + String &operator =(const String &str); + String &operator =(char c); + String &operator +=(const char *str); + String &operator +=(const String &str); + String &operator +=(char c); + + bool operator ==(const String &x) const; + bool operator ==(const char *x) const; + bool operator !=(const String &x) const; + bool operator !=(const char *x) const; + + bool operator <(const String &x) const; + bool operator <=(const String &x) const; + bool operator >(const String &x) const; + bool operator >=(const String &x) const; + + bool equals(const String &x) const; + bool equalsIgnoreCase(const String &x) const; + int compareTo(const String &x) const; // strcmp clone + int compareToIgnoreCase(const String &x) const; // stricmp clone + + bool equals(const char *x) const; + bool equalsIgnoreCase(const char *x) const; + int compareTo(const char *x) const; // strcmp clone + int compareToIgnoreCase(const char *x) const; // stricmp clone + + bool hasSuffix(const char *x) const; + bool hasPrefix(const char *x) const; + + bool contains(const char *x) const; + bool contains(char x) const; + + inline const char *c_str() const { return _str; } + inline uint size() const { return _len; } + + inline bool empty() const { return (_len == 0); } + char lastChar() const { return (_len > 0) ? _str[_len-1] : 0; } + + char operator [](int idx) const { + assert(_str && idx >= 0 && idx < (int)_len); + return _str[idx]; + } + + /** Remove the last character from the string. */ + void deleteLastChar(); + + /** Remove the character at position p from the string. */ + void deleteChar(uint32 p); + + /** Set character c at position p, replacing the previous character there. */ + void setChar(char c, uint32 p); + + /** Set character c at position p. */ + void insertChar(char c, uint32 p); + + void clear(); + + void toLowercase(); + void toUppercase(); + + uint hash() const; + +public: + typedef char * iterator; + typedef const char * const_iterator; + + iterator begin() { + return _str; + } + + iterator end() { + return begin() + size(); + } + + const_iterator begin() const { + return _str; + } + + const_iterator end() const { + return begin() + size(); + } + +protected: + void ensureCapacity(uint32 new_len, bool keep_old); + void incRefCount() const; + void decRefCount(int *oldRefCount); +}; + +// Append two strings to form a new (temp) string +String operator +(const String &x, const String &y); + +String operator +(const char *x, const String &y); +String operator +(const String &x, const char *y); + +String operator +(const String &x, char y); +String operator +(char x, const String &y); + +// Some useful additional comparision operators for Strings +bool operator == (const char *x, const String &y); +bool operator != (const char *x, const String &y); + +// Utility functions to remove leading and trailing whitespaces +extern char *ltrim(char *t); +extern char *rtrim(char *t); +extern char *trim(char *t); + +class StringList : public Array { +public: + void push_back(const char *str) { + ensureCapacity(_size + 1); + _data[_size++] = str; + } + + void push_back(const String &str) { + ensureCapacity(_size + 1); + _data[_size++] = str; + } +}; + +} // End of namespace Common + +#endif diff --git a/common/sys.h b/common/sys.h index 188dc716c71..ddafa171eb9 100644 --- a/common/sys.h +++ b/common/sys.h @@ -23,107 +23,250 @@ #ifndef COMMON_SYS_H #define COMMON_SYS_H +#include +#include +#include +#include +#include +#include +#include + +extern "C" int residual_main(int argc, char *argv[]); #ifndef _MSC_VER +#include +#include #include #endif -#if defined(WIN32) - #ifdef _MSC_VER #pragma once #pragma warning( disable : 4068 ) // turn off "unknown pragma" warning #pragma warning( disable : 4244 ) // turn off "conversion type" warning #endif -#if !defined(_WIN32_WCE) +#ifndef LOCAL_PI +#define LOCAL_PI 3.14159265358979323846 +#endif +// Use config.h, generated by configure +#if defined(HAVE_CONFIG_H) +#include "config.h" +#endif -#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers -#define NOGDICAPMASKS -#define OEMRESOURCE -#define NONLS -#define NOICONS -#define NOMCX -#define NOPROFILER -#define NOKANJI -#define NOSERVICE -#define NOMETAFILE -#define NOCOMM -#define NOCRYPT -#define NOIME -#define NOATOM -#define NOCTLMGR -#define NOCLIPBOARD -#define NOMEMMGR -#define NOSYSMETRICS -#define NOMENUS -#define NOOPENFILE -#define NOWH -#define NOSOUND -#define NODRAWTEXT - +// In the following we configure various targets, in particular those +// which can't use our "configure" tool and hence don't use config.h. +// +// Some #defines that occur here frequently: +// SYSTEM_LITTLE_ENDIAN +// - Define this on a little endian target +// SYSTEM_BIG_ENDIAN +// - Define this on a big endian target +// SYSTEM_NEED_ALIGNMENT +// - Define this if your system has problems reading e.g. an int32 from an odd address +// SYSTEM_USE_LONG_INT +// - Define this if your port needs to use 'long' for the int32 datatype +// (i.e. an integer with exactly 32 bits). +// SYSTEM_DONT_DEFINE_TYPES +// - Define this if you need to provide your own typedefs, e.g. because your +// system headers conflict with our typenames, or because you have odd +// type requirements. +// SMALL_SCREEN_DEVICE +// - ... +// ... +// We define all types in config.h, so we don't want to typedef those types +// here again! +#ifdef HAVE_CONFIG_H +#define SYSTEM_DONT_DEFINE_TYPES #endif -#include -#if defined(ARRAYSIZE) -// VS2005beta2 introduces new stuff in winnt.h -#undef ARRAYSIZE -#endif -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#define strcasecmp stricmp -#define M_PI 3.14159265358979323846 +#if defined(__SYMBIAN32__) -#ifndef _MSC_VER -#include -#include + #define strcasecmp stricmp + + #define SYSTEM_LITTLE_ENDIAN + #define SYSTEM_NEED_ALIGNMENT + + #define SMALL_SCREEN_DEVICE + + // Enable Symbians own datatypes + // This is done for two reasons + // a) uint is already defined by Symbians libc component + // b) Symbian is using its "own" datatyping, and the Scummvm port + // should follow this to ensure the best compability possible. + #define SYSTEM_DONT_DEFINE_TYPES + typedef unsigned char byte; + + typedef unsigned char uint8; + typedef signed char int8; + + typedef unsigned short int uint16; + typedef signed short int int16; + + typedef unsigned long int uint32; + typedef signed long int int32; + +#elif defined(_WIN32_WCE) + + #define strcasecmp stricmp + + #define SYSTEM_LITTLE_ENDIAN + #define SYSTEM_NEED_ALIGNMENT + + #define SMALL_SCREEN_DEVICE + + typedef signed char int8_t; + typedef signed short int16_t; + typedef unsigned char uint8_t; + typedef unsigned short uint16_t; + +#elif defined(_MSC_VER) + + #define strcasecmp stricmp + + #define SYSTEM_LITTLE_ENDIAN + + typedef signed char int8_t; + typedef signed short int16_t; + typedef unsigned char uint8_t; + typedef unsigned short uint16_t; + +#elif defined(__MINGW32__) + + #define strcasecmp stricmp + + #define SYSTEM_LITTLE_ENDIAN + +#elif defined(UNIX) + + #ifndef CONFIG_H + /* need this for the SDL_BYTEORDER define */ + #include + + #if SDL_BYTEORDER == SDL_LIL_ENDIAN + #define SCUMM_LITTLE_ENDIAN + #elif SDL_BYTEORDER == SDL_BIG_ENDIAN + #define SCUMM_BIG_ENDIAN + #else + #error Neither SDL_BIG_ENDIAN nor SDL_LIL_ENDIAN is set. + #endif + #endif + + // You need to set this manually if necessary +// #define SYSTEM_NEED_ALIGNMENT + + #if defined(__DECCXX) // Assume alpha architecture + #define INVERSE_MKID + #define SYSTEM_NEED_ALIGNMENT + #endif + +#elif defined(__PALMOS_TRAPS__) || defined (__PALMOS_ARMLET__) + +#ifdef __PALMOS_ARMLET__ + #include #endif + #define SYSTEM_LITTLE_ENDIAN + + #define strcasecmp stricmp + + #define SYSTEM_NEED_ALIGNMENT + #define STRINGBUFLEN 256 + +#elif defined(__DC__) + + #define SYSTEM_LITTLE_ENDIAN + #define SYSTEM_NEED_ALIGNMENT + +#elif defined(__PLAYSTATION2__) + + #define SYSTEM_LITTLE_ENDIAN + #define SYSTEM_NEED_ALIGNMENT + +#elif defined(__PSP__) + + #define SYSTEM_LITTLE_ENDIAN + #define SYSTEM_NEED_ALIGNMENT + +#elif defined(__amigaos4__) + + #define SYSTEM_BIG_ENDIAN + #define SYSTEM_NEED_ALIGNMENT + +#elif defined (__DS__) //NeilM + + #define strcasecmp stricmp + + #define SYSTEM_NEED_ALIGNMENT + #define SYSTEM_LITTLE_ENDIAN + + #include "nds/jtypes.h" + + #define SYSTEM_DONT_DEFINE_TYPES + + #define STRINGBUFLEN 256 + #define printf(fmt, ...) consolePrintf(fmt, ##__VA_ARGS__) + +#elif defined(__WII__) + + #define SYSTEM_BIG_ENDIAN + #define SYSTEM_NEED_ALIGNMENT #else - -#if defined(__MORPHOS__) -#include -#undef CMD_INVALID -#endif -#if !defined(macintosh) -#include -#if !defined(__DC__) -#include -#endif -#endif -#if !defined (__BEOS__) -#include -#endif -#if defined(__QNXNTO__) -#include /* For strcasecmp */ -#endif -#include -#include -#include -#include -#include -#include -#include -#if defined(__DC__) -#include -#else -#include -#endif - + #error No system type defined #endif +// +// Typedef our system types unless SYSTEM_DONT_DEFINE_TYPES is set. +// +#ifndef SYSTEM_DONT_DEFINE_TYPES + + typedef unsigned char byte; + + typedef unsigned char uint8; + typedef signed char int8; + + typedef unsigned short uint16; + typedef signed short int16; + + #ifdef SYSTEM_USE_LONG_INT + typedef unsigned long uint32; + typedef signed long int32; + typedef unsigned long uint; + #else + typedef unsigned int uint32; + typedef signed int int32; + typedef unsigned int uint; + #endif #endif + +// +// Fallbacks / default values for various special macros +// +#ifndef FORCEINLINE +#define FORCEINLINE inline +#endif + +#ifndef NORETURN +#define NORETURN +#endif + +#ifndef STRINGBUFLEN +#define STRINGBUFLEN 1024 +#endif + +#ifndef MAXPATHLEN +#define MAXPATHLEN 256 +#endif + +#ifndef CDECL +#define CDECL +#endif + +#ifndef NORETURN +#define NORETURN +#endif + +#endif // COMMON_SYS_H diff --git a/common/util.h b/common/util.h new file mode 100644 index 00000000000..80e8bb19f86 --- /dev/null +++ b/common/util.h @@ -0,0 +1,60 @@ +/* ScummVM - Graphic Adventure Engine + * + * ScummVM is the legal property of its developers, whose names + * are too numerous to list here. Please refer to the COPYRIGHT + * file distributed with this source distribution. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * $URL$ + * $Id$ + */ + +#ifndef COMMON_UTIL_H +#define COMMON_UTIL_H + +#include "common/sys.h" + +#ifdef MIN +#undef MIN +#endif + +#ifdef MAX +#undef MAX +#endif + +template inline T ABS (T x) { return (x>=0) ? x : -x; } +template inline T MIN (T a, T b) { return (a inline T MAX (T a, T b) { return (a>b) ? a : b; } +template inline T CLIP (T v, T amin, T amax) + { if (v < amin) return amin; else if (v > amax) return amax; else return v; } + +/** + * Template method which swaps the vaulues of its two parameters. + */ +template inline void SWAP(T &a, T &b) { T tmp = a; a = b; b = tmp; } + +#if defined(ARRAYSIZE) +// VS2005beta2 introduces new stuff in winnt.h +#undef ARRAYSIZE +#endif +#define ARRAYSIZE(x) ((int)(sizeof(x) / sizeof(x[0]))) + +#ifndef round +#define round(x) ((x > 0.0) ? floor((x) + 0.5) : ceil((x) - 0.5)) +#endif + + +#endif diff --git a/common/vector3d.h b/common/vector3d.h index f6d4c863ea0..8adf007eb6f 100644 --- a/common/vector3d.h +++ b/common/vector3d.h @@ -24,10 +24,7 @@ #define COMMON_VECTOR3D_H #include - -#ifndef PI -#define PI 3.14159265358979323846 -#endif +#include class Vector3d { public: @@ -40,18 +37,18 @@ public: float& z() { return _coords[2]; } float z() const { return _coords[2]; } - Vector3d() { this->x() = 0; this->y() = 0; this->z() = 0; } + Vector3d() { x() = 0; y() = 0; z() = 0; } - Vector3d(float x, float y, float z) { - this->x() = x; this->y() = y; this->z() = z; + Vector3d(float lx, float ly, float lz) { + x() = lx; y() = ly; z() = lz; } Vector3d(const Vector3d &v) { x() = v.x(); y() = v.y(); z() = v.z(); } - void set(float x, float y, float z) { - this->x() = x; this->y() = y; this->z() = z; + void set(float lx, float ly, float lz) { + x() = lx; y() = ly; z() = lz; } Vector3d& operator =(const Vector3d &v) { @@ -99,7 +96,7 @@ public: float yaw; // find the angle on the upper half of the unit circle - yaw = std::acos(a) * (180.0f / (float)PI); + yaw = std::acos(a) * (180.0f / LOCAL_PI); if (b < 0.0f) // adjust for the lower half of the unit circle return 360.0f - yaw; @@ -169,4 +166,28 @@ inline bool operator ==(const Vector3d& v1, const Vector3d& v2) { return v1.x() == v2.x() && v1.y() == v2.y() && v1.z() == v2.z(); } +#if defined(SYSTEM_BIG_ENDIAN) + +inline float get_float(const char *data) { + const unsigned char *udata = reinterpret_cast(data); + unsigned char fdata[4]; + fdata[0] = udata[3]; + fdata[1] = udata[2]; + fdata[2] = udata[1]; + fdata[3] = udata[0]; + return *(reinterpret_cast(fdata)); +} + +#else + +inline float get_float(const char *data) { + return *(reinterpret_cast(data)); +} +#endif + +inline Vector3d get_vector3d(const char *data) { + return Vector3d(get_float(data), get_float(data + 4), get_float(data + 8)); +} + + #endif diff --git a/common/zlib.cpp b/common/zlib.cpp new file mode 100644 index 00000000000..cd48bfc449c --- /dev/null +++ b/common/zlib.cpp @@ -0,0 +1,41 @@ +/* Residual - Virtual machine to run LucasArts' 3D adventure games + * Copyright (C) 2003-2008 The ScummVM-Residual Team (www.scummvm.org) + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * $URL$ + * $Id$ + */ + +#include "common/zlib.h" + +#if defined(USE_ZLIB) + +#ifdef __SYMBIAN32__ +#include +#else +#include +#endif + +namespace Common { + +int uncompress(byte *dst, unsigned long *dstLen, const byte *src, unsigned long srcLen) { + return ::uncompress(dst, dstLen, src, srcLen); +} + +} // end of namespace Common + +#endif + diff --git a/common/zlib.h b/common/zlib.h new file mode 100644 index 00000000000..b2bd7c4e0c8 --- /dev/null +++ b/common/zlib.h @@ -0,0 +1,48 @@ +/* Residual - Virtual machine to run LucasArts' 3D adventure games + * Copyright (C) 2003-2008 The ScummVM-Residual Team (www.scummvm.org) + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * $URL$ + * $Id$ + */ + +#include "common/sys.h" + +#if defined(USE_ZLIB) + +#ifndef COMMON_ZLIB_H +#define COMMON_ZLIB_H + +#ifdef __SYMBIAN32__ +#include +#else +#include +#endif + +namespace Common { + +enum { + ZLIB_OK = Z_OK +}; + +int uncompress(byte *dst, unsigned long *dstLen, const byte *src, unsigned long srcLen); + +} // end of namespace Common + +#endif + +#endif + diff --git a/config.guess b/config.guess new file mode 100755 index 00000000000..278f9e9e07c --- /dev/null +++ b/config.guess @@ -0,0 +1,1516 @@ +#! /bin/sh +# Attempt to guess a canonical system name. +# Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, +# 2000, 2001, 2002, 2003, 2004, 2005, 2006 Free Software Foundation, +# Inc. + +timestamp='2007-07-22' + +# This file is free software; you can redistribute it and/or modify it +# under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA +# 02110-1301, USA. +# +# As a special exception to the GNU General Public License, if you +# distribute this file as part of a program that contains a +# configuration script generated by Autoconf, you may include it under +# the same distribution terms that you use for the rest of that program. + + +# Originally written by Per Bothner . +# Please send patches to . Submit a context +# diff and a properly formatted ChangeLog entry. +# +# This script attempts to guess a canonical system name similar to +# config.sub. If it succeeds, it prints the system name on stdout, and +# exits with 0. Otherwise, it exits with 1. +# +# The plan is that this can be called by configure scripts if you +# don't specify an explicit build system type. + +me=`echo "$0" | sed -e 's,.*/,,'` + +usage="\ +Usage: $0 [OPTION] + +Output the configuration name of the system \`$me' is run on. + +Operation modes: + -h, --help print this help, then exit + -t, --time-stamp print date of last modification, then exit + -v, --version print version number, then exit + +Report bugs and patches to ." + +version="\ +GNU config.guess ($timestamp) + +Originally written by Per Bothner. +Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005 +Free Software Foundation, Inc. + +This is free software; see the source for copying conditions. There is NO +warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE." + +help=" +Try \`$me --help' for more information." + +# Parse command line +while test $# -gt 0 ; do + case $1 in + --time-stamp | --time* | -t ) + echo "$timestamp" ; exit ;; + --version | -v ) + echo "$version" ; exit ;; + --help | --h* | -h ) + echo "$usage"; exit ;; + -- ) # Stop option processing + shift; break ;; + - ) # Use stdin as input. + break ;; + -* ) + echo "$me: invalid option $1$help" >&2 + exit 1 ;; + * ) + break ;; + esac +done + +if test $# != 0; then + echo "$me: too many arguments$help" >&2 + exit 1 +fi + +trap 'exit 1' 1 2 15 + +# CC_FOR_BUILD -- compiler used by this script. Note that the use of a +# compiler to aid in system detection is discouraged as it requires +# temporary files to be created and, as you can see below, it is a +# headache to deal with in a portable fashion. + +# Historically, `CC_FOR_BUILD' used to be named `HOST_CC'. We still +# use `HOST_CC' if defined, but it is deprecated. + +# Portable tmp directory creation inspired by the Autoconf team. + +set_cc_for_build=' +trap "exitcode=\$?; (rm -f \$tmpfiles 2>/dev/null; rmdir \$tmp 2>/dev/null) && exit \$exitcode" 0 ; +trap "rm -f \$tmpfiles 2>/dev/null; rmdir \$tmp 2>/dev/null; exit 1" 1 2 13 15 ; +: ${TMPDIR=/tmp} ; + { tmp=`(umask 077 && mktemp -d "$TMPDIR/cgXXXXXX") 2>/dev/null` && test -n "$tmp" && test -d "$tmp" ; } || + { test -n "$RANDOM" && tmp=$TMPDIR/cg$$-$RANDOM && (umask 077 && mkdir $tmp) ; } || + { tmp=$TMPDIR/cg-$$ && (umask 077 && mkdir $tmp) && echo "Warning: creating insecure temp directory" >&2 ; } || + { echo "$me: cannot create a temporary directory in $TMPDIR" >&2 ; exit 1 ; } ; +dummy=$tmp/dummy ; +tmpfiles="$dummy.c $dummy.o $dummy.rel $dummy" ; +case $CC_FOR_BUILD,$HOST_CC,$CC in + ,,) echo "int x;" > $dummy.c ; + for c in cc gcc c89 c99 ; do + if ($c -c -o $dummy.o $dummy.c) >/dev/null 2>&1 ; then + CC_FOR_BUILD="$c"; break ; + fi ; + done ; + if test x"$CC_FOR_BUILD" = x ; then + CC_FOR_BUILD=no_compiler_found ; + fi + ;; + ,,*) CC_FOR_BUILD=$CC ;; + ,*,*) CC_FOR_BUILD=$HOST_CC ;; +esac ; set_cc_for_build= ;' + +# This is needed to find uname on a Pyramid OSx when run in the BSD universe. +# (ghazi@noc.rutgers.edu 1994-08-24) +if (test -f /.attbin/uname) >/dev/null 2>&1 ; then + PATH=$PATH:/.attbin ; export PATH +fi + +UNAME_MACHINE=`(uname -m) 2>/dev/null` || UNAME_MACHINE=unknown +UNAME_RELEASE=`(uname -r) 2>/dev/null` || UNAME_RELEASE=unknown +UNAME_SYSTEM=`(uname -s) 2>/dev/null` || UNAME_SYSTEM=unknown +UNAME_VERSION=`(uname -v) 2>/dev/null` || UNAME_VERSION=unknown + +# Note: order is significant - the case branches are not exclusive. + +case "${UNAME_MACHINE}:${UNAME_SYSTEM}:${UNAME_RELEASE}:${UNAME_VERSION}" in + *:NetBSD:*:*) + # NetBSD (nbsd) targets should (where applicable) match one or + # more of the tupples: *-*-netbsdelf*, *-*-netbsdaout*, + # *-*-netbsdecoff* and *-*-netbsd*. For targets that recently + # switched to ELF, *-*-netbsd* would select the old + # object file format. This provides both forward + # compatibility and a consistent mechanism for selecting the + # object file format. + # + # Note: NetBSD doesn't particularly care about the vendor + # portion of the name. We always set it to "unknown". + sysctl="sysctl -n hw.machine_arch" + UNAME_MACHINE_ARCH=`(/sbin/$sysctl 2>/dev/null || \ + /usr/sbin/$sysctl 2>/dev/null || echo unknown)` + case "${UNAME_MACHINE_ARCH}" in + armeb) machine=armeb-unknown ;; + arm*) machine=arm-unknown ;; + sh3el) machine=shl-unknown ;; + sh3eb) machine=sh-unknown ;; + sh5el) machine=sh5le-unknown ;; + *) machine=${UNAME_MACHINE_ARCH}-unknown ;; + esac + # The Operating System including object format, if it has switched + # to ELF recently, or will in the future. + case "${UNAME_MACHINE_ARCH}" in + arm*|i386|m68k|ns32k|sh3*|sparc|vax) + eval $set_cc_for_build + if echo __ELF__ | $CC_FOR_BUILD -E - 2>/dev/null \ + | grep __ELF__ >/dev/null + then + # Once all utilities can be ECOFF (netbsdecoff) or a.out (netbsdaout). + # Return netbsd for either. FIX? + os=netbsd + else + os=netbsdelf + fi + ;; + *) + os=netbsd + ;; + esac + # The OS release + # Debian GNU/NetBSD machines have a different userland, and + # thus, need a distinct triplet. However, they do not need + # kernel version information, so it can be replaced with a + # suitable tag, in the style of linux-gnu. + case "${UNAME_VERSION}" in + Debian*) + release='-gnu' + ;; + *) + release=`echo ${UNAME_RELEASE}|sed -e 's/[-_].*/\./'` + ;; + esac + # Since CPU_TYPE-MANUFACTURER-KERNEL-OPERATING_SYSTEM: + # contains redundant information, the shorter form: + # CPU_TYPE-MANUFACTURER-OPERATING_SYSTEM is used. + echo "${machine}-${os}${release}" + exit ;; + *:OpenBSD:*:*) + UNAME_MACHINE_ARCH=`arch | sed 's/OpenBSD.//'` + echo ${UNAME_MACHINE_ARCH}-unknown-openbsd${UNAME_RELEASE} + exit ;; + *:ekkoBSD:*:*) + echo ${UNAME_MACHINE}-unknown-ekkobsd${UNAME_RELEASE} + exit ;; + *:SolidBSD:*:*) + echo ${UNAME_MACHINE}-unknown-solidbsd${UNAME_RELEASE} + exit ;; + macppc:MirBSD:*:*) + echo powerpc-unknown-mirbsd${UNAME_RELEASE} + exit ;; + *:MirBSD:*:*) + echo ${UNAME_MACHINE}-unknown-mirbsd${UNAME_RELEASE} + exit ;; + alpha:OSF1:*:*) + case $UNAME_RELEASE in + *4.0) + UNAME_RELEASE=`/usr/sbin/sizer -v | awk '{print $3}'` + ;; + *5.*) + UNAME_RELEASE=`/usr/sbin/sizer -v | awk '{print $4}'` + ;; + esac + # According to Compaq, /usr/sbin/psrinfo has been available on + # OSF/1 and Tru64 systems produced since 1995. I hope that + # covers most systems running today. This code pipes the CPU + # types through head -n 1, so we only detect the type of CPU 0. + ALPHA_CPU_TYPE=`/usr/sbin/psrinfo -v | sed -n -e 's/^ The alpha \(.*\) processor.*$/\1/p' | head -n 1` + case "$ALPHA_CPU_TYPE" in + "EV4 (21064)") + UNAME_MACHINE="alpha" ;; + "EV4.5 (21064)") + UNAME_MACHINE="alpha" ;; + "LCA4 (21066/21068)") + UNAME_MACHINE="alpha" ;; + "EV5 (21164)") + UNAME_MACHINE="alphaev5" ;; + "EV5.6 (21164A)") + UNAME_MACHINE="alphaev56" ;; + "EV5.6 (21164PC)") + UNAME_MACHINE="alphapca56" ;; + "EV5.7 (21164PC)") + UNAME_MACHINE="alphapca57" ;; + "EV6 (21264)") + UNAME_MACHINE="alphaev6" ;; + "EV6.7 (21264A)") + UNAME_MACHINE="alphaev67" ;; + "EV6.8CB (21264C)") + UNAME_MACHINE="alphaev68" ;; + "EV6.8AL (21264B)") + UNAME_MACHINE="alphaev68" ;; + "EV6.8CX (21264D)") + UNAME_MACHINE="alphaev68" ;; + "EV6.9A (21264/EV69A)") + UNAME_MACHINE="alphaev69" ;; + "EV7 (21364)") + UNAME_MACHINE="alphaev7" ;; + "EV7.9 (21364A)") + UNAME_MACHINE="alphaev79" ;; + esac + # A Pn.n version is a patched version. + # A Vn.n version is a released version. + # A Tn.n version is a released field test version. + # A Xn.n version is an unreleased experimental baselevel. + # 1.2 uses "1.2" for uname -r. + echo ${UNAME_MACHINE}-dec-osf`echo ${UNAME_RELEASE} | sed -e 's/^[PVTX]//' | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz'` + exit ;; + Alpha\ *:Windows_NT*:*) + # How do we know it's Interix rather than the generic POSIX subsystem? + # Should we change UNAME_MACHINE based on the output of uname instead + # of the specific Alpha model? + echo alpha-pc-interix + exit ;; + 21064:Windows_NT:50:3) + echo alpha-dec-winnt3.5 + exit ;; + Amiga*:UNIX_System_V:4.0:*) + echo m68k-unknown-sysv4 + exit ;; + *:[Aa]miga[Oo][Ss]:*:*) + echo ${UNAME_MACHINE}-unknown-amigaos + exit ;; + *:[Mm]orph[Oo][Ss]:*:*) + echo ${UNAME_MACHINE}-unknown-morphos + exit ;; + *:OS/390:*:*) + echo i370-ibm-openedition + exit ;; + *:z/VM:*:*) + echo s390-ibm-zvmoe + exit ;; + *:OS400:*:*) + echo powerpc-ibm-os400 + exit ;; + arm:RISC*:1.[012]*:*|arm:riscix:1.[012]*:*) + echo arm-acorn-riscix${UNAME_RELEASE} + exit ;; + arm:riscos:*:*|arm:RISCOS:*:*) + echo arm-unknown-riscos + exit ;; + SR2?01:HI-UX/MPP:*:* | SR8000:HI-UX/MPP:*:*) + echo hppa1.1-hitachi-hiuxmpp + exit ;; + Pyramid*:OSx*:*:* | MIS*:OSx*:*:* | MIS*:SMP_DC-OSx*:*:*) + # akee@wpdis03.wpafb.af.mil (Earle F. Ake) contributed MIS and NILE. + if test "`(/bin/universe) 2>/dev/null`" = att ; then + echo pyramid-pyramid-sysv3 + else + echo pyramid-pyramid-bsd + fi + exit ;; + NILE*:*:*:dcosx) + echo pyramid-pyramid-svr4 + exit ;; + DRS?6000:unix:4.0:6*) + echo sparc-icl-nx6 + exit ;; + DRS?6000:UNIX_SV:4.2*:7* | DRS?6000:isis:4.2*:7*) + case `/usr/bin/uname -p` in + sparc) echo sparc-icl-nx7; exit ;; + esac ;; + sun4H:SunOS:5.*:*) + echo sparc-hal-solaris2`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'` + exit ;; + sun4*:SunOS:5.*:* | tadpole*:SunOS:5.*:*) + echo sparc-sun-solaris2`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'` + exit ;; + i86pc:SunOS:5.*:* | i86xen:SunOS:5.*:*) + echo i386-pc-solaris2`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'` + exit ;; + sun4*:SunOS:6*:*) + # According to config.sub, this is the proper way to canonicalize + # SunOS6. Hard to guess exactly what SunOS6 will be like, but + # it's likely to be more like Solaris than SunOS4. + echo sparc-sun-solaris3`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'` + exit ;; + sun4*:SunOS:*:*) + case "`/usr/bin/arch -k`" in + Series*|S4*) + UNAME_RELEASE=`uname -v` + ;; + esac + # Japanese Language versions have a version number like `4.1.3-JL'. + echo sparc-sun-sunos`echo ${UNAME_RELEASE}|sed -e 's/-/_/'` + exit ;; + sun3*:SunOS:*:*) + echo m68k-sun-sunos${UNAME_RELEASE} + exit ;; + sun*:*:4.2BSD:*) + UNAME_RELEASE=`(sed 1q /etc/motd | awk '{print substr($5,1,3)}') 2>/dev/null` + test "x${UNAME_RELEASE}" = "x" && UNAME_RELEASE=3 + case "`/bin/arch`" in + sun3) + echo m68k-sun-sunos${UNAME_RELEASE} + ;; + sun4) + echo sparc-sun-sunos${UNAME_RELEASE} + ;; + esac + exit ;; + aushp:SunOS:*:*) + echo sparc-auspex-sunos${UNAME_RELEASE} + exit ;; + # The situation for MiNT is a little confusing. The machine name + # can be virtually everything (everything which is not + # "atarist" or "atariste" at least should have a processor + # > m68000). The system name ranges from "MiNT" over "FreeMiNT" + # to the lowercase version "mint" (or "freemint"). Finally + # the system name "TOS" denotes a system which is actually not + # MiNT. But MiNT is downward compatible to TOS, so this should + # be no problem. + atarist[e]:*MiNT:*:* | atarist[e]:*mint:*:* | atarist[e]:*TOS:*:*) + echo m68k-atari-mint${UNAME_RELEASE} + exit ;; + atari*:*MiNT:*:* | atari*:*mint:*:* | atarist[e]:*TOS:*:*) + echo m68k-atari-mint${UNAME_RELEASE} + exit ;; + *falcon*:*MiNT:*:* | *falcon*:*mint:*:* | *falcon*:*TOS:*:*) + echo m68k-atari-mint${UNAME_RELEASE} + exit ;; + milan*:*MiNT:*:* | milan*:*mint:*:* | *milan*:*TOS:*:*) + echo m68k-milan-mint${UNAME_RELEASE} + exit ;; + hades*:*MiNT:*:* | hades*:*mint:*:* | *hades*:*TOS:*:*) + echo m68k-hades-mint${UNAME_RELEASE} + exit ;; + *:*MiNT:*:* | *:*mint:*:* | *:*TOS:*:*) + echo m68k-unknown-mint${UNAME_RELEASE} + exit ;; + m68k:machten:*:*) + echo m68k-apple-machten${UNAME_RELEASE} + exit ;; + powerpc:machten:*:*) + echo powerpc-apple-machten${UNAME_RELEASE} + exit ;; + RISC*:Mach:*:*) + echo mips-dec-mach_bsd4.3 + exit ;; + RISC*:ULTRIX:*:*) + echo mips-dec-ultrix${UNAME_RELEASE} + exit ;; + VAX*:ULTRIX*:*:*) + echo vax-dec-ultrix${UNAME_RELEASE} + exit ;; + 2020:CLIX:*:* | 2430:CLIX:*:*) + echo clipper-intergraph-clix${UNAME_RELEASE} + exit ;; + mips:*:*:UMIPS | mips:*:*:RISCos) + eval $set_cc_for_build + sed 's/^ //' << EOF >$dummy.c +#ifdef __cplusplus +#include /* for printf() prototype */ + int main (int argc, char *argv[]) { +#else + int main (argc, argv) int argc; char *argv[]; { +#endif + #if defined (host_mips) && defined (MIPSEB) + #if defined (SYSTYPE_SYSV) + printf ("mips-mips-riscos%ssysv\n", argv[1]); exit (0); + #endif + #if defined (SYSTYPE_SVR4) + printf ("mips-mips-riscos%ssvr4\n", argv[1]); exit (0); + #endif + #if defined (SYSTYPE_BSD43) || defined(SYSTYPE_BSD) + printf ("mips-mips-riscos%sbsd\n", argv[1]); exit (0); + #endif + #endif + exit (-1); + } +EOF + $CC_FOR_BUILD -o $dummy $dummy.c && + dummyarg=`echo "${UNAME_RELEASE}" | sed -n 's/\([0-9]*\).*/\1/p'` && + SYSTEM_NAME=`$dummy $dummyarg` && + { echo "$SYSTEM_NAME"; exit; } + echo mips-mips-riscos${UNAME_RELEASE} + exit ;; + Motorola:PowerMAX_OS:*:*) + echo powerpc-motorola-powermax + exit ;; + Motorola:*:4.3:PL8-*) + echo powerpc-harris-powermax + exit ;; + Night_Hawk:*:*:PowerMAX_OS | Synergy:PowerMAX_OS:*:*) + echo powerpc-harris-powermax + exit ;; + Night_Hawk:Power_UNIX:*:*) + echo powerpc-harris-powerunix + exit ;; + m88k:CX/UX:7*:*) + echo m88k-harris-cxux7 + exit ;; + m88k:*:4*:R4*) + echo m88k-motorola-sysv4 + exit ;; + m88k:*:3*:R3*) + echo m88k-motorola-sysv3 + exit ;; + AViiON:dgux:*:*) + # DG/UX returns AViiON for all architectures + UNAME_PROCESSOR=`/usr/bin/uname -p` + if [ $UNAME_PROCESSOR = mc88100 ] || [ $UNAME_PROCESSOR = mc88110 ] + then + if [ ${TARGET_BINARY_INTERFACE}x = m88kdguxelfx ] || \ + [ ${TARGET_BINARY_INTERFACE}x = x ] + then + echo m88k-dg-dgux${UNAME_RELEASE} + else + echo m88k-dg-dguxbcs${UNAME_RELEASE} + fi + else + echo i586-dg-dgux${UNAME_RELEASE} + fi + exit ;; + M88*:DolphinOS:*:*) # DolphinOS (SVR3) + echo m88k-dolphin-sysv3 + exit ;; + M88*:*:R3*:*) + # Delta 88k system running SVR3 + echo m88k-motorola-sysv3 + exit ;; + XD88*:*:*:*) # Tektronix XD88 system running UTekV (SVR3) + echo m88k-tektronix-sysv3 + exit ;; + Tek43[0-9][0-9]:UTek:*:*) # Tektronix 4300 system running UTek (BSD) + echo m68k-tektronix-bsd + exit ;; + *:IRIX*:*:*) + echo mips-sgi-irix`echo ${UNAME_RELEASE}|sed -e 's/-/_/g'` + exit ;; + ????????:AIX?:[12].1:2) # AIX 2.2.1 or AIX 2.1.1 is RT/PC AIX. + echo romp-ibm-aix # uname -m gives an 8 hex-code CPU id + exit ;; # Note that: echo "'`uname -s`'" gives 'AIX ' + i*86:AIX:*:*) + echo i386-ibm-aix + exit ;; + ia64:AIX:*:*) + if [ -x /usr/bin/oslevel ] ; then + IBM_REV=`/usr/bin/oslevel` + else + IBM_REV=${UNAME_VERSION}.${UNAME_RELEASE} + fi + echo ${UNAME_MACHINE}-ibm-aix${IBM_REV} + exit ;; + *:AIX:2:3) + if grep bos325 /usr/include/stdio.h >/dev/null 2>&1; then + eval $set_cc_for_build + sed 's/^ //' << EOF >$dummy.c + #include + + main() + { + if (!__power_pc()) + exit(1); + puts("powerpc-ibm-aix3.2.5"); + exit(0); + } +EOF + if $CC_FOR_BUILD -o $dummy $dummy.c && SYSTEM_NAME=`$dummy` + then + echo "$SYSTEM_NAME" + else + echo rs6000-ibm-aix3.2.5 + fi + elif grep bos324 /usr/include/stdio.h >/dev/null 2>&1; then + echo rs6000-ibm-aix3.2.4 + else + echo rs6000-ibm-aix3.2 + fi + exit ;; + *:AIX:*:[45]) + IBM_CPU_ID=`/usr/sbin/lsdev -C -c processor -S available | sed 1q | awk '{ print $1 }'` + if /usr/sbin/lsattr -El ${IBM_CPU_ID} | grep ' POWER' >/dev/null 2>&1; then + IBM_ARCH=rs6000 + else + IBM_ARCH=powerpc + fi + if [ -x /usr/bin/oslevel ] ; then + IBM_REV=`/usr/bin/oslevel` + else + IBM_REV=${UNAME_VERSION}.${UNAME_RELEASE} + fi + echo ${IBM_ARCH}-ibm-aix${IBM_REV} + exit ;; + *:AIX:*:*) + echo rs6000-ibm-aix + exit ;; + ibmrt:4.4BSD:*|romp-ibm:BSD:*) + echo romp-ibm-bsd4.4 + exit ;; + ibmrt:*BSD:*|romp-ibm:BSD:*) # covers RT/PC BSD and + echo romp-ibm-bsd${UNAME_RELEASE} # 4.3 with uname added to + exit ;; # report: romp-ibm BSD 4.3 + *:BOSX:*:*) + echo rs6000-bull-bosx + exit ;; + DPX/2?00:B.O.S.:*:*) + echo m68k-bull-sysv3 + exit ;; + 9000/[34]??:4.3bsd:1.*:*) + echo m68k-hp-bsd + exit ;; + hp300:4.4BSD:*:* | 9000/[34]??:4.3bsd:2.*:*) + echo m68k-hp-bsd4.4 + exit ;; + 9000/[34678]??:HP-UX:*:*) + HPUX_REV=`echo ${UNAME_RELEASE}|sed -e 's/[^.]*.[0B]*//'` + case "${UNAME_MACHINE}" in + 9000/31? ) HP_ARCH=m68000 ;; + 9000/[34]?? ) HP_ARCH=m68k ;; + 9000/[678][0-9][0-9]) + if [ -x /usr/bin/getconf ]; then + sc_cpu_version=`/usr/bin/getconf SC_CPU_VERSION 2>/dev/null` + sc_kernel_bits=`/usr/bin/getconf SC_KERNEL_BITS 2>/dev/null` + case "${sc_cpu_version}" in + 523) HP_ARCH="hppa1.0" ;; # CPU_PA_RISC1_0 + 528) HP_ARCH="hppa1.1" ;; # CPU_PA_RISC1_1 + 532) # CPU_PA_RISC2_0 + case "${sc_kernel_bits}" in + 32) HP_ARCH="hppa2.0n" ;; + 64) HP_ARCH="hppa2.0w" ;; + '') HP_ARCH="hppa2.0" ;; # HP-UX 10.20 + esac ;; + esac + fi + if [ "${HP_ARCH}" = "" ]; then + eval $set_cc_for_build + sed 's/^ //' << EOF >$dummy.c + + #define _HPUX_SOURCE + #include + #include + + int main () + { + #if defined(_SC_KERNEL_BITS) + long bits = sysconf(_SC_KERNEL_BITS); + #endif + long cpu = sysconf (_SC_CPU_VERSION); + + switch (cpu) + { + case CPU_PA_RISC1_0: puts ("hppa1.0"); break; + case CPU_PA_RISC1_1: puts ("hppa1.1"); break; + case CPU_PA_RISC2_0: + #if defined(_SC_KERNEL_BITS) + switch (bits) + { + case 64: puts ("hppa2.0w"); break; + case 32: puts ("hppa2.0n"); break; + default: puts ("hppa2.0"); break; + } break; + #else /* !defined(_SC_KERNEL_BITS) */ + puts ("hppa2.0"); break; + #endif + default: puts ("hppa1.0"); break; + } + exit (0); + } +EOF + (CCOPTS= $CC_FOR_BUILD -o $dummy $dummy.c 2>/dev/null) && HP_ARCH=`$dummy` + test -z "$HP_ARCH" && HP_ARCH=hppa + fi ;; + esac + if [ ${HP_ARCH} = "hppa2.0w" ] + then + eval $set_cc_for_build + + # hppa2.0w-hp-hpux* has a 64-bit kernel and a compiler generating + # 32-bit code. hppa64-hp-hpux* has the same kernel and a compiler + # generating 64-bit code. GNU and HP use different nomenclature: + # + # $ CC_FOR_BUILD=cc ./config.guess + # => hppa2.0w-hp-hpux11.23 + # $ CC_FOR_BUILD="cc +DA2.0w" ./config.guess + # => hppa64-hp-hpux11.23 + + if echo __LP64__ | (CCOPTS= $CC_FOR_BUILD -E - 2>/dev/null) | + grep __LP64__ >/dev/null + then + HP_ARCH="hppa2.0w" + else + HP_ARCH="hppa64" + fi + fi + echo ${HP_ARCH}-hp-hpux${HPUX_REV} + exit ;; + ia64:HP-UX:*:*) + HPUX_REV=`echo ${UNAME_RELEASE}|sed -e 's/[^.]*.[0B]*//'` + echo ia64-hp-hpux${HPUX_REV} + exit ;; + 3050*:HI-UX:*:*) + eval $set_cc_for_build + sed 's/^ //' << EOF >$dummy.c + #include + int + main () + { + long cpu = sysconf (_SC_CPU_VERSION); + /* The order matters, because CPU_IS_HP_MC68K erroneously returns + true for CPU_PA_RISC1_0. CPU_IS_PA_RISC returns correct + results, however. */ + if (CPU_IS_PA_RISC (cpu)) + { + switch (cpu) + { + case CPU_PA_RISC1_0: puts ("hppa1.0-hitachi-hiuxwe2"); break; + case CPU_PA_RISC1_1: puts ("hppa1.1-hitachi-hiuxwe2"); break; + case CPU_PA_RISC2_0: puts ("hppa2.0-hitachi-hiuxwe2"); break; + default: puts ("hppa-hitachi-hiuxwe2"); break; + } + } + else if (CPU_IS_HP_MC68K (cpu)) + puts ("m68k-hitachi-hiuxwe2"); + else puts ("unknown-hitachi-hiuxwe2"); + exit (0); + } +EOF + $CC_FOR_BUILD -o $dummy $dummy.c && SYSTEM_NAME=`$dummy` && + { echo "$SYSTEM_NAME"; exit; } + echo unknown-hitachi-hiuxwe2 + exit ;; + 9000/7??:4.3bsd:*:* | 9000/8?[79]:4.3bsd:*:* ) + echo hppa1.1-hp-bsd + exit ;; + 9000/8??:4.3bsd:*:*) + echo hppa1.0-hp-bsd + exit ;; + *9??*:MPE/iX:*:* | *3000*:MPE/iX:*:*) + echo hppa1.0-hp-mpeix + exit ;; + hp7??:OSF1:*:* | hp8?[79]:OSF1:*:* ) + echo hppa1.1-hp-osf + exit ;; + hp8??:OSF1:*:*) + echo hppa1.0-hp-osf + exit ;; + i*86:OSF1:*:*) + if [ -x /usr/sbin/sysversion ] ; then + echo ${UNAME_MACHINE}-unknown-osf1mk + else + echo ${UNAME_MACHINE}-unknown-osf1 + fi + exit ;; + parisc*:Lites*:*:*) + echo hppa1.1-hp-lites + exit ;; + C1*:ConvexOS:*:* | convex:ConvexOS:C1*:*) + echo c1-convex-bsd + exit ;; + C2*:ConvexOS:*:* | convex:ConvexOS:C2*:*) + if getsysinfo -f scalar_acc + then echo c32-convex-bsd + else echo c2-convex-bsd + fi + exit ;; + C34*:ConvexOS:*:* | convex:ConvexOS:C34*:*) + echo c34-convex-bsd + exit ;; + C38*:ConvexOS:*:* | convex:ConvexOS:C38*:*) + echo c38-convex-bsd + exit ;; + C4*:ConvexOS:*:* | convex:ConvexOS:C4*:*) + echo c4-convex-bsd + exit ;; + CRAY*Y-MP:*:*:*) + echo ymp-cray-unicos${UNAME_RELEASE} | sed -e 's/\.[^.]*$/.X/' + exit ;; + CRAY*[A-Z]90:*:*:*) + echo ${UNAME_MACHINE}-cray-unicos${UNAME_RELEASE} \ + | sed -e 's/CRAY.*\([A-Z]90\)/\1/' \ + -e y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/ \ + -e 's/\.[^.]*$/.X/' + exit ;; + CRAY*TS:*:*:*) + echo t90-cray-unicos${UNAME_RELEASE} | sed -e 's/\.[^.]*$/.X/' + exit ;; + CRAY*T3E:*:*:*) + echo alphaev5-cray-unicosmk${UNAME_RELEASE} | sed -e 's/\.[^.]*$/.X/' + exit ;; + CRAY*SV1:*:*:*) + echo sv1-cray-unicos${UNAME_RELEASE} | sed -e 's/\.[^.]*$/.X/' + exit ;; + *:UNICOS/mp:*:*) + echo craynv-cray-unicosmp${UNAME_RELEASE} | sed -e 's/\.[^.]*$/.X/' + exit ;; + F30[01]:UNIX_System_V:*:* | F700:UNIX_System_V:*:*) + FUJITSU_PROC=`uname -m | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz'` + FUJITSU_SYS=`uname -p | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz' | sed -e 's/\///'` + FUJITSU_REL=`echo ${UNAME_RELEASE} | sed -e 's/ /_/'` + echo "${FUJITSU_PROC}-fujitsu-${FUJITSU_SYS}${FUJITSU_REL}" + exit ;; + 5000:UNIX_System_V:4.*:*) + FUJITSU_SYS=`uname -p | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz' | sed -e 's/\///'` + FUJITSU_REL=`echo ${UNAME_RELEASE} | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz' | sed -e 's/ /_/'` + echo "sparc-fujitsu-${FUJITSU_SYS}${FUJITSU_REL}" + exit ;; + i*86:BSD/386:*:* | i*86:BSD/OS:*:* | *:Ascend\ Embedded/OS:*:*) + echo ${UNAME_MACHINE}-pc-bsdi${UNAME_RELEASE} + exit ;; + sparc*:BSD/OS:*:*) + echo sparc-unknown-bsdi${UNAME_RELEASE} + exit ;; + *:BSD/OS:*:*) + echo ${UNAME_MACHINE}-unknown-bsdi${UNAME_RELEASE} + exit ;; + *:FreeBSD:*:*) + case ${UNAME_MACHINE} in + pc98) + echo i386-unknown-freebsd`echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'` ;; + amd64) + echo x86_64-unknown-freebsd`echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'` ;; + *) + echo ${UNAME_MACHINE}-unknown-freebsd`echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'` ;; + esac + exit ;; + i*:CYGWIN*:*) + echo ${UNAME_MACHINE}-pc-cygwin + exit ;; + *:MINGW*:*) + echo ${UNAME_MACHINE}-pc-mingw32 + exit ;; + i*:windows32*:*) + # uname -m includes "-pc" on this system. + echo ${UNAME_MACHINE}-mingw32 + exit ;; + i*:PW*:*) + echo ${UNAME_MACHINE}-pc-pw32 + exit ;; + *:Interix*:[3456]*) + case ${UNAME_MACHINE} in + x86) + echo i586-pc-interix${UNAME_RELEASE} + exit ;; + EM64T | authenticamd) + echo x86_64-unknown-interix${UNAME_RELEASE} + exit ;; + esac ;; + [345]86:Windows_95:* | [345]86:Windows_98:* | [345]86:Windows_NT:*) + echo i${UNAME_MACHINE}-pc-mks + exit ;; + i*:Windows_NT*:* | Pentium*:Windows_NT*:*) + # How do we know it's Interix rather than the generic POSIX subsystem? + # It also conflicts with pre-2.0 versions of AT&T UWIN. Should we + # UNAME_MACHINE based on the output of uname instead of i386? + echo i586-pc-interix + exit ;; + i*:UWIN*:*) + echo ${UNAME_MACHINE}-pc-uwin + exit ;; + amd64:CYGWIN*:*:* | x86_64:CYGWIN*:*:*) + echo x86_64-unknown-cygwin + exit ;; + p*:CYGWIN*:*) + echo powerpcle-unknown-cygwin + exit ;; + prep*:SunOS:5.*:*) + echo powerpcle-unknown-solaris2`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'` + exit ;; + *:GNU:*:*) + # the GNU system + echo `echo ${UNAME_MACHINE}|sed -e 's,[-/].*$,,'`-unknown-gnu`echo ${UNAME_RELEASE}|sed -e 's,/.*$,,'` + exit ;; + *:GNU/*:*:*) + # other systems with GNU libc and userland + echo ${UNAME_MACHINE}-unknown-`echo ${UNAME_SYSTEM} | sed 's,^[^/]*/,,' | tr '[A-Z]' '[a-z]'``echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'`-gnu + exit ;; + i*86:Minix:*:*) + echo ${UNAME_MACHINE}-pc-minix + exit ;; + arm*:Linux:*:*) + echo ${UNAME_MACHINE}-unknown-linux-gnu + exit ;; + avr32*:Linux:*:*) + echo ${UNAME_MACHINE}-unknown-linux-gnu + exit ;; + cris:Linux:*:*) + echo cris-axis-linux-gnu + exit ;; + crisv32:Linux:*:*) + echo crisv32-axis-linux-gnu + exit ;; + frv:Linux:*:*) + echo frv-unknown-linux-gnu + exit ;; + ia64:Linux:*:*) + echo ${UNAME_MACHINE}-unknown-linux-gnu + exit ;; + m32r*:Linux:*:*) + echo ${UNAME_MACHINE}-unknown-linux-gnu + exit ;; + m68*:Linux:*:*) + echo ${UNAME_MACHINE}-unknown-linux-gnu + exit ;; + mips:Linux:*:*) + eval $set_cc_for_build + sed 's/^ //' << EOF >$dummy.c + #undef CPU + #undef mips + #undef mipsel + #if defined(__MIPSEL__) || defined(__MIPSEL) || defined(_MIPSEL) || defined(MIPSEL) + CPU=mipsel + #else + #if defined(__MIPSEB__) || defined(__MIPSEB) || defined(_MIPSEB) || defined(MIPSEB) + CPU=mips + #else + CPU= + #endif + #endif +EOF + eval "`$CC_FOR_BUILD -E $dummy.c 2>/dev/null | sed -n ' + /^CPU/{ + s: ::g + p + }'`" + test x"${CPU}" != x && { echo "${CPU}-unknown-linux-gnu"; exit; } + ;; + mips64:Linux:*:*) + eval $set_cc_for_build + sed 's/^ //' << EOF >$dummy.c + #undef CPU + #undef mips64 + #undef mips64el + #if defined(__MIPSEL__) || defined(__MIPSEL) || defined(_MIPSEL) || defined(MIPSEL) + CPU=mips64el + #else + #if defined(__MIPSEB__) || defined(__MIPSEB) || defined(_MIPSEB) || defined(MIPSEB) + CPU=mips64 + #else + CPU= + #endif + #endif +EOF + eval "`$CC_FOR_BUILD -E $dummy.c 2>/dev/null | sed -n ' + /^CPU/{ + s: ::g + p + }'`" + test x"${CPU}" != x && { echo "${CPU}-unknown-linux-gnu"; exit; } + ;; + or32:Linux:*:*) + echo or32-unknown-linux-gnu + exit ;; + ppc:Linux:*:*) + echo powerpc-unknown-linux-gnu + exit ;; + ppc64:Linux:*:*) + echo powerpc64-unknown-linux-gnu + exit ;; + alpha:Linux:*:*) + case `sed -n '/^cpu model/s/^.*: \(.*\)/\1/p' < /proc/cpuinfo` in + EV5) UNAME_MACHINE=alphaev5 ;; + EV56) UNAME_MACHINE=alphaev56 ;; + PCA56) UNAME_MACHINE=alphapca56 ;; + PCA57) UNAME_MACHINE=alphapca56 ;; + EV6) UNAME_MACHINE=alphaev6 ;; + EV67) UNAME_MACHINE=alphaev67 ;; + EV68*) UNAME_MACHINE=alphaev68 ;; + esac + objdump --private-headers /bin/sh | grep ld.so.1 >/dev/null + if test "$?" = 0 ; then LIBC="libc1" ; else LIBC="" ; fi + echo ${UNAME_MACHINE}-unknown-linux-gnu${LIBC} + exit ;; + parisc:Linux:*:* | hppa:Linux:*:*) + # Look for CPU level + case `grep '^cpu[^a-z]*:' /proc/cpuinfo 2>/dev/null | cut -d' ' -f2` in + PA7*) echo hppa1.1-unknown-linux-gnu ;; + PA8*) echo hppa2.0-unknown-linux-gnu ;; + *) echo hppa-unknown-linux-gnu ;; + esac + exit ;; + parisc64:Linux:*:* | hppa64:Linux:*:*) + echo hppa64-unknown-linux-gnu + exit ;; + s390:Linux:*:* | s390x:Linux:*:*) + echo ${UNAME_MACHINE}-ibm-linux + exit ;; + sh64*:Linux:*:*) + echo ${UNAME_MACHINE}-unknown-linux-gnu + exit ;; + sh*:Linux:*:*) + echo ${UNAME_MACHINE}-unknown-linux-gnu + exit ;; + sparc:Linux:*:* | sparc64:Linux:*:*) + echo ${UNAME_MACHINE}-unknown-linux-gnu + exit ;; + vax:Linux:*:*) + echo ${UNAME_MACHINE}-dec-linux-gnu + exit ;; + x86_64:Linux:*:*) + echo x86_64-unknown-linux-gnu + exit ;; + xtensa:Linux:*:*) + echo xtensa-unknown-linux-gnu + exit ;; + i*86:Linux:*:*) + # The BFD linker knows what the default object file format is, so + # first see if it will tell us. cd to the root directory to prevent + # problems with other programs or directories called `ld' in the path. + # Set LC_ALL=C to ensure ld outputs messages in English. + ld_supported_targets=`cd /; LC_ALL=C ld --help 2>&1 \ + | sed -ne '/supported targets:/!d + s/[ ][ ]*/ /g + s/.*supported targets: *// + s/ .*// + p'` + case "$ld_supported_targets" in + elf32-i386) + TENTATIVE="${UNAME_MACHINE}-pc-linux-gnu" + ;; + a.out-i386-linux) + echo "${UNAME_MACHINE}-pc-linux-gnuaout" + exit ;; + coff-i386) + echo "${UNAME_MACHINE}-pc-linux-gnucoff" + exit ;; + "") + # Either a pre-BFD a.out linker (linux-gnuoldld) or + # one that does not give us useful --help. + echo "${UNAME_MACHINE}-pc-linux-gnuoldld" + exit ;; + esac + # Determine whether the default compiler is a.out or elf + eval $set_cc_for_build + sed 's/^ //' << EOF >$dummy.c + #include + #ifdef __ELF__ + # ifdef __GLIBC__ + # if __GLIBC__ >= 2 + LIBC=gnu + # else + LIBC=gnulibc1 + # endif + # else + LIBC=gnulibc1 + # endif + #else + #if defined(__INTEL_COMPILER) || defined(__PGI) || defined(__SUNPRO_C) || defined(__SUNPRO_CC) + LIBC=gnu + #else + LIBC=gnuaout + #endif + #endif + #ifdef __dietlibc__ + LIBC=dietlibc + #endif +EOF + eval "`$CC_FOR_BUILD -E $dummy.c 2>/dev/null | sed -n ' + /^LIBC/{ + s: ::g + p + }'`" + test x"${LIBC}" != x && { + echo "${UNAME_MACHINE}-pc-linux-${LIBC}" + exit + } + test x"${TENTATIVE}" != x && { echo "${TENTATIVE}"; exit; } + ;; + i*86:DYNIX/ptx:4*:*) + # ptx 4.0 does uname -s correctly, with DYNIX/ptx in there. + # earlier versions are messed up and put the nodename in both + # sysname and nodename. + echo i386-sequent-sysv4 + exit ;; + i*86:UNIX_SV:4.2MP:2.*) + # Unixware is an offshoot of SVR4, but it has its own version + # number series starting with 2... + # I am not positive that other SVR4 systems won't match this, + # I just have to hope. -- rms. + # Use sysv4.2uw... so that sysv4* matches it. + echo ${UNAME_MACHINE}-pc-sysv4.2uw${UNAME_VERSION} + exit ;; + i*86:OS/2:*:*) + # If we were able to find `uname', then EMX Unix compatibility + # is probably installed. + echo ${UNAME_MACHINE}-pc-os2-emx + exit ;; + i*86:XTS-300:*:STOP) + echo ${UNAME_MACHINE}-unknown-stop + exit ;; + i*86:atheos:*:*) + echo ${UNAME_MACHINE}-unknown-atheos + exit ;; + i*86:syllable:*:*) + echo ${UNAME_MACHINE}-pc-syllable + exit ;; + i*86:LynxOS:2.*:* | i*86:LynxOS:3.[01]*:* | i*86:LynxOS:4.0*:*) + echo i386-unknown-lynxos${UNAME_RELEASE} + exit ;; + i*86:*DOS:*:*) + echo ${UNAME_MACHINE}-pc-msdosdjgpp + exit ;; + i*86:*:4.*:* | i*86:SYSTEM_V:4.*:*) + UNAME_REL=`echo ${UNAME_RELEASE} | sed 's/\/MP$//'` + if grep Novell /usr/include/link.h >/dev/null 2>/dev/null; then + echo ${UNAME_MACHINE}-univel-sysv${UNAME_REL} + else + echo ${UNAME_MACHINE}-pc-sysv${UNAME_REL} + fi + exit ;; + i*86:*:5:[678]*) + # UnixWare 7.x, OpenUNIX and OpenServer 6. + case `/bin/uname -X | grep "^Machine"` in + *486*) UNAME_MACHINE=i486 ;; + *Pentium) UNAME_MACHINE=i586 ;; + *Pent*|*Celeron) UNAME_MACHINE=i686 ;; + esac + echo ${UNAME_MACHINE}-unknown-sysv${UNAME_RELEASE}${UNAME_SYSTEM}${UNAME_VERSION} + exit ;; + i*86:*:3.2:*) + if test -f /usr/options/cb.name; then + UNAME_REL=`sed -n 's/.*Version //p' /dev/null >/dev/null ; then + UNAME_REL=`(/bin/uname -X|grep Release|sed -e 's/.*= //')` + (/bin/uname -X|grep i80486 >/dev/null) && UNAME_MACHINE=i486 + (/bin/uname -X|grep '^Machine.*Pentium' >/dev/null) \ + && UNAME_MACHINE=i586 + (/bin/uname -X|grep '^Machine.*Pent *II' >/dev/null) \ + && UNAME_MACHINE=i686 + (/bin/uname -X|grep '^Machine.*Pentium Pro' >/dev/null) \ + && UNAME_MACHINE=i686 + echo ${UNAME_MACHINE}-pc-sco$UNAME_REL + else + echo ${UNAME_MACHINE}-pc-sysv32 + fi + exit ;; + pc:*:*:*) + # Left here for compatibility: + # uname -m prints for DJGPP always 'pc', but it prints nothing about + # the processor, so we play safe by assuming i386. + echo i386-pc-msdosdjgpp + exit ;; + Intel:Mach:3*:*) + echo i386-pc-mach3 + exit ;; + paragon:*:*:*) + echo i860-intel-osf1 + exit ;; + i860:*:4.*:*) # i860-SVR4 + if grep Stardent /usr/include/sys/uadmin.h >/dev/null 2>&1 ; then + echo i860-stardent-sysv${UNAME_RELEASE} # Stardent Vistra i860-SVR4 + else # Add other i860-SVR4 vendors below as they are discovered. + echo i860-unknown-sysv${UNAME_RELEASE} # Unknown i860-SVR4 + fi + exit ;; + mini*:CTIX:SYS*5:*) + # "miniframe" + echo m68010-convergent-sysv + exit ;; + mc68k:UNIX:SYSTEM5:3.51m) + echo m68k-convergent-sysv + exit ;; + M680?0:D-NIX:5.3:*) + echo m68k-diab-dnix + exit ;; + M68*:*:R3V[5678]*:*) + test -r /sysV68 && { echo 'm68k-motorola-sysv'; exit; } ;; + 3[345]??:*:4.0:3.0 | 3[34]??A:*:4.0:3.0 | 3[34]??,*:*:4.0:3.0 | 3[34]??/*:*:4.0:3.0 | 4400:*:4.0:3.0 | 4850:*:4.0:3.0 | SKA40:*:4.0:3.0 | SDS2:*:4.0:3.0 | SHG2:*:4.0:3.0 | S7501*:*:4.0:3.0) + OS_REL='' + test -r /etc/.relid \ + && OS_REL=.`sed -n 's/[^ ]* [^ ]* \([0-9][0-9]\).*/\1/p' < /etc/.relid` + /bin/uname -p 2>/dev/null | grep 86 >/dev/null \ + && { echo i486-ncr-sysv4.3${OS_REL}; exit; } + /bin/uname -p 2>/dev/null | /bin/grep entium >/dev/null \ + && { echo i586-ncr-sysv4.3${OS_REL}; exit; } ;; + 3[34]??:*:4.0:* | 3[34]??,*:*:4.0:*) + /bin/uname -p 2>/dev/null | grep 86 >/dev/null \ + && { echo i486-ncr-sysv4; exit; } ;; + m68*:LynxOS:2.*:* | m68*:LynxOS:3.0*:*) + echo m68k-unknown-lynxos${UNAME_RELEASE} + exit ;; + mc68030:UNIX_System_V:4.*:*) + echo m68k-atari-sysv4 + exit ;; + TSUNAMI:LynxOS:2.*:*) + echo sparc-unknown-lynxos${UNAME_RELEASE} + exit ;; + rs6000:LynxOS:2.*:*) + echo rs6000-unknown-lynxos${UNAME_RELEASE} + exit ;; + PowerPC:LynxOS:2.*:* | PowerPC:LynxOS:3.[01]*:* | PowerPC:LynxOS:4.0*:*) + echo powerpc-unknown-lynxos${UNAME_RELEASE} + exit ;; + SM[BE]S:UNIX_SV:*:*) + echo mips-dde-sysv${UNAME_RELEASE} + exit ;; + RM*:ReliantUNIX-*:*:*) + echo mips-sni-sysv4 + exit ;; + RM*:SINIX-*:*:*) + echo mips-sni-sysv4 + exit ;; + *:SINIX-*:*:*) + if uname -p 2>/dev/null >/dev/null ; then + UNAME_MACHINE=`(uname -p) 2>/dev/null` + echo ${UNAME_MACHINE}-sni-sysv4 + else + echo ns32k-sni-sysv + fi + exit ;; + PENTIUM:*:4.0*:*) # Unisys `ClearPath HMP IX 4000' SVR4/MP effort + # says + echo i586-unisys-sysv4 + exit ;; + *:UNIX_System_V:4*:FTX*) + # From Gerald Hewes . + # How about differentiating between stratus architectures? -djm + echo hppa1.1-stratus-sysv4 + exit ;; + *:*:*:FTX*) + # From seanf@swdc.stratus.com. + echo i860-stratus-sysv4 + exit ;; + i*86:VOS:*:*) + # From Paul.Green@stratus.com. + echo ${UNAME_MACHINE}-stratus-vos + exit ;; + *:VOS:*:*) + # From Paul.Green@stratus.com. + echo hppa1.1-stratus-vos + exit ;; + mc68*:A/UX:*:*) + echo m68k-apple-aux${UNAME_RELEASE} + exit ;; + news*:NEWS-OS:6*:*) + echo mips-sony-newsos6 + exit ;; + R[34]000:*System_V*:*:* | R4000:UNIX_SYSV:*:* | R*000:UNIX_SV:*:*) + if [ -d /usr/nec ]; then + echo mips-nec-sysv${UNAME_RELEASE} + else + echo mips-unknown-sysv${UNAME_RELEASE} + fi + exit ;; + BeBox:BeOS:*:*) # BeOS running on hardware made by Be, PPC only. + echo powerpc-be-beos + exit ;; + BeMac:BeOS:*:*) # BeOS running on Mac or Mac clone, PPC only. + echo powerpc-apple-beos + exit ;; + BePC:BeOS:*:*) # BeOS running on Intel PC compatible. + echo i586-pc-beos + exit ;; + SX-4:SUPER-UX:*:*) + echo sx4-nec-superux${UNAME_RELEASE} + exit ;; + SX-5:SUPER-UX:*:*) + echo sx5-nec-superux${UNAME_RELEASE} + exit ;; + SX-6:SUPER-UX:*:*) + echo sx6-nec-superux${UNAME_RELEASE} + exit ;; + SX-7:SUPER-UX:*:*) + echo sx7-nec-superux${UNAME_RELEASE} + exit ;; + SX-8:SUPER-UX:*:*) + echo sx8-nec-superux${UNAME_RELEASE} + exit ;; + SX-8R:SUPER-UX:*:*) + echo sx8r-nec-superux${UNAME_RELEASE} + exit ;; + Power*:Rhapsody:*:*) + echo powerpc-apple-rhapsody${UNAME_RELEASE} + exit ;; + *:Rhapsody:*:*) + echo ${UNAME_MACHINE}-apple-rhapsody${UNAME_RELEASE} + exit ;; + *:Darwin:*:*) + UNAME_PROCESSOR=`uname -p` || UNAME_PROCESSOR=unknown + case $UNAME_PROCESSOR in + unknown) UNAME_PROCESSOR=powerpc ;; + esac + echo ${UNAME_PROCESSOR}-apple-darwin${UNAME_RELEASE} + exit ;; + *:procnto*:*:* | *:QNX:[0123456789]*:*) + UNAME_PROCESSOR=`uname -p` + if test "$UNAME_PROCESSOR" = "x86"; then + UNAME_PROCESSOR=i386 + UNAME_MACHINE=pc + fi + echo ${UNAME_PROCESSOR}-${UNAME_MACHINE}-nto-qnx${UNAME_RELEASE} + exit ;; + *:QNX:*:4*) + echo i386-pc-qnx + exit ;; + NSE-?:NONSTOP_KERNEL:*:*) + echo nse-tandem-nsk${UNAME_RELEASE} + exit ;; + NSR-?:NONSTOP_KERNEL:*:*) + echo nsr-tandem-nsk${UNAME_RELEASE} + exit ;; + *:NonStop-UX:*:*) + echo mips-compaq-nonstopux + exit ;; + BS2000:POSIX*:*:*) + echo bs2000-siemens-sysv + exit ;; + DS/*:UNIX_System_V:*:*) + echo ${UNAME_MACHINE}-${UNAME_SYSTEM}-${UNAME_RELEASE} + exit ;; + *:Plan9:*:*) + # "uname -m" is not consistent, so use $cputype instead. 386 + # is converted to i386 for consistency with other x86 + # operating systems. + if test "$cputype" = "386"; then + UNAME_MACHINE=i386 + else + UNAME_MACHINE="$cputype" + fi + echo ${UNAME_MACHINE}-unknown-plan9 + exit ;; + *:TOPS-10:*:*) + echo pdp10-unknown-tops10 + exit ;; + *:TENEX:*:*) + echo pdp10-unknown-tenex + exit ;; + KS10:TOPS-20:*:* | KL10:TOPS-20:*:* | TYPE4:TOPS-20:*:*) + echo pdp10-dec-tops20 + exit ;; + XKL-1:TOPS-20:*:* | TYPE5:TOPS-20:*:*) + echo pdp10-xkl-tops20 + exit ;; + *:TOPS-20:*:*) + echo pdp10-unknown-tops20 + exit ;; + *:ITS:*:*) + echo pdp10-unknown-its + exit ;; + SEI:*:*:SEIUX) + echo mips-sei-seiux${UNAME_RELEASE} + exit ;; + *:DragonFly:*:*) + echo ${UNAME_MACHINE}-unknown-dragonfly`echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'` + exit ;; + *:*VMS:*:*) + UNAME_MACHINE=`(uname -p) 2>/dev/null` + case "${UNAME_MACHINE}" in + A*) echo alpha-dec-vms ; exit ;; + I*) echo ia64-dec-vms ; exit ;; + V*) echo vax-dec-vms ; exit ;; + esac ;; + *:XENIX:*:SysV) + echo i386-pc-xenix + exit ;; + i*86:skyos:*:*) + echo ${UNAME_MACHINE}-pc-skyos`echo ${UNAME_RELEASE}` | sed -e 's/ .*$//' + exit ;; + i*86:rdos:*:*) + echo ${UNAME_MACHINE}-pc-rdos + exit ;; +esac + +#echo '(No uname command or uname output not recognized.)' 1>&2 +#echo "${UNAME_MACHINE}:${UNAME_SYSTEM}:${UNAME_RELEASE}:${UNAME_VERSION}" 1>&2 + +eval $set_cc_for_build +cat >$dummy.c < +# include +#endif +main () +{ +#if defined (sony) +#if defined (MIPSEB) + /* BFD wants "bsd" instead of "newsos". Perhaps BFD should be changed, + I don't know.... */ + printf ("mips-sony-bsd\n"); exit (0); +#else +#include + printf ("m68k-sony-newsos%s\n", +#ifdef NEWSOS4 + "4" +#else + "" +#endif + ); exit (0); +#endif +#endif + +#if defined (__arm) && defined (__acorn) && defined (__unix) + printf ("arm-acorn-riscix\n"); exit (0); +#endif + +#if defined (hp300) && !defined (hpux) + printf ("m68k-hp-bsd\n"); exit (0); +#endif + +#if defined (NeXT) +#if !defined (__ARCHITECTURE__) +#define __ARCHITECTURE__ "m68k" +#endif + int version; + version=`(hostinfo | sed -n 's/.*NeXT Mach \([0-9]*\).*/\1/p') 2>/dev/null`; + if (version < 4) + printf ("%s-next-nextstep%d\n", __ARCHITECTURE__, version); + else + printf ("%s-next-openstep%d\n", __ARCHITECTURE__, version); + exit (0); +#endif + +#if defined (MULTIMAX) || defined (n16) +#if defined (UMAXV) + printf ("ns32k-encore-sysv\n"); exit (0); +#else +#if defined (CMU) + printf ("ns32k-encore-mach\n"); exit (0); +#else + printf ("ns32k-encore-bsd\n"); exit (0); +#endif +#endif +#endif + +#if defined (__386BSD__) + printf ("i386-pc-bsd\n"); exit (0); +#endif + +#if defined (sequent) +#if defined (i386) + printf ("i386-sequent-dynix\n"); exit (0); +#endif +#if defined (ns32000) + printf ("ns32k-sequent-dynix\n"); exit (0); +#endif +#endif + +#if defined (_SEQUENT_) + struct utsname un; + + uname(&un); + + if (strncmp(un.version, "V2", 2) == 0) { + printf ("i386-sequent-ptx2\n"); exit (0); + } + if (strncmp(un.version, "V1", 2) == 0) { /* XXX is V1 correct? */ + printf ("i386-sequent-ptx1\n"); exit (0); + } + printf ("i386-sequent-ptx\n"); exit (0); + +#endif + +#if defined (vax) +# if !defined (ultrix) +# include +# if defined (BSD) +# if BSD == 43 + printf ("vax-dec-bsd4.3\n"); exit (0); +# else +# if BSD == 199006 + printf ("vax-dec-bsd4.3reno\n"); exit (0); +# else + printf ("vax-dec-bsd\n"); exit (0); +# endif +# endif +# else + printf ("vax-dec-bsd\n"); exit (0); +# endif +# else + printf ("vax-dec-ultrix\n"); exit (0); +# endif +#endif + +#if defined (alliant) && defined (i860) + printf ("i860-alliant-bsd\n"); exit (0); +#endif + + exit (1); +} +EOF + +$CC_FOR_BUILD -o $dummy $dummy.c 2>/dev/null && SYSTEM_NAME=`$dummy` && + { echo "$SYSTEM_NAME"; exit; } + +# Apollos put the system type in the environment. + +test -d /usr/apollo && { echo ${ISP}-apollo-${SYSTYPE}; exit; } + +# Convex versions that predate uname can use getsysinfo(1) + +if [ -x /usr/convex/getsysinfo ] +then + case `getsysinfo -f cpu_type` in + c1*) + echo c1-convex-bsd + exit ;; + c2*) + if getsysinfo -f scalar_acc + then echo c32-convex-bsd + else echo c2-convex-bsd + fi + exit ;; + c34*) + echo c34-convex-bsd + exit ;; + c38*) + echo c38-convex-bsd + exit ;; + c4*) + echo c4-convex-bsd + exit ;; + esac +fi + +cat >&2 < in order to provide the needed +information to handle your system. + +config.guess timestamp = $timestamp + +uname -m = `(uname -m) 2>/dev/null || echo unknown` +uname -r = `(uname -r) 2>/dev/null || echo unknown` +uname -s = `(uname -s) 2>/dev/null || echo unknown` +uname -v = `(uname -v) 2>/dev/null || echo unknown` + +/usr/bin/uname -p = `(/usr/bin/uname -p) 2>/dev/null` +/bin/uname -X = `(/bin/uname -X) 2>/dev/null` + +hostinfo = `(hostinfo) 2>/dev/null` +/bin/universe = `(/bin/universe) 2>/dev/null` +/usr/bin/arch -k = `(/usr/bin/arch -k) 2>/dev/null` +/bin/arch = `(/bin/arch) 2>/dev/null` +/usr/bin/oslevel = `(/usr/bin/oslevel) 2>/dev/null` +/usr/convex/getsysinfo = `(/usr/convex/getsysinfo) 2>/dev/null` + +UNAME_MACHINE = ${UNAME_MACHINE} +UNAME_RELEASE = ${UNAME_RELEASE} +UNAME_SYSTEM = ${UNAME_SYSTEM} +UNAME_VERSION = ${UNAME_VERSION} +EOF + +exit 1 + +# Local variables: +# eval: (add-hook 'write-file-hooks 'time-stamp) +# time-stamp-start: "timestamp='" +# time-stamp-format: "%:y-%02m-%02d" +# time-stamp-end: "'" +# End: diff --git a/config.sub b/config.sub new file mode 100755 index 00000000000..1761d8bdf63 --- /dev/null +++ b/config.sub @@ -0,0 +1,1626 @@ +#! /bin/sh +# Configuration validation subroutine script. +# Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, +# 2000, 2001, 2002, 2003, 2004, 2005, 2006 Free Software Foundation, +# Inc. + +timestamp='2007-06-28' + +# This file is (in principle) common to ALL GNU software. +# The presence of a machine in this file suggests that SOME GNU software +# can handle that machine. It does not imply ALL GNU software can. +# +# This file is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA +# 02110-1301, USA. +# +# As a special exception to the GNU General Public License, if you +# distribute this file as part of a program that contains a +# configuration script generated by Autoconf, you may include it under +# the same distribution terms that you use for the rest of that program. + + +# Please send patches to . Submit a context +# diff and a properly formatted ChangeLog entry. +# +# Configuration subroutine to validate and canonicalize a configuration type. +# Supply the specified configuration type as an argument. +# If it is invalid, we print an error message on stderr and exit with code 1. +# Otherwise, we print the canonical config type on stdout and succeed. + +# This file is supposed to be the same for all GNU packages +# and recognize all the CPU types, system types and aliases +# that are meaningful with *any* GNU software. +# Each package is responsible for reporting which valid configurations +# it does not support. The user should be able to distinguish +# a failure to support a valid configuration from a meaningless +# configuration. + +# The goal of this file is to map all the various variations of a given +# machine specification into a single specification in the form: +# CPU_TYPE-MANUFACTURER-OPERATING_SYSTEM +# or in some cases, the newer four-part form: +# CPU_TYPE-MANUFACTURER-KERNEL-OPERATING_SYSTEM +# It is wrong to echo any other type of specification. + +me=`echo "$0" | sed -e 's,.*/,,'` + +usage="\ +Usage: $0 [OPTION] CPU-MFR-OPSYS + $0 [OPTION] ALIAS + +Canonicalize a configuration name. + +Operation modes: + -h, --help print this help, then exit + -t, --time-stamp print date of last modification, then exit + -v, --version print version number, then exit + +Report bugs and patches to ." + +version="\ +GNU config.sub ($timestamp) + +Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005 +Free Software Foundation, Inc. + +This is free software; see the source for copying conditions. There is NO +warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE." + +help=" +Try \`$me --help' for more information." + +# Parse command line +while test $# -gt 0 ; do + case $1 in + --time-stamp | --time* | -t ) + echo "$timestamp" ; exit ;; + --version | -v ) + echo "$version" ; exit ;; + --help | --h* | -h ) + echo "$usage"; exit ;; + -- ) # Stop option processing + shift; break ;; + - ) # Use stdin as input. + break ;; + -* ) + echo "$me: invalid option $1$help" + exit 1 ;; + + *local*) + # First pass through any local machine types. + echo $1 + exit ;; + + * ) + break ;; + esac +done + +case $# in + 0) echo "$me: missing argument$help" >&2 + exit 1;; + 1) ;; + *) echo "$me: too many arguments$help" >&2 + exit 1;; +esac + +# Separate what the user gave into CPU-COMPANY and OS or KERNEL-OS (if any). +# Here we must recognize all the valid KERNEL-OS combinations. +maybe_os=`echo $1 | sed 's/^\(.*\)-\([^-]*-[^-]*\)$/\2/'` +case $maybe_os in + nto-qnx* | linux-gnu* | linux-dietlibc | linux-newlib* | linux-uclibc* | \ + uclinux-uclibc* | uclinux-gnu* | kfreebsd*-gnu* | knetbsd*-gnu* | netbsd*-gnu* | \ + storm-chaos* | os2-emx* | rtmk-nova*) + os=-$maybe_os + basic_machine=`echo $1 | sed 's/^\(.*\)-\([^-]*-[^-]*\)$/\1/'` + ;; + *) + basic_machine=`echo $1 | sed 's/-[^-]*$//'` + if [ $basic_machine != $1 ] + then os=`echo $1 | sed 's/.*-/-/'` + else os=; fi + ;; +esac + +### Let's recognize common machines as not being operating systems so +### that things like config.sub decstation-3100 work. We also +### recognize some manufacturers as not being operating systems, so we +### can provide default operating systems below. +case $os in + -sun*os*) + # Prevent following clause from handling this invalid input. + ;; + -dec* | -mips* | -sequent* | -encore* | -pc532* | -sgi* | -sony* | \ + -att* | -7300* | -3300* | -delta* | -motorola* | -sun[234]* | \ + -unicom* | -ibm* | -next | -hp | -isi* | -apollo | -altos* | \ + -convergent* | -ncr* | -news | -32* | -3600* | -3100* | -hitachi* |\ + -c[123]* | -convex* | -sun | -crds | -omron* | -dg | -ultra | -tti* | \ + -harris | -dolphin | -highlevel | -gould | -cbm | -ns | -masscomp | \ + -apple | -axis | -knuth | -cray) + os= + basic_machine=$1 + ;; + -sim | -cisco | -oki | -wec | -winbond) + os= + basic_machine=$1 + ;; + -scout) + ;; + -wrs) + os=-vxworks + basic_machine=$1 + ;; + -chorusos*) + os=-chorusos + basic_machine=$1 + ;; + -chorusrdb) + os=-chorusrdb + basic_machine=$1 + ;; + -hiux*) + os=-hiuxwe2 + ;; + -sco6) + os=-sco5v6 + basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'` + ;; + -sco5) + os=-sco3.2v5 + basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'` + ;; + -sco4) + os=-sco3.2v4 + basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'` + ;; + -sco3.2.[4-9]*) + os=`echo $os | sed -e 's/sco3.2./sco3.2v/'` + basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'` + ;; + -sco3.2v[4-9]*) + # Don't forget version if it is 3.2v4 or newer. + basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'` + ;; + -sco5v6*) + # Don't forget version if it is 3.2v4 or newer. + basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'` + ;; + -sco*) + os=-sco3.2v2 + basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'` + ;; + -udk*) + basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'` + ;; + -isc) + os=-isc2.2 + basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'` + ;; + -clix*) + basic_machine=clipper-intergraph + ;; + -isc*) + basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'` + ;; + -lynx*) + os=-lynxos + ;; + -ptx*) + basic_machine=`echo $1 | sed -e 's/86-.*/86-sequent/'` + ;; + -windowsnt*) + os=`echo $os | sed -e 's/windowsnt/winnt/'` + ;; + -psos*) + os=-psos + ;; + -mint | -mint[0-9]*) + basic_machine=m68k-atari + os=-mint + ;; +esac + +# Decode aliases for certain CPU-COMPANY combinations. +case $basic_machine in + # Recognize the basic CPU types without company name. + # Some are omitted here because they have special meanings below. + 1750a | 580 \ + | a29k \ + | alpha | alphaev[4-8] | alphaev56 | alphaev6[78] | alphapca5[67] \ + | alpha64 | alpha64ev[4-8] | alpha64ev56 | alpha64ev6[78] | alpha64pca5[67] \ + | am33_2.0 \ + | arc | arm | arm[bl]e | arme[lb] | armv[2345] | armv[345][lb] | avr | avr32 \ + | bfin \ + | c4x | clipper \ + | d10v | d30v | dlx | dsp16xx \ + | fido | fr30 | frv \ + | h8300 | h8500 | hppa | hppa1.[01] | hppa2.0 | hppa2.0[nw] | hppa64 \ + | i370 | i860 | i960 | ia64 \ + | ip2k | iq2000 \ + | m32c | m32r | m32rle | m68000 | m68k | m88k \ + | maxq | mb | microblaze | mcore | mep \ + | mips | mipsbe | mipseb | mipsel | mipsle \ + | mips16 \ + | mips64 | mips64el \ + | mips64vr | mips64vrel \ + | mips64orion | mips64orionel \ + | mips64vr4100 | mips64vr4100el \ + | mips64vr4300 | mips64vr4300el \ + | mips64vr5000 | mips64vr5000el \ + | mips64vr5900 | mips64vr5900el \ + | mipsisa32 | mipsisa32el \ + | mipsisa32r2 | mipsisa32r2el \ + | mipsisa64 | mipsisa64el \ + | mipsisa64r2 | mipsisa64r2el \ + | mipsisa64sb1 | mipsisa64sb1el \ + | mipsisa64sr71k | mipsisa64sr71kel \ + | mipstx39 | mipstx39el \ + | mn10200 | mn10300 \ + | mt \ + | msp430 \ + | nios | nios2 \ + | ns16k | ns32k \ + | or32 \ + | pdp10 | pdp11 | pj | pjl \ + | powerpc | powerpc64 | powerpc64le | powerpcle | ppcbe \ + | pyramid \ + | score \ + | sh | sh[1234] | sh[24]a | sh[23]e | sh[34]eb | sheb | shbe | shle | sh[1234]le | sh3ele \ + | sh64 | sh64le \ + | sparc | sparc64 | sparc64b | sparc64v | sparc86x | sparclet | sparclite \ + | sparcv8 | sparcv9 | sparcv9b | sparcv9v \ + | spu | strongarm \ + | tahoe | thumb | tic4x | tic80 | tron \ + | v850 | v850e \ + | we32k \ + | x86 | xc16x | xscale | xscalee[bl] | xstormy16 | xtensa \ + | z8k) + basic_machine=$basic_machine-unknown + ;; + m6811 | m68hc11 | m6812 | m68hc12) + # Motorola 68HC11/12. + basic_machine=$basic_machine-unknown + os=-none + ;; + m88110 | m680[12346]0 | m683?2 | m68360 | m5200 | v70 | w65 | z8k) + ;; + ms1) + basic_machine=mt-unknown + ;; + + # We use `pc' rather than `unknown' + # because (1) that's what they normally are, and + # (2) the word "unknown" tends to confuse beginning users. + i*86 | x86_64) + basic_machine=$basic_machine-pc + ;; + # Object if more than one company name word. + *-*-*) + echo Invalid configuration \`$1\': machine \`$basic_machine\' not recognized 1>&2 + exit 1 + ;; + # Recognize the basic CPU types with company name. + 580-* \ + | a29k-* \ + | alpha-* | alphaev[4-8]-* | alphaev56-* | alphaev6[78]-* \ + | alpha64-* | alpha64ev[4-8]-* | alpha64ev56-* | alpha64ev6[78]-* \ + | alphapca5[67]-* | alpha64pca5[67]-* | arc-* \ + | arm-* | armbe-* | armle-* | armeb-* | armv*-* \ + | avr-* | avr32-* \ + | bfin-* | bs2000-* \ + | c[123]* | c30-* | [cjt]90-* | c4x-* | c54x-* | c55x-* | c6x-* \ + | clipper-* | craynv-* | cydra-* \ + | d10v-* | d30v-* | dlx-* \ + | elxsi-* \ + | f30[01]-* | f700-* | fido-* | fr30-* | frv-* | fx80-* \ + | h8300-* | h8500-* \ + | hppa-* | hppa1.[01]-* | hppa2.0-* | hppa2.0[nw]-* | hppa64-* \ + | i*86-* | i860-* | i960-* | ia64-* \ + | ip2k-* | iq2000-* \ + | m32c-* | m32r-* | m32rle-* \ + | m68000-* | m680[012346]0-* | m68360-* | m683?2-* | m68k-* \ + | m88110-* | m88k-* | maxq-* | mcore-* \ + | mips-* | mipsbe-* | mipseb-* | mipsel-* | mipsle-* \ + | mips16-* \ + | mips64-* | mips64el-* \ + | mips64vr-* | mips64vrel-* \ + | mips64orion-* | mips64orionel-* \ + | mips64vr4100-* | mips64vr4100el-* \ + | mips64vr4300-* | mips64vr4300el-* \ + | mips64vr5000-* | mips64vr5000el-* \ + | mips64vr5900-* | mips64vr5900el-* \ + | mipsisa32-* | mipsisa32el-* \ + | mipsisa32r2-* | mipsisa32r2el-* \ + | mipsisa64-* | mipsisa64el-* \ + | mipsisa64r2-* | mipsisa64r2el-* \ + | mipsisa64sb1-* | mipsisa64sb1el-* \ + | mipsisa64sr71k-* | mipsisa64sr71kel-* \ + | mipstx39-* | mipstx39el-* \ + | mmix-* \ + | mt-* \ + | msp430-* \ + | nios-* | nios2-* \ + | none-* | np1-* | ns16k-* | ns32k-* \ + | orion-* \ + | pdp10-* | pdp11-* | pj-* | pjl-* | pn-* | power-* \ + | powerpc-* | powerpc64-* | powerpc64le-* | powerpcle-* | ppcbe-* \ + | pyramid-* \ + | romp-* | rs6000-* \ + | sh-* | sh[1234]-* | sh[24]a-* | sh[23]e-* | sh[34]eb-* | sheb-* | shbe-* \ + | shle-* | sh[1234]le-* | sh3ele-* | sh64-* | sh64le-* \ + | sparc-* | sparc64-* | sparc64b-* | sparc64v-* | sparc86x-* | sparclet-* \ + | sparclite-* \ + | sparcv8-* | sparcv9-* | sparcv9b-* | sparcv9v-* | strongarm-* | sv1-* | sx?-* \ + | tahoe-* | thumb-* \ + | tic30-* | tic4x-* | tic54x-* | tic55x-* | tic6x-* | tic80-* \ + | tron-* \ + | v850-* | v850e-* | vax-* \ + | we32k-* \ + | x86-* | x86_64-* | xc16x-* | xps100-* | xscale-* | xscalee[bl]-* \ + | xstormy16-* | xtensa-* \ + | ymp-* \ + | z8k-*) + ;; + # Recognize the various machine names and aliases which stand + # for a CPU type and a company and sometimes even an OS. + 386bsd) + basic_machine=i386-unknown + os=-bsd + ;; + 3b1 | 7300 | 7300-att | att-7300 | pc7300 | safari | unixpc) + basic_machine=m68000-att + ;; + 3b*) + basic_machine=we32k-att + ;; + a29khif) + basic_machine=a29k-amd + os=-udi + ;; + abacus) + basic_machine=abacus-unknown + ;; + adobe68k) + basic_machine=m68010-adobe + os=-scout + ;; + alliant | fx80) + basic_machine=fx80-alliant + ;; + altos | altos3068) + basic_machine=m68k-altos + ;; + am29k) + basic_machine=a29k-none + os=-bsd + ;; + amd64) + basic_machine=x86_64-pc + ;; + amd64-*) + basic_machine=x86_64-`echo $basic_machine | sed 's/^[^-]*-//'` + ;; + amdahl) + basic_machine=580-amdahl + os=-sysv + ;; + amiga | amiga-*) + basic_machine=m68k-unknown + ;; + amigaos | amigados) + basic_machine=m68k-unknown + os=-amigaos + ;; + amigaunix | amix) + basic_machine=m68k-unknown + os=-sysv4 + ;; + apollo68) + basic_machine=m68k-apollo + os=-sysv + ;; + apollo68bsd) + basic_machine=m68k-apollo + os=-bsd + ;; + aux) + basic_machine=m68k-apple + os=-aux + ;; + balance) + basic_machine=ns32k-sequent + os=-dynix + ;; + c90) + basic_machine=c90-cray + os=-unicos + ;; + convex-c1) + basic_machine=c1-convex + os=-bsd + ;; + convex-c2) + basic_machine=c2-convex + os=-bsd + ;; + convex-c32) + basic_machine=c32-convex + os=-bsd + ;; + convex-c34) + basic_machine=c34-convex + os=-bsd + ;; + convex-c38) + basic_machine=c38-convex + os=-bsd + ;; + cray | j90) + basic_machine=j90-cray + os=-unicos + ;; + craynv) + basic_machine=craynv-cray + os=-unicosmp + ;; + cr16) + basic_machine=cr16-unknown + os=-elf + ;; + crds | unos) + basic_machine=m68k-crds + ;; + crisv32 | crisv32-* | etraxfs*) + basic_machine=crisv32-axis + ;; + cris | cris-* | etrax*) + basic_machine=cris-axis + ;; + crx) + basic_machine=crx-unknown + os=-elf + ;; + da30 | da30-*) + basic_machine=m68k-da30 + ;; + decstation | decstation-3100 | pmax | pmax-* | pmin | dec3100 | decstatn) + basic_machine=mips-dec + ;; + decsystem10* | dec10*) + basic_machine=pdp10-dec + os=-tops10 + ;; + decsystem20* | dec20*) + basic_machine=pdp10-dec + os=-tops20 + ;; + delta | 3300 | motorola-3300 | motorola-delta \ + | 3300-motorola | delta-motorola) + basic_machine=m68k-motorola + ;; + delta88) + basic_machine=m88k-motorola + os=-sysv3 + ;; + djgpp) + basic_machine=i586-pc + os=-msdosdjgpp + ;; + dpx20 | dpx20-*) + basic_machine=rs6000-bull + os=-bosx + ;; + dpx2* | dpx2*-bull) + basic_machine=m68k-bull + os=-sysv3 + ;; + ebmon29k) + basic_machine=a29k-amd + os=-ebmon + ;; + elxsi) + basic_machine=elxsi-elxsi + os=-bsd + ;; + encore | umax | mmax) + basic_machine=ns32k-encore + ;; + es1800 | OSE68k | ose68k | ose | OSE) + basic_machine=m68k-ericsson + os=-ose + ;; + fx2800) + basic_machine=i860-alliant + ;; + genix) + basic_machine=ns32k-ns + ;; + gmicro) + basic_machine=tron-gmicro + os=-sysv + ;; + go32) + basic_machine=i386-pc + os=-go32 + ;; + h3050r* | hiux*) + basic_machine=hppa1.1-hitachi + os=-hiuxwe2 + ;; + h8300hms) + basic_machine=h8300-hitachi + os=-hms + ;; + h8300xray) + basic_machine=h8300-hitachi + os=-xray + ;; + h8500hms) + basic_machine=h8500-hitachi + os=-hms + ;; + harris) + basic_machine=m88k-harris + os=-sysv3 + ;; + hp300-*) + basic_machine=m68k-hp + ;; + hp300bsd) + basic_machine=m68k-hp + os=-bsd + ;; + hp300hpux) + basic_machine=m68k-hp + os=-hpux + ;; + hp3k9[0-9][0-9] | hp9[0-9][0-9]) + basic_machine=hppa1.0-hp + ;; + hp9k2[0-9][0-9] | hp9k31[0-9]) + basic_machine=m68000-hp + ;; + hp9k3[2-9][0-9]) + basic_machine=m68k-hp + ;; + hp9k6[0-9][0-9] | hp6[0-9][0-9]) + basic_machine=hppa1.0-hp + ;; + hp9k7[0-79][0-9] | hp7[0-79][0-9]) + basic_machine=hppa1.1-hp + ;; + hp9k78[0-9] | hp78[0-9]) + # FIXME: really hppa2.0-hp + basic_machine=hppa1.1-hp + ;; + hp9k8[67]1 | hp8[67]1 | hp9k80[24] | hp80[24] | hp9k8[78]9 | hp8[78]9 | hp9k893 | hp893) + # FIXME: really hppa2.0-hp + basic_machine=hppa1.1-hp + ;; + hp9k8[0-9][13679] | hp8[0-9][13679]) + basic_machine=hppa1.1-hp + ;; + hp9k8[0-9][0-9] | hp8[0-9][0-9]) + basic_machine=hppa1.0-hp + ;; + hppa-next) + os=-nextstep3 + ;; + hppaosf) + basic_machine=hppa1.1-hp + os=-osf + ;; + hppro) + basic_machine=hppa1.1-hp + os=-proelf + ;; + i370-ibm* | ibm*) + basic_machine=i370-ibm + ;; +# I'm not sure what "Sysv32" means. Should this be sysv3.2? + i*86v32) + basic_machine=`echo $1 | sed -e 's/86.*/86-pc/'` + os=-sysv32 + ;; + i*86v4*) + basic_machine=`echo $1 | sed -e 's/86.*/86-pc/'` + os=-sysv4 + ;; + i*86v) + basic_machine=`echo $1 | sed -e 's/86.*/86-pc/'` + os=-sysv + ;; + i*86sol2) + basic_machine=`echo $1 | sed -e 's/86.*/86-pc/'` + os=-solaris2 + ;; + i386mach) + basic_machine=i386-mach + os=-mach + ;; + i386-vsta | vsta) + basic_machine=i386-unknown + os=-vsta + ;; + iris | iris4d) + basic_machine=mips-sgi + case $os in + -irix*) + ;; + *) + os=-irix4 + ;; + esac + ;; + isi68 | isi) + basic_machine=m68k-isi + os=-sysv + ;; + m88k-omron*) + basic_machine=m88k-omron + ;; + magnum | m3230) + basic_machine=mips-mips + os=-sysv + ;; + merlin) + basic_machine=ns32k-utek + os=-sysv + ;; + mingw32) + basic_machine=i386-pc + os=-mingw32 + ;; + mingw32ce) + basic_machine=arm-unknown + os=-mingw32ce + ;; + miniframe) + basic_machine=m68000-convergent + ;; + *mint | -mint[0-9]* | *MiNT | *MiNT[0-9]*) + basic_machine=m68k-atari + os=-mint + ;; + mips3*-*) + basic_machine=`echo $basic_machine | sed -e 's/mips3/mips64/'` + ;; + mips3*) + basic_machine=`echo $basic_machine | sed -e 's/mips3/mips64/'`-unknown + ;; + monitor) + basic_machine=m68k-rom68k + os=-coff + ;; + morphos) + basic_machine=powerpc-unknown + os=-morphos + ;; + msdos) + basic_machine=i386-pc + os=-msdos + ;; + ms1-*) + basic_machine=`echo $basic_machine | sed -e 's/ms1-/mt-/'` + ;; + mvs) + basic_machine=i370-ibm + os=-mvs + ;; + ncr3000) + basic_machine=i486-ncr + os=-sysv4 + ;; + netbsd386) + basic_machine=i386-unknown + os=-netbsd + ;; + netwinder) + basic_machine=armv4l-rebel + os=-linux + ;; + news | news700 | news800 | news900) + basic_machine=m68k-sony + os=-newsos + ;; + news1000) + basic_machine=m68030-sony + os=-newsos + ;; + news-3600 | risc-news) + basic_machine=mips-sony + os=-newsos + ;; + necv70) + basic_machine=v70-nec + os=-sysv + ;; + next | m*-next ) + basic_machine=m68k-next + case $os in + -nextstep* ) + ;; + -ns2*) + os=-nextstep2 + ;; + *) + os=-nextstep3 + ;; + esac + ;; + nh3000) + basic_machine=m68k-harris + os=-cxux + ;; + nh[45]000) + basic_machine=m88k-harris + os=-cxux + ;; + nindy960) + basic_machine=i960-intel + os=-nindy + ;; + mon960) + basic_machine=i960-intel + os=-mon960 + ;; + nonstopux) + basic_machine=mips-compaq + os=-nonstopux + ;; + np1) + basic_machine=np1-gould + ;; + nsr-tandem) + basic_machine=nsr-tandem + ;; + op50n-* | op60c-*) + basic_machine=hppa1.1-oki + os=-proelf + ;; + openrisc | openrisc-*) + basic_machine=or32-unknown + ;; + os400) + basic_machine=powerpc-ibm + os=-os400 + ;; + OSE68000 | ose68000) + basic_machine=m68000-ericsson + os=-ose + ;; + os68k) + basic_machine=m68k-none + os=-os68k + ;; + pa-hitachi) + basic_machine=hppa1.1-hitachi + os=-hiuxwe2 + ;; + paragon) + basic_machine=i860-intel + os=-osf + ;; + pbd) + basic_machine=sparc-tti + ;; + pbb) + basic_machine=m68k-tti + ;; + pc532 | pc532-*) + basic_machine=ns32k-pc532 + ;; + pc98) + basic_machine=i386-pc + ;; + pc98-*) + basic_machine=i386-`echo $basic_machine | sed 's/^[^-]*-//'` + ;; + pentium | p5 | k5 | k6 | nexgen | viac3) + basic_machine=i586-pc + ;; + pentiumpro | p6 | 6x86 | athlon | athlon_*) + basic_machine=i686-pc + ;; + pentiumii | pentium2 | pentiumiii | pentium3) + basic_machine=i686-pc + ;; + pentium4) + basic_machine=i786-pc + ;; + pentium-* | p5-* | k5-* | k6-* | nexgen-* | viac3-*) + basic_machine=i586-`echo $basic_machine | sed 's/^[^-]*-//'` + ;; + pentiumpro-* | p6-* | 6x86-* | athlon-*) + basic_machine=i686-`echo $basic_machine | sed 's/^[^-]*-//'` + ;; + pentiumii-* | pentium2-* | pentiumiii-* | pentium3-*) + basic_machine=i686-`echo $basic_machine | sed 's/^[^-]*-//'` + ;; + pentium4-*) + basic_machine=i786-`echo $basic_machine | sed 's/^[^-]*-//'` + ;; + pn) + basic_machine=pn-gould + ;; + power) basic_machine=power-ibm + ;; + ppc) basic_machine=powerpc-unknown + ;; + ppc-*) basic_machine=powerpc-`echo $basic_machine | sed 's/^[^-]*-//'` + ;; + ppcle | powerpclittle | ppc-le | powerpc-little) + basic_machine=powerpcle-unknown + ;; + ppcle-* | powerpclittle-*) + basic_machine=powerpcle-`echo $basic_machine | sed 's/^[^-]*-//'` + ;; + ppc64) basic_machine=powerpc64-unknown + ;; + ppc64-*) basic_machine=powerpc64-`echo $basic_machine | sed 's/^[^-]*-//'` + ;; + ppc64le | powerpc64little | ppc64-le | powerpc64-little) + basic_machine=powerpc64le-unknown + ;; + ppc64le-* | powerpc64little-*) + basic_machine=powerpc64le-`echo $basic_machine | sed 's/^[^-]*-//'` + ;; + ps2) + basic_machine=i386-ibm + ;; + pw32) + basic_machine=i586-unknown + os=-pw32 + ;; + rdos) + basic_machine=i386-pc + os=-rdos + ;; + rom68k) + basic_machine=m68k-rom68k + os=-coff + ;; + rm[46]00) + basic_machine=mips-siemens + ;; + rtpc | rtpc-*) + basic_machine=romp-ibm + ;; + s390 | s390-*) + basic_machine=s390-ibm + ;; + s390x | s390x-*) + basic_machine=s390x-ibm + ;; + sa29200) + basic_machine=a29k-amd + os=-udi + ;; + sb1) + basic_machine=mipsisa64sb1-unknown + ;; + sb1el) + basic_machine=mipsisa64sb1el-unknown + ;; + sde) + basic_machine=mipsisa32-sde + os=-elf + ;; + sei) + basic_machine=mips-sei + os=-seiux + ;; + sequent) + basic_machine=i386-sequent + ;; + sh) + basic_machine=sh-hitachi + os=-hms + ;; + sh5el) + basic_machine=sh5le-unknown + ;; + sh64) + basic_machine=sh64-unknown + ;; + sparclite-wrs | simso-wrs) + basic_machine=sparclite-wrs + os=-vxworks + ;; + sps7) + basic_machine=m68k-bull + os=-sysv2 + ;; + spur) + basic_machine=spur-unknown + ;; + st2000) + basic_machine=m68k-tandem + ;; + stratus) + basic_machine=i860-stratus + os=-sysv4 + ;; + sun2) + basic_machine=m68000-sun + ;; + sun2os3) + basic_machine=m68000-sun + os=-sunos3 + ;; + sun2os4) + basic_machine=m68000-sun + os=-sunos4 + ;; + sun3os3) + basic_machine=m68k-sun + os=-sunos3 + ;; + sun3os4) + basic_machine=m68k-sun + os=-sunos4 + ;; + sun4os3) + basic_machine=sparc-sun + os=-sunos3 + ;; + sun4os4) + basic_machine=sparc-sun + os=-sunos4 + ;; + sun4sol2) + basic_machine=sparc-sun + os=-solaris2 + ;; + sun3 | sun3-*) + basic_machine=m68k-sun + ;; + sun4) + basic_machine=sparc-sun + ;; + sun386 | sun386i | roadrunner) + basic_machine=i386-sun + ;; + sv1) + basic_machine=sv1-cray + os=-unicos + ;; + symmetry) + basic_machine=i386-sequent + os=-dynix + ;; + t3e) + basic_machine=alphaev5-cray + os=-unicos + ;; + t90) + basic_machine=t90-cray + os=-unicos + ;; + tic54x | c54x*) + basic_machine=tic54x-unknown + os=-coff + ;; + tic55x | c55x*) + basic_machine=tic55x-unknown + os=-coff + ;; + tic6x | c6x*) + basic_machine=tic6x-unknown + os=-coff + ;; + tx39) + basic_machine=mipstx39-unknown + ;; + tx39el) + basic_machine=mipstx39el-unknown + ;; + toad1) + basic_machine=pdp10-xkl + os=-tops20 + ;; + tower | tower-32) + basic_machine=m68k-ncr + ;; + tpf) + basic_machine=s390x-ibm + os=-tpf + ;; + udi29k) + basic_machine=a29k-amd + os=-udi + ;; + ultra3) + basic_machine=a29k-nyu + os=-sym1 + ;; + v810 | necv810) + basic_machine=v810-nec + os=-none + ;; + vaxv) + basic_machine=vax-dec + os=-sysv + ;; + vms) + basic_machine=vax-dec + os=-vms + ;; + vpp*|vx|vx-*) + basic_machine=f301-fujitsu + ;; + vxworks960) + basic_machine=i960-wrs + os=-vxworks + ;; + vxworks68) + basic_machine=m68k-wrs + os=-vxworks + ;; + vxworks29k) + basic_machine=a29k-wrs + os=-vxworks + ;; + w65*) + basic_machine=w65-wdc + os=-none + ;; + w89k-*) + basic_machine=hppa1.1-winbond + os=-proelf + ;; + xbox) + basic_machine=i686-pc + os=-mingw32 + ;; + xps | xps100) + basic_machine=xps100-honeywell + ;; + ymp) + basic_machine=ymp-cray + os=-unicos + ;; + z8k-*-coff) + basic_machine=z8k-unknown + os=-sim + ;; + none) + basic_machine=none-none + os=-none + ;; + +# Here we handle the default manufacturer of certain CPU types. It is in +# some cases the only manufacturer, in others, it is the most popular. + w89k) + basic_machine=hppa1.1-winbond + ;; + op50n) + basic_machine=hppa1.1-oki + ;; + op60c) + basic_machine=hppa1.1-oki + ;; + romp) + basic_machine=romp-ibm + ;; + mmix) + basic_machine=mmix-knuth + ;; + rs6000) + basic_machine=rs6000-ibm + ;; + vax) + basic_machine=vax-dec + ;; + pdp10) + # there are many clones, so DEC is not a safe bet + basic_machine=pdp10-unknown + ;; + pdp11) + basic_machine=pdp11-dec + ;; + we32k) + basic_machine=we32k-att + ;; + sh[1234] | sh[24]a | sh[34]eb | sh[1234]le | sh[23]ele) + basic_machine=sh-unknown + ;; + sparc | sparcv8 | sparcv9 | sparcv9b | sparcv9v) + basic_machine=sparc-sun + ;; + cydra) + basic_machine=cydra-cydrome + ;; + orion) + basic_machine=orion-highlevel + ;; + orion105) + basic_machine=clipper-highlevel + ;; + mac | mpw | mac-mpw) + basic_machine=m68k-apple + ;; + pmac | pmac-mpw) + basic_machine=powerpc-apple + ;; + *-unknown) + # Make sure to match an already-canonicalized machine name. + ;; + *) + echo Invalid configuration \`$1\': machine \`$basic_machine\' not recognized 1>&2 + exit 1 + ;; +esac + +# Here we canonicalize certain aliases for manufacturers. +case $basic_machine in + *-digital*) + basic_machine=`echo $basic_machine | sed 's/digital.*/dec/'` + ;; + *-commodore*) + basic_machine=`echo $basic_machine | sed 's/commodore.*/cbm/'` + ;; + *) + ;; +esac + +# Decode manufacturer-specific aliases for certain operating systems. + +if [ x"$os" != x"" ] +then +case $os in + # First match some system type aliases + # that might get confused with valid system types. + # -solaris* is a basic system type, with this one exception. + -solaris1 | -solaris1.*) + os=`echo $os | sed -e 's|solaris1|sunos4|'` + ;; + -solaris) + os=-solaris2 + ;; + -svr4*) + os=-sysv4 + ;; + -unixware*) + os=-sysv4.2uw + ;; + -gnu/linux*) + os=`echo $os | sed -e 's|gnu/linux|linux-gnu|'` + ;; + # First accept the basic system types. + # The portable systems comes first. + # Each alternative MUST END IN A *, to match a version number. + # -sysv* is not here because it comes later, after sysvr4. + -gnu* | -bsd* | -mach* | -minix* | -genix* | -ultrix* | -irix* \ + | -*vms* | -sco* | -esix* | -isc* | -aix* | -sunos | -sunos[34]*\ + | -hpux* | -unos* | -osf* | -luna* | -dgux* | -solaris* | -sym* \ + | -amigaos* | -amigados* | -msdos* | -newsos* | -unicos* | -aof* \ + | -aos* \ + | -nindy* | -vxsim* | -vxworks* | -ebmon* | -hms* | -mvs* \ + | -clix* | -riscos* | -uniplus* | -iris* | -rtu* | -xenix* \ + | -hiux* | -386bsd* | -knetbsd* | -mirbsd* | -netbsd* \ + | -openbsd* | -solidbsd* \ + | -ekkobsd* | -kfreebsd* | -freebsd* | -riscix* | -lynxos* \ + | -bosx* | -nextstep* | -cxux* | -aout* | -elf* | -oabi* \ + | -ptx* | -coff* | -ecoff* | -winnt* | -domain* | -vsta* \ + | -udi* | -eabi* | -lites* | -ieee* | -go32* | -aux* \ + | -chorusos* | -chorusrdb* \ + | -cygwin* | -pe* | -psos* | -moss* | -proelf* | -rtems* \ + | -mingw32* | -linux-gnu* | -linux-newlib* | -linux-uclibc* \ + | -uxpv* | -beos* | -mpeix* | -udk* \ + | -interix* | -uwin* | -mks* | -rhapsody* | -darwin* | -opened* \ + | -openstep* | -oskit* | -conix* | -pw32* | -nonstopux* \ + | -storm-chaos* | -tops10* | -tenex* | -tops20* | -its* \ + | -os2* | -vos* | -palmos* | -uclinux* | -nucleus* \ + | -morphos* | -superux* | -rtmk* | -rtmk-nova* | -windiss* \ + | -powermax* | -dnix* | -nx6 | -nx7 | -sei* | -dragonfly* \ + | -skyos* | -haiku* | -rdos* | -toppers* | -drops*) + # Remember, each alternative MUST END IN *, to match a version number. + ;; + -qnx*) + case $basic_machine in + x86-* | i*86-*) + ;; + *) + os=-nto$os + ;; + esac + ;; + -nto-qnx*) + ;; + -nto*) + os=`echo $os | sed -e 's|nto|nto-qnx|'` + ;; + -sim | -es1800* | -hms* | -xray | -os68k* | -none* | -v88r* \ + | -windows* | -osx | -abug | -netware* | -os9* | -beos* | -haiku* \ + | -macos* | -mpw* | -magic* | -mmixware* | -mon960* | -lnews*) + ;; + -mac*) + os=`echo $os | sed -e 's|mac|macos|'` + ;; + -linux-dietlibc) + os=-linux-dietlibc + ;; + -linux*) + os=`echo $os | sed -e 's|linux|linux-gnu|'` + ;; + -sunos5*) + os=`echo $os | sed -e 's|sunos5|solaris2|'` + ;; + -sunos6*) + os=`echo $os | sed -e 's|sunos6|solaris3|'` + ;; + -opened*) + os=-openedition + ;; + -os400*) + os=-os400 + ;; + -wince*) + os=-wince + ;; + -osfrose*) + os=-osfrose + ;; + -osf*) + os=-osf + ;; + -utek*) + os=-bsd + ;; + -dynix*) + os=-bsd + ;; + -acis*) + os=-aos + ;; + -atheos*) + os=-atheos + ;; + -syllable*) + os=-syllable + ;; + -386bsd) + os=-bsd + ;; + -ctix* | -uts*) + os=-sysv + ;; + -nova*) + os=-rtmk-nova + ;; + -ns2 ) + os=-nextstep2 + ;; + -nsk*) + os=-nsk + ;; + # Preserve the version number of sinix5. + -sinix5.*) + os=`echo $os | sed -e 's|sinix|sysv|'` + ;; + -sinix*) + os=-sysv4 + ;; + -tpf*) + os=-tpf + ;; + -triton*) + os=-sysv3 + ;; + -oss*) + os=-sysv3 + ;; + -svr4) + os=-sysv4 + ;; + -svr3) + os=-sysv3 + ;; + -sysvr4) + os=-sysv4 + ;; + # This must come after -sysvr4. + -sysv*) + ;; + -ose*) + os=-ose + ;; + -es1800*) + os=-ose + ;; + -xenix) + os=-xenix + ;; + -*mint | -mint[0-9]* | -*MiNT | -MiNT[0-9]*) + os=-mint + ;; + -aros*) + os=-aros + ;; + -kaos*) + os=-kaos + ;; + -zvmoe) + os=-zvmoe + ;; + -none) + ;; + *) + # Get rid of the `-' at the beginning of $os. + os=`echo $os | sed 's/[^-]*-//'` + echo Invalid configuration \`$1\': system \`$os\' not recognized 1>&2 + exit 1 + ;; +esac +else + +# Here we handle the default operating systems that come with various machines. +# The value should be what the vendor currently ships out the door with their +# machine or put another way, the most popular os provided with the machine. + +# Note that if you're going to try to match "-MANUFACTURER" here (say, +# "-sun"), then you have to tell the case statement up towards the top +# that MANUFACTURER isn't an operating system. Otherwise, code above +# will signal an error saying that MANUFACTURER isn't an operating +# system, and we'll never get to this point. + +case $basic_machine in + score-*) + os=-elf + ;; + spu-*) + os=-elf + ;; + *-acorn) + os=-riscix1.2 + ;; + arm*-rebel) + os=-linux + ;; + arm*-semi) + os=-aout + ;; + c4x-* | tic4x-*) + os=-coff + ;; + # This must come before the *-dec entry. + pdp10-*) + os=-tops20 + ;; + pdp11-*) + os=-none + ;; + *-dec | vax-*) + os=-ultrix4.2 + ;; + m68*-apollo) + os=-domain + ;; + i386-sun) + os=-sunos4.0.2 + ;; + m68000-sun) + os=-sunos3 + # This also exists in the configure program, but was not the + # default. + # os=-sunos4 + ;; + m68*-cisco) + os=-aout + ;; + mep-*) + os=-elf + ;; + mips*-cisco) + os=-elf + ;; + mips*-*) + os=-elf + ;; + or32-*) + os=-coff + ;; + *-tti) # must be before sparc entry or we get the wrong os. + os=-sysv3 + ;; + sparc-* | *-sun) + os=-sunos4.1.1 + ;; + *-be) + os=-beos + ;; + *-haiku) + os=-haiku + ;; + *-ibm) + os=-aix + ;; + *-knuth) + os=-mmixware + ;; + *-wec) + os=-proelf + ;; + *-winbond) + os=-proelf + ;; + *-oki) + os=-proelf + ;; + *-hp) + os=-hpux + ;; + *-hitachi) + os=-hiux + ;; + i860-* | *-att | *-ncr | *-altos | *-motorola | *-convergent) + os=-sysv + ;; + *-cbm) + os=-amigaos + ;; + *-dg) + os=-dgux + ;; + *-dolphin) + os=-sysv3 + ;; + m68k-ccur) + os=-rtu + ;; + m88k-omron*) + os=-luna + ;; + *-next ) + os=-nextstep + ;; + *-sequent) + os=-ptx + ;; + *-crds) + os=-unos + ;; + *-ns) + os=-genix + ;; + i370-*) + os=-mvs + ;; + *-next) + os=-nextstep3 + ;; + *-gould) + os=-sysv + ;; + *-highlevel) + os=-bsd + ;; + *-encore) + os=-bsd + ;; + *-sgi) + os=-irix + ;; + *-siemens) + os=-sysv4 + ;; + *-masscomp) + os=-rtu + ;; + f30[01]-fujitsu | f700-fujitsu) + os=-uxpv + ;; + *-rom68k) + os=-coff + ;; + *-*bug) + os=-coff + ;; + *-apple) + os=-macos + ;; + *-atari*) + os=-mint + ;; + *) + os=-none + ;; +esac +fi + +# Here we handle the case where we know the os, and the CPU type, but not the +# manufacturer. We pick the logical manufacturer. +vendor=unknown +case $basic_machine in + *-unknown) + case $os in + -riscix*) + vendor=acorn + ;; + -sunos*) + vendor=sun + ;; + -aix*) + vendor=ibm + ;; + -beos*) + vendor=be + ;; + -hpux*) + vendor=hp + ;; + -mpeix*) + vendor=hp + ;; + -hiux*) + vendor=hitachi + ;; + -unos*) + vendor=crds + ;; + -dgux*) + vendor=dg + ;; + -luna*) + vendor=omron + ;; + -genix*) + vendor=ns + ;; + -mvs* | -opened*) + vendor=ibm + ;; + -os400*) + vendor=ibm + ;; + -ptx*) + vendor=sequent + ;; + -tpf*) + vendor=ibm + ;; + -vxsim* | -vxworks* | -windiss*) + vendor=wrs + ;; + -aux*) + vendor=apple + ;; + -hms*) + vendor=hitachi + ;; + -mpw* | -macos*) + vendor=apple + ;; + -*mint | -mint[0-9]* | -*MiNT | -MiNT[0-9]*) + vendor=atari + ;; + -vos*) + vendor=stratus + ;; + esac + basic_machine=`echo $basic_machine | sed "s/unknown/$vendor/"` + ;; +esac + +echo $basic_machine$os +exit + +# Local variables: +# eval: (add-hook 'write-file-hooks 'time-stamp) +# time-stamp-start: "timestamp='" +# time-stamp-format: "%:y-%02m-%02d" +# time-stamp-end: "'" +# End: diff --git a/configure b/configure new file mode 100755 index 00000000000..4166796889a --- /dev/null +++ b/configure @@ -0,0 +1,1238 @@ +#!/bin/sh +# +# configure -- custom configure script for Residual. +# +# ScummVM is the legal property of its developers, whose names +# are too numerous to list here. Please refer to the COPYRIGHT +# file distributed with this source distribution. +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# as published by the Free Software Foundation; either version 2 +# of the License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +# +# $URL$ +# $Id$ + +# Save the current environment variables for next runs +SAVED_CONFIGFLAGS=$@ +SAVED_LDFLAGS=$LDFLAGS +SAVED_CXX=$CXX +SAVED_CXXFLAGS=$CXXFLAGS +SAVED_CPPFLAGS=$CPPFLAGS + +# use environment vars if set +CXXFLAGS="$CXXFLAGS $CPPFLAGS" + +# Backslashes into forward slashes: +# The following OS/2 specific code is performed to deal with handling of backslashes by ksh. +# Borrowed from the Sane configure script + +if test "$ac_emxsupport" != "no" -a "$ac_emxsupport" != "NO"; then + ac_save_IFS="$IFS" + IFS="\\" + ac_TEMP_PATH= + for ac_dir in $PATH; do + IFS=$ac_save_IFS + if test -z "$ac_TEMP_PATH"; then + ac_TEMP_PATH="$ac_dir" + else + ac_TEMP_PATH="$ac_TEMP_PATH/$ac_dir" + fi + done + PATH="$ac_TEMP_PATH" + export PATH + unset ac_TEMP_PATH +fi + + +# default lib behaviour yes/no/auto +_vorbis=auto +_tremor=auto +_flac=auto +_mad=auto +_alsa=auto +_zlib=auto +_mpeg2=auto + +_endian=unknown +_need_memalign=no +_have_x86=no + +# more defaults +_backend=sdl +_ranlib=ranlib +_ar="ar cru" +_windres=windres +_win32path="C:/residual" +_aos4path="Games:Residual" +_sdlconfig=sdl-config +_sdlpath="$PATH" +_prefix=/usr/local + +_srcdir=`dirname $0` + +# Determine a tmp file name, using mktemp(1) when available. +if type mktemp > /dev/null 2>&1 ; then + TMPO=`mktemp` +else + TMPO=${_srcdir}/residual-conf +fi +TMPC=${TMPO}.cpp +TMPLOG=${_srcdir}/config.log + +# For cross compiling +_host="" +_host_cpu="" +_host_vendor="" +_host_os="" + +cc_check() { + echo >> "$TMPLOG" + cat "$TMPC" >> "$TMPLOG" + echo >> "$TMPLOG" + echo "$CXX $TMPC -o $TMPO$EXEEXT $@" >> "$TMPLOG" + rm -f "$TMPO$EXEEXT" + rm -rf "$TMPO.dSYM" + ( $CXX $CXXFLAGS "$TMPC" -o "$TMPO$EXEEXT" "$@" ) >> "$TMPLOG" 2>&1 + TMP="$?" + echo >> "$TMPLOG" + return "$TMP" +} + +echocheck () { + echo_n "Checking for $@... " +} + +# Add a line of data to config.mk. +add_line_to_config_mk() { + _config_mk_data="$_config_mk_data"' +'"$1" +} + +# Add a line of data to config.h. +add_line_to_config_h() { + _config_h_data="$_config_h_data"' +'"$1" +} + +add_to_config_h_if_yes() { + if test "$1" = yes ; then + add_line_to_config_h "$2" + else + add_line_to_config_h "/* $2 */" + fi +} + +# Conditionally add a line of data to config.mk. Takes two parameters: +# The first one can be set to 'no' to "comment out" the line, i.e. +# make it ineffective, use 'yes' otherwise. +# The second param is the line to insert. +add_to_config_mk_if_yes() { + if test "$1" = yes ; then + add_line_to_config_mk "$2" + else + add_line_to_config_mk "# $2" + fi +} + +# Conditionally add a line of data to config.mk. Takes two parameters: +# The first one can be set to 'yes' to "comment out" the line, i.e. +# make it ineffective, use 'no' otherwise. +# The second param is the line to insert. +add_to_config_mk_if_no() { + if test "$1" = no ; then + add_line_to_config_mk "$2" + else + add_line_to_config_mk "# $2" + fi +} + +# +# Check whether the given command is a working C++ compiler +# +test_compiler () +{ +cat <tmp_cxx_compiler.cpp +class Foo { + int a; +}; +int main(int argc, char **argv) +{ + Foo *a = new Foo(); + delete a; + return 0; +} +EOF + +if test -n "$_host"; then + # In cross-compiling mode, we cannot run the result + eval "$1 $CXXFLAGS $LDFLAGS -o tmp_cxx_compiler$EXEEXT tmp_cxx_compiler.cpp" 2> /dev/null && rm -rf tmp_cxx_compiler$EXEEXT tmp_cxx_compiler.cpp tmp_cxx_compiler.dSYM +else + eval "$1 $CXXFLAGS $LDFLAGS -o tmp_cxx_compiler$EXEEXT tmp_cxx_compiler.cpp" 2> /dev/null && eval "./tmp_cxx_compiler$EXEEXT 2> /dev/null" && rm -rf tmp_cxx_compiler$EXEEXT tmp_cxx_compiler.cpp tmp_cxx_compiler.dSYM +fi +} + +# +# Determine sdl-config +# +# TODO: small bit of code to test sdl useability +find_sdlconfig() +{ + + echo_n "Looking for sdl-config... " + sdlconfigs="$_sdlconfig:sdl-config:sdl11-config:sdl12-config" + _sdlconfig= + + IFS="${IFS= }"; ac_save_ifs="$IFS"; IFS="$SEPARATOR" + for path_dir in $_sdlpath; do + #reset separator to parse sdlconfigs + IFS=":" + for sdlconfig in $sdlconfigs; do + if test -f "$path_dir/$sdlconfig" ; then + _sdlconfig="$path_dir/$sdlconfig" + echo $_sdlconfig + # Save the prefix + _sdlpath=$path_dir + if test `basename $path_dir` = bin ; then + _sdlpath=`dirname $path_dir` + fi + # break at first sdl-config found in path + break 2 + fi + done + done + + IFS="$ac_save_ifs" + + if test -z "$_sdlconfig"; then + echo "none found!" + exit 1 + fi +} + +# +# Function to provide echo -n for bourne shells that don't have it +# +echo_n() +{ + printf "$@" +} + +# +# Determine a data type with the given length +# +find_type_with_size () +{ +for datatype in int short char long unknown; do +cat <tmp_find_type_with_size.cpp +typedef $datatype ac__type_sizeof_; +int main() { + static int test_array [1 - 2 * !(((long int) (sizeof (ac__type_sizeof_))) == $1)]; + test_array [0] = 0; + return 0; +} +EOF +if $CXX $CXXFLAGS -c -o tmp_find_type_with_size$EXEEXT tmp_find_type_with_size.cpp 2>/dev/null ; then + break +else + if test "$datatype" = "unknown"; then + echo "couldn't find data type with $1 bytes" + exit 1 + fi + continue +fi +done +rm -f tmp_find_type_with_size$EXEEXT tmp_find_type_with_size.cpp +echo $datatype +} + +# Show the configure help line for an option +option_help() { + tmpopt=`echo $1 | sed 's/_/-/g'` + option=`echo "--${tmpopt} " | sed "s/\(.\{23\}\).*/\1/"` + echo " ${option} ${2}" +} + +# +# Greet user +# + +echo "Running Residual configure..." +echo "Configure run on" `date` > $TMPLOG + +# +# Check any parameters we received +# +# TODO: +# * Change --disable-mad / --enable-mad to the way it's done in autoconf: +# That is, --without-mad / --with-mad=/prefix/to/mad. Useful for people +# who have Mad/Vorbis/ALSA installed in a non-standard locations. +# + +for parm in "$@" ; do + if test "$parm" = "--help" || test "$parm" = "-help" || test "$parm" = "-h" ; then + cat << EOF + +Usage: $0 [OPTIONS]... + +Configuration: + -h, --help display this help and exit + --backend=BACKEND backend to build (sdl, morphos, dc, gp2x, iphone, null) [sdl] + +Installation directories: + --prefix=DIR use this prefix for installing Residual [/usr/local] + --bindir=DIR directory to install the scummvm binary in [PREFIX/bin] + --mandir=DIR directory to install the manpage in [PREFIX/share/man] + --datadir=DIR directory to install the data files in [PREFIX/share] + --libdir=DIR directory to install the plugins in [PREFIX/lib] + +Special configuration feature: + --host=HOST cross-compile to target HOST (arm-linux, ...) + special targets: linupy for Yopy PDA + +Optional Features: + --disable-debug disable building with debugging symbols + --enable-Werror treat warnings as errors + +Optional Libraries: + --with-alsa-prefix=DIR Prefix where alsa is installed (optional) + --disable-alsa disable ALSA midi sound support [autodetect] + + --with-ogg-prefix=DIR Prefix where libogg is installed (optional) + --with-vorbis-prefix=DIR Prefix where libvorbis is installed (optional) + --disable-vorbis disable Ogg Vorbis support [autodetect] + + --with-tremor-prefix=DIR Prefix where tremor is installed (optional) + --disable-tremor disable tremor support [autodetect] + + --with-mad-prefix=DIR Prefix where libmad is installed (optional) + --disable-mad disable libmad (MP3) support [autodetect] + + --with-flac-prefix=DIR Prefix where libFLAC is installed (optional) + --disable-flac disable FLAC support [autodetect] + + --with-zlib-prefix=DIR Prefix where zlib is installed (optional) + --disable-zlib disable zlib (compression) support [autodetect] + + --with-mpeg2-prefix=DIR Prefix where libmpeg2 is installed (optional) + --disable-mpeg2 disable mpeg2 codec for cutscenes [autodetect] + + --with-sdl-prefix=DIR Prefix where the sdl-config script is installed (optional) + +Some influential environment variables: + LDFLAGS linker flags, e.g. -L if you have libraries in a + nonstandard directory + CXX C++ compiler command + CXXFLAGS C++ compiler flags + CPPFLAGS C++ preprocessor flags, e.g. -I if you have + headers in a nonstandard directory + +EOF + exit 0 + fi +done # for parm in ... + +DEBFLAGS="-g" + +option_error() { + echo "error: unrecognised option: $ac_option +Try \`$0 --help' for more information." >&2 + exit 1 +} + +for ac_option in $@; do + case "$ac_option" in + --enable-alsa) _alsa=yes ;; + --disable-alsa) _alsa=no ;; + --enable-vorbis) _vorbis=yes ;; + --disable-vorbis) _vorbis=no ;; + --enable-tremor) _tremor=yes ;; + --disable-tremor) _tremor=no ;; + --enable-flac) _flac=yes ;; + --disable-flac) _flac=no ;; + --enable-mad) _mad=yes ;; + --disable-mad) _mad=no ;; + --enable-zlib) _zlib=yes ;; + --disable-zlib) _zlib=no ;; + --disable-mpeg2) _mpeg2=no ;; + --with-mpeg2-prefix=*) + arg=`echo $ac_option | cut -d '=' -f 2` + MPEG2_CFLAGS="-I$arg/include" + MPEG2_LIBS="-L$arg/lib" + ;; + --with-alsa-prefix=*) + arg=`echo $ac_option | cut -d '=' -f 2` + ALSA_CFLAGS="-I$arg/include" + ALSA_LIBS="-L$arg/lib" + ;; + --with-ogg-prefix=*) + arg=`echo $ac_option | cut -d '=' -f 2` + OGG_CFLAGS="-I$arg/include" + OGG_LIBS="-L$arg/lib" + ;; + --with-vorbis-prefix=*) + arg=`echo $ac_option | cut -d '=' -f 2` + VORBIS_CFLAGS="-I$arg/include" + VORBIS_LIBS="-L$arg/lib" + ;; + --with-tremor-prefix=*) + arg=`echo $ac_option | cut -d '=' -f 2` + TREMOR_CFLAGS="-I$arg/include" + TREMOR_LIBS="-L$arg/lib" + ;; + --with-flac-prefix=*) + arg=`echo $ac_option | cut -d '=' -f 2` + FLAC_CFLAGS="-I$arg/include" + FLAC_LIBS="-L$arg/lib" + ;; + --with-mad-prefix=*) + arg=`echo $ac_option | cut -d '=' -f 2` + MAD_CFLAGS="-I$arg/include" + MAD_LIBS="-L$arg/lib" + ;; + --with-zlib-prefix=*) + arg=`echo $ac_option | cut -d '=' -f 2` + ZLIB_CFLAGS="-I$arg/include" + ZLIB_LIBS="-L$arg/lib" + ;; + --backend=*) + _backend=`echo $ac_option | cut -d '=' -f 2` + ;; + --enable-debug) + # debug is enabled by default + ;; + --disable-debug) + DEBFLAGS="" + ;; + --enable-Werror) + CXXFLAGS="$CXXFLAGS -Werror" + ;; + --enable-release) + DEBFLAGS="-O2 -Wuninitialized" + ;; + --with-sdl-prefix=*) + arg=`echo $ac_option | cut -d '=' -f 2` + _sdlpath="$arg:$arg/bin" + ;; + --host=*) + _host=`echo $ac_option | cut -d '=' -f 2` + ;; + --prefix=*) + _prefix=`echo $ac_option | cut -d '=' -f 2` + ;; + --bindir=*) + _bindir=`echo $ac_option | cut -d '=' -f 2` + ;; + --mandir=*) + _mandir=`echo $ac_option | cut -d '=' -f 2` + ;; + --datadir=*) + _datadir=`echo $ac_option | cut -d '=' -f 2` + ;; + --libdir=*) + _libdir=`echo $ac_option | cut -d '=' -f 2` + ;; + --enable-*) + engine_enable `echo $ac_option | cut -d '-' -f 4-` + ;; + --disable-*) + engine_disable `echo $ac_option | cut -d '-' -f 4-` + ;; + *) + option_error + ;; + esac; +done; + +CXXFLAGS="$CXXFLAGS $DEBFLAGS" + +case $_host in +linupy) + _host_os=linux + _host_cpu=arm + ;; +arm-riscos) + _host_os=riscos + _host_cpu=arm + ;; +ppc-amigaos) + _host_os=amigaos + _host_cpu=ppc + ;; +i586-mingw32msvc) + _host_os=mingw32msvc + _host_cpu=i586 + ;; +iphone) + _host_os=iphone + _host_cpu=arm + ;; +*) + if test -z "$_host"; then + guessed_host=`$_srcdir/config.guess` + else + guessed_host=`$_srcdir/config.sub $_host` + fi + _host_cpu=`echo $guessed_host | sed 's/^\([^-]*\)-\([^-]*\)-\(.*\)$/\1/'` + _host_os=`echo $guessed_host | sed 's/^\([^-]*\)-\([^-]*\)-\(.*\)$/\3/'` + _host_vendor=`echo $guessed_host | sed 's/^\([^-]*\)-\([^-]*\)-\(.*\)$/\2/'` + ;; +esac + +# +# Determine extension used for executables +# +case $_host_os in +mingw* | cygwin* | os2-emx*) + EXEEXT=".exe" + ;; +arm-riscos) + EXEEXT=",ff8" + ;; +gp2x-linux) + EXEEXT=".gp2x" + ;; +*) + EXEEXT="" + ;; +esac + +# +# Determine separator used for $PATH +# +case $_host_os in +os2-emx* ) + SEPARATOR=";" + ;; +* ) + SEPARATOR=":" + ;; +esac + +# +# Determine the C++ compiler +# +echo_n "Looking for C++ compiler... " +if test -n "$_host"; then + compilers="$CXX $_host_cpu-$_host_os-g++ $_host_cpu-$_host_os-c++ $_host-g++ $_host-c++" +else + compilers="$CXX g++ c++" +fi + +CXX= +for compiler in $compilers; do + if test_compiler $compiler; then + CXX=$compiler + echo $CXX + break + fi +done +if test -z "$CXX"; then + echo "none found!" + exit 1 +fi + +# +# Determine the compiler version + +echocheck "compiler version" + +case $_host_os in + # On Solaris, use Unix-compliant tail + solaris*) + tail=/usr/xpg4/bin/tail + ;; + + # All other OSes: use the tail in PATH + *) + tail=tail + ;; +esac + + +cxx_version=`( $CXX -dumpversion ) 2>&1` +if test "$?" -gt 0; then + cxx_version="not found" +fi + +case $cxx_version in + 2.95.[2-9]|2.95.[2-9][-.]*|3.[0-9]|3.[0-9].[0-9]|3.[0-9].[0-9][-.]*|4.[0-9].[0-9]|4.[0-9].[0-9][-.]*) + _cxx_major=`echo $cxx_version | cut -d '.' -f 1` + _cxx_minor=`echo $cxx_version | cut -d '.' -f 2` + cxx_version="$cxx_version, ok" + cxx_verc_fail=no + ;; + # whacky beos version strings + 2.9-beos-991026*|2.9-beos-000224*) + _cxx_major=2 + _cxx_minor=95 + cxx_version="$cxx_version, ok" + cxx_verc_fail=no + ;; + 3_4) + _cxx_major=3 + _mxx_minor=4 + ;; + 'not found') + cxx_verc_fail=yes + ;; + *) + cxx_version="$cxx_version, bad" + cxx_verc_fail=yes + ;; +esac + +echo "$cxx_version" + +if test "$cxx_verc_fail" = yes ; then + echo + echo "The version of your compiler is not supported at this time" + echo "Please ensure you are using GCC >= 2.95" + exit 1 +fi + +# +# Do CXXFLAGS now we know the compiler version +# + +if test "$_cxx_major" -ge "3" ; then + case $_host_os in + mingw* | cygwin*) + CXXFLAGS="$CXXFLAGS -W -Wno-unused-parameter" + ;; + *) + CXXFLAGS="$CXXFLAGS -ansi -W -Wno-unused-parameter" + ;; + esac + add_line_to_config_mk 'HAVE_GCC3 = 1' +fi; + +if test "$_cxx_major" -ge "4" && test "$_cxx_minor" -ge "3" ; then + CXXFLAGS="$CXXFLAGS -Wno-parentheses -Wno-empty-body" +else + CXXFLAGS="$CXXFLAGS -Wconversion" +fi; + +# +# Check for endianness +# +echo_n "Checking endianness... " +cat <tmp_endianness_check.cpp +short ascii_mm[] = { 0x4249, 0x4765, 0x6E44, 0x6961, 0x6E53, 0x7953, 0 }; +short ascii_ii[] = { 0x694C, 0x5454, 0x656C, 0x6E45, 0x6944, 0x6E61, 0 }; +void _ascii() { char* s = (char*) ascii_mm; s = (char*) ascii_ii; } +short ebcdic_ii[] = { 0x89D3, 0xE3E3, 0x8593, 0x95C5, 0x89C4, 0x9581, 0 }; +short ebcdic_mm[] = { 0xC2C9, 0xC785, 0x95C4, 0x8981, 0x95E2, 0xA8E2, 0 }; +void _ebcdic() { char* s = (char*) ebcdic_mm; s = (char*) ebcdic_ii; } +int main() { _ascii (); _ebcdic (); return 0; } +EOF +$CXX $CXXFLAGS -c -o tmp_endianness_check.o tmp_endianness_check.cpp +if strings tmp_endianness_check.o | grep BIGenDianSyS >/dev/null; then + _endian=big +else + _endian=little +fi +echo $_endian; +rm -f tmp_endianness_check.o tmp_endianness_check.cpp + +# +# Determine data type sizes +# TODO: proper error checking +# TODO: Actually, we should check individually for both signed & unsigned +# data types - there are systems on which the size of an unsigned int +# differs from that of a signed int! +# However, so far we haven't encountered one of those, so we can live with +# the limited check for now. +# +echo_n "Type with 1 byte... " +type_1_byte=`find_type_with_size 1` +TMP="$?" +echo "$type_1_byte" +test $TMP -eq 0 || exit 1 # check exit code of subshell + +echo_n "Type with 2 bytes... " +type_2_byte=`find_type_with_size 2` +TMP="$?" +echo "$type_2_byte" +test $TMP -eq 0 || exit 1 # check exit code of subshell + +echo_n "Type with 4 bytes... " +type_4_byte=`find_type_with_size 4` +TMP="$?" +echo "$type_4_byte" +test $TMP -eq 0 || exit 1 # check exit code of subshell + +# +# Check whether we can use x86 asm routines +# +echo_n "Running on x86... " +case $_host_cpu in + i386|i486|i586|i686) + _have_x86=yes + ;; + *) + _have_x86=no + ;; +esac +echo "$_have_x86" + +# +# Determine build settings +# +# TODO - also add an command line option to override this?!? +echo_n "Checking hosttype... " +echo $_host_os +case $_host_os in + linux* | uclinux* | openbsd* | freebsd* | netbsd* | bsd* | sunos* | hpux*) + DEFINES="$DEFINES -DUNIX" + LIBS="$LIBS -lGL -lGLU -L/usr/X11/lib" + ;; + beos*) + DEFINES="$DEFINES -DUNIX -DSYSTEM_NOT_SUPPORTING_D_TYPE" + LIBS="$LIBS -lbind" + type_1_byte='char' + type_2_byte='short' + type_4_byte='long' + ;; + solaris*) + DEFINES="$DEFINES -DUNIX -DSYSTEM_NOT_SUPPORTING_D_TYPE" + LIBS="$LIBS -lnsl" + ;; + irix*) + DEFINES="$DEFINES -DUNIX -DIRIX -DSYSTEM_NOT_SUPPORTING_D_TYPE" + LIBS="$LIBS -lmd" + _ranlib=: + ;; + darwin*) + DEFINES="$DEFINES -DUNIX -DMACOSX" + LIBS="$LIBS -framework QuickTime -framework AudioUnit -framework AudioToolbox -framework Carbon -lGL -lGLU -L/usr/X11/lib \ + -dylib_file /System/Library/Frameworks/OpenGL.framework/Versions/A/Libraries/libGL.dylib:/System/Library/Frameworks/OpenGL.framework/Versions/A/Libraries/libGL.dylib" + ;; + mingw*) + DEFINES="$DEFINES -DWIN32" + LIBS="$LIBS -lmingw32 -lopengl32 -lglu32" + #OBJS="$OBJS residualico.o" + ;; + cygwin*) + DEFINES="$DEFINES -mno-cygwin -DWIN32" + LIBS="$LIBS -mno-cygwin -lmingw32 -lopengl32 -lglu32" + #OBJS="$OBJS residualico.o" + ;; + os2-emx*) + DEFINES="$DEFINES -DUNIX" + ;; + mint*) + DEFINES="$DEFINES -DUNIX -DSYSTEM_NOT_SUPPORTING_D_TYPE" + ;; + amigaos*) + # TODO: anything to be added here? + ;; + # given this is a shell script assume some type of unix + *) + echo "WARNING: could not establish system type, assuming unix like" + DEFINES="$DEFINES -DUNIX" + ;; +esac + +if test -n "$_host"; then + # Cross-compiling mode - add your target here if needed + case "$_host" in + linupy|arm-riscos) + echo "Cross-compiling to $_host, forcing endianness, alignment and type sizes" + DEFINES="$DEFINES -DUNIX" + _endian=little + _need_memalign=yes + add_line_to_config_h "#define LINUPY" + type_1_byte='char' + type_2_byte='short' + type_4_byte='int' + ;; + arm-linux|arm*-linux-gnueabi|arm-*-linux|*-angstrom-linux) + echo "Cross-compiling to $_host, forcing endianness, alignment and type sizes" + DEFINES="$DEFINES -DUNIX -DUSE_ARM_SOUND_ASM" + #not true for all ARM systems, but the interesting ones are all LE. Most (if not all) BE arm devices don't have a screen + _endian=little + _need_memalign=yes + type_1_byte='char' + type_2_byte='short' + type_4_byte='int' + add_line_to_config_mk 'USE_ARM_SOUND_ASM = 1' + ;; + bfin*) + _need_memalign=yes + ;; + gp2x) + echo "Cross-compiling to $_host, forcing endianness, alignment and type sizes" + DEFINES="$DEFINES -DUNIX -DGP2X -DUSE_ARM_SOUND_ASM" + _endian=little + _need_memalign=yes + type_1_byte='char' + type_2_byte='short' + type_4_byte='int' + add_line_to_config_mk 'USE_ARM_SOUND_ASM = 1' + _backend="gp2x" + ;; + ppc-amigaos) + echo "Cross-compiling to $_host, forcing endianness, alignment and type sizes" + _endian=big + _need_memalign=yes + type_1_byte='char' + type_2_byte='short' + type_4_byte='long' + CXXFLAGS="$CFLAGS -mcrt=newlib -mstrict-align -mcpu=750 -mtune=7400" + LDFLAGS="$LDFLAGS -mcrt=newlib" + ;; + m68k-atari-mint) + echo "Cross-compiling to $_host, forcing endianness, alignment and type sizes" + DEFINES="$DEFINES -DUNIX -DSYSTEM_NOT_SUPPORTING_D_TYPE" + _endian=big + _need_memalign=yes + type_1_byte='char' + type_2_byte='short' + type_4_byte='long' + _ranlib=m68k-atari-mint-ranlib + _ar="m68k-atari-mint-ar cru" + ;; + *mingw32*) + echo "Cross-compiling to $_host, forcing endianness, alignment and type sizes" + _endian=little + _have_x86=yes + type_1_byte='char' + type_2_byte='short' + type_4_byte='int' + _sdlconfig=$_host-sdl-config + _windres=$_host-windres + _ar="$_host-ar cru" + _ranlib=$_host-ranlib + ;; + iphone) + echo "Cross-compiling to $_host, forcing endianness, alignment and type sizes" + DEFINES="$DEFINES -DIPHONE -DUNIX -DUSE_ARM_SOUND_ASM" + _endian=little + _need_memalign=yes + type_1_byte='char' + type_2_byte='short' + type_4_byte='int' + add_line_to_config_mk 'USE_ARM_SOUND_ASM = 1' + _backend="iphone" + ;; + *) + echo "Continuing with auto-detected values ... if you have problems, please add your target to configure." + ;; + esac + +else + # + # Check whether memory alignment is required + # + echo_n "Alignment required... " + case $_host_cpu in + arm*) + _need_memalign=yes + ;; + alpha*) + # Hardcode alignment requirements for Alpha processsors + _need_memalign=yes + ;; + sh*) + # Hardcode alignment requirements for SH processsors. + # While these can emulate unaligned memory access, this + # emulation is rather slow. + _need_memalign=yes + ;; + mips*) + # Hardcode alignment requirements for MIPS processsors. + # While these can emulate unaligned memory access, this + # emulation is rather slow. + _need_memalign=yes + ;; + *) + # Try to auto-detect.... + cat > $TMPC << EOF +#include +#include +int main(int argc, char **argv) +{ + unsigned char test[8] = { 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88 }; + signal(SIGBUS, exit); + signal(SIGABRT, exit); + signal(SIGSEGV, exit); + if (*((unsigned int *)(test + 1)) != 0x55443322 && *((unsigned int *)(test + 1)) != 0x22334455) { + return 1; + } + return 0; +} +EOF + _need_memalign=yes + cc_check && $TMPO$EXEEXT && _need_memalign=no + ;; + esac + echo "$_need_memalign" +fi + +# +# Add the results of the above checks to config.h +# +case $_endian in + big) + add_line_to_config_h '/* #define SYSTEM_LITTLE_ENDIAN */' + add_line_to_config_h '#define SYSTEM_BIG_ENDIAN' + ;; + little) + add_line_to_config_h '#define SYSTEM_LITTLE_ENDIAN' + add_line_to_config_h '/* #define SYSTEM_BIG_ENDIAN */' + ;; + *) + exit 1 + ;; +esac + +add_to_config_h_if_yes $_have_x86 '#define HAVE_X86' + +add_to_config_h_if_yes $_need_memalign '#define SYSTEM_NEED_ALIGNMENT' + +# +# Check for math lib +# +cat > $TMPC << EOF +int main(void) { return 0; } +EOF +cc_check $LDFLAGS $CXXFLAGS && LDFLAGS="$LDFLAGS" + +# +# Check for Ogg Vorbis +# +echocheck "Ogg Vorbis" +if test "$_vorbis" = auto ; then + _vorbis=no + cat > $TMPC << EOF +#include +int main(void) { vorbis_packet_blocksize(0,0); return 0; } +EOF + cc_check $LDFLAGS $CXXFLAGS $OGG_CFLAGS $OGG_LIBS $VORBIS_CFLAGS $VORBIS_LIBS \ + -lvorbisfile -lvorbis -logg && _vorbis=yes +fi +if test "$_vorbis" = yes ; then + _def_vorbis='#define USE_VORBIS' + LIBS="$LIBS $OGG_LIBS $VORBIS_LIBS -lvorbisfile -lvorbis -logg" + INCLUDES="$INCLUDES $OGG_CFLAGS $VORBIS_CFLAGS" +else + _def_vorbis='#undef USE_VORBIS' +fi +add_to_config_mk_if_yes "$_vorbis" 'USE_VORBIS = 1' +echo "$_vorbis" + +# +# Check for Tremor +# +echocheck "Tremor" +if test "$_tremor" = auto ; then + _tremor=no + cat > $TMPC << EOF +#include +int main(void) { vorbis_packet_blocksize(0,0); return 0; } +EOF + cc_check $LDFLAGS $CXXFLAGS $TREMOR_CFLAGS $TREMOR_LIBS -lvorbisidec && \ + _tremor=yes +fi +if test "$_tremor" = yes && test "$_vorbis" = no; then + _def_tremor='#define USE_TREMOR' + _def_vorbis='#define USE_VORBIS' + LIBS="$LIBS $TREMOR_LIBS -lvorbisidec" + INCLUDES="$INCLUDES $TREMOR_CFLAGS" +else + if test "$_vorbis" = yes; then + _tremor="no (Ogg Vorbis/Tremor support is mutually exclusive)" + fi + _def_tremor='#undef USE_TREMOR' +fi +add_to_config_mk_if_yes "$_tremor" 'USE_TREMOR = 1' +echo "$_tremor" + +# +# Check for FLAC +# +echocheck "FLAC >= 1.0.1" +if test "$_flac" = auto ; then + _flac=no + cat > $TMPC << EOF +#include +int main(void) { return FLAC__STREAM_SYNC_LEN >> 30; /* guaranteed to be 0 */ } +EOF + cc_check $LDFLAGS $CXXFLAGS $FLAC_CFLAGS $FLAC_LIBS $OGG_CFLAGS $OGG_LIBS \ + -lFLAC -logg && _flac=yes +fi +if test "$_flac" = yes ; then + _def_flac='#define USE_FLAC' + if test "$_vorbis" = yes ; then + LIBS="$LIBS $FLAC_LIBS $OGG_LIBS -lFLAC -logg" + else + LIBS="$LIBS $FLAC_LIBS -lFLAC" + fi + INCLUDES="$INCLUDES $FLAC_CFLAGS" +else + _def_flac='#undef USE_FLAC' +fi +add_to_config_mk_if_yes "$_flac" 'USE_FLAC = 1' +echo "$_flac" + +# +# Check for MAD (MP3 library) +# +echocheck "MAD" +if test "$_mad" = auto ; then + _mad=no + cat > $TMPC << EOF +#include +int main(void) {return 0; } +EOF + cc_check $LDFLAGS $CXXFLAGS $MAD_CFLAGS $MAD_LIBS -lmad && _mad=yes +fi +if test "$_mad" = yes ; then + _def_mad='#define USE_MAD' + LIBS="$LIBS $MAD_LIBS -lmad" + INCLUDES="$INCLUDES $MAD_CFLAGS" +else + _def_mad='#undef USE_MAD' +fi +add_to_config_mk_if_yes "$_mad" 'USE_MAD = 1' +echo "$_mad" + +# +# Check for ALSA +# +echocheck "ALSA >= 0.9" +if test "$_alsa" = auto ; then + _alsa=no + cat > $TMPC << EOF +#include +int main(void) { return (!(SND_LIB_MAJOR==0 && SND_LIB_MINOR==9)); } +EOF + cc_check $LDFLAGS $CXXFLAGS $ALSA_CFLAGS $ALSA_LIBS -lasound && _alsa=yes +fi +if test "$_alsa" = yes ; then + _def_alsa='#define USE_ALSA' + LIBS="$LIBS $ALSA_LIBS -lasound" + INCLUDES="$INCLUDES $ALSA_CFLAGS" +else + _def_alsa='#undef USE_ALSA' +fi +echo "$_alsa" + +# +# Check for ZLib +# +echocheck "zlib" +if test "$_zlib" = auto ; then + _zlib=no + cat > $TMPC << EOF +#include +#include +int main(void) { return strcmp(ZLIB_VERSION, zlibVersion()); } +EOF + cc_check $LDFLAGS $CXXFLAGS $ZLIB_CFLAGS $ZLIB_LIBS -lz && _zlib=yes +fi +if test "$_zlib" = yes ; then + _def_zlib='#define USE_ZLIB' + LIBS="$LIBS $ZLIB_LIBS -lz" + INCLUDES="$INCLUDES $ZLIB_CFLAGS" +else + _def_zlib='#undef USE_ZLIB' +fi +echo "$_zlib" + +# +# Check for LibMPEG2 +# +echocheck "libmpeg2 >= 0.3.2" +if test "$_mpeg2" = auto ; then + _mpeg2=no + cat > $TMPC << EOF +typedef signed $type_1_byte int8_t; +typedef signed $type_2_byte int16_t; +typedef signed $type_4_byte int32_t; + +typedef unsigned $type_1_byte uint8_t; +typedef unsigned $type_2_byte uint16_t; +typedef unsigned $type_4_byte uint32_t; + +#include +int main(void) { + /* mpeg2_state_t first appears in 0.4.0 */ + mpeg2_state_t state; + + #ifdef MPEG2_RELEASE + if (MPEG2_RELEASE >= MPEG2_VERSION(0, 3, 2)) + return 0; + #endif + return 1; +} +EOF + + if test -n "$_host"; then + # don't execute while cross compiling + cc_check $LDFLAGS $CXXFLAGS $MPEG2_CFLAGS $MPEG2_LIBS -lmpeg2 && _mpeg2=yes + else + cc_check $LDFLAGS $CXXFLAGS $MPEG2_CFLAGS $MPEG2_LIBS -lmpeg2 && $TMPO$EXEXT && _mpeg2=yes + fi +fi +if test "$_mpeg2" = yes ; then + _def_mpeg2='#define USE_MPEG2' + INCLUDES="$INCLUDES $MPEG2_CFLAGS" + LIBS="$LIBS $MPEG2_LIBS -lmpeg2" +else + _def_mpeg2='#undef USE_MPEG2' +fi +add_to_config_mk_if_yes "$_mpeg2" 'USE_MPEG2 = 1' +echo "$_mpeg2" + +rm -rf $TMPC $TMPO$EXEEXT $TMPO.dSYM + +# +# figure out installation directories +# +test -z "$_bindir" && _bindir="$_prefix/bin" +test -z "$_mandir" && _mandir="$_prefix/share/man" +test -z "$_datadir" && _datadir="$_prefix/share" +test -z "$_libdir" && _libdir="$_prefix/lib" + +DEFINES="$DEFINES -DDATA_PATH=\\\"$_datadir/residual\\\"" + + +# +# Backend related stuff +# +case $_backend in + sdl) + find_sdlconfig + INCLUDES="$INCLUDES `$_sdlconfig --prefix="$_sdlpath" --cflags`" + LIBS="$LIBS `$_sdlconfig --prefix="$_sdlpath" --libs`" + DEFINES="$DEFINES -DSDL_BACKEND" + MODULES="$MODULES engine/backend/sdl" + ;; + gp2x) + find_sdlconfig + INCLUDES="$INCLUDES `$_sdlconfig --prefix="$_sdlpath" --cflags`" + LIBS="$LIBS `$_sdlconfig --prefix="$_sdlpath" --libs`" + LDFLAGS="$LDFLAGS -static" + CXXFLAGS="$CXXFLAGS -march=armv4t" + MODULES="$MODULES backend/gp2x" + ;; + iphone) + OBJCFLAGS="$OBJCFLAGS --std=c99" + LIBS="$LIBS -lobjc -framework UIKit -framework CoreGraphics -framework CoreSurface -framework LayerKit -framework GraphicsServices -framework CoreFoundation -framework Foundation -framework AudioToolbox -framework CoreAudio" + DEFINES="$DEFINES -DIPHONE_BACKEND" + MODULES="$MODULES backend/iphone" + ;; + *) + echo "support for $_backend backend not implemented in configure script yet" + exit 1 + ;; +esac + +echo +echo "Creating config.h" +cat > config.h << EOF +/* This file is automatically generated by configure */ +/* DO NOT EDIT MANUALLY */ + +#ifndef CONFIG_H +#define CONFIG_H + +$_config_h_data + +/* Data types */ +typedef unsigned $type_1_byte byte; +typedef unsigned int uint; +typedef unsigned $type_1_byte uint8; +typedef unsigned $type_2_byte uint16; +typedef unsigned $type_4_byte uint32; +typedef signed $type_1_byte int8; +typedef signed $type_2_byte int16; +typedef signed $type_4_byte int32; + +/* Libs */ +$_def_vorbis +$_def_tremor +$_def_flac +$_def_mad +$_def_alsa +$_def_zlib +$_def_mpeg2 + +/* Plugin settings */ +$_def_plugin + +#endif /* CONFIG_H */ +EOF + +echo "Creating config.mk" +cat > config.mk << EOF +# -------- Generated by configure ----------- + +CXX := $CXX +CXXFLAGS := $CXXFLAGS +LIBS += $LIBS +RANLIB := $_ranlib +AR := $_ar +WINDRES := $_windres +WIN32PATH=$_win32path +AOS4PATH=$_aos4path + +BACKEND := $_backend +MODULES += $MODULES +MODULE_DIRS += $MODULE_DIRS +EXEEXT := $EXEEXT + +PREFIX := $_prefix +BINDIR := $_bindir +MANDIR := $_mandir +DATADIR := $_datadir +LIBDIR := $_libdir + +$_config_mk_data + +INCLUDES += $INCLUDES +OBJS += $OBJS +DEFINES += $DEFINES +LDFLAGS += $LDFLAGS + +$_mak_plugins + +SAVED_CONFIGFLAGS := $SAVED_CONFIGFLAGS +SAVED_LDFLAGS := $SAVED_LDFLAGS +SAVED_CXX := $SAVED_CXX +SAVED_CXXFLAGS := $SAVED_CXXFLAGS +SAVED_CPPFLAGS := $SAVED_CPPFLAGS +EOF + +# +# Create a custom Makefile when building outside the source tree +# TODO: Add a better check than just looking for 'Makefile' +# +if test ! -f Makefile ; then +echo "Creating Makefile" + +cat > Makefile << EOF +# -------- Generated by configure ----------- +srcdir = $_srcdir +vpath %.h \$(srcdir) +vpath %.cpp \$(srcdir) +vpath %.c \$(srcdir) +vpath %.m \$(srcdir) +vpath %.asm \$(srcdir) +vpath %.s \$(srcdir) +include \$(srcdir)/Makefile +EOF + +fi diff --git a/dists/residual.rc b/dists/residual.rc index 5c3f23cda1f..4f14d9dc9f1 100644 --- a/dists/residual.rc +++ b/dists/residual.rc @@ -20,11 +20,11 @@ BEGIN BLOCK "040904b0" BEGIN VALUE "Comments", "\0" - VALUE "CompanyName", "ScummVM Team\0" + VALUE "CompanyName", "ScummVM-Residual Team\0" VALUE "FileDescription", "http://www.scummvm.org/\0" VALUE "FileVersion", "SVN\0" VALUE "InternalName", "residual\0" - VALUE "LegalCopyright", "Copyright © 2003-2007 The ScummVM Team\0" + VALUE "LegalCopyright", "Copyright © 2003-2008 The ScummVM Team\0" VALUE "LegalTrademarks", "\0" VALUE "OriginalFilename", "residual.exe\0" VALUE "PrivateBuild", "\0" diff --git a/engine/actor.cpp b/engine/actor.cpp index 661adcb84b3..226661025d0 100644 --- a/engine/actor.cpp +++ b/engine/actor.cpp @@ -127,7 +127,7 @@ bool Actor::isTurning() const { void Actor::walkForward() { float dist = g_engine->perSecond(_walkRate); - float yaw_rad = _yaw * (M_PI / 180), pitch_rad = _pitch * (M_PI / 180); + float yaw_rad = _yaw * (LOCAL_PI / 180), pitch_rad = _pitch * (LOCAL_PI / 180); //float yaw; Vector3d forwardVec(-std::sin(yaw_rad) * std::cos(pitch_rad), std::cos(yaw_rad) * std::cos(pitch_rad), @@ -178,7 +178,7 @@ void Actor::walkForward() { break; } - ei.angleWithEdge *= (float)(180.0 / M_PI); + ei.angleWithEdge *= (float)(180 / LOCAL_PI); int turnDir = 1; if (ei.angleWithEdge > 90) { ei.angleWithEdge = 180 - ei.angleWithEdge; @@ -196,7 +196,7 @@ void Actor::walkForward() { } Vector3d Actor::puckVector() const { - float yaw_rad = _yaw * (M_PI / 180); + float yaw_rad = _yaw * (LOCAL_PI / 180); Vector3d forwardVec(-std::sin(yaw_rad), std::cos(yaw_rad), 0); Sector *sector = g_engine->currScene()->findPointSector(_pos, 0x1000); @@ -280,12 +280,12 @@ void Actor::turn(int dir) { } float Actor::angleTo(const Actor &a) const { - float yaw_rad = _yaw * (M_PI / 180); + float yaw_rad = _yaw * (LOCAL_PI / 180); Vector3d forwardVec(-std::sin(yaw_rad), std::cos(yaw_rad), 0); Vector3d delta = a.pos() - _pos; delta.z() = 0; - return angle(forwardVec, delta) * (180 / M_PI); + return angle(forwardVec, delta) * (180 / LOCAL_PI); } float Actor::yawTo(Vector3d p) const { @@ -294,7 +294,7 @@ float Actor::yawTo(Vector3d p) const { if (dpos.x() == 0 && dpos.y() == 0) return 0; else - return std::atan2(-dpos.x(), dpos.y()) * (180 / M_PI); + return std::atan2(-dpos.x(), dpos.y()) * (180 / LOCAL_PI); } void Actor::sayLine(const char *msg, const char *msgId) { diff --git a/engine/backend/dc/driver_ronin_gfx.cpp b/engine/backend/dc/driver_ronin_gfx.cpp index 46f1f956075..2867a087532 100644 --- a/engine/backend/dc/driver_ronin_gfx.cpp +++ b/engine/backend/dc/driver_ronin_gfx.cpp @@ -48,7 +48,7 @@ void DriverRonin::setupCamera(float fov, float nclip, float fclip, float roll) clearMatrixStack(); - float cot_fov = 1 / std::tan(fov * (M_PI / 180 / 2)); + float cot_fov = 1 / std::tan(fov * (LOCAL_PI / 180 / 2)); float frustum[4][4] = { { (-640/2) * cot_fov, 0, 0, 0 }, { 0, (480/2 / 0.75) * cot_fov, 0, 0 }, diff --git a/engine/backend/driver.h b/engine/backend/driver.h index 6bdbb75223e..daef4d1c790 100644 --- a/engine/backend/driver.h +++ b/engine/backend/driver.h @@ -23,7 +23,7 @@ #ifndef BACKEND_DRIVER_H #define BACKEND_DRIVER_H -#include "common/platform.h" +#include "common/sys.h" #include "common/vector3d.h" #include "common/mutex.h" diff --git a/engine/backend/module.mk b/engine/backend/module.mk new file mode 100644 index 00000000000..3f379576d63 --- /dev/null +++ b/engine/backend/module.mk @@ -0,0 +1,7 @@ +MODULE := engine/backend + +MODULE_OBJS := \ + default-timer.o + +# Include common rules +include $(srcdir)/rules.mk diff --git a/engine/backend/sdl/driver_gl.cpp b/engine/backend/sdl/driver_gl.cpp index 3671eaba888..7e71f9c36c3 100644 --- a/engine/backend/sdl/driver_gl.cpp +++ b/engine/backend/sdl/driver_gl.cpp @@ -21,6 +21,7 @@ */ #include "common/debug.h" +#include "common/endian.h" #include "engine/colormap.h" #include "engine/material.h" @@ -82,7 +83,7 @@ void DriverGL::setupCamera(float fov, float nclip, float fclip, float roll) { glMatrixMode(GL_PROJECTION); glLoadIdentity(); - float right = nclip * std::tan(fov / 2 * (M_PI / 180)); + float right = nclip * std::tan(fov / 2 * (LOCAL_PI / 180)); glFrustum(-right, right, -right * 0.75, right * 0.75, nclip, fclip); glMatrixMode(GL_MODELVIEW); diff --git a/engine/backend/sdl/driver_gl.h b/engine/backend/sdl/driver_gl.h index e622449fe5a..c018c1ecc55 100644 --- a/engine/backend/sdl/driver_gl.h +++ b/engine/backend/sdl/driver_gl.h @@ -23,7 +23,7 @@ #ifndef BACKEND_DRIVER_GL_H #define BACKEND_DRIVER_GL_H -#include "common/platform.h" +#include "common/sys.h" #include "common/vector3d.h" #include "engine/color.h" diff --git a/engine/backend/sdl/driver_sdl.cpp b/engine/backend/sdl/driver_sdl.cpp index 5b400a4bdd6..4abc11f5472 100644 --- a/engine/backend/sdl/driver_sdl.cpp +++ b/engine/backend/sdl/driver_sdl.cpp @@ -24,6 +24,10 @@ #include "engine/backend/sdl/driver_sdl.h" +#ifdef _WIN32 +#include +#endif + // NOTE: This is not a complete driver, it needs to be subclassed // to provide rendering functionality. @@ -436,3 +440,17 @@ void DriverSDL::quit() { if (SDL_PushEvent(&event) != 0) error("Unable to push exit event!"); } + +#if defined (WIN32) +int __stdcall WinMain(HINSTANCE /*hInst*/, HINSTANCE /*hPrevInst*/, LPSTR /*lpCmdLine*/, int /*iShowCmd*/) { + SDL_SetModuleHandle(GetModuleHandle(NULL)); + return main(__argc, __argv); +} +#endif + +int main(int argc, char *argv[]) { + int res = residual_main(argc, argv); + + return res; +} + diff --git a/engine/backend/sdl/driver_tinygl.cpp b/engine/backend/sdl/driver_tinygl.cpp index 09fa0582a24..ac3ad239786 100644 --- a/engine/backend/sdl/driver_tinygl.cpp +++ b/engine/backend/sdl/driver_tinygl.cpp @@ -20,6 +20,8 @@ * */ +#include "common/sys.h" +#include "common/endian.h" #include "common/debug.h" #include "engine/colormap.h" @@ -147,7 +149,7 @@ void DriverTinyGL::setupCamera(float fov, float nclip, float fclip, float roll) tglMatrixMode(TGL_PROJECTION); tglLoadIdentity(); - float right = nclip * std::tan(fov / 2 * (M_PI / 180)); + float right = nclip * std::tan(fov / 2 * (LOCAL_PI / 180)); tglFrustum(-right, right, -right * 0.75, right * 0.75, nclip, fclip); tglMatrixMode(TGL_MODELVIEW); diff --git a/engine/backend/sdl/driver_tinygl.h b/engine/backend/sdl/driver_tinygl.h index ebe7f69aec4..cadc39cfabf 100644 --- a/engine/backend/sdl/driver_tinygl.h +++ b/engine/backend/sdl/driver_tinygl.h @@ -23,7 +23,7 @@ #ifndef BACKEND_DRIVER_TINYGL_H #define BACKEND_DRIVER_TINYGL_H -#include "common/platform.h" +#include "common/sys.h" #include "common/vector3d.h" #include "engine/color.h" diff --git a/engine/backend/sdl/module.mk b/engine/backend/sdl/module.mk new file mode 100644 index 00000000000..e51c2a3201c --- /dev/null +++ b/engine/backend/sdl/module.mk @@ -0,0 +1,12 @@ +MODULE := engine/backend/sdl + +MODULE_OBJS := \ + driver_gl.o \ + driver_sdl.o \ + driver_tinygl.o + +MODULE_DIRS += \ + engine/backend/sdl/ + +# We don't use the rules.mk here on purpose +OBJS := $(addprefix $(MODULE)/, $(MODULE_OBJS)) $(OBJS) diff --git a/engine/bitmap.cpp b/engine/bitmap.cpp index 9a48b1e8194..df581c3e278 100644 --- a/engine/bitmap.cpp +++ b/engine/bitmap.cpp @@ -21,8 +21,8 @@ */ #include "common/sys.h" -#include "common/platform.h" #include "common/debug.h" +#include "common/endian.h" #include "engine/bitmap.h" #include "engine/smush/smush.h" diff --git a/engine/color.h b/engine/color.h index e2b2bc7b87b..34bf0b5fc49 100644 --- a/engine/color.h +++ b/engine/color.h @@ -23,7 +23,7 @@ #ifndef COLOR_H #define COLOR_H -#include "common/platform.h" +#include "common/sys.h" class Color { public: diff --git a/engine/costume.cpp b/engine/costume.cpp index 979e63c5e73..e70c3ca306c 100644 --- a/engine/costume.cpp +++ b/engine/costume.cpp @@ -21,6 +21,7 @@ */ #include "common/sys.h" +#include "common/endian.h" #include "common/debug.h" #include "engine/colormap.h" @@ -877,30 +878,30 @@ void Costume::Chore::update() { } Costume::Component *Costume::loadComponent (tag32 tag, Costume::Component *parent, int parentID, const char *name, Costume::Component *prevComponent) { - if (tag == MKID('MMDL')) + if (FROM_BE_32(tag) == MKID_BE('MMDL')) return new MainModelComponent(parent, parentID, name, prevComponent, tag); - else if (tag == MKID('MODL')) + else if (FROM_BE_32(tag) == MKID_BE('MODL')) return new ModelComponent(parent, parentID, name, prevComponent, tag); - else if (tag == MKID('CMAP')) + else if (FROM_BE_32(tag) == MKID_BE('CMAP')) return new ColormapComponent(parent, parentID, name, tag); - else if (tag == MKID('KEYF')) + else if (FROM_BE_32(tag) == MKID_BE('KEYF')) return new KeyframeComponent(parent, parentID, name, tag); - else if (tag == MKID('MESH')) + else if (FROM_BE_32(tag) == MKID_BE('MESH')) return new MeshComponent(parent, parentID, name, tag); - else if (tag == MKID('LUAV')) + else if (FROM_BE_32(tag) == MKID_BE('LUAV')) return new LuaVarComponent(parent, parentID, name, tag); - else if (tag == MKID('IMLS')) + else if (FROM_BE_32(tag) == MKID_BE('IMLS')) return new SoundComponent(parent, parentID, name, tag); - else if (tag == MKID('BKND')) + else if (FROM_BE_32(tag) == MKID_BE('BKND')) return new BitmapComponent(parent, parentID, name, tag); - else if (tag == MKID('MAT ')) + else if (FROM_BE_32(tag) == MKID_BE('MAT ')) return new MaterialComponent(parent, parentID, name, tag); - else if (tag == MKID('SPRT')) + else if (FROM_BE_32(tag) == MKID_BE('SPRT')) return NULL;// new SpriteComponent(parent, parentID, name); char t[4]; std::memcpy(t, &tag, sizeof(tag32)); - error("Unknown tag '%c%c%c%c', name '%s'\n", t[0], t[1], t[2], t[3], name); + error("loadComponent: Unknown tag '%c%c%c%c', name '%s'\n", t[0], t[1], t[2], t[3], name); return NULL; } @@ -911,7 +912,7 @@ Model::HierNode *Costume::getModelNodes() continue; // Needs to handle Main Models (pigeons) and normal Models // (when Manny climbs the rope) - if (_components[i]->tag() == MKID('MMDL')) + if (_components[i]->tag() == MKID_BE('MMDL')) return dynamic_cast(_components[i])->hierarchy(); } return NULL; diff --git a/engine/engine.cpp b/engine/engine.cpp index 71be4077e5d..afde070dca6 100644 --- a/engine/engine.cpp +++ b/engine/engine.cpp @@ -49,6 +49,8 @@ int g_flags = 0; #ifdef _WIN32 +#include + WIN32_FIND_DATAA g_find_file_data; HANDLE g_searchFile; bool g_firstFind; diff --git a/engine/engine.h b/engine/engine.h index 673c198191d..88d89d126a7 100644 --- a/engine/engine.h +++ b/engine/engine.h @@ -207,19 +207,6 @@ extern int g_imuseState; extern Actor *g_currentUpdatedActor; -#ifdef _WIN32 - -extern WIN32_FIND_DATAA g_find_file_data; -extern HANDLE g_searchFile; -extern bool g_firstFind; - -#else - -extern char g_find_file_data[100]; -extern DIR *g_searchFile; - -#endif - void vimaInit(uint16 *destTable); void decompressVima(const byte *src, int16 *dest, int destLen, uint16 *destTable); diff --git a/engine/font.cpp b/engine/font.cpp index fc98c30e646..29d4b33269d 100644 --- a/engine/font.cpp +++ b/engine/font.cpp @@ -21,7 +21,7 @@ */ #include "common/sys.h" -#include "common/platform.h" +#include "common/endian.h" #include "common/debug.h" #include "engine/font.h" diff --git a/engine/font.h b/engine/font.h index 30c1b427cbd..81316f30584 100644 --- a/engine/font.h +++ b/engine/font.h @@ -23,7 +23,7 @@ #ifndef FONT_H #define FONT_H -#include "common/platform.h" +#include "common/sys.h" #include "engine/resource.h" diff --git a/engine/imuse/imuse.cpp b/engine/imuse/imuse.cpp index 253949b58e6..4824aa868c2 100644 --- a/engine/imuse/imuse.cpp +++ b/engine/imuse/imuse.cpp @@ -21,7 +21,6 @@ */ #include "common/sys.h" -#include "common/platform.h" #include "common/debug.h" #include "common/timer.h" #include "common/mutex.h" diff --git a/engine/imuse/imuse.h b/engine/imuse/imuse.h index 0db58ceb766..4e31177a7ab 100644 --- a/engine/imuse/imuse.h +++ b/engine/imuse/imuse.h @@ -24,7 +24,6 @@ #define IMUSE_H #include "common/sys.h" -#include "common/platform.h" #include "common/debug.h" #include "engine/lua.h" diff --git a/engine/imuse/imuse_mcmp_mgr.cpp b/engine/imuse/imuse_mcmp_mgr.cpp index 2b1739ef824..e5af67c43ed 100644 --- a/engine/imuse/imuse_mcmp_mgr.cpp +++ b/engine/imuse/imuse_mcmp_mgr.cpp @@ -21,7 +21,7 @@ */ #include "common/sys.h" -#include "common/platform.h" +#include "common/endian.h" #include "common/debug.h" #include "engine/resource.h" diff --git a/engine/imuse/imuse_mcmp_mgr.h b/engine/imuse/imuse_mcmp_mgr.h index 6add6ba4f6a..af340656c70 100644 --- a/engine/imuse/imuse_mcmp_mgr.h +++ b/engine/imuse/imuse_mcmp_mgr.h @@ -24,7 +24,6 @@ #define MCMP_MGR_H #include "common/sys.h" -#include "common/platform.h" #include "common/debug.h" #include "common/timer.h" diff --git a/engine/imuse/imuse_music.cpp b/engine/imuse/imuse_music.cpp index 81af597d0c1..d903bbe17e1 100644 --- a/engine/imuse/imuse_music.cpp +++ b/engine/imuse/imuse_music.cpp @@ -21,7 +21,6 @@ */ #include "common/sys.h" -#include "common/platform.h" #include "common/debug.h" #include "engine/imuse/imuse.h" diff --git a/engine/imuse/imuse_script.cpp b/engine/imuse/imuse_script.cpp index fc5e8f1afb1..91a66d04bea 100644 --- a/engine/imuse/imuse_script.cpp +++ b/engine/imuse/imuse_script.cpp @@ -21,7 +21,6 @@ */ #include "common/sys.h" -#include "common/platform.h" #include "common/debug.h" #include "common/timer.h" #include "common/mutex.h" diff --git a/engine/imuse/imuse_sndmgr.cpp b/engine/imuse/imuse_sndmgr.cpp index 19e70dc6311..fe1a3f889b1 100644 --- a/engine/imuse/imuse_sndmgr.cpp +++ b/engine/imuse/imuse_sndmgr.cpp @@ -21,7 +21,7 @@ */ #include "common/sys.h" -#include "common/platform.h" +#include "common/endian.h" #include "common/debug.h" #include "common/timer.h" @@ -73,7 +73,7 @@ void ImuseSndMgr::countElements(byte *ptr, int &numRegions, int &numJumps) { } void ImuseSndMgr::parseSoundHeader(byte *ptr, SoundDesc *sound, int &headerSize) { - if (READ_UINT32(ptr) == MKID('RIFF')) { + if (READ_BE_UINT32(ptr) == MKID_BE('RIFF')) { sound->region = new Region[1]; sound->jump = new Jump[0]; sound->numJumps = 0; @@ -84,7 +84,7 @@ void ImuseSndMgr::parseSoundHeader(byte *ptr, SoundDesc *sound, int &headerSize) sound->freq = READ_LE_UINT32(ptr + 24); sound->channels = *(ptr + 22); headerSize = 44; - } else if (READ_UINT32(ptr) == MKID('iMUS')) { + } else if (READ_BE_UINT32(ptr) == MKID_BE('iMUS')) { uint32 tag; int32 size = 0; byte *s_ptr = ptr; diff --git a/engine/imuse/imuse_sndmgr.h b/engine/imuse/imuse_sndmgr.h index 2ca070d07b7..b517a945a26 100644 --- a/engine/imuse/imuse_sndmgr.h +++ b/engine/imuse/imuse_sndmgr.h @@ -24,7 +24,6 @@ #define IMUSE_SNDMGR_H #include "common/sys.h" -#include "common/platform.h" #include "common/debug.h" #include "common/timer.h" diff --git a/engine/imuse/imuse_tables.cpp b/engine/imuse/imuse_tables.cpp index 9c1c282ceb0..abc439755b2 100644 --- a/engine/imuse/imuse_tables.cpp +++ b/engine/imuse/imuse_tables.cpp @@ -21,7 +21,6 @@ */ #include "common/sys.h" -#include "common/platform.h" #include "common/debug.h" #include "engine/imuse/imuse.h" diff --git a/engine/imuse/imuse_tables.h b/engine/imuse/imuse_tables.h index 9d06d6ee101..eee8eccdd77 100644 --- a/engine/imuse/imuse_tables.h +++ b/engine/imuse/imuse_tables.h @@ -24,7 +24,6 @@ #define IMUSE_TABLES_H #include "common/sys.h" -#include "common/platform.h" #include "common/debug.h" #include "engine/lua.h" diff --git a/engine/imuse/imuse_track.cpp b/engine/imuse/imuse_track.cpp index 5006c016371..0ed215ad928 100644 --- a/engine/imuse/imuse_track.cpp +++ b/engine/imuse/imuse_track.cpp @@ -21,7 +21,6 @@ */ #include "common/sys.h" -#include "common/platform.h" #include "common/debug.h" #include "common/mutex.h" diff --git a/engine/imuse/imuse_track.h b/engine/imuse/imuse_track.h index 333db107f28..69f52f2010d 100644 --- a/engine/imuse/imuse_track.h +++ b/engine/imuse/imuse_track.h @@ -24,7 +24,6 @@ #define IMUSE_TRACK_H #include "common/sys.h" -#include "common/platform.h" #include "common/debug.h" #include "engine/lua.h" diff --git a/engine/imuse/module.mk b/engine/imuse/module.mk new file mode 100644 index 00000000000..f60453a6f85 --- /dev/null +++ b/engine/imuse/module.mk @@ -0,0 +1,13 @@ +MODULE := engine/imuse + +MODULE_OBJS := \ + imuse.o \ + imuse_mcmp_mgr.o \ + imuse_music.o \ + imuse_script.o \ + imuse_sndmgr.o \ + imuse_tables.o \ + imuse_track.o + +# Include common rules +include $(srcdir)/rules.mk diff --git a/engine/keyframe.cpp b/engine/keyframe.cpp index ee9475ed693..1ba19055290 100644 --- a/engine/keyframe.cpp +++ b/engine/keyframe.cpp @@ -21,7 +21,7 @@ */ #include "common/sys.h" -#include "common/platform.h" +#include "common/endian.h" #include "common/debug.h" #include "engine/keyframe.h" diff --git a/engine/lab.cpp b/engine/lab.cpp index a8f0d07416a..787c1f32e81 100644 --- a/engine/lab.cpp +++ b/engine/lab.cpp @@ -21,7 +21,7 @@ */ #include "common/sys.h" -#include "common/platform.h" +#include "common/endian.h" #include "engine/lab.h" #include diff --git a/engine/lipsynch.cpp b/engine/lipsynch.cpp index 19ea82ad6e4..f11aa7eaa42 100644 --- a/engine/lipsynch.cpp +++ b/engine/lipsynch.cpp @@ -21,7 +21,7 @@ */ #include "common/sys.h" -#include "common/platform.h" +#include "common/endian.h" #include "common/debug.h" #include "engine/lipsynch.h" diff --git a/engine/lipsynch.h b/engine/lipsynch.h index a7d379bd3b8..c8b70b5a0d2 100644 --- a/engine/lipsynch.h +++ b/engine/lipsynch.h @@ -23,7 +23,8 @@ #ifndef LIPSYNCH_H #define LIPSYNCH_H -#include "common/platform.h" +#include "common/sys.h" + #include "engine/resource.h" #include diff --git a/engine/lua.cpp b/engine/lua.cpp index 73827cbeea7..5a3792c7e67 100644 --- a/engine/lua.cpp +++ b/engine/lua.cpp @@ -21,6 +21,8 @@ */ #include "common/sys.h" +#include "common/endian.h" +#include "common/util.h" #include "common/debug.h" #include "engine/lua.h" @@ -50,6 +52,21 @@ extern Imuse *g_imuse; +#ifdef _WIN32 + +#include + +extern WIN32_FIND_DATAA g_find_file_data; +extern HANDLE g_searchFile; +extern bool g_firstFind; + +#else + +extern char g_find_file_data[100]; +extern DIR *g_searchFile; + +#endif + #define strmatch(src, dst) (strlen(src) == strlen(dst) && strcmp(src, dst) == 0) #define DEBUG_FUNCTION() debugFunction("Function", __FUNCTION__) @@ -58,35 +75,35 @@ static void stubWarning(char *funcName); static inline bool isObject(int num) { lua_Object param = lua_getparam(num); - if (lua_isuserdata(param) && lua_tag(param) == MKID('STAT')) + if (lua_isuserdata(param) && lua_tag(param) == MKID_BE('STAT')) return true; return false; } static inline bool isActor(int num) { lua_Object param = lua_getparam(num); - if (lua_isuserdata(param) && lua_tag(param) == MKID('ACTR')) + if (lua_isuserdata(param) && lua_tag(param) == MKID_BE('ACTR')) return true; return false; } static inline bool isColor(int num) { lua_Object param = lua_getparam(num); - if (lua_isuserdata(param) && lua_tag(param) == MKID('COLR')) + if (lua_isuserdata(param) && lua_tag(param) == MKID_BE('COLR')) return true; return false; } static inline bool isFont(int num) { lua_Object param = lua_getparam(num); - if (lua_isuserdata(param) && lua_tag(param) == MKID('FONT')) + if (lua_isuserdata(param) && lua_tag(param) == MKID_BE('FONT')) return true; return false; } static inline bool isBitmapObject(int num) { lua_Object param = lua_getparam(num); - if (lua_isuserdata(param) && lua_tag(param) == MKID('VBUF')) + if (lua_isuserdata(param) && lua_tag(param) == MKID_BE('VBUF')) return true; return false; } @@ -94,7 +111,7 @@ static inline bool isBitmapObject(int num) { // Helper functions to ensure the arguments we get are what we expect static inline ObjectState *check_object(int num) { lua_Object param = lua_getparam(num); - if (lua_isuserdata(param) && lua_tag(param) == MKID('STAT')) + if (lua_isuserdata(param) && lua_tag(param) == MKID_BE('STAT')) return static_cast(lua_getuserdata(param)); luaL_argerror(num, "objectstate expected"); return NULL; @@ -102,7 +119,7 @@ static inline ObjectState *check_object(int num) { static inline Actor *check_actor(int num) { lua_Object param = lua_getparam(num); - if (lua_isuserdata(param) && lua_tag(param) == MKID('ACTR')) + if (lua_isuserdata(param) && lua_tag(param) == MKID_BE('ACTR')) return static_cast(lua_getuserdata(param)); luaL_argerror(num, "actor expected"); return NULL; @@ -110,7 +127,7 @@ static inline Actor *check_actor(int num) { static inline Color *check_color(int num) { lua_Object param = lua_getparam(num); - if (lua_isuserdata(param) && lua_tag(param) == MKID('COLR')) + if (lua_isuserdata(param) && lua_tag(param) == MKID_BE('COLR')) return static_cast(lua_getuserdata(param)); luaL_argerror(num, "color expected"); return NULL; @@ -118,7 +135,7 @@ static inline Color *check_color(int num) { static inline Font *check_font(int num) { lua_Object param = lua_getparam(num); - if (lua_isuserdata(param) && lua_tag(param) == MKID('FONT')) + if (lua_isuserdata(param) && lua_tag(param) == MKID_BE('FONT')) return static_cast(lua_getuserdata(param)); luaL_argerror(num, "font expected"); return NULL; @@ -126,7 +143,7 @@ static inline Font *check_font(int num) { static inline PrimitiveObject *check_primobject(int num) { lua_Object param = lua_getparam(num); - if (lua_isuserdata(param) && lua_tag(param) == MKID('PRIM')) + if (lua_isuserdata(param) && lua_tag(param) == MKID_BE('PRIM')) return static_cast(lua_getuserdata(param)); luaL_argerror(num, "primitive expected"); return NULL; @@ -134,7 +151,7 @@ static inline PrimitiveObject *check_primobject(int num) { static inline TextObject *check_textobject(int num) { lua_Object param = lua_getparam(num); - if (lua_isuserdata(param) && lua_tag(param) == MKID('TEXT')) + if (lua_isuserdata(param) && lua_tag(param) == MKID_BE('TEXT')) return static_cast(lua_getuserdata(param)); luaL_argerror(num, "textobject expected"); return NULL; @@ -142,7 +159,7 @@ static inline TextObject *check_textobject(int num) { static inline Bitmap *check_bitmapobject(int num) { lua_Object param = lua_getparam(num); - if (lua_isuserdata(param) && lua_tag(param) == MKID('VBUF')) + if (lua_isuserdata(param) && lua_tag(param) == MKID_BE('VBUF')) return static_cast(lua_getuserdata(param)); luaL_argerror(num, "image object expected"); return NULL; @@ -315,7 +332,7 @@ static void MakeColor() { DEBUG_FUNCTION(); c = new Color (clamp_color(check_int(1)), clamp_color(check_int(2)), clamp_color(check_int(3))); - lua_pushusertag(c, MKID('COLR')); + lua_pushusertag(c, MKID_BE('COLR')); } static void GetColorComponents() { @@ -360,7 +377,7 @@ static void LoadActor() { name = ""; else name = luaL_check_string(1); - lua_pushusertag(new Actor(name), MKID('ACTR')); + lua_pushusertag(new Actor(name), MKID_BE('ACTR')); } static void GetActorTimeScale() { @@ -388,7 +405,7 @@ static void GetCameraActor() { DEBUG_FUNCTION(); stubWarning("VERIFY: GetCameraActor"); act = g_engine->selectedActor(); - lua_pushusertag(act, MKID('ACTR')); + lua_pushusertag(act, MKID_BE('ACTR')); } static void SetSayLineDefaults() { @@ -439,7 +456,7 @@ static void GetActorTalkColor() { DEBUG_FUNCTION(); act = check_actor(1); c = new Color(act->talkColor()); - lua_pushusertag(c, MKID('COLR')); + lua_pushusertag(c, MKID_BE('COLR')); } static void SetActorRestChore() { @@ -1254,8 +1271,8 @@ static void RotateVector() { rotateObject = getIndexedTableValue(param2, 2); rotate = lua_getnumber(rotateObject); Vector3d baseVector(std::sin(0.0f), std::cos(0.0f), 0); - currAngle = angle(baseVector, vec1) * (180 / M_PI); - newAngle = (currAngle - rotate) * (M_PI / 180); + currAngle = angle(baseVector, vec1) * (180 / LOCAL_PI); + newAngle = (currAngle - rotate) * (LOCAL_PI / 180); Vector3d vec2(std::sin(newAngle), std::cos(newAngle), 0); vec2 *= vec1.magnitude(); @@ -1388,7 +1405,7 @@ static void GetVisibleThings() { // Consider the active actor visible if (sel == (*i) || sel->angleTo(*(*i)) < 90) { lua_pushobject(result); - lua_pushusertag(*i, MKID('ACTR')); + lua_pushusertag(*i, MKID_BE('ACTR')); lua_pushnumber(1); lua_settable(); } @@ -2265,7 +2282,7 @@ static void GetImage() { bitmapName = luaL_check_string(1); Bitmap *image = g_resourceloader->loadBitmap(bitmapName); image->luaRef(); - lua_pushusertag(image, MKID('VBUF')); + lua_pushusertag(image, MKID_BE('VBUF')); } static void FreeImage() { @@ -2469,7 +2486,7 @@ static void MakeTextObject() { textObject->createBitmap(); g_engine->registerTextObject(textObject); - lua_pushusertag(textObject, MKID('TEXT')); + lua_pushusertag(textObject, MKID_BE('TEXT')); lua_pushnumber(textObject->getBitmapWidth()); lua_pushnumber(textObject->getBitmapHeight()); } @@ -2660,7 +2677,7 @@ static void DrawPolygon() { lua_pushobject(tableObj2); lua_pushstring("color"); lua_Object colorObj = lua_gettable(); - if (lua_isuserdata(colorObj) && lua_tag(colorObj) == MKID('COLR')) { + if (lua_isuserdata(colorObj) && lua_tag(colorObj) == MKID_BE('COLR')) { color = static_cast(lua_getuserdata(colorObj)); } } @@ -2668,7 +2685,7 @@ static void DrawPolygon() { PrimitiveObject *p = new PrimitiveObject(); p->createPolygon(x1, y1, x2, y2, x3, y3, x4, y4, color); g_engine->registerPrimitiveObject(p); - lua_pushusertag(p, MKID('PRIM')); + lua_pushusertag(p, MKID_BE('PRIM')); } static void DrawLine() { @@ -2690,7 +2707,7 @@ static void DrawLine() { lua_pushobject(tableObj); lua_pushstring("color"); lua_Object colorObj = lua_gettable(); - if (lua_isuserdata(colorObj) && lua_tag(colorObj) == MKID('COLR')) { + if (lua_isuserdata(colorObj) && lua_tag(colorObj) == MKID_BE('COLR')) { color = static_cast(lua_getuserdata(colorObj)); } } @@ -2698,7 +2715,7 @@ static void DrawLine() { PrimitiveObject *p = new PrimitiveObject(); p->createLine(x1, x2, y1, y2, color); g_engine->registerPrimitiveObject(p); - lua_pushusertag(p, MKID('PRIM')); + lua_pushusertag(p, MKID_BE('PRIM')); } static void ChangePrimitive() { @@ -2734,7 +2751,7 @@ static void ChangePrimitive() { lua_pushobject(tableObj); lua_pushstring("color"); lua_Object colorObj = lua_gettable(); - if (lua_isuserdata(colorObj) && lua_tag(colorObj) == MKID('COLR')) { + if (lua_isuserdata(colorObj) && lua_tag(colorObj) == MKID_BE('COLR')) { color = static_cast(lua_getuserdata(colorObj)); pmodify->setColor(color); } @@ -2781,7 +2798,7 @@ static void DrawRectangle() { lua_pushobject(tableObj); lua_pushstring("color"); lua_Object colorObj = lua_gettable(); - if (lua_isuserdata(colorObj) && lua_tag(colorObj) == MKID('COLR')) { + if (lua_isuserdata(colorObj) && lua_tag(colorObj) == MKID_BE('COLR')) { color = static_cast(lua_getuserdata(colorObj)); } @@ -2795,7 +2812,7 @@ static void DrawRectangle() { PrimitiveObject *p = new PrimitiveObject(); p->createRectangle(x1, x2, y1, y2, color, filled); g_engine->registerPrimitiveObject(p); - lua_pushusertag(p, MKID('PRIM')); + lua_pushusertag(p, MKID_BE('PRIM')); } static void BlastRect() { @@ -2819,7 +2836,7 @@ static void BlastRect() { lua_pushobject(tableObj); lua_pushstring("color"); lua_Object colorObj = lua_gettable(); - if (lua_isuserdata(colorObj) && lua_tag(colorObj) == MKID('COLR')) { + if (lua_isuserdata(colorObj) && lua_tag(colorObj) == MKID_BE('COLR')) { color = static_cast(lua_getuserdata(colorObj)); } @@ -2878,7 +2895,7 @@ static void NewObjectState() { state = new ObjectState(setupID, pos, bitmap, zbitmap, visible); g_engine->currScene()->addObjectState(state); - lua_pushusertag(state, MKID('STAT')); + lua_pushusertag(state, MKID_BE('STAT')); } static void FreeObjectState() { @@ -2894,7 +2911,7 @@ static void SendObjectToBack() { DEBUG_FUNCTION(); param = lua_getparam(1); - if (lua_isuserdata(param) && lua_tag(param) == MKID('STAT')) { + if (lua_isuserdata(param) && lua_tag(param) == MKID_BE('STAT')) { ObjectState *state = static_cast(lua_getuserdata(param)); // moving object to top in list ? g_engine->currScene()->moveObjectStateToFirst(state); @@ -2906,7 +2923,7 @@ static void SendObjectToFront() { DEBUG_FUNCTION(); param = lua_getparam(1); - if (lua_isuserdata(param) && lua_tag(param) == MKID('STAT')) { + if (lua_isuserdata(param) && lua_tag(param) == MKID_BE('STAT')) { ObjectState *state = static_cast(lua_getuserdata(param)); // moving object to last in list ? g_engine->currScene()->moveObjectStateToLast(state); @@ -2942,7 +2959,7 @@ static void ScreenShot() { g_engine->setMode(mode); if (screenshot) { screenshot->luaRef(); - lua_pushusertag(screenshot, MKID('VBUF')); + lua_pushusertag(screenshot, MKID_BE('VBUF')); } else { lua_pushnil(); } @@ -2968,7 +2985,7 @@ static void GetSaveGameImage() { screenshot = new Bitmap(data, width, height, "screenshot"); if (screenshot) { screenshot->luaRef(); - lua_pushusertag(screenshot, MKID('VBUF')); + lua_pushusertag(screenshot, MKID_BE('VBUF')); } else { lua_pushnil(); error("Could not restore screenshot from file!"); @@ -3099,7 +3116,7 @@ static void LockFont() { Font *result = g_resourceloader->loadFont(fontName); if (result) { result->luaRef(); - lua_pushusertag(result, MKID('FONT')); + lua_pushusertag(result, MKID_BE('FONT')); } } } @@ -3231,10 +3248,10 @@ static void debugFunction(char *debugMessage, const char *funcName) { else if (lua_istable(lua_getparam(i))) fprintf(output, "{...}"); else if (lua_isuserdata(lua_getparam(i))) { - if (lua_tag(lua_getparam(i)) == MKID('ACTR')) { + if (lua_tag(lua_getparam(i)) == MKID_BE('ACTR')) { Actor *a = check_actor(i); fprintf(output, "", a->name()); - } else if (lua_tag(lua_getparam(i)) == MKID('COLR')) { + } else if (lua_tag(lua_getparam(i)) == MKID_BE('COLR')) { Color *c = check_color(i); fprintf(output, "", c->red(), c->green(), c->blue()); } else diff --git a/engine/lua.h b/engine/lua.h index 34f19ea0bac..cfddb59227e 100644 --- a/engine/lua.h +++ b/engine/lua.h @@ -23,6 +23,8 @@ #ifndef LUA_HH #define LUA_HH +#include "common/vector3d.h" + #include "engine/lua/lua.h" #include "engine/lua/lualib.h" #include "engine/lua/luadebug.h" diff --git a/engine/lua/lmathlib.cpp b/engine/lua/lmathlib.cpp index 049bfcb9432..f56590a24ea 100644 --- a/engine/lua/lmathlib.cpp +++ b/engine/lua/lmathlib.cpp @@ -12,13 +12,13 @@ #include "lua.h" #include "lualib.h" -#ifndef PI -#define PI ((double)3.14159265358979323846) +#ifndef LOCAL_PI +#define LOCAL_PI (3.14159265358979323846) #endif -#define FROMRAD(a) ((a)*(180.0/PI)) -#define TORAD(a) ((a)*(PI/180.0)) +#define FROMRAD(a) ((a)*(180.0/LOCAL_PI)) +#define TORAD(a) ((a)*(LOCAL_PI/180.0)) static void math_abs (void) @@ -105,12 +105,12 @@ static void math_exp (void) static void math_deg (void) { - lua_pushnumber(luaL_check_number(1)*(180.0/PI)); + lua_pushnumber(luaL_check_number(1)*(180.0/LOCAL_PI)); } static void math_rad (void) { - lua_pushnumber(luaL_check_number(1)*(PI/180.0)); + lua_pushnumber(luaL_check_number(1)*(LOCAL_PI/180.0)); } static void math_frexp (void) { @@ -211,6 +211,6 @@ void lua_mathlibopen (void) lua_pushcfunction(math_pow); lua_pushnumber(0); /* to get its tag */ lua_settagmethod(lua_tag(lua_pop()), "pow"); - lua_pushnumber(PI); lua_setglobal("PI"); + lua_pushnumber(LOCAL_PI); lua_setglobal("PI"); } diff --git a/engine/lua/module.mk b/engine/lua/module.mk new file mode 100644 index 00000000000..6b26e96c031 --- /dev/null +++ b/engine/lua/module.mk @@ -0,0 +1,30 @@ +MODULE := engine/lua + +MODULE_OBJS := \ + lapi.o \ + lauxlib.o \ + lbuffer.o \ + lbuiltin.o \ + ldo.o \ + lfunc.o \ + lgc.o \ + liolib.o \ + llex.o \ + lmathlib.o \ + lmem.o \ + lobject.o \ + lparser.o \ + lrestore.o \ + lsave.o \ + lstate.o \ + lstring.o \ + lstrlib.o \ + ltable.o \ + ltask.o \ + ltm.o \ + lundump.o \ + lvm.o \ + lzio.o + +# Include common rules +include $(srcdir)/rules.mk diff --git a/engine/main.cpp b/engine/main.cpp index 0fd0bb4e5dd..1ca15da4e1d 100644 --- a/engine/main.cpp +++ b/engine/main.cpp @@ -22,6 +22,7 @@ #include "common/sys.h" #include "common/debug.h" +#include "common/timer.h" #include "engine/bitmap.h" #include "engine/resource.h" @@ -29,7 +30,6 @@ #include "engine/registry.h" #include "engine/localize.h" #include "engine/engine.h" -#include "common/timer.h" #include "engine/smush/smush.h" #include "engine/backend/sdl/driver_gl.h" @@ -42,16 +42,6 @@ #include #include -#if defined (WIN32) && !defined (_MSC_VER) -int WinMain(HINSTANCE /*hInst*/, HINSTANCE /*hPrevInst*/, LPSTR /*lpCmdLine*/, int /*iShowCmd*/) { - return main(__argc, __argv); -} -#endif - -#ifdef _MSC_VER - #undef main -#endif - // Hacky global toggles for experimental/debug code bool ZBUFFER_GLOBAL, SHOWFPS_GLOBAL, TINYGL_GLOBAL; enDebugLevels debugLevel = DEBUG_NONE; @@ -89,7 +79,7 @@ static bool parseBoolStr(const char *val) { void quit(); -int main(int argc, char *argv[]) { +extern "C" int residual_main(int argc, char *argv[]) { int i; g_registry = new Registry(); diff --git a/engine/material.cpp b/engine/material.cpp index 68ba59ec3a5..d94adfc5a8a 100644 --- a/engine/material.cpp +++ b/engine/material.cpp @@ -21,7 +21,7 @@ */ #include "common/sys.h" -#include "common/platform.h" +#include "common/endian.h" #include "common/debug.h" #include "engine/material.h" diff --git a/engine/model.cpp b/engine/model.cpp index b437f59e9f7..1e2af7ae4ec 100644 --- a/engine/model.cpp +++ b/engine/model.cpp @@ -21,7 +21,7 @@ */ #include "common/sys.h" -#include "common/platform.h" +#include "common/endian.h" #include "common/debug.h" #include "engine/model.h" diff --git a/engine/module.mk b/engine/module.mk new file mode 100644 index 00000000000..49185e368f6 --- /dev/null +++ b/engine/module.mk @@ -0,0 +1,28 @@ +MODULE := engine + +MODULE_OBJS := \ + actor.o \ + bitmap.o \ + costume.o \ + engine.o \ + font.o \ + keyframe.o \ + lab.o \ + lipsynch.o \ + localize.o \ + lua.o \ + main.o \ + material.o \ + model.o \ + objectstate.o \ + primitives.o \ + registry.o \ + resource.o \ + savegame.o \ + scene.o \ + textobject.o \ + textsplit.o \ + walkplane.o + +# Include common rules +include $(srcdir)/rules.mk diff --git a/engine/resource.cpp b/engine/resource.cpp index b0d9f399758..6a7ea4dd008 100644 --- a/engine/resource.cpp +++ b/engine/resource.cpp @@ -40,6 +40,10 @@ #include #include +#ifdef _WIN32 +#include +#endif + static void makeLower(std::string& s) { std::transform(s.begin(), s.end(), s.begin(), tolower); } diff --git a/engine/smush/blocky16.cpp b/engine/smush/blocky16.cpp index c40a18b6045..ea4fcc0873f 100644 --- a/engine/smush/blocky16.cpp +++ b/engine/smush/blocky16.cpp @@ -21,7 +21,7 @@ */ #include "common/sys.h" -#include "common/platform.h" +#include "common/endian.h" #include "common/debug.h" #include "engine/smush/blocky16.h" diff --git a/engine/smush/blocky16.h b/engine/smush/blocky16.h index dcb189beda4..b3ae5dac2d2 100644 --- a/engine/smush/blocky16.h +++ b/engine/smush/blocky16.h @@ -23,7 +23,7 @@ #ifndef BLOCKY16_H #define BLOCKY16_H -#include "common/platform.h" +#include "common/sys.h" class Blocky16 { private: diff --git a/engine/smush/module.mk b/engine/smush/module.mk new file mode 100644 index 00000000000..14b6cc99f3d --- /dev/null +++ b/engine/smush/module.mk @@ -0,0 +1,9 @@ +MODULE := engine/smush + +MODULE_OBJS := \ + blocky16.o \ + smush.o \ + vima.o + +# Include common rules +include $(srcdir)/rules.mk diff --git a/engine/smush/smush.cpp b/engine/smush/smush.cpp index 811e14cd599..aba818936e5 100644 --- a/engine/smush/smush.cpp +++ b/engine/smush/smush.cpp @@ -21,7 +21,7 @@ */ #include "common/sys.h" -#include "common/platform.h" +#include "common/endian.h" #include "common/debug.h" #include "common/timer.h" diff --git a/engine/smush/smush.h b/engine/smush/smush.h index 6f0ebc2d284..82fef62ca8b 100644 --- a/engine/smush/smush.h +++ b/engine/smush/smush.h @@ -24,7 +24,6 @@ #define SMUSH_PLAYER_H #include "common/sys.h" -#include "common/platform.h" #include "common/debug.h" #include "engine/smush/blocky16.h" diff --git a/engine/smush/vima.cpp b/engine/smush/vima.cpp index bae4a63dc08..9f02d5e76a9 100644 --- a/engine/smush/vima.cpp +++ b/engine/smush/vima.cpp @@ -21,7 +21,7 @@ */ #include "common/sys.h" -#include "common/platform.h" +#include "common/endian.h" #include "common/debug.h" static int16 imcTable1[] = { diff --git a/engine/textobject.cpp b/engine/textobject.cpp index 5d94dcb1064..275fe0d40df 100644 --- a/engine/textobject.cpp +++ b/engine/textobject.cpp @@ -21,6 +21,7 @@ */ #include "common/sys.h" +#include "common/util.h" #include "engine/textobject.h" #include "engine/engine.h" diff --git a/engine/tinygl/light.cpp b/engine/tinygl/light.cpp index 068ad63a6e3..8419db7525f 100644 --- a/engine/tinygl/light.cpp +++ b/engine/tinygl/light.cpp @@ -115,7 +115,7 @@ void glopLight(GLContext *c, TGLParam *p) { assert(a == 180 || (a >= 0 && a <= 90)); l->spot_cutoff=a; if (a != 180) - l->cos_spot_cutoff = (float)(cos(a * PI / 180.0)); + l->cos_spot_cutoff = (float)(cos(a * LOCAL_PI / 180.0)); } break; case TGL_CONSTANT_ATTENUATION: diff --git a/engine/tinygl/matrix.cpp b/engine/tinygl/matrix.cpp index 8fe19582535..c826c4f9c5f 100644 --- a/engine/tinygl/matrix.cpp +++ b/engine/tinygl/matrix.cpp @@ -104,7 +104,7 @@ void glopRotate(GLContext *c, TGLParam *p) { float angle; int dir_code; - angle = (float)(p[1].f * PI / 180.0); + angle = (float)(p[1].f * LOCAL_PI / 180.0); u[0] = p[2].f; u[1] = p[3].f; u[2] = p[4].f; diff --git a/engine/tinygl/module.mk b/engine/tinygl/module.mk new file mode 100644 index 00000000000..4d08763d99a --- /dev/null +++ b/engine/tinygl/module.mk @@ -0,0 +1,28 @@ +MODULE := engine/tinygl + +MODULE_OBJS := \ + api.o \ + arrays.o \ + clear.o \ + clip.o \ + error.o \ + get.o \ + image_util.o \ + init.o \ + light.o \ + list.o \ + matrix.o \ + memory.o \ + misc.o \ + msghandling.o \ + select.o \ + specbuf.o \ + texture.o \ + vertex.o \ + zbuffer.o \ + zline.o \ + zmath.o \ + ztriangle.o + +# Include common rules +include $(srcdir)/rules.mk diff --git a/engine/tinygl/zgl.h b/engine/tinygl/zgl.h index ed6f3c8182c..7b61c75f216 100644 --- a/engine/tinygl/zgl.h +++ b/engine/tinygl/zgl.h @@ -322,10 +322,6 @@ GLContext *gl_get_context(void); void gl_fatal_error(char *format, ...); -#ifndef PI -#define PI 3.14159265358979323846 -#endif - // specular buffer "api" GLSpecBuf *specbuf_get_buffer(GLContext *c, const int shininess_i, const float shininess); @@ -335,6 +331,10 @@ GLSpecBuf *specbuf_get_buffer(GLContext *c, const int shininess_i, const float s #define dprintf #endif +#ifndef LOCAL_PI +#define LOCAL_PI (3.14159265358979323846) +#endif + // glopXXX functions #define ADD_OP(a,b,c) void glop ## a (GLContext *, TGLParam *); diff --git a/mixer/audiostream.cpp b/mixer/audiostream.cpp index 6c0f37c3911..81fc96882ee 100644 --- a/mixer/audiostream.cpp +++ b/mixer/audiostream.cpp @@ -21,13 +21,15 @@ */ #include "common/sys.h" -#include "common/debug.h" +#include "common/endian.h" #include "common/list.h" +#include "common/util.h" #include "engine/backend/driver.h" -#include "mixer/mixer.h" #include "mixer/audiostream.h" +#include "mixer/mixer.h" + // This used to be an inline template function, but // buggy template function handling in MSVC6 forced @@ -44,6 +46,11 @@ namespace Audio { #pragma mark --- LinearMemoryStream --- #pragma mark - +inline int32 calculatePlayTime(int rate, int samples) { + int32 seconds = samples / rate; + int32 milliseconds = (1000 * (samples % rate)) / rate; + return seconds * 1000 + milliseconds; +} /** * A simple raw audio stream, purely memory based. It operates on a single @@ -64,23 +71,26 @@ protected: const byte *_loopEnd; const int _rate; const byte *_origPtr; + const int32 _playtime; public: LinearMemoryStream(int rate, const byte *ptr, uint len, uint loopOffset, uint loopLen, bool autoFreeMemory) - : _ptr(ptr), _end(ptr+len), _loopPtr(0), _loopEnd(0), _rate(rate) { + : _ptr(ptr), _end(ptr+len), _loopPtr(0), _loopEnd(0), _rate(rate), _playtime(calculatePlayTime(rate, len / (is16Bit ? 2 : 1) / (stereo ? 2 : 1))) { // Verify the buffer sizes are sane - if (is16Bit && stereo) + if (is16Bit && stereo) { assert((len & 3) == 0 && (loopLen & 3) == 0); - else if (is16Bit || stereo) + } else if (is16Bit || stereo) { assert((len & 1) == 0 && (loopLen & 1) == 0); + } if (loopLen) { _loopPtr = _ptr + loopOffset; _loopEnd = _loopPtr + loopLen; } - if (stereo) // Stereo requires even sized data + if (stereo) { // Stereo requires even sized data assert(len % 2 == 0); + } _origPtr = autoFreeMemory ? ptr : 0; } @@ -89,10 +99,11 @@ public: } int readBuffer(int16 *buffer, const int numSamples); - bool isStereo() const { return stereo; } - bool endOfData() const { return _ptr >= _end; } + bool isStereo() const { return stereo; } + bool endOfData() const { return _ptr >= _end; } - int getRate() const { return _rate; } + int getRate() const { return _rate; } + int32 getTotalPlayTime() const { return _playtime; } }; template @@ -242,7 +253,7 @@ int AppendableMemoryStream::readBuffer(int16 assert(buf.start <= _pos && _pos <= buf.end); const int samplesLeftInCurBuffer = buf.end - _pos; if (samplesLeftInCurBuffer == 0) { - delete [] buf.start; + delete[] buf.start; _bufferQueue.erase(_bufferQueue.begin()); _pos = 0; continue; @@ -264,10 +275,11 @@ void AppendableMemoryStream::queueBuffer(byte Common::StackLock lock(_mutex); // Verify the buffer size is sane - if (is16Bit && stereo) + if (is16Bit && stereo) { assert((size & 3) == 0); - else if (is16Bit || stereo) + } else if (is16Bit || stereo) { assert((size & 1) == 0); + } // Verify that the stream has not yet been finalized (by a call to finish()) assert(!_finalized); diff --git a/mixer/audiostream.h b/mixer/audiostream.h index 275e5b01c41..f80615b71f2 100644 --- a/mixer/audiostream.h +++ b/mixer/audiostream.h @@ -24,7 +24,6 @@ #define AUDIOSTREAM_H #include "common/sys.h" -#include "common/platform.h" namespace Audio { @@ -90,7 +89,7 @@ AudioStream *makeLinearInputStream(const byte *ptr, uint32 len, int rate, byte f /** * An audio stream to which additional data can be appended on-the-fly. - * Used by SMUSH, iMuseDigital, and the Kyrandia 3 VQA player. + * Used by SMUSH, iMuseDigital, the Kyrandia 3 VQA player, etc. */ class AppendableAudioStream : public Audio::AudioStream { public: @@ -107,7 +106,7 @@ public: /** * Mark the stream as finished, that is, signal that no further data * will be appended to it. Only after this has been done can the - * AppendableAudioStream ever 'end' ( + * AppendableAudioStream ever 'end' */ virtual void finish() = 0; }; diff --git a/mixer/mixer.cpp b/mixer/mixer.cpp index 4237358051a..000fc087b3d 100644 --- a/mixer/mixer.cpp +++ b/mixer/mixer.cpp @@ -21,7 +21,7 @@ */ #include "common/sys.h" -#include "common/platform.h" +#include "common/util.h" #include "common/debug.h" #include "engine/backend/driver.h" diff --git a/mixer/mixer.h b/mixer/mixer.h index c44e3b34584..882118e3e39 100644 --- a/mixer/mixer.h +++ b/mixer/mixer.h @@ -24,7 +24,6 @@ #define SOUND_MIXER_H #include "common/sys.h" -#include "common/platform.h" #include "common/mutex.h" namespace Audio { diff --git a/mixer/module.mk b/mixer/module.mk new file mode 100644 index 00000000000..16855f971b6 --- /dev/null +++ b/mixer/module.mk @@ -0,0 +1,18 @@ +MODULE := mixer + +MODULE_OBJS := \ + audiostream.o \ + mixer.o \ + rate.o + +ifndef USE_ARM_SOUND_ASM +MODULE_OBJS += \ + rate.o +else +MODULE_OBJS += \ + rate_arm.o \ + rate_arm_asm.o +endif + +# Include common rules +include $(srcdir)/rules.mk diff --git a/mixer/rate.cpp b/mixer/rate.cpp index f86ccb12b89..7b6ff25916e 100644 --- a/mixer/rate.cpp +++ b/mixer/rate.cpp @@ -29,6 +29,7 @@ */ #include "common/sys.h" +#include "common/util.h" #include "common/debug.h" #include "common/frac.h" diff --git a/mixer/rate.h b/mixer/rate.h index 45edd7c97e0..dfb8f094a10 100644 --- a/mixer/rate.h +++ b/mixer/rate.h @@ -23,7 +23,7 @@ #ifndef SOUND_RATE_H #define SOUND_RATE_H -#include "common/platform.h" +#include "common/sys.h" class AudioStream; diff --git a/ports.mk b/ports.mk new file mode 100644 index 00000000000..b0bcec950f8 --- /dev/null +++ b/ports.mk @@ -0,0 +1,177 @@ +# This file contains port specific Makefile rules. It is automatically +# included by the default (main) Makefile. +# +# $URL$ +# $Id$ + + +# +# UNIX specific +# +install: all + $(INSTALL) -d "$(DESTDIR)$(BINDIR)" + $(INSTALL) -c -s -m 755 "$(srcdir)/residual$(EXEEXT)" "$(DESTDIR)$(BINDIR)/residual$(EXEEXT)" + #$(INSTALL) -d "$(DESTDIR)$(MANDIR)/man6/" + #$(INSTALL) -c -m 644 "$(srcdir)/dists/residual.6" "$(DESTDIR)$(MANDIR)/man6/residual.6" + #$(INSTALL) -d "$(DESTDIR)$(PREFIX)/share/pixmaps/" + #$(INSTALL) -c -m 644 "$(srcdir)/icons/residual.xpm" "$(DESTDIR)$(PREFIX)/share/pixmaps/residual.xpm" + #$(INSTALL) -d "$(DESTDIR)$(PREFIX)/share/doc/residual/" + $(INSTALL) -c -m 644 "$(srcdir)/AUTHORS" "$(srcdir)/COPYING" "$(srcdir)/COPYRIGHT" "$(srcdir)/NEWS" "$(srcdir)/README" "$(DESTDIR)$(PREFIX)/share/doc/residual/" + $(INSTALL) -d "$(DESTDIR)$(DATADIR)/residual/" + $(INSTALL) -c -m 644 $(DIST_FILES_THEMES) $(DIST_FILES_ENGINEDATA) "$(DESTDIR)$(DATADIR)/residual/" + +uninstall: + rm -f "$(DESTDIR)$(BINDIR)/residual$(EXEEXT)" + #rm -f "$(DESTDIR)$(MANDIR)/man6/residual.6" + #rm -f "$(DESTDIR)$(PREFIX)/share/pixmaps/residual.xpm" + #rm -rf "$(DESTDIR)$(PREFIX)/share/doc/residual/" + #rm -rf "$(DESTDIR)$(DATADIR)/residual/" + +deb: + ln -sf dists/debian; + debian/prepare + fakeroot debian/rules binary + + +# Special target to create a application wrapper for Mac OS X +bundle_name = Residual.app +bundle: scummvm-static $(srcdir)/dists/macosx/Info.plist + mkdir -p $(bundle_name)/Contents/MacOS + mkdir -p $(bundle_name)/Contents/Resources + echo "APPL????" > $(bundle_name)/Contents/PkgInfo + cp $(srcdir)/dists/macosx/Info.plist $(bundle_name)/Contents/ + cp $(srcdir)/icons/residual.icns $(bundle_name)/Contents/Resources/ + cp $(srcdir)/dists/pred.dic $(bundle_name)/Contents/Resources/ + cp $(DIST_FILES_THEMES) $(bundle_name)/Contents/Resources/ + cp $(DIST_FILES_ENGINEDATA) $(bundle_name)/Contents/Resources/ + $(srcdir)/tools/credits.pl --rtf > $(bundle_name)/Contents/Resources/Credits.rtf + chmod 644 $(bundle_name)/Contents/Resources/* + cp residual-static $(bundle_name)/Contents/MacOS/residual + chmod 755 $(bundle_name)/Contents/MacOS/residual + strip $(bundle_name)/Contents/MacOS/residual + +iphonebundle: $(srcdir)/dists/iphone/Info.plist + mkdir -p $(bundle_name) + cp $(srcdir)/dists/iphone/Info.plist $(bundle_name)/ + cp $(srcdir)/dists/pred.dic $(bundle_name)/ + cp $(DIST_FILES_THEMES) $(bundle_name)/ + cp $(DIST_FILES_ENGINEDATA) $(bundle_name)/ + cp residual $(bundle_name)/Residual + cp $(srcdir)/dists/iphone/icon.png $(bundle_name)/icon.png + cp $(srcdir)/dists/iphone/Default.png $(bundle_name)/Default.png + +# location of additional libs for OS X usually /sw/ for fink or +# /opt/local/ for darwinports +OSXOPT=/sw + +# Location of static libs for the iPhone +ifeq ($(BACKEND), iphone) +OSXOPT=/usr/local/arm-apple-darwin +else +# Static libaries, used for the scummvm-static and iphone targets +OSX_STATIC_LIBS := `$(OSXOPT)/bin/sdl-config --static-libs` +endif + +ifdef USE_VORBIS +OSX_STATIC_LIBS += \ + $(OSXOPT)/lib/libvorbisfile.a \ + $(OSXOPT)/lib/libvorbis.a \ + $(OSXOPT)/lib/libogg.a +endif + +ifdef USE_TREMOR +OSX_STATIC_LIBS += $(OSXOPT)/lib/libvorbisidec.a +endif + +ifdef USE_FLAC +OSX_STATIC_LIBS += $(OSXOPT)/lib/libFLAC.a +endif + +ifdef USE_MAD +OSX_STATIC_LIBS += $(OSXOPT)/lib/libmad.a +endif + +ifdef USE_MPEG2 +OSX_STATIC_LIBS += $(OSXOPT)/lib/libmpeg2.a +endif + +# Special target to create a static linked binary for Mac OS X. +# We use -force_cpusubtype_ALL to ensure the binary runs on every +# PowerPC machine. +residual-static: $(OBJS) + $(CXX) $(LDFLAGS) -force_cpusubtype_ALL -o residual-static $(OBJS) \ + -framework CoreMIDI \ + $(OSX_STATIC_LIBS) \ + -lSystemStubs \ + -lz +# $(OSXOPT)/lib/libz.a + +# Special target to create a static linked binary for the iPhone +iphone: $(OBJS) + $(CXX) $(LDFLAGS) -o residual $(OBJS) \ + $(OSX_STATIC_LIBS) \ + -framework UIKit -framework CoreGraphics -framework CoreSurface \ + -framework LayerKit -framework GraphicsServices -framework CoreFoundation \ + -framework Foundation -framework AudioToolbox -framework CoreAudio \ + -lobjc -lz + +# Special target to create a snapshot disk image for Mac OS X +# TODO: Replace AUTHORS by Credits.rtf +osxsnap: bundle credits + mkdir Residual-snapshot + cp $(srcdir)/AUTHORS ./Residual-snapshot/Authors + cp $(srcdir)/COPYING ./Residual-snapshot/License + cp $(srcdir)/COPYRIGHT ./Residual-snapshot/Copyright\ Holders + cp $(srcdir)/NEWS ./Residual-snapshot/News + cp $(srcdir)/README ./Residual-snapshot/Residual\ ReadMe + /Developer/Tools/SetFile -t ttro -c ttxt ./Residual-snapshot/* + /Developer/Tools/CpMac -r $(bundle_name) ./Residual-snapshot/ + cp $(srcdir)/dists/macosx/DS_Store ./Residual-snapshot/.DS_Store + cp $(srcdir)/dists/macosx/background.jpg ./Residual-snapshot/background.jpg + /Developer/Tools/SetFile -a V ./Residual-snapshot/.DS_Store + /Developer/Tools/SetFile -a V ./Residual-snapshot/background.jpg + hdiutil create -ov -format UDZO -imagekey zlib-level=9 -fs HFS+ \ + -srcfolder Residual-snapshot \ + -volname "Residual snapshot" \ + Residual-snapshot.dmg + rm -rf Residual-snapshot + +# +# Windows specific +# + +residualico.o: $(srcdir)/icons/residual.ico + $(WINDRES) -I$(srcdir) $(srcdir)/dists/residual.rc residualico.o + +# Special target to create a win32 snapshot binary +win32dist: residual$(EXEEXT) + mkdir -p $(WIN32PATH) + #strip residual.exe -o $(WIN32PATH)/residual$(EXEEXT) + #cp $(srcdir)/AUTHORS $(WIN32PATH)/AUTHORS.txt + cp $(srcdir)/COPYING $(WIN32PATH)/COPYING.txt + #cp $(srcdir)/COPYRIGHT $(WIN32PATH)/COPYRIGHT.txt + #cp $(srcdir)/NEWS $(WIN32PATH)/NEWS.txt + cp $(srcdir)/README $(WIN32PATH)/README.txt + cp /usr/local/README-SDL.txt $(WIN32PATH) + cp /usr/local/bin/SDL.dll $(WIN32PATH) + u2d $(WIN32PATH)/*.txt + +# +# AmigaOS specific +# + +# Special target to create an AmigaOS snapshot installation +aos4dist: residual + mkdir -p $(AOS4PATH) + strip -R.comment $< -o $(AOS4PATH)/$<_SVN + cp icons/residual.info $(AOS4PATH)/$<_SVN.info + cp $(DIST_FILES_THEMES) $(AOS4PATH)/themes/ + cp $(DIST_FILES_ENGINEDATA) $(AOS4PATH)/extras/ + #cp $(srcdir)/AUTHORS $(AOS4PATH)/AUTHORS.txt + cp $(srcdir)/COPYING $(AOS4PATH)/COPYING.txt + #cp $(srcdir)/COPYRIGHT $(AOS4PATH)/COPYRIGHT.txt + #cp $(srcdir)/NEWS $(AOS4PATH)/NEWS.txt + cp $(srcdir)/README $(AOS4PATH)/README.txt + cp /sdk/local/documentation/SDL-1.2.9/README-SDL.txt $(AOS4PATH) + +.PHONY: deb bundle osxsnap win32dist install uninstall diff --git a/rules.mk b/rules.mk new file mode 100644 index 00000000000..1a8e1253f00 --- /dev/null +++ b/rules.mk @@ -0,0 +1,67 @@ +############################################### +# Common build rules, used by the sub modules and their module.mk files +# +# $URL$ +# $Id$ +############################################### + + +# Copy the list of objects to a new variable. The name of the new variable +# contains the module name, a trick we use so we can keep multiple different +# module object lists, one for each module. +MODULE_OBJS-$(MODULE) := $(addprefix $(MODULE)/, $(MODULE_OBJS)) + +# Add all involved directories to the MODULE_DIRS list +MODULE_DIRS += $(sort $(dir $(MODULE_OBJS-$(MODULE)))) + + + +ifdef TOOL_EXECUTABLE +################################################ +# Build rule for (tool) executables. +# TODO: Refactor this, so that even our master executable can use this rule? +################################################ +TOOL-$(MODULE) := $(MODULE)/$(TOOL_EXECUTABLE)$(EXEEXT) +$(TOOL-$(MODULE)): $(MODULE_OBJS-$(MODULE)) + $(CXX) $(LDFLAGS) $+ -o $@ + +# Reset TOOL_EXECUTABLE var +TOOL_EXECUTABLE:= + +# Add to "tools" target +tools: $(TOOL-$(MODULE)) + +# Pseudo target for comfort, allows for "make tools/skycpt", etc. +$(MODULE): $(TOOL-$(MODULE)) +clean-tools: clean-$(MODULE) + +else +################################################ +# Build rule for static modules/plugins +################################################ +MODULE_LIB-$(MODULE) := $(MODULE)/lib$(notdir $(MODULE)).a + +# If not building as a plugin, add the object files to the main OBJS list +OBJS += $(MODULE_LIB-$(MODULE)) + +# Convenience library target +$(MODULE_LIB-$(MODULE)): $(MODULE_OBJS-$(MODULE)) + -$(RM) $@ + $(AR) $@ $+ + $(RANLIB) $@ + +# Pseudo target for comfort, allows for "make common", "make gui" etc. +$(MODULE): $(MODULE_LIB-$(MODULE)) + +endif # TOOL_EXECUTABLE + +############################################### +# Clean target, removes all object files. This looks a bit hackish, as we have to +# copy the content of MODULE_OBJS to another unique variable (the next module.mk +# will overwrite it after all). The same for the libMODULE.a library file. +############################################### +clean: clean-$(MODULE) +clean-$(MODULE): clean-% : + -$(RM) $(MODULE_OBJS-$*) $(MODULE_LIB-$*) $(PLUGIN-$*) $(TOOL-$*) + +.PHONY: clean-$(MODULE) $(MODULE)