Change directory in makefile for main shell

3.3k views Asked by At

I have a following scenario in my build system.

1. 1000 makefiles in src directories
2. There is common.make file being included for all 1000 makefiles
3. links were created for makefiles and sources in object directory from source directory. Hence all makefiles and many more scripts inside makefile are written in such a way as it exists in build directory. 
4. obj directory is the dynamic location.
5. Now I removed all links.no more links in object directory.
6. I want to execute all makefiles in source directory where I expect to change the object directory (dynamic directory name) before executing. (I can't use make -C here, because I do not know what directory to change). I can set VPATH for finding sources.
7. I want to make use common.make to change the directory dynamically, but whatever cd, $(shell cd ...) I do in common.make is not reflected in main Makefile.
8. If I do not do this, I will end up in modifying all 1000 makefiles. I do not want to do this.

Please let me know the best of way of doing it. In simple words, I want to change the directory (through common.make) before executing my 1000 makefiles, 

I expect common.make to do the following.

1) save srcpath = current path (current path is source directory)
2) Change to output directory (Directory name is dynamic here).
3) set VPATH=srcpath 
4) now any makefile in source directory can make use of common.make to compile and have the binaries and objects in output directory.

# This is one of the sample Makefile. I have shortened this file. All makefiles are not using the same names like SRCS, CMDSRCS. It would be different.
# this is existing makefile. Source location /home/user/project/src/mod1/lib/resmgr>make BD=100. I want the output to 
# /home/user/project/build/swout100/mod1/lib/resmgr/*. common.make (common make) might validate the argument BD here. BD=101 is not allowed.
# We can force the user to do make -C /home/user/project/build/swout100/mod1/lib/resmgr (no BD validation here. user should know what directory to go). 
# I would expect common.make would help the user as utility makefile
TOPDIR        = ../../..
MAKEDIR        = $(TOPDIR)/make
include $(MAKEDIR)/common.make    # It is included in most makefiles. This can be treated as common makefile. I thought of modifying common.make
include ........  #(More includes here)
TARGET        = resmgrd
CMDSRCS        = resmgr_cli.c \
          resmgrlogshow.c \
# more source files here
CMDOBJS        = $(CMDSRCS:.c=.o)
CMDHNDLR    = resmgrcmd
#... CFLAGS here and library flags here
MDSRC        = main.c
SRCS        = resmgr.c \
#  more source files here
HDRS        = resmgr.h
MDOBJ        = $(MDSRC:.c=.o)
OBJS        = $(SRCS:.c=.o)
$(OBJS) $(MDOBJ) $(CMDOBJS): $(HDRS)
DEPENDSRCS    = $(MDSRC) $(SRCS) $(CMDSRCS)
ST_LIBS = $(DEVOSLIBSRC)/apixdr/libapixdr.a
$(TARGET):    $(MDOBJ) $(OBJS)
    $(CC) $(LDFLAGS) -o $@ $^ $(LDLIBS) $(ST_LIBS)
$(CMDHNDLR):    $(CMDOBJS)
    $(CC) $(LDFLAGS) -o $@ $^ $(DEVOSLIBS) $(IPCLIB) $(KILIB) $(MIAUXLIB) \
            $(RESMGRLIB) $(RBACLIB)
install::    install-server
install-server: $(TARGET) $(TARGET).options $(DEVOSSBINDIR) $(DEVOSCONFDIR)
    $(INSTALL) -m 755 $(TARGET) $(DEVOSSBINDIR)
install-commands:    $(DEVOSBINDIR)/$(CMDHNDLR) \
    install-admin-cmds install-user-cmds
clean::
    $(RM) $(OBJS) $(TARGET) $(SCRIPTS) $(RAWMAN) $(CMDHNDLR) $(ZIPMAN)

1

There are 1 answers

0
Jegan On BEST ANSWER

I found an answer to my question.

http://make.paulandlesley.org/multi-arch.html