FBNeo/makefile.sdl
2012-01-01 17:58:04 +00:00

557 lines
13 KiB
Plaintext

# Makefile for FBASDL, for use with GNU make & GCC
#
# The first pass makes sure all intermediary targets are present. The second pass updates
# any targets, if necessary. (Intermediary) targets which have their own unique rules
# are generated as required.
unexport
#
# Flags. Uncomment any of these declarations to enable their function.
#
# Check for changes in header files
DEPEND = 1
#
# Declare variables
#
# Specify the name of the executable file, without ".exe"
NAME = fbasdl
ifdef BUILD_X64_EXE
ifdef BUILD_A68K
undefine BUILD_A68K
endif
ifdef BUILD_X86_ASM
undefine BUILD_X86_ASM
endif
endif
ifndef CPUTYPE
CPUTYPE = i686
endif
MMX = 0
ifndef BUILD_X86_ASM
NAME := $(NAME)n
endif
ifdef BUILD_X64_EXE
NAME = $(NAME)64
endif
ifdef DEBUG
NAME := $(NAME)d
endif
ifdef SYMBOL
NAME := $(NAME)s
endif
ifndef UNICODE
NAME := $(NAME)a
endif
ifeq ($(CPUTYPE),i686)
ppro = ppro
else
NAME := $(NAME)$(CPUTYPE)
endif
#
# Specify paths/files
#
objdir = obj/SDL/$(NAME)/
srcdir = src/
include makefile.rules
incdir = $(foreach dir,$(alldir),-I$(srcdir)$(dir)) -I$(objdir)depend/generated
lib += `sdl-config --libs`
depobj += resource.o \
autdep = $(depobj:.o=.d)
ifdef BUILD_A68K
a68k.o = $(objdir)cpu/a68k/a68k.o
endif
license.rtf = $(srcdir)depend/generated/license.rtf
driverlist.h = $(srcdir)depend/generated/driverlist.h
ctv.h = $(srcdir)depend/generated/ctv.h
toa_gp9001_func.h = $(srcdir)depend/generated/toa_gp9001_func.h
neo_sprite_func.h = $(srcdir)depend/generated/neo_sprite_func.h
cave_tile_func.h = $(srcdir)depend/generated/cave_tile_func.h
cave_sprite_func.h = $(srcdir)depend/generated/cave_sprite_func.h
psikyo_tile_func.h = $(srcdir)depend/generated/psikyo_tile_func.h
pgm_sprite.h = $(srcdir)depend/generated/pgm_sprite.h
build_details.h = $(srcdir)depend/generated/build_details.h
allobj = $(objdir)cpu/m68k/m68kcpu.o $(objdir)cpu/m68k/m68kopnz.o $(objdir)cpu/m68k/m68kopdm.o $(objdir)cpu/m68k/m68kopac.o $(objdir)cpu/m68k/m68kops.o \
$(foreach file,$(autobj:.o=.c), \
$(foreach dir,$(alldir),$(subst $(srcdir),$(objdir), \
$(firstword $(subst .c,.o,$(wildcard $(srcdir)$(dir)/$(file))))))) \
$(foreach file,$(autobj:.o=.cpp), \
$(foreach dir,$(alldir),$(subst $(srcdir),$(objdir), \
$(firstword $(subst .cpp,.o,$(wildcard $(srcdir)$(dir)/$(file))))))) \
$(foreach file,$(autobj:.o=.asm), \
$(foreach dir,$(alldir),$(subst $(srcdir),$(objdir), \
$(firstword $(subst .asm,.o,$(wildcard $(srcdir)$(dir)/$(file))))))) \
ifdef BUILD_A68K
allobj += $(a68k.o)
endif
alldep = $(foreach file,$(autobj:.o=.c), \
$(foreach dir,$(alldir),$(subst $(srcdir),$(objdir), \
$(firstword $(subst .c,.d,$(wildcard $(srcdir)$(dir)/$(file))))))) \
$(foreach file,$(autobj:.o=.cpp), \
$(foreach dir,$(alldir),$(subst $(srcdir),$(objdir), \
$(firstword $(subst .cpp,.d,$(wildcard $(srcdir)$(dir)/$(file))))))) \
#
#
# Specify compiler/linker/assembler
#
#
CC = gcc
CXX = g++
LD = $(CXX)
AS = nasm
LDFLAGS = -static
CFLAGS = -pipe \
-std=gnu99 -march=$(CPUTYPE) -O1 \
-fforce-mem -fforce-addr -finline-limit=1200 -fthread-jumps \
-freduce-all-givs -fmove-all-movables -fexpensive-optimizations \
-Wall -Wno-long-long -Wno-sign-compare -Wno-uninitialized -Wno-unused \
$(DEF) $(incdir) `sdl-config --cflags`
CXXFLAGS = -pipe \
-march=$(CPUTYPE) -O1 \
-fforce-mem -fforce-addr -finline-limit=1200 -fthread-jumps \
-freduce-all-givs -fmove-all-movables -fexpensive-optimizations \
-fcheck-new \
-Wall -W -pedantic -Wno-long-long \
-Wunknown-pragmas -Wundef -Wconversion -Wno-missing-braces \
-Wuninitialized -Wpointer-arith -Winline -Wno-multichar \
$(DEF) $(incdir) `sdl-config --cflags`
endif
ifdef BUILD_X64_EXE
CFLAGS += -m64
CXXFLAGS += -m64
LDFLAGS += -m64
else
CFLAGS += -m32
CXXFLAGS += -m32
LDFLAGS += -m32
endif
endif
ASFLAGS = -O1 -f coff -w-orphan-labels
# D3DUtils & D3DMath need these
# DEF = -Dsinf=\(float\)sin -Dcosf=\(float\)cos -Dasinf=\(float\)asin -Dacosf=\(float\)acos -Dsqrtf=\(float\)sqrt
DEF := -DUSE_SPEEDHACKS -DFILENAME=$(NAME) -DMMX=0
ifdef UNICODE
DEF := $(DEF) -D_UNICODE
endif
ifdef SPECIALBUILD
DEF := $(DEF) -DSPECIALBUILD=$(SPECIALBUILD)
endif
ifdef FASTCALL
DEF := $(DEF) -DFASTCALL
endif
ifdef DEBUG
DEF := $(DEF) -DFBA_DEBUG
endif
ifdef ROM_VERIFY
DEF := $(DEF) -DROM_VERIFY
endif
ifdef BUILD_A68K
DEF := $(DEF) -DBUILD_A68K
endif
ifdef BUILD_X86_ASM
DEF := $(DEF) -DBUILD_X86_ASM
endif
ifdef BUILD_X64_EXE
DEF := $(DEF) -DBUILD_X64_EXE
endif
ifdef SYMBOL
CFLAGS += -ggdb3
ASFLAGS += -g
DEF := $(DEF) -D_DEBUG
ifdef PROFILE
CFLAGS += -pg
CXXFLAGS += -pg
else
CFLAGS += -fomit-frame-pointer
CXXFLAGS += -fomit-frame-pointer
endif
else
LDFLAGS += -s
endif
# For zlib
DEF := $(DEF) -DNO_VIZ -D_LARGEFILE64_SOURCE=0 -D_FILE_OFFSET_BITS=32
#
#
# Specify paths
#
#
vpath %.asm $(foreach dir,$(alldir),$(srcdir)$(dir)/ )
vpath %.cpp $(foreach dir,$(alldir),$(srcdir)$(dir)/ )
vpath %.c $(foreach dir,$(alldir),$(srcdir)$(dir)/ )
vpath %.h $(foreach dir,$(alldir),$(srcdir)$(dir)/ )
vpath %.o $(foreach dir,$(alldir),$(objdir)$(dir)/ )
vpath %.d $(foreach dir,$(alldir),$(objdir)$(dir)/ )
#
#
# Rules
#
#
.PHONY: all init cleandep touch clean
ifeq ($(MAKELEVEL),1)
ifdef DEPEND
all: init $(autdep) $(autobj)
@$(MAKE) -f makefile.sdl
else
all: init $(autobj)
@$(MAKE) -f makefile.sdl
endif
else
all: $(NAME).exe
endif
#
#
# Rule for linking the executable
#
#
ifeq ($(MAKELEVEL),2)
$(NAME).exe: $(allobj)
@echo
@echo Linking executable... $(NAME).exe
@$(LD) $(CFLAGS) $(LDFLAGS) -o $@ $^ $(lib)
ifdef DEBUG
# Don't compress when making a debug build
else
ifdef COMPRESS
@upx --best $@
endif
endif
endif
ifeq ($(MAKELEVEL),1)
ifdef FORCE_UPDATE
$(build_details.h): FORCE
endif
endif
#
# Generate the gamelist
#
burn.o burn.d: driverlist.h
$(driverlist.h): $(drvobj) $(srcdir)depend/scripts/gamelist.pl
ifdef PERL
@$(srcdir)depend/scripts/gamelist.pl -o $@ -l gamelist.txt \
$(filter %.cpp,$(foreach file,$(drvobj:.o=.cpp),$(foreach dir,$(alldir), \
$(firstword $(wildcard $(srcdir)$(dir)/$(file))))))
else
ifeq ($(MAKELEVEL),2)
@echo
@echo Warning: Perl is not available on this system.
@echo $@ cannot be updated or created!
@echo
endif
endif
#
# Verify if driverlist.h needs to be updated
#
#ifeq ($(MAKELEVEL),1)
#ifdef FORCE_UPDATE
#$(driverlist.h): FORCE
#endif
#endif
#
# Generate some info on the build details
#
about.o about.d: $(build_details.h)
$(build_details.h): $(srcdir)depend/scripts/build_details.cpp
@$(CXX) -mconsole $(CXXFLAGS) $(LDFLAGS) $< -o $(objdir)depend/generated/build_details.exe
@$(objdir)depend/generated/build_details.exe >$@
#
# Compile 68000 cores
#
# A68K
ifdef BUILD_A68K
$(a68k.o): fba_make68k.c
@echo Compiling A68K MC68000 core...
@$(CC) -mconsole $(CFLAGS) $(LDFLAGS) -DWIN32 -Wno-unused -Wno-conversion -Wno-missing-prototypes \
-s $< -o $(subst $(srcdir),$(objdir),$(<D))/$(<F:.c=.exe)
@$(subst $(srcdir),$(objdir),$(<D))/$(<F:.c=.exe) $(@:.o=.asm) \
$(@D)/a68k_tab.asm 00 $(ppro)
@echo Assembling A68K MC68000 core...
@$(AS) $(ASFLAGS) $(@:.o=.asm) -o $@
endif
# Musashi
$(objdir)cpu/m68k/m68kcpu.o: $(srcdir)cpu/m68k/m68kcpu.c $(objdir)depend/generated/m68kops.h $(srcdir)cpu/m68k/m68k.h $(srcdir)cpu/m68k/m68kconf.h
@echo Compiling Musashi MC680x0 core \(m68kcpu.c\)...
@$(CC) $(CFLAGS) -c $(srcdir)cpu/m68k/m68kcpu.c -o $(objdir)cpu/m68k/m68kcpu.o
$(objdir)cpu/m68k/m68kops.o: $(objdir)cpu/m68k/m68kmake.exe $(objdir)depend/generated/m68kops.h $(objdir)depend/generated/m68kops.c $(srcdir)cpu/m68k/m68k.h $(srcdir)cpu/m68k/m68kconf.h
@echo Compiling Musashi MC680x0 core \(m68kops.c\)...
@$(CC) $(CFLAGS) -c $(objdir)depend/generated/m68kops.c -o $(objdir)cpu/m68k/m68kops.o
$(objdir)cpu/m68k/m68kopac.o: $(objdir)cpu/m68k/m68kmake.exe $(objdir)depend/generated/m68kops.h $(objdir)depend/generated/m68kopac.c $(srcdir)cpu/m68k/m68k.h $(srcdir)cpu/m68k/m68kconf.h
@echo Compiling Musashi MC680x0 core \(m68kopac.c\)...
@$(CC) $(CFLAGS) -c $(objdir)depend/generated/m68kopac.c -o $(objdir)cpu/m68k/m68kopac.o
$(objdir)cpu/m68k/m68kopdm.o: $(objdir)cpu/m68k/m68kmake.exe $(objdir)depend/generated/m68kops.h $(objdir)depend/generated/m68kopdm.c $(srcdir)cpu/m68k/m68k.h $(srcdir)cpu/m68k/m68kconf.h
@echo Compiling Musashi MC680x0 core \(m68kopdm.c\)...
@$(CC) $(CFLAGS) -c $(objdir)depend/generated/m68kopdm.c -o $(objdir)cpu/m68k/m68kopdm.o
$(objdir)cpu/m68k/m68kopnz.o: $(objdir)cpu/m68k/m68kmake.exe $(objdir)depend/generated/m68kops.h $(objdir)depend/generated/m68kopnz.c $(srcdir)cpu/m68k/m68k.h $(srcdir)cpu/m68k/m68kconf.h
@echo Compiling Musashi MC680x0 core \(m68kopnz.c\)...
@$(CC) $(CFLAGS) -c $(objdir)depend/generated/m68kopnz.c -o $(objdir)cpu/m68k/m68kopnz.o
$(objdir)depend/generated/m68kops.h: $(objdir)cpu/m68k/m68kmake.exe $(srcdir)cpu/m68k/m68k_in.c
$(objdir)/cpu/m68k/m68kmake $(objdir)depend/generated/ $(srcdir)cpu/m68k/m68k_in.c
$(objdir)cpu/m68k/m68kmake.exe: $(srcdir)cpu/m68k/m68kmake.c
@echo Compiling Musashi MC680x0 core \(m68kmake.c\)...
@$(CC) $(CFLAGS) $(srcdir)cpu/m68k/m68kmake.c -o $(objdir)cpu/m68k/m68kmake.exe
#
# Extra rules for generated header file cvt.h, needed by ctv.cpp
#
ctv.d ctv.o: $(ctv.h)
$(ctv.h): ctv_make.cpp
@echo Generating $(srcdir)depend/generated/$(@F)...
@$(CC) -mconsole $(CXXFLAGS) $(LDFLAGS) $< \
-o $(subst $(srcdir),$(objdir),$(<D))/$(<F:.cpp=.exe)
@$(subst $(srcdir),$(objdir),$(<D))/$(<F:.cpp=.exe) >$@
#
# Extra rules for generated header file toa_gp9001_func.h, needed by toa_gp9001.cpp
#
toa_bcu2.d toa_bcu2.o toa_gp9001.d toa_gp9001.o: $(toa_gp9001_func.h)
$(toa_gp9001_func.h): $(srcdir)depend/scripts/toa_gp9001_func.pl
@$(srcdir)depend/scripts/toa_gp9001_func.pl -o $(toa_gp9001_func.h)
#
# Extra rules for generated header file neo_sprite_func.h, needed by neo_sprite.cpp
#
neo_sprite.d neo_sprite.o: $(neo_sprite_func.h)
$(neo_sprite_func.h): $(srcdir)depend/scripts/neo_sprite_func.pl
@$(srcdir)depend/scripts/neo_sprite_func.pl -o $(neo_sprite_func.h)
#
# Extra rules for generated header file cave_tile_func.h, needed by cave_tile.cpp
#
cave_tile.d cave_tile.o: $(cave_tile_func.h)
$(cave_tile_func.h): $(srcdir)depend/scripts/cave_tile_func.pl
@$(srcdir)depend/scripts/cave_tile_func.pl -o $(cave_tile_func.h)
#
# Extra rules for generated header file cave_sprite_func.h, needed by cave_sprite.cpp
#
cave_sprite.d cave_sprite.o: $(cave_sprite_func.h)
$(cave_sprite_func.h): $(srcdir)depend/scripts/cave_sprite_func.pl
@$(srcdir)depend/scripts/cave_sprite_func.pl -o $(cave_sprite_func.h)
#
# Extra rules for generated header file psikyo_tile_func.h / psikyo_sprite_func.h, needed by psikyo_tile.cpp / psikyo_sprite.cpp
#
psikyo_tile.d psikyo_tile.o psikyosprite.d psikyo_sprite.o: $(psikyo_tile_func.h)
$(psikyo_tile_func.h): $(srcdir)depend/scripts/psikyo_tile_func.pl
$(srcdir)depend/scripts/psikyo_tile_func.pl -o $(psikyo_tile_func.h)
#
# Extra rules for generated header file pgm_sprite.h, needed by pgm_draw.cpp
#
pgm_draw.d pgm_draw.o: $(pgm_sprite.h)
$(pgm_sprite.h): pgm_sprite_create.cpp
@echo Generating $(srcdir)depend/generated/$(@F)...
@$(CC) -mconsole $(CXXFLAGS) $(LDFLAGS) $< \
-o $(subst $(srcdir),$(objdir),$(<D))/$(<F:.cpp=.exe)
@$(subst $(srcdir),$(objdir),$(<D))/$(<F:.cpp=.exe) >$@
ifeq ($(MAKELEVEL),2)
ifdef DEPEND
include $(alldep)
endif
endif
#
# Generic rules for C/C++ files
#
ifeq ($(MAKELEVEL),1)
%.o: %.cpp
@echo Compiling $<...
@$(CC) $(CXXFLAGS) -c $< -o $(subst $(srcdir),$(objdir),$(<D))/$(@F)
%.o: %.c
@echo Compiling $<...
@$(CC) $(CFLAGS) -c $< -o $(subst $(srcdir),$(objdir),$(<D))/$(@F)
%.o: %.asm
@echo Assembling $<...
@$(AS) $(ASFLAGS) $< -o $(subst $(srcdir),$(objdir),$(<D))/$(@F)
else
%.o: %.c
@echo Compiling $<...
@$(CC) $(CFLAGS) -c $< -o $@
%.o: %.asm
@echo Assembling $<...
@$(AS) $(ASFLAGS) $< -o $@
%.o:
@echo Compiling $<...
@$(CC) $(CXXFLAGS) -c $< -o $@
endif
#
# Generate dependencies for C/C++ files
#
ifdef DEPEND
%.d: %.c
@echo Generating depend file for $<...
@$(CC) -MM -MT "$(subst $(srcdir),$(objdir),$(<D))/$(*F).o $(subst $(srcdir),$(objdir),$(<D))/$(@F)" -x c++ $(CXXFLAGS) $< >$(subst $(srcdir),$(objdir),$(<D))/$(@F)
%.d: %.cpp
@echo Generating depend file for $<...
@$(CC) -MM -MT "$(subst $(srcdir),$(objdir),$(<D))/$(*F).o $(subst $(srcdir),$(objdir),$(<D))/$(@F)" -x c++ $(CXXFLAGS) $< >$(subst $(srcdir),$(objdir),$(<D))/$(@F)
%.d: %.rc
@echo Generating depend file for $<...
@$(CC) -MM -MT "$(subst $(srcdir),$(objdir),$(<D))/$(*F).o $(subst $(srcdir),$(objdir),$(<D))/$(@F)" -x c++ $(CXXFLAGS) $< >$(subst $(srcdir),$(objdir),$(<D))/$(@F)
endif
#
# Phony targets
#
init:
ifdef DEBUG
@echo Making debug build...
else
@echo Making normal build...
endif
@echo
@mkdir -p $(foreach dir, $(alldir),$(objdir)$(dir))
@mkdir -p $(srcdir)depend/generated
cleandep:
@echo Removing depend files from $(objdir)...
-@for dir in $(alldir); do rm -f $(objdir)$$dir/*.d; done
touch:
@echo Marking all targets for $(NAME) as uptodate...
-@touch $(NAME).exe
-@touch -c -r $(NAME).exe $(srcdir)/depend/generated/*
-@for dir in $(alldir); do touch -c -r $(NAME).exe $(objdir)$$dir/*; done
clean:
@echo Removing all files from $(objdir)...
-@rm -f -r $(objdir)
-@rm -f -r $(ctv.h)
ifdef PERL
@echo Removing all files generated with perl scripts...
-@rm -f -r $(driverlist)
endif
#
# Rule to force recompilation of any target that depends on it
#
FORCE: