From bca5121051383933e5fdf15f6bcb04ddb797ac45 Mon Sep 17 00:00:00 2001 From: Kelly Rauchenberger Date: Mon, 22 Jun 2009 09:35:52 -0400 Subject: Added cross compiliation --- .hgignore | 1 + Makefile | 53 +++++++++++++++++++++++++++++++++-------------------- htpstate.cpp | 11 +++-------- resources.h | 25 +++++++++++-------------- titlestate.cpp | 7 ++----- 5 files changed, 50 insertions(+), 47 deletions(-) create mode 100644 .hgignore diff --git a/.hgignore b/.hgignore new file mode 100644 index 0000000..378eac2 --- /dev/null +++ b/.hgignore @@ -0,0 +1 @@ +build diff --git a/Makefile b/Makefile index a4fe8ff..e7429a5 100644 --- a/Makefile +++ b/Makefile @@ -1,27 +1,40 @@ -SOURCES = mazeoflife.cpp titlestate.cpp htpstate.cpp gamestate.cpp -OBJS = $(SOURCES:.cpp=.cpp.o) -IMAGES = title.bmp pointer.bmp htp1.bmp htp2.bmp -CIMAGES = $(IMAGES:.bmp=.bmp.o) +PROJECT = mazeoflife +LTARGET = build/$(PROJECT) +WTARGET = build/$(PROJECT).exe CC = g++ -CFLAGS = `pkg-config sdl --cflags` -LIBS = `pkg-config sdl --libs` +WINCC = i586-mingw32msvc-g++ +FILES = $(addprefix build/,$(wildcard *.cpp)) +MODULES = $(patsubst %.cpp,%,$(FILES)) +SOURCES = $(addsuffix .o,$(MODULES)) +WINSRC = $(addsuffix win,$(SOURCES)) +IMAGES = $(wildcard *.bmp) +CIMAGES = $(addprefix build/,$(IMAGES:.bmp=.bmp.o)) +LINCCFL = `sdl-config --cflags` +LINLDFL = `sdl-config --libs` +WINCCFL = `/opt/SDL-1.2.9/bin/i386-mingw32msvc-sdl-config --cflags` -DWINDOWS +WINLDFL = `/opt/SDL-1.2.9/bin/i386-mingw32msvc-sdl-config --libs` -mazeoflife: $(OBJS) $(CIMAGES) - $(CC) $(OBJS) $(CIMAGES) $(LIBS) -o mazeoflife +all: init $(LTARGET) $(WTARGET) +linux: init $(LTARGET) +windows: init $(WTARGET) -%.cpp.o: %.cpp - $(CC) -c $< $(CFLAGS) -o $@ +init: + mkdir -p build -%.d: %.cpp - @set -e; rm -f $@; \ - $(CC) -MM $(CFLAGS) $< > $@.$$$$; \ - sed 's,\($*\)\.o[ :]*,\1.o $@ : ,g' < $@.$$$$ > $@; \ - rm -f $@.$$$$ +clean: + rm -rdfv build -%.bmp.o: %.bmp - objcopy --input binary --output elf32-i386 -B i386 $< $@ +$(LTARGET): $(SOURCES) $(CIMAGES) + $(CC) $(SOURCES) $(CIMAGES) -o $(LTARGET) $(LINLDFL) -include $(OBJS:.cpp.o=.d) +$(SOURCES): build/%.o: %.cpp + $(CC) -c $? -o $@ $(LINCCFL) -clean: - rm -rdfv $(OBJS) $(OBJS:.cpp.o=.d) $(CIMAGES) mazeoflife +$(WTARGET): $(WINSRC) $(CIMAGES) + $(WINCC) $(WINSRC) $(CIMAGES) -o $(WTARGET) $(WINLDFL) + +$(WINSRC): build/%.owin: %.cpp + $(WINCC) -c $? -o $@ $(WINCCFL) + +$(CIMAGES): build/%.bmp.o: %.bmp + objcopy --input binary --output elf32-i386 -B i386 $? $@ diff --git a/htpstate.cpp b/htpstate.cpp index 30d58a2..8de884f 100644 --- a/htpstate.cpp +++ b/htpstate.cpp @@ -2,14 +2,9 @@ HowToPlayState::HowToPlayState() { - SDL_RWops *rw = SDL_RWFromMem(&_binary_htp1_bmp_start, (int) &_binary_htp1_bmp_size); - background1 = SDL_LoadBMP_RW(rw, 1); - - rw = SDL_RWFromMem(&_binary_htp2_bmp_start, (int) &_binary_htp2_bmp_size); - background2 = SDL_LoadBMP_RW(rw, 1); - - rw = SDL_RWFromMem(&_binary_pointer_bmp_start, (int) &_binary_pointer_bmp_size); - pointer = SDL_LoadBMP_RW(rw, 1); + LOADIMAGE(background1,htp1) + LOADIMAGE(background2,htp2) + LOADIMAGE(pointer,pointer) secondPage = false; selection = 0; diff --git a/resources.h b/resources.h index 4e01a90..457fbec 100644 --- a/resources.h +++ b/resources.h @@ -1,20 +1,17 @@ #ifndef RESOURCES_H #define RESOURCES_H -// title.bmp -extern int* _binary_title_bmp_start; -extern int* _binary_title_bmp_size; - -// pointer.bmp -extern int* _binary_pointer_bmp_start; -extern int* _binary_pointer_bmp_size; - -// htp1.bmp -extern int* _binary_htp1_bmp_start; -extern int* _binary_htp1_bmp_size; +#ifdef WINDOWS +#define LOADIMAGE(var,title) SDL_RWops * title ## _rw = SDL_RWFromMem(&binary_ ## title ## _bmp_start, (int) &binary_ ## title ## _bmp_size); var = SDL_LoadBMP_RW( title ## _rw, 1); +#define DEFIMAGE(title) extern int* binary_ ## title ## _bmp_start; extern int* binary_ ## title ## _bmp_size; +#else +#define LOADIMAGE(var,title) SDL_RWops * title ## _rw = SDL_RWFromMem(&_binary_ ## title ## _bmp_start, (int) &_binary_ ## title ## _bmp_size); var = SDL_LoadBMP_RW( title ## _rw, 1); +#define DEFIMAGE(title) extern int* _binary_ ## title ## _bmp_start; extern int* _binary_ ## title ## _bmp_size; +#endif -// htp2.bmp -extern int* _binary_htp2_bmp_start; -extern int* _binary_htp2_bmp_size; +DEFIMAGE(title) +DEFIMAGE(pointer) +DEFIMAGE(htp1) +DEFIMAGE(htp2) #endif diff --git a/titlestate.cpp b/titlestate.cpp index c011480..6c4401d 100644 --- a/titlestate.cpp +++ b/titlestate.cpp @@ -2,11 +2,8 @@ TitleState::TitleState() { - SDL_RWops *rw = SDL_RWFromMem(&_binary_title_bmp_start, (int) &_binary_title_bmp_size); - background = SDL_LoadBMP_RW(rw, 1); - - rw = SDL_RWFromMem(&_binary_pointer_bmp_start, (int) &_binary_pointer_bmp_size); - pointer = SDL_LoadBMP_RW(rw, 1); + LOADIMAGE(background,title) + LOADIMAGE(pointer,pointer) selection = 0; -- cgit 1.4.1