1
votes

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
Please show us one of the 1000 makefiles (which you don't want to alter).Beta
include ~/project/make/common.make ; # most makefiles creates binaries and objects files followed by this common include. Which was done in output directory earlier with links. But now links are removed. Each makefile uses different variable name for referring sources and objects. Hence there is no way of changing in common. Now compilation should happen in source directory and the output should come to output directory. Is there anything I can do in common.make to have my all binaries and objects in output directory? Changing the directory is the best option which I do not know how to do it.Jegan
What you're asking might be possible, but it depends on the makefiles and how you call them. There is no solution that works for all possible makefiles, but there might be one that works for your particular makefiles, or most of them. If you give us the information we ask for, maybe we can help you.Beta
Ok I understand. How do I do attach the file here?Jegan
If it's not more than 40 lines or so, just edit your question again to append it. (If it's longer, you should shorten it first.) And tell us how you invoke it (e.g. make or make foo or make DEST=somedir).Beta

1 Answers

1
votes