I'm trying to remove any implementation specific (GNU Make) details from my Makefiles but having a hard time fixing some issues. The structure of my projects is like so;
1) The mere presence of an obj directory at the root level of my project causes BSD make to chdir to it before doing anything else. I can avoid this by putting compiled objects into tmp instead, but it is annoying nonetheless! What is the rationale behind this unexpected behaviour?
2) I have a GNU make pattern rule (see below) to allow building an object file in the obj directory tree from the respective source file in the src directory tree. I understand that POSIX make doesn't support pattern rules such as this, and instead one must use suffix rules such as .c.o instead. However, using a suffix rule does not seem to cope with the directory tree structure which is handled by the GNU make pattern rule;
Please could someone show an example of how this can be accomplished in a standards compliant way?
Thanks,
James
Code:
myapp/
Makefile
src/
foo/
foo1.c
foo2.c
bar/
bar1.c
obj/
1) The mere presence of an obj directory at the root level of my project causes BSD make to chdir to it before doing anything else. I can avoid this by putting compiled objects into tmp instead, but it is annoying nonetheless! What is the rationale behind this unexpected behaviour?
2) I have a GNU make pattern rule (see below) to allow building an object file in the obj directory tree from the respective source file in the src directory tree. I understand that POSIX make doesn't support pattern rules such as this, and instead one must use suffix rules such as .c.o instead. However, using a suffix rule does not seem to cope with the directory tree structure which is handled by the GNU make pattern rule;
Code:
$(OBJDIR)/%.o: $(SRCDIR)/%.c
@$(MKDIR) $(@D)
$(CC) $(CFLAGS) -c $< -o $@
Please could someone show an example of how this can be accomplished in a standards compliant way?
Thanks,
James