List Info

Thread: Re: targets in subdirectories




Re: targets in subdirectories
country flaguser name
United States
2007-06-20 09:37:53
Thanks Paul for the reply --
 
Good point -- it IS using the default rule: %.o : %.c --
how do I circumvent that? ; I am using this as part of recursive make process, so the real
(ultimate) target is not listed in this makefile.   At the risk of too much disclosure, here is the entire makefile (with my voluminous comments removed):
 
Of course, constructive comments are always welcome -- you have a better way -- Great -- let me know. ;
 
But my primary concern is: how do I keep the object files out of the directory with the source files. 
 
Thanks (and apologies) to everyone!
 
-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) ;         ;     
&nbsp;   $(CC) -H $(CFLAGS) $< -o $*.o  2> ; $*._deplist ; &nbsp; &nbsp; &nbsp;  
&nbsp; &nbsp; perl -w $(PROJ_ROOT)/mkdep.pl $* $(SHADOW_TREE) $(PROJ_ROOT) $*._deplist ; &nbsp;
 &nbsp;  echo $(BUILD_DIR)/$*.o >> $(BUILD_DIR)/objlist.txt ;&nbsp;   ; &nbsp; 
&nbsp; &nbsp; rm -f $*._deplist ;&nbsp; &nbsp; &nbsp;   ; &nbsp; &nbsp; &nbsp; 
  ;  mv $*.o $(BUILD_DIR) ;
 
$(BUILD_DIR)/%.o : %.c
    echo "using real rule" ;
 &nbsp;  mkdir -p $(BUILD_DIR) ;&nbsp; &nbsp;   ; &nbsp;
 &nbsp;  $(CC) $(CFLAGS)&nbsp; $< ; -o $ ; &nbsp; &nbsp; &nbsp; 
 &nbsp;  echo $(BUILD_DIR)/$ >> $(BUILD_DIR)/objlist.txt; &nbsp;
 ; &nbsp; cp $ $(BUILD_DIR)

.PHONY : local_package
local_package : $(objects)
 $(foreach subdir, $(subsystems), $(MAKE) -C $(subdir);
 
%.o : %.c
   echo "using default rule"
 
.PHONY : clean
clean :
 &nbsp; echo Cleaning
&nbsp;  rm -f *.a $(objects) *.L *.swp *~ *.d
   rm -f $(foreach srcfile, $(sources), $(SHADOW_TREE)/$(srcfile:.c=.d))
 &nbsp; rm -f $(foreach srcfile, $(sources), $(BUILD_DIR)/$(srcfile:.c=.o))
#
# eof: Makefile
#


Paul Smith <psmithgnu.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

Re: targets in subdirectories
country flaguser name
United States
2007-06-20 10:03:47
On 2007-06-20 14:37Z, kilgore trout wrote:
>  
> Good point -- it IS using the default rule: %.o : %.c
--
> how do I circumvent that?

You can cancel all builtin rules with '--no-builtin-rules'.
Also see "Canceling Implicit Rules" in the
manual.


_______________________________________________
Help-make mailing list
Help-makegnu.org
http:
//lists.gnu.org/mailman/listinfo/help-make

[1-2]

about | contact  Other archives ( Real Estate discussion Medical topics )