1
0
Fork 0

Makefile: Use just one makefile; improvements

- Do not use wildcards to generate the list of sources (this has many
   problems and is discouraged, especially for bigger problems)
 - Specify the toolchain to be used through implicit variables
    * mingw32 vs. i686-w64-mingw32
    * g++ vs clang++
 - Use g++ binary instead of gcc
 - automatically generate dependencies (header files) for compilation
pull/29/head
Leonard Koenig 2018-06-20 15:48:56 +02:00
parent 49a6f4f9fc
commit 2a8bbc82dc
7 changed files with 106 additions and 46 deletions

1
.gitignore vendored
View File

@ -2,3 +2,4 @@
*.lib
*.dll
*.exe
*.d

4
3rdParty/PKWare/objs.mak vendored Normal file
View File

@ -0,0 +1,4 @@
PKWARE_OBJS=3rdParty/PKWare/explode.o \
3rdParty/PKWare/implode.o
-include *.d

View File

@ -1,30 +1,42 @@
DIABLO_SRC=$(wildcard Source/*.cpp)
DIABLO_OBJ=$(DIABLO_SRC:.cpp=.o)
# For 32-bit build systems, the executable is just mingw32
MINGW32 ?= i686-w64-mingw32
# Used s.t. we can try to use clang to compile code
_CXX ?= g++
PKWARE_SRC=$(wildcard 3rdParty/PKWare/*.cpp)
PKWARE_OBJ=$(PKWARE_SRC:.cpp=.o)
CXX=$(MINGW32)-$(_CXX)
DLLTOOL=$(MINGW32)-dlltool
# Clang doesn't understand permissive compilation, we need to "fix" invalid
# casts from a pointer type there using
# static_cast<NEW_TYPE>(reinterpret_cast<uintptr_t>(ptr))
# instead of
# (NEW_TYPE)(ptr)
CXXFLAGS=-std=c++98 -fpermissive -Wno-write-strings
CPPFLAGS=-MMD -MF $*.d
LDLIBS=-lgdi32 -lversion -ldiabloui -lstorm
LDFLAGS=-L./
all: devilution.exe
devilution.exe: $(DIABLO_OBJ) $(PKWARE_OBJ) diabloui.lib storm.lib
i686-w64-mingw32-gcc -L./ -o $@ $^ -lgdi32 -lversion -ldiabloui -lstorm
include 3rdParty/PKWare/objs.mak
include Source/objs.mak
%.o: %.cpp
i686-w64-mingw32-gcc -c -fpermissive -Wno-write-strings -o $@ $<
devilution.exe: $(OBJS) $(PKWARE_OBJS) diabloui.lib storm.lib
$(CXX) $(LDFLAGS) -o $@ $^ $(LDLIBS)
diabloui.lib: diabloui.dll DiabloUI/diabloui_gcc.def
i686-w64-mingw32-dlltool -d DiabloUI/diabloui_gcc.def -D diabloui.dll -l diabloui.lib
$(DLLTOOL) -d DiabloUI/diabloui_gcc.def -D $< -l $@
diabloui.dll:
echo "Please copy diabloui.dll (version 1.09b) here."
$(error Please copy diabloui.dll (version 1.09b) here)
storm.lib: storm.dll 3rdParty/Storm/Source/storm_gcc.def
i686-w64-mingw32-dlltool -d 3rdParty/Storm/Source/storm_gcc.def -D storm.dll -l storm.lib
$(DLLTOOL) -d 3rdParty/Storm/Source/storm_gcc.def -D $< -l $@
storm.dll:
echo "Please copy storm.dll (version 1.09b) here."
$(error Please copy storm.dll (version 1.09b) here)
clean:
rm -f $(DIABLO_OBJ) $(PKWARE_OBJ)
@$(RM) -v $(OBJS) $(OBJS:.o=.d) $(PKWARE_OBJS) $(PKWARE_OBJS:.o=d)
.PHONY: clean all

View File

@ -1,30 +0,0 @@
DIABLO_SRC=$(wildcard Source/*.cpp)
DIABLO_OBJ=$(DIABLO_SRC:.cpp=.o)
PKWARE_SRC=$(wildcard 3rdParty/PKWare/*.cpp)
PKWARE_OBJ=$(PKWARE_SRC:.cpp=.o)
all: devilution.exe
devilution.exe: $(DIABLO_OBJ) $(PKWARE_OBJ) diabloui.lib storm.lib
mingw32-gcc -L./ -o $@ $^ -lgdi32 -lversion -ldiabloui -lstorm
%.o: %.cpp
mingw32-gcc -c -fpermissive -Wno-write-strings -o $@ $<
diabloui.lib: diabloui.dll DiabloUI/diabloui_gcc.def
dlltool -d DiabloUI/diabloui_gcc.def -D diabloui.dll -l diabloui.lib
diabloui.dll:
echo "Please copy diabloui.dll (version 1.09b) here."
storm.lib: storm.dll 3rdParty/Storm/Source/storm_gcc.def
dlltool -d 3rdParty/Storm/Source/storm_gcc.def -D storm.dll -l storm.lib
storm.dll:
echo "Please copy storm.dll (version 1.09b) here."
clean:
rm -f $(DIABLO_OBJ) $(PKWARE_OBJ)
.PHONY: clean all

View File

@ -28,7 +28,7 @@ Building with Visual C++ 5.10
Building with MinGW(32/64)
- Ensure that the MinGW binary paths have been added to the command line.
- For MinGW32, navigate to the project root and execute `mingw32-make -f Makefile32`. The process will take longer than Visual Studio.
- For MinGW32, navigate to the project root and execute `make MINGW32=mingw32`. The process will take longer than Visual Studio.
- For MinGW64, refer to the respective documentation: [Linux](Support/INSTALL_linux.md) | [Windows](Support/INSTALL_windows.md). Note that only x86 systems may be targeted for the time being.
Compiling Definitions

70
Source/objs.mak Normal file
View File

@ -0,0 +1,70 @@
OBJS=Source/path.o \
Source/monster.o \
Source/engine.o \
Source/world.o \
Source/help.o \
Source/interfac.o \
Source/effects.o \
Source/towners.o \
Source/gendung.o \
Source/sound.o \
Source/sha.o \
Source/dead.o \
Source/multi.o \
Source/items.o \
Source/drlg_l2.o \
Source/codec.o \
Source/pfile.o \
Source/drlg_l4.o \
Source/gamemenu.o \
Source/appfat.o \
Source/error.o \
Source/restrict.o \
Source/player.o \
Source/capture.o \
Source/mpqapi.o \
Source/nthread.o \
Source/setmaps.o \
Source/trigs.o \
Source/diablo.o \
Source/dx.o \
Source/portal.o \
Source/msgcmd.o \
Source/plrmsg.o \
Source/themes.o \
Source/control.o \
Source/doom.o \
Source/init.o \
Source/cursor.o \
Source/debug.o \
Source/pack.o \
Source/stores.o \
Source/msg.o \
Source/loadsave.o \
Source/objects.o \
Source/palette.o \
Source/quests.o \
Source/wave.o \
Source/tmsg.o \
Source/minitext.o \
Source/scrollrt.o \
Source/sync.o \
Source/missiles.o \
Source/gmenu.o \
Source/town.o \
Source/dthread.o \
Source/logging.o \
Source/textdat.o \
Source/lighting.o \
Source/automap.o \
Source/inv.o \
Source/drlg_l1.o \
Source/spells.o \
Source/encrypt.o \
Source/fault.o \
Source/track.o \
Source/movie.o \
Source/drlg_l3.o \
Source/mainmenu.o
-include *.d

View File

@ -2,9 +2,9 @@
## Dependencies
Arch Linux:
Arch Linux
```bash
pacman -Sy mingw-w64-gcc mingw-w64-binutils
pacman -S mingw-w64-gcc mingw-w64-binutils
```
## Building
@ -17,6 +17,9 @@ cp /path/to/diablo_game_dir/storm.dll .
make
```
On a 32-bit host, `$ make MINGW32=mingw32` should be used, to specify the 32-bit
toolchain.
## Install
```bash