FlashBurn wrote:I want to edit the makefile every time I add a source file, because I have some .c files which should not get compiled and linked.
Put them in a different directory?
In PDCLib (my project), I explicitly excluded all .c files on the
top directory level from compilation, which allows me to have e.g. "test.c" and "test2.c" in my working dir without screwing up my make process.
I don´t know if I´m right, but with your solution it would not work, if I changed a header file that only the files get recompiled which include this header file!?
Dependencies are cumulative, i.e. the dependencies from your DEPFILE would still apply. My rule states the .c file as dependency so that I can use the implicit variables $@ and $< in the command line.
Also what are the other points you would improve my makefile? I´m always open for learning new things and making things better!
Don't define CC or LD within your Makefile. They are for the
user to override. Use ${CC} instead of 'gcc', but don't define it; 'make' will use a sensible default if it isn't defined, or use whatever the user did set to override it. See the 'make' manual for a list of these variables, and their defaults. I would even consider not defining CFLAGS and LDFLAGS either, as they are similarily used for user overrides.
Your targets 'dep' and 'loader' don't create a file of the same name, but '.depend' and 'osloader', respectively. That means those files get re-made every time, no matter if they're outdated or not. Use 'depend.d' (or something else) as both dependency file name and Makefile target, and either rename the 'loader' target to 'osloader', or the file 'osloader' to 'loader'.
Add '.PHONY: all iso clean' to state that those three targets should always be re-made, even if an up-to-date file of that name already exists. (Try 'touch clean', and your 'make clean' won't get executed unless you remove that file 'clean' again.
)
Try to replace:
Code: Select all
loader_16bit.o: $(PREFIX)loader_16bit.asm
nasm -O3 $(PREFIX)loader_16bit.asm -f bin -o loader_16bit.o
smp_startup.o: $(PREFIX)smp_startup.asm
nasm -O3 $(PREFIX)smp_startup.asm -f bin -o smp_startup.o
with:
Code: Select all
%.o: $(PREFIX)%.asm
nasm -O3 $(PREFIX)$< -f bin -o $@
Not sure if it works for your $PREFIX magic, but that way you can state generic rules, instead of repeating them for every file.