-
Notifications
You must be signed in to change notification settings - Fork 3
/
MakefileM32
134 lines (110 loc) · 4.52 KB
/
MakefileM32
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
# MakefileM32: Copyright 2019-2023 Valerio Messina efa@iol.it
#
# MakefileM32 is part of Wilderland - A Hobbit Environment
# Wilderland 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.
#
# Wilderland 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 Wilderland. If not, see <http://www.gnu.org/licenses/>.
# Makefile to cross-build 'Wilderland' for Win32 on Linux using GCC+GNUtoolchain
# To be used on: Linux=>Win.bin32 (MXE.static build)
# require MXE SDL2_image in /opt/mxe/usr/i686-w64-mingw32.static
# To use z80emu emulator build with: $ make CPUEMUL=ez80emu OR $ make
# To use Z80 emulator build with: $ make CPUEMUL=eZ80
# To avoid include and link libcurl and libzip build with: $ make NODL=1
# To build for debug use: $ make BUILD=debug
PKG = MXE32
CPU = i686
BIT = 32
OS = $(shell uname -o)
# select the CPU emulator, CPUEMUL must be: eZ80 or ez80emu
eZ80 = 1
ez80emu = 2
ifeq ($(CPUEMUL),) # default to ez80emu
CPUEMUL = ez80emu
endif
ifeq ($(CPUEMUL),eZ80)
CPUIF=Z80/Z80.h
CPUOBJ=Z80.o
endif
ifeq ($(CPUEMUL),ez80emu)
CPUIF=z80emu/z80emu.h
CPUOBJ=z80emu.o
endif
BUILD?=release
ifeq ($(BUILD),debug)
COPT=-O1 -g -fsanitize=address -fno-omit-frame-pointer
LOPT=-fsanitize=address
else
COPT=-O3
endif
# MHOST cross-compiler target
# MCROSS cross-toolchain prefix
# MXEROOT point to cross-compiler root path
# MXE point to cross-compiler tools path
MHOST=i686-w64-mingw32.static
MCROSS = $(MHOST)-
MXEROOT = /opt/mxe
MXE = $(MXEROOT)/usr/bin
PATH:=$(MXE):$(PATH)
CC = $(MCROSS)gcc
LD = $(MCROSS)gcc
STRIP = $(MCROSS)strip
PKG_CONFIG=$(MCROSS)pkg-config
CFLAGS = -std=c99 -Wall $(COPT) -D__USE_MINGW_ANSI_STDIO=1 -m32 -DCPUEMUL=$(CPUEMUL) -fomit-frame-pointer
SDLCFLAGS = $(shell PKG_CONFIG_PATH_i686_w64_mingw32_static=$(MXEROOT)/usr/i686-w64-mingw32.static/lib/pkgconfig: $(MXE)/$(PKG_CONFIG) --cflags SDL2_image)
SDLMINGWLDFLAGS = -mconsole # on MinGW + SDL force console for debug
LDFLAGS = $(shell PKG_CONFIG_PATH_i686_w64_mingw32_static=$(MXEROOT)/usr/i686-w64-mingw32.static/lib/pkgconfig: $(MXE)/$(PKG_CONFIG) --libs SDL2_image) $(SDLMINGWLDFLAGS) -m32 $(LOPT)
ifndef NODL
CFLAGS += $(shell PKG_CONFIG_PATH_i686_w64_mingw32_static=$(MXEROOT)/usr/i686-w64-mingw32.static/lib/pkgconfig: $(MXE)/$(PKG_CONFIG) --cflags libcurl)
CFLAGS += $(shell PKG_CONFIG_PATH_i686_w64_mingw32_static=$(MXEROOT)/usr/i686-w64-mingw32.static/lib/pkgconfig: $(MXE)/$(PKG_CONFIG) --cflags libzip)
LDFLAGS += $(shell PKG_CONFIG_PATH_i686_w64_mingw32_static=$(MXEROOT)/usr/i686-w64-mingw32.static/lib/pkgconfig: $(MXE)/$(PKG_CONFIG) --libs libcurl)
LDFLAGS += $(shell PKG_CONFIG_PATH_i686_w64_mingw32_static=$(MXEROOT)/usr/i686-w64-mingw32.static/lib/pkgconfig: $(MXE)/$(PKG_CONFIG) --libs libzip)
else
CFLAGS += -DNODL
endif
FILE = WL
SOURCE = $(FILE)
TARGET = $(FILE)mxe32.exe
TAPCON = TapCon/TapConMxe32.exe
all: $(TARGET) $(TAPCON)
$(TARGET): $(SOURCE).o SDLTWE.o spectrum.o $(CPUOBJ)
$(MXE)/$(LD) $^ $(LDFLAGS) -o $@
$(SOURCE).o: $(SOURCE).c WL.h GlobalVars.h MapCoordinates.h SDLTWE.h Spectrum.h $(CPUIF)
$(MXE)/$(CC) $(CFLAGS) $(SDLCFLAGS) -c $< -o $@
SDLTWE.o: SDLTWE.c WL.h SDLTWE.h
$(MXE)/$(CC) $(CFLAGS) $(SDLCFLAGS) -c $< -o $@
spectrum.o: Spectrum.c GlobalVars.h Spectrum.h WL.h SDLTWE.h $(CPUIF)
$(MXE)/$(CC) $(CFLAGS) $(SDLCFLAGS) -c $< -o $@
z80emu/tables.h: z80emu/maketables.c
$(CC) -Wall $< -o z80emu/maketables
@echo "Generated 'maketables', now run it to output 'tables.h'"
./z80emu/maketables > $@
z80emu.o: z80emu/z80emu.c z80emu/z80emu.h z80emu/z80config.h z80emu/z80user.h \
z80emu/instructions.h z80emu/macros.h z80emu/tables.h Spectrum.h
$(CC) -I. $(CFLAGS) -c $<
Z80.o: Z80/Z80.c GlobalVars.h Spectrum.h Z80/Codes.h Z80/CodesCB.h Z80/CodesED.h Z80/CodesXCB.h Z80/CodesXX.h Z80/Tables.h Z80/Z80.h
$(MXE)/$(CC) -I. $(CFLAGS) $(SDLCFLAGS) -c $< -o $@
$(TAPCON): TapCon/TapCon.c WL.h
$(MXE)/$(CC) $(CFLAGS) $< $(LDFLAGS) -o $@
strip:
$(MXE)/$(STRIP) $(TARGET) $(TAPCON)
cleanobj:
rm -f *.o
cleanbin:
rm -f $(TARGET) $(TAPCON)
clean: cleanobj cleanbin
debug: clean all cleanobj
bin: all cleanobj strip
force: clean bin
rm -f *.o
pkg:
@WLpkg.sh $(PKG) $(BIT)
rel: force pkg