Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow cross compiling #17

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 46 additions & 16 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -18,30 +18,58 @@ VPATH=src $(wildcard src/cpu/*)
# compiler, linker and utilities
MD = @mkdir -p
RM = rm -f
CC = gcc
CPP = g++
AS = as
LD = gcc
STRIP = strip
CC ?= $(CROSS_COMPILE)gcc
CXX ?= $(CROSS_COMPILE)g++
AS ?= $(CROSS_COMPILE)as
STRIP ?= $(CROSS_COMPILE)strip
PKGCONF ?= pkg-config

EMULATOR = $(TARGET)$(EXE)

DEFS = -DGP2X -DLSB_FIRST -DALIGN_INTS -DALIGN_SHORTS -DINLINE="static __inline" -Dasm="__asm__ __volatile__" -DMAME_UNDERCLOCK -DENABLE_AUTOFIRE -DBIGCASE
##sq DEFS = -DGP2X -DLSB_FIRST -DALIGN_INTS -DALIGN_SHORTS -DINLINE="static __inline" -Dasm="__asm__ __volatile__" -DMAME_UNDERCLOCK -DMAME_FASTSOUND -DENABLE_AUTOFIRE -DBIGCASE

HAS_PKGCONF := $(if $(shell which $(PKGCONF)),yes,no)

ifeq ($(HAS_PKGCONF),yes)
SDL_CFLAGS ?= $(shell $(PKGCONF) --cflags sdl)
SDL_LIBS ?= $(shell $(PKGCONF) --libs sdl)
VCSM_CFLAGS ?= $(shell $(PKGCONF) --cflags vcsm)
VCSM_LIBS ?= $(shell $(PKGCONF) --libs vcsm)
EGL_CFLAGS ?= $(shell $(PKGCONF) --cflags egl)
EGL_LIBS ?= $(shell $(PKGCONF) --libs egl)
GLIB_CFLAGS ?= $(shell $(PKGCONF) --cflags glib-2.0)
GLIB_LIBS ?= $(shell $(PKGCONF) --libs glib-2.0)
ALSA_CFLAGS ?= $(shell $(PKGCONF) --cflags alsa)
ALSA_LIBS ?= $(shell $(PKGCONF) --libs alsa)
else
SDL_CFLAGS ?= -I/usr/include/SDL
SDL_LIBS ?= -lSDL
VCSM_CFLAGS ?= -I$(SDKSTAGE)/opt/vc/include
VCSM_LIBS ?= -L$(SDKSTAGE)/opt/vc/lib
EGL_CFLAGS ?= -I$(SDKSTAGE)/opt/vc/include/interface/vcos/pthreads -I$(SDKSTAGE)/opt/vc/include/interface/vmcs_host/linux
EGL_LIBS ?= -lbcm_host -lbrcmGLESv2 -lbrcmEGL
GLIB_CFLAGS ?= -I/usr/include/glib-2.0 -I/usr/lib/arm-linux-gnueabihf/glib-2.0/include
GLIB_LIBS ?= -lglib-2.0
ALSA_CFLAGS ?=
ALSA_LIBS ?= -lasound
endif


CFLAGS += -fsigned-char $(DEVLIBS) \
-Isrc -Isrc/$(MAMEOS) -Isrc/zlib \
-I/usr/include/SDL \
-I$(SDKSTAGE)/opt/vc/include -I$(SDKSTAGE)/opt/vc/include/interface/vcos/pthreads \
-I$(SDKSTAGE)/opt/vc/include/interface/vmcs_host/linux \
-I/usr/include/glib-2.0 -I/usr/lib/arm-linux-gnueabihf/glib-2.0/include \
$(SDL_CFLAGS) \
$(VCSM_CFLAGS) \
$(EGL_CFLAGS) \
$(GLIB_CFLAGS) \
$(ALSA_CFLAGS) \
-O3 -ffast-math -fno-builtin -fsingle-precision-constant \
-Wall -Wno-sign-compare -Wunused -Wpointer-arith -Wcast-align -Waggregate-return -Wshadow \
-Wno-narrowing

LDFLAGS = $(CFLAGS)

LIBS = -lm -lpthread -lSDL -L$(SDKSTAGE)/opt/vc/lib -lbcm_host -lbrcmGLESv2 -lbrcmEGL -lglib-2.0 -lasound -lrt
LIBS = -lm -ldl -lpthread -lrt $(SDL_LIBS) $(VCSM_LIBS) $(EGL_LIBS) $(GLIB_LIBS) $(ALSA_LIBS)

OBJ = obj_$(TARGET)_$(MAMEOS)
OBJDIRS = $(OBJ) $(OBJ)/cpu $(OBJ)/sound $(OBJ)/$(MAMEOS) \
Expand All @@ -60,25 +88,27 @@ include src/$(MAMEOS)/$(MAMEOS).mak
# combine the various definitions to one
CDEFS = $(DEFS) $(COREDEFS) $(CPUDEFS) $(SOUNDDEFS)

$(EMULATOR): $(COREOBJS) $(OSOBJS) $(DRVOBJS)
$(LD) $(LDFLAGS) $(COREOBJS) $(OSOBJS) $(LIBS) $(DRVOBJS) -o $@
$(STRIP) $(EMULATOR)
$(EMULATOR): $(OBJ)/$(EMULATOR)
$(STRIP) -o $@ $<

$(OBJ)/$(EMULATOR): $(COREOBJS) $(OSOBJS) $(DRVOBJS)
$(CC) $(LDFLAGS) $(COREOBJS) $(OSOBJS) $(LIBS) $(DRVOBJS) -o $@

$(OBJ)/%.o: src/%.c
@echo Compiling $<...
$(CC) $(CDEFS) $(CFLAGS) -c $< -o $@

$(OBJ)/%.o: src/%.cpp
@echo Compiling $<...
$(CPP) $(CDEFS) $(CFLAGS) -fno-rtti -c $< -o $@
$(CXX) $(CDEFS) $(CFLAGS) -fno-rtti -c $< -o $@

$(OBJ)/%.o: src/%.s
@echo Compiling $<...
$(CPP) $(CDEFS) $(CFLAGS) -c $< -o $@
$(CXX) $(CDEFS) $(CFLAGS) -c $< -o $@

$(OBJ)/%.o: src/%.S
@echo Compiling $<...
$(CPP) $(CDEFS) $(CFLAGS) -c $< -o $@
$(CXX) $(CDEFS) $(CFLAGS) -c $< -o $@

$(sort $(OBJDIRS)):
$(MD) $@
Expand Down