1 2 Previous Next 15 Replies Latest reply: Nov 23, 2011 1:27 AM by NikMolchanov RSS

    vpath doesn't work?

    10605701
      I have a simple make file like this:

      vpath %.c ${WPCP}:${CPCP}
      vpath %.pc ${WPGM}:${CPGM}
      vpath %.o $(WOBJ):$(COBJ)

      PCCFLAGS = maxopencursors=30 \
      sqlcheck=semantics \
      userid=$(USERID) \
      code=ansi_c mode=oracle ltype=none \
      include=$(WINC) include=$(CINC) \
      include=$(ORACLE_HOME_DTB)/rdbms/public \
      $(DEBUGPL)

      foo.c: foo.pc
      proc $(PCCFLAGS) oname=${WPCP}/$*.c iname=$<;\

      CFLAG = $(DBG) $(DEBUG) \
      $(ICIS_CC_OPT) \
      -I $(WINC) -I $(CINC) \
      -I$(ORACLE_HOME_DTB)/rdbms/demo \
      -I$(ORACLE_HOME_DTB)/rdbms/public \
      -I$(ORACLE_HOME_DTB)/precomp/public \
      $(C64BIT:64=-q64)
      foo.o: foo.c
      $(CC) $(CFLAG) -fPIC -c $< -o ${WOBJ}/$*.o

      If I make foo.c, then make foo.o (in two separate steps), it works fine.
      But if I directly make foo.o, it says foo.c not found after foo.c is actually generated.
      So what is the problem here? Does 'cc' somehow runs before foo.c is generated, or doesn't vpath work?

      Edited by: 10605701 on 2011/11/15 上午 12:41
        • 1. Re: vpath doesn't work?
          10605701
          And, if I am in the directory where .c should be, then, make foo.o also works. But if I am not in that directory, then cc complains that foo.c doesn't exist if I directly make foo.o. So it seems cc cannot search foo.c in vpath?
          • 2. Re: vpath doesn't work?
            paul_floyd
            Hi

            vpath is a GNU make extension to make. If you want to use vpath than you will need to use gmake (e.g., /usr/sfw/bin/gmake on Solaris 10) instead of Solaris make (e.g., /usr/xpg4/bin/make or /usr/ccs/bin/make).

            Paul
            • 3. Re: vpath doesn't work?
              10605701
              I am using Oracle Linux 5.7, not Solaris. Is this a wrong forum for me?
              • 4. Re: vpath doesn't work?
                10605701
                I just checked, on my system, make and gmake are the same. gmake is a link that points to make.
                • 5. Re: vpath doesn't work?
                  paul_floyd
                  Hi

                  I'd say that 'make' questions are a bit off topic. Linux rather than Solaris, thopugh, isn't off topic.

                  Paul
                  • 6. Re: vpath doesn't work?
                    paul_floyd
                    Hi

                    And I assume that make is gmake (make --version gives GNU Make version info).

                    I think that the problem is that foo.c is both a target and a dependency. When make starts to execute, all variables and rules will have been evaluated, and it's only when the 2nd rule triggers that make notices that the 2nd dependency (foo.c) didn't exist when it started.

                    One solution would be to combine the two rules into one, so instead of

                    foo.c: foo.pc
                    <tab>command to make foo.c from foop.c

                    foo.o: foo.c
                    <tab>command to make foo.o from foo.c

                    do this directly

                    foo.o: foo.pc
                    <tab>command to make foo.c from foo.pc
                    <tab>command to make foo.o from foo.c

                    Paul

                    Edited by: paul_floyd on Nov 21, 2011 8:36 AM
                    • 7. Re: vpath doesn't work?
                      10605701
                      I made the following modification by combining the two rules:

                      vpath %.c ${WPCP}:${CPCP}
                      vpath %.pc ${WPGM}:${CPGM}
                      vpath %.o $(WOBJ):$(COBJ)

                      #
                      .SUFFIXES: # Delete the default suffixes
                      .SUFFIXES: .pc .c .o .exe .so .fmb .fmx .pll .plx .mmb .mmx # Define our suffix list

                      PCCFLAGS = maxopencursors=30 sqlcheck=semantics userid=$(USERID) code=ansi_c mode=oracle ltype=none include=$(WINC) include=$(CINC) \
                      include=$(ORACLE_HOME_DTB)/rdbms/public $(DEBUGPL)

                      CFLAG = $(DBG) $(DEBUG) -I $(WINC) -I $(CINC) -I$(ORACLE_HOME_DTB)/rdbms/demo -I$(ORACLE_HOME_DTB)/rdbms/public \
                      -I$(ORACLE_HOME_DTB)/precomp/public $(C64BIT:64=-q64)

                      %.o: %.pc
                      export ORACLE_HOME=${ORACLE_HOME_DTB};\
                      proc $(PCCFLAGS) oname=${WPCP}/$*.c iname=$<;\
                      ls ${WPCP}/$*.c
                      $(CC) $(CFLAG) -fPIC -c $*.c -o ${WOBJ}/$*.o
                      ls -l ${WOBJ}/$*.o

                      Unluckily it still doesn't work:
                      --> cpl foo.o
                      Remaining argument = foo.o
                      Number of option = 0
                      Remaining argument = foo.o
                      export ORACLE_HOME=/u01/app/oracle/HOME;\
                      proc maxopencursors=30 sqlcheck=semantics userid=user/pwd@db1 code=ansi_c mode=oracle ltype=none include=/work/wk1/dtb/inclu
                      de include=/reference/ACCP/conf/dtb/include include=/u01/app/oracle/HOME/rdbms/public oname=/work/wk1/dtb/pgm/precomp/foo.c iname=/work/wk1/dtb/pgm/foo.pc;\
                      ls /work/wk1/dtb/pgm/precomp/foo.c

                      Pro*C/C++: Release 11.2.0.2.0 - Production on Tue Nov 22 09:02:54 2011

                      Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved.

                      System default option values taken from: /u01/app/oracle/HOME/precomp/admin/pcscfg.cfg

                      /work/wk1/dtb/pgm/precomp/foo.c
                      cc -I /work/wk1/dtb/include -I /reference/ACCP/conf/dtb/include -I/u01/app/oracle/HOME/rdbms/demo -I/u01/app/oracle/HOME/
                      rdbms/public -I/u01/app/oracle/HOME/precomp/public -fPIC -c foo.c -o /work/wk1/dtb/bin/obj/foo.o
                      cc: foo.c: No such file or directory
                      cc: no input files
                      make: *** [foo.o] Error 1

                      It still couldn't find foo.c, which was actually generated.
                      If I was in .c folder, then everything would be OK.
                      If I do a 'cd <.c folder>' before cc, it also works.

                      The same makefile worked under Aix, but now after migrating to Linux, it behaves differently.
                      • 8. Re: vpath doesn't work?
                        NikMolchanov
                        Well, this make file does not look as a "simple make file" to me :-)
                        Is it an automatically generated make file? Or you wrote it yourself?
                        Or probably there is a huge automatically generated make file,
                        and you tried to simplify it to localise the problem?
                        We do not support gmake, but I'm responsible for dmake, which is
                        a part of Oracle Solaris Studio product, so I can try to help you with
                        this make file problem. Can you provide more details about the directory
                        structure, where all files are, where you run "make"?

                        Thanks.
                        Nik
                        • 9. Re: vpath doesn't work?
                          10605701
                          The makefile is simplified from a more complicated one to demonstrate to problem. It can be further simlified. Let's say We put .pc in $WPGM, .c in $WPCP, .o in $WOBJ. We want to run make anywhere. For example, $WPGM=/dtb/pgm, $WOBJ=/dtb/bin/obj, $WPCP=/dtb/pgm/precomp.
                          I read a post here which seems to point out an issue:
                          http://mad-scientist.net/make/vpath.html
                          Do you think it is the case?
                          Thanks!
                          • 10. Re: vpath doesn't work?
                            NikMolchanov
                            10605701 wrote:
                            The makefile is simplified from a more complicated one to demonstrate to problem. It can be further simplified. Let's say We put .pc in $WPGM, .c in $WPCP, .o in $WOBJ. We want to run make anywhere. For example, $WPGM=/dtb/pgm, $WOBJ=/dtb/bin/obj, $WPCP=/dtb/pgm/precomp.
                            I read a post here which seems to point out an issue:
                            http://mad-scientist.net/make/vpath.html
                            Do you think it is the case?
                            Thanks!
                            Yes, I think this is an excellent explanation! But I guess it is not exactly what you want, unless you agree to use this approach instead of using VPATH.
                            I'll play a little with your make file and let you know if I see an acceptable solution.

                            Thanks.
                            Nik
                            • 11. Re: vpath doesn't work?
                              10605701
                              Right, the post figured out the problem but I don't really want to abandon vpath completely. My temporary solution is to issue a 'cd $WPCP' before invoking 'cc', but I don't like this solution. If you can have a better solution it will be much appreciated.
                              • 12. Re: vpath doesn't work?
                                NikMolchanov
                                I made a few small changes in your original make file to satisfy this recommendation: VPATH was designed to find sources, not targets
                                Here is my make file:

                                >
                                nikm@nikm-VGN-FW280J:~/dev/nikm/d1/d2$ cat Makefile
                                # Makefile to build a program using VPATH
                                # Example:
                                # $WPGM=/dtb/pgm, $WOBJ=/dtb/bin/obj, $WPCP=/dtb/pgm/precomp

                                WPCP=precomp
                                WOBJ=obj
                                WPGM=pgm

                                vpath %.c ${WPCP}:${CPCP}
                                vpath %.pc ${WPGM}:${CPGM}
                                vpath %.o $(WOBJ):$(COBJ)

                                PCCFLAGS = maxopencursors=30 \
                                sqlcheck=semantics \
                                userid=$(USERID) \
                                code=ansi_c mode=oracle ltype=none \
                                include=$(WINC) include=$(CINC) \
                                include=$(ORACLE_HOME_DTB)/rdbms/public \
                                $(DEBUGPL)

                                ${WPCP}/foo.c: foo.pc
                                     # proc $(PCCFLAGS) oname=${WPCP}/$*.c iname=$<;
                                     cp $< $@

                                CFLAG = $(DBG) $(DEBUG) \
                                $(ICIS_CC_OPT) \
                                -I $(WINC) -I $(CINC) \
                                -I$(ORACLE_HOME_DTB)/rdbms/demo \
                                -I$(ORACLE_HOME_DTB)/rdbms/public \
                                -I$(ORACLE_HOME_DTB)/precomp/public \
                                $(C64BIT:64=-q64)
                                ${WOBJ}/foo.o: foo.c
                                     #$(CC) $(CFLAG) -fPIC -c $< -o ${WOBJ}/$*.o
                                     cp $< $@

                                all: ${WOBJ}/foo.o

                                clean:
                                     rm -f ${WOBJ}/foo.o ${WPCP}/foo.c

                                >

                                Here is my build directory structure after 'make clean':

                                >
                                nikm@nikm-VGN-FW280J:~/dev/nikm/d1/d2$ make clean
                                rm -f obj/foo.o precomp/foo.c
                                nikm@nikm-VGN-FW280J:~/dev/nikm/d1/d2$ ls -l
                                -rw-r--r-- 1 nikm nikm 838 2011-11-22 21:03 Makefile
                                drwxr-xr-x 2 nikm nikm 4096 2011-11-22 21:05 obj
                                drwxr-xr-x 2 nikm nikm 4096 2011-11-22 20:59 pgm
                                drwxr-xr-x 2 nikm nikm 4096 2011-11-22 21:05 precomp
                                nikm@nikm-VGN-FW280J:~/dev/nikm/d1/d2$ ls -l obj
                                total 0
                                nikm@nikm-VGN-FW280J:~/dev/nikm/d1/d2$ ls -l precomp
                                total 0
                                nikm@nikm-VGN-FW280J:~/dev/nikm/d1/d2$ ls -l pgm
                                -rw-r--r-- 1 nikm nikm 0 2011-11-22 20:58 foo.pc
                                >

                                Here is the output from 'make all':
                                >
                                nikm@nikm-VGN-FW280J:~/dev/nikm/d1/d2$ make all
                                # proc maxopencursors=30 sqlcheck=semantics userid= code=ansi_c mode=oracle ltype=none include= include= include=/rdbms/public oname=precomp/precomp/foo.c iname=pgm/foo.pc;
                                cp pgm/foo.pc precomp/foo.c
                                #cc -I -I -I/rdbms/demo -I/rdbms/public -I/precomp/public -fPIC -c precomp/foo.c -o obj/obj/foo.o
                                cp precomp/foo.c obj/foo.o
                                >

                                Here is my build directory structure after 'make all':

                                >
                                nikm@nikm-VGN-FW280J:~/dev/nikm/d1/d2$ ls -l
                                -rw-r--r-- 1 nikm nikm 838 2011-11-22 21:03 Makefile
                                drwxr-xr-x 2 nikm nikm 4096 2011-11-22 21:06 obj
                                drwxr-xr-x 2 nikm nikm 4096 2011-11-22 20:59 pgm
                                drwxr-xr-x 2 nikm nikm 4096 2011-11-22 21:06 precomp
                                nikm@nikm-VGN-FW280J:~/dev/nikm/d1/d2$ ls -l obj
                                -rw-r--r-- 1 nikm nikm 0 2011-11-22 21:06 foo.o
                                nikm@nikm-VGN-FW280J:~/dev/nikm/d1/d2$ ls -l precomp
                                -rw-r--r-- 1 nikm nikm 0 2011-11-22 21:06 foo.c
                                >

                                Does it look close to what you want?

                                Thanks.
                                Nik
                                • 13. Re: vpath doesn't work?
                                  10605701
                                  If I understood well, you included the folder as part of the target, and performs a copy to put files to the right folder?
                                  • 14. Re: vpath doesn't work?
                                    NikMolchanov
                                    Yes, I changed the target to eliminate VPATH search in target name, and replaced compilation with "cp" just to make this example simpler.

                                    Thanks.
                                    Nik
                                    1 2 Previous Next