Tuesday 14 August 2012

Crossplatform Development?

So. I'm finally going back to C++... and remembering why I learned Python to get away from certain things.

Most notably is the pain of setting up Makefiles by hand. Still. I think I've hit on something. Relative to my project's directory...

I have a folder for my build which contains a Makefile customised for that platform. On windows this is...
mingw_debug/Makefile:

CC=mingw32-gcc.exe
CXX=mingw32-g++.exe

CFLAGS=-g -O0 -Wall -pedantic -Wno-long-long
LIBS=-lmingw32 -lSDLmain -lSDL -lopengl32 -lphysfs

DLL=SDL.dll libphysfs.dll

include ../src/Makefile.core


It explicitly specifies CC and CXX because I tend to use Cygwin as a replacement shell and it allows me to use make instead of mingw32-make.exe.

src/Makefile.core

SOURCES=hello.cxx
OBJECTS=$(SOURCES:.cxx=.o)
DEPS=$(OBJECTS:.o=.d)

CFLAGS+=-I../src/

all: Coulomb.exe $(DLL)

-include $(DEPS)

Coulomb.exe: $(OBJECTS)
$(CXX) -o Coulomb.exe $(OBJECTS) $(LIBS)

define cc-command
$(CXX) -o $@ -c $< $(CFLAGS)
endef

define depend-command
$(CXX) -MM -MF $(patsubst %.o,%.d,$@) $< $(CFLAGS)
endef

data/%.o: ../src/data/%.cxx
$(depend-command)
$(cc-command)


%.o: ../src/%.cxx
$(depend-command)
$(cc-command)

%.dll: ../%.dll
cp $< .

.phony: all clean


clean:
rm -rf *.exe
rm -rf *.o
rm -rf data/*.o
rm -rf *.d
rm -rf data/*.d
rm -rf *.dll

Unfortunately I still don't really know what I'm going to do with this set up yet. I'd appreciate any comments on the Makefile set up though.

No comments:

Post a Comment