But my primary concern is: how do I keep the object files out of the directory with the source files.
-kt.
all : local_package
.DEFAULT_GOAL := local_package
SHELL = c:/msys/1.0/bin/sh.exe
# * * * * * * * * * * * * * * * * * * * * *
* * * * * * * * * * * *
# modify 'subsystems' to list all immediate subdirectories to be
# included in the build. Leave blank if there are none.
# * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
subsystems =
# PROJ_ROOT :- base directory of the project
ifndef PROJ_ROOT
PROJ_ROOT
= $(PWD)
echo "PROJ_ROOT is not set -- using current Working Dir: $(PROJ_ROOT)"
echo "This is probably wrong."
endif # DIAB_BIN_PATH :- path to the Diab compiler, linker, et al.
ifndef DIAB_BIN_PATH
DIAB_BIN_PATH = c:/diab/4.4b/WIN32/bin
endif
# if the Gnu compiler is considered the C compiler, change it to Diab.
ifeq ($(CC),gcc)
CC = $(DIAB_BIN_PATH)/dcc
endif
# if the compiler isn't defined, define it.
ifndef CC
CC = $(DIAB_BIN_PATH)/dcc
endif
ifndef INCLUDE_PATH
INCLUDE_PATH = -I$(PROJ_ROOT)/include -I$(PROJ_ROOT)
endif
ifndef TARGET_OPTIONS
TARGET_OPTIONS = -WDDTARGET=PPC555 -WDDOBJECT=E -WDDFP=H -WDDENVIRON=simple -WDDLINKOPT=yes
endif
# compiler flags
ifndef CFLAGS
CFLAGS = -g -c $(INCLUDE_PATH) -Xmismatch-warning=2
endif
ifndef LIB_TOOL
LIB_TOOL = $(DIAB_BIN_PATH)/dar
endif
ifndef ADD_LIBCMD
ADD_LIBCMD = -r
endif
ifndef BUILD_DIR
BUILD_DIR = $(PROJ_ROOT)/build_dir
endif
ifndef SHADOW_TREE_NAME
SHADOW_TREE_NAME=.shadow_tree
endif
objects = $(patsubst %.c,%.o,$(wildcard *.c))
sources = $(wildcard *.c)
CUR_DIR_NAMES = $(subst /, ,$(shell pwd))
NUM_WORDS = $(words $(CUR_DIR_NAMES))
DIR_NAMES = $(wordlist 2, $(NUM_WORDS), $(CUR_DIR_NAMES))
PROJ_PATH = $(subst /, ,$(PROJ_ROOT))
SUB_TREE = $(filter-out $(PROJ_PATH), $(DIR_NAMES))
TMP_PATH = $(PROJ_ROOT)/$(SHADOW_TREE_NAME)/$(SUB_TREE)
SHADOW_TREE = $(subst / ,/,$(foreach wd, $(TMP_PATH),$(wd)/))
VPATH = %.h include $(PROJ_ROOT)/include
VPATH = %.c
VPATH = %.o $(BUILD_DIR)
VPATH = %.d $(SHADOW_TREE)
$(SHADOW_TREE)%.d : %.c
mkdir -p $(SHADOW_TREE) ;
$(CC) -H $(CFLAGS) $< -o $*.o 2> $*._deplist ;
perl -w $(PROJ_ROOT)/mkdep.pl $* $(SHADOW_TREE) $(PROJ_ROOT) $*._deplist ;
echo $(BUILD_DIR)/$*.o >> $(BUILD_DIR)/objlist.txt ;
rm -f
$*._deplist ;
mv $*.o $(BUILD_DIR) ;
.PHONY : local_package
local_package : $(objects)
$(foreach subdir, $(subsystems), $(MAKE) -C $(subdir); )
%.o : %.c
echo "using default rule"
.PHONY : clean
clean :
echo Cleaning
rm -f *.a $(objects) *.L *.swp *~ *.d
rm -f
$(foreach srcfile, $(sources), $(SHADOW_TREE)/$(srcfile:.c=.d))
rm -f $(foreach srcfile, $(sources), $(BUILD_DIR)/$(srcfile:.c=.o))
#
# eof: Makefile
#
Paul Smith <psmith
gnu.org> wrote: On Wed, 2007-06-20 at 06:29 -0700, kilgore trout wrote:
> When the commands are echoed to the console, $
expands to CAN_init.o
> rather than c:/ashell/trunk/ashell/build_dir/CAN_init.o (where
> $(BUILD_DIR) is c:/ashell/trunk/ashell/build_dir ). So that the
> compiler output is put in the local (current) directory rather than
> $(BUILD_DIR)/CAN_init.o .
Are you SURE it's using that rule? I suspect it's really using the
default %.o : %.c rule. When it prints the commands does it show the
mkdir, etc. part?
You have only provided half of the information needed to
debug your
problem: you show the rule but not the prerequisites that match it.
Probably you have this somewhere in your makefile:
foo: foo.o bar.o baz.o
You can't do that: "foo.o" cannot match a pattern "$(BUILD_DIR)/%.o".
You have to write:
foo: $(BUILD_DIR)/foo.o $(BUILD_DIR)/bar.o $(BUILD_DIR)/baz.o
or use make functions like $(addprefix ...).
--
-------------------------------------------------------------------------------
Paul D. Smith GNU.ORG>Find some GNU make tips at:
http://www.gnu.org http://make.paulandlesley.org
"Please remain calm...I may be mad, but I am a professional." --Mad Scientist