Liiiim
November 17th, 2011, 08:36 PM
I'm trying to create a simple makefile for my project, but I'm running into some issues. Here it is...
DIR=./
OBJECTS=$(DIR)main.o $(DIR)ui.o $(DIR)screen.o $(DIR)parsefile.o $(DIR)machine.o $(DIR)instructions.o
CC=gcc
CFLAGS=`pkg-config --cflags gtk+-2.0` -c -Wall
LDFLAGS=`pkg-config --libs gtk+-2.0`
EXE=sim
windows: DIR=./windows/
windows: CC=i486-mingw32-gcc
windows: CFLAGS=`pkg-config-script --cflags gtk+-2.0` -c -mms-bitfields -O2 -mwindows -Wall
windows: LDFLAGS=`pkg-config-script --libs gtk+-2.0`
widnows: EXE=sim.exe
windows: $(OBJECTS)
$(CC) $(LDFLAGS) $(OBJECTS) -o $(DIR)$(EXE)
all: $(OBJECTS)
$(CC) $(LDFLAGS) $(OBJECTS) -o $(DIR)$(EXE)
$(DIR)main.o: main.c common.h
$(CC) $(CFLAGS) main.c -o $(DIR)$@
$(DIR)ui.o: ui.c common.h
$(CC) $(CFLAGS) ui.c -o $(DIR)$@
$(DIR)parsefile.o: parsefile.c common.h
$(CC) $(CFLAGS) parsefile.c -o $(DIR)$@
$(DIR)machine.o: machine.c common.h instructions.h
$(CC) $(CFLAGS) machine.c -o $(DIR)$@
$(DIR)instructions.o: instructions.c instructions.h
$(CC) $(CFLAGS) instructions.c -o $(DIR)$@
$(DIR)screen.o: screen.c common.h
$(CC) $(CFLAGS) screen.c -o $(DIR)$@
clean:
rm *.o
rm ./windows/*.o
It's supposed to let you run 'make all', 'make windows', or 'make clean' to compile the program for Linux, for Windows, or remove the object files. Running 'make all' works, running 'make clean' works, and running 'make windows' after 'make clean' works, but if I run 'make windows' after 'make all' it doesn't compile new object files. I assume it's because it's checking the object files as defined originally, without the new value of DIR. But I tried setting OBJECTS again, with
windows: OBJECTS=$(DIR)main.o $(DIR)ui.o $(DIR)screen.o $(DIR)parsefile.o $(DIR)machine.o $(DIR)instructions.o after setting a new value of DIR and it still doesn't build the object files. This is the first Makefile I've tried to write, so I'm a little clueless. Does anyone know how I would accomplish what I'm trying to do?
Any advice is much appreciated :)
DIR=./
OBJECTS=$(DIR)main.o $(DIR)ui.o $(DIR)screen.o $(DIR)parsefile.o $(DIR)machine.o $(DIR)instructions.o
CC=gcc
CFLAGS=`pkg-config --cflags gtk+-2.0` -c -Wall
LDFLAGS=`pkg-config --libs gtk+-2.0`
EXE=sim
windows: DIR=./windows/
windows: CC=i486-mingw32-gcc
windows: CFLAGS=`pkg-config-script --cflags gtk+-2.0` -c -mms-bitfields -O2 -mwindows -Wall
windows: LDFLAGS=`pkg-config-script --libs gtk+-2.0`
widnows: EXE=sim.exe
windows: $(OBJECTS)
$(CC) $(LDFLAGS) $(OBJECTS) -o $(DIR)$(EXE)
all: $(OBJECTS)
$(CC) $(LDFLAGS) $(OBJECTS) -o $(DIR)$(EXE)
$(DIR)main.o: main.c common.h
$(CC) $(CFLAGS) main.c -o $(DIR)$@
$(DIR)ui.o: ui.c common.h
$(CC) $(CFLAGS) ui.c -o $(DIR)$@
$(DIR)parsefile.o: parsefile.c common.h
$(CC) $(CFLAGS) parsefile.c -o $(DIR)$@
$(DIR)machine.o: machine.c common.h instructions.h
$(CC) $(CFLAGS) machine.c -o $(DIR)$@
$(DIR)instructions.o: instructions.c instructions.h
$(CC) $(CFLAGS) instructions.c -o $(DIR)$@
$(DIR)screen.o: screen.c common.h
$(CC) $(CFLAGS) screen.c -o $(DIR)$@
clean:
rm *.o
rm ./windows/*.o
It's supposed to let you run 'make all', 'make windows', or 'make clean' to compile the program for Linux, for Windows, or remove the object files. Running 'make all' works, running 'make clean' works, and running 'make windows' after 'make clean' works, but if I run 'make windows' after 'make all' it doesn't compile new object files. I assume it's because it's checking the object files as defined originally, without the new value of DIR. But I tried setting OBJECTS again, with
windows: OBJECTS=$(DIR)main.o $(DIR)ui.o $(DIR)screen.o $(DIR)parsefile.o $(DIR)machine.o $(DIR)instructions.o after setting a new value of DIR and it still doesn't build the object files. This is the first Makefile I've tried to write, so I'm a little clueless. Does anyone know how I would accomplish what I'm trying to do?
Any advice is much appreciated :)