Friday, September 19, 2014

Developing cross platform program/game from ground up - part 3


Ok, now I'm going explain a bit more about Makesfiles, and also try to condense this makefile.os4 and makefile.os3 and makefile.linux into one file.

Forst of all now we description how to build 4 different .o files, but we are using gcc to generate this files in the same way.

obj/display.o:
          gcc os3/display.c -o obj/display.o -c

obj/filesystem.o:
          gcc os3/filesystem.c -o obj/filesystem.o -c

obj/joystick.o:
          gcc os3/joystick.c -o obj/joystick.o -c

obj/audio.o:
          gcc os3/audio.c -o obj/audio.o -c

however this can be written as.

obj/%.o: $(os)/%.c
          gcc $< -o $@ -c

I know this looks cryptic but what it does is when compiler is looking for obj/filesystem.o it will use label obj/%.o as it matches the filename, $(os)/%.c means that linux/filesystem.c is needed by obj/filesystem.o.

The next line gcc $< -o $@ -c work like this.

$< is replaced by whats after the label so its going to be $(os)/%.c and this translated into linux/filesystem.c

$@ is synonym with the name to compile.

So if this is the filesystem that is compiled it will be interpreted by the compiler as:.

gcc linux/filesystem.c -o obj/filesystem.o -c

so this two lines do the same as the 8 line in the first example.

And also you can easily change build target to OS4 or OS3 or Linux or what ever you like.

By setting os=linux or os=os4 or os=os3, simple do you agree?

No comments:

Post a Comment