Page 1 of 1
Makefile
Posted: Wed May 25, 2011 9:35 pm
by Nessphoro
Okay guys this is killing me,
In my makefile, I tell it to use G++ along with some custom flags to compile, but those flags do not appear to work, they don't even appear in a command line.
Makefile:
CPP_FILES := $(wildcard source/*.cpp)
OBJ_FILES := $(patsubst %.cpp,%.o,$(CPP_FILES))
LD_FLAGS := -T linker.ld
CC_FLAGS := -ggdb -Wall -Wextra -nostdlib -fno-builtin -nostartfiles -nodefaultlibs -fno-exceptions -fno-rtti -fno-stack-protector -fleading-underscore
kernel.bin: $(OBJ_FILES) ; ld $(LD_FLAGS) -o kernel.bin boot.o $(OBJ_FILES)
source/%.o: source/%cpp ; g++ $(CC_FLAGS) -o $@ $<
P.S: LD_FLAGS work flawlessly
Re: Makefile Lulz
Posted: Wed May 25, 2011 10:46 pm
by bluemoon
Code: Select all
source/%.o: source/%cpp ; g++ $(CC_FLAGS) -o $@ $<
Do you mean
source/%.cpp?
if things does not match any rule, the default action would be made such as invoke g++ without your custom flags.
The easiest way is to replace or insert echo checkpoints to debug, which is essential skill for general programming.
Re: Makefile Lulz
Posted: Wed May 25, 2011 11:12 pm
by Solar
Code: Select all
source/%.o: source/%cpp ; g++ $(CC_FLAGS) -o $@ $<
What's the semicolon doing there?
Everything after the colon is the dependency. The command(s) to be executed should be on subsequent lines, starting with a tab. This is important!
Code: Select all
source/%.o: source/%.cpp
$(CXX) $(CC_FLAGS) -o $@ $<
You might want to check out the
Makefile tutorial for more things regarding 'make'.
Re: Makefile Lulz
Posted: Wed May 25, 2011 11:47 pm
by Nessphoro
Yeah thanks that worked, but how do I go on adding ASM code support, because this doesn't work
PROJECT_DIRS := source
CPP_FILES := $(wildcard source/*.cpp)
ASM_FILES :=$(wildcard source/*.asm)
OBJ_FILES := $(patsubst %.cpp,%.o,$(CPP_FILES))
ASM_OBJ :=$(patsubst %.asm,%.o,$(ASM_FILES))
LD_FLAGS := -T linker.ld
CC_FLAGS := -ggdb -Wall -Wextra -nostdlib -fno-builtin -nostartfiles -nodefaultlibs -fno-exceptions -fno-rtti -fno-stack-protector -fleading-underscore
kernel.bin: $(OBJ_FILES)
ld $(LD_FLAGS) -o kernel.bin $(OBJ_FILES) $(ASM_OBJ)
source/%.o: source/%.cpp
g++ $(CC_FLAGS) -o $@ $<
source/%.o: source/%.asm
nasm -f elf -o $@ $<
Re: Makefile Lulz
Posted: Thu May 26, 2011 12:07 am
by bluemoon
As a positive suggestion you should read
Getting_Started, specifically
Required Knowledge &
Toolchain
To your question, it's quite obvious you didn't include assembly files in your definition of OBJ_FILES; or otherwise include ASM_OBJ in kernel.bin.
Re: Makefile
Posted: Thu May 26, 2011 8:19 am
by Nessphoro
Gotcha,
Well sorry guys, I had my OS compiling but the problem was that it was a bash file and everytime I added a file, I needed to make changes myself, so I looked into makefile, even though with some fail
Re: Makefile
Posted: Mon May 30, 2011 3:11 am
by Solar
Make sure you really understand 'make'. Using a half-understood tool in a non-trivial project is an error source unto itself.
For example, your Makefile doesn't cater to changes made in header files. You change a constant in a header file, you might be in for a lengthy debug session before you realize that your object files didn't get recompiled. Might I recommend the
Makefile tutorial a second time?