title: Compiling .c files and .s files from different different subdirectories
body: <p>Here is my makefile <a href="http://pastie.org/1104332" rel="nofollow noreferrer">http://pastie.org/1104332</a>. I am trying to compile different .c files and .s files (assembly files) from different sub directories into E:/em35x/build/mfg-sample-app-cortexm3-iar-em357-em3xx-dev0680/ then the linker should link all the .o files from the build directory (E:/em35x/build/mfg-sample-app-cortexm3-iar-em357-em3xx-dev0680) into a file named mfg-sample-app.out.
  When I run the makefile which I posted above then the compiler compiles all the source files into object files in the build directory but the linker can not open the object files because its not looking for them in the build directory which is E:/em35x/build/mfg-sample-app-cortexm3-iar-em357-em3xx-dev0680. I dont know how why the linker does not look there? that is the error I get:</p>
  
  <pre><code>E:\IARSystems\EmbeddedWorkbench5.4Evaluation\arm\bin\ilinkarm.exe"      -o E:/e
  m35x/build/mfg-sample-app-cortexm3-iar-em357-em3xx-dev0680/mfg-sample-app.out --
  map E:/em35x/build/mfg-sample-app-cortexm3-iar-em357-em3xx-dev0680/mfg-sample-ap
  p.map --log initialization,modules,sections,veneers --log_file E:/em35x/build/mf
  g-sample-app-cortexm3-iar-em357-em3xx-dev0680/mfg-sample-app.log --config E:/em3
  5x/app/mfglib/ewb-em357/../../../hal/micro/cortexm3/em35x/em357/iar-cfg.icf --di
  ag_suppress Lp012 --entry halEntryPoint  E:/em35x/build/alarm-library-cortexm3-i
  ar-em357-em3xx/alarm-library.a E:/em35x/build/binding-table-stub-library-cortexm
  3-iar-em357-em3xx/binding-table-stub-library.a  E:/em35x/build/cbke-stub-library
  -cortexm3-iar-em357-em3xx/cbke-stub-library.a E:/em35x/build/end-device-bind-stu
  b-library-cortexm3-iar-em357-em3xx/end-device-bind-stub-library.a  E:/em35x/buil
  d/hal-library-cortexm3-iar-em357-em3xx/hal-library.a E:/em35x/build/mfglib-libra
  ry-cortexm3-iar-em357-em3xx/mfglib-library.a  E:/em35x/build/security-library-co
  re-cortexm3-iar-em357-em3xx/security-library-core.a E:/em35x/build/security-libr
  ary-link-keys-stub-cortexm3-iar-em357-em3xx/security-library-link-keys-stub.a E:
  /em35x/build/zigbee-pro-stack-cortexm3-iar-em357-em3xx/zigbee-pro-stack.a E:/em3
  5x/app/mfglib/mfg-sample.o E:/em35x/hal/ember-configuration.o E:/em35x/hal/micro
  /cortexm3/adc.o E:/em35x/hal/micro/cortexm3/bootloader-interface-app.o E:/em35x/
  hal/micro/cortexm3/bootloader-interface-standalone.o E:/em35x/hal/micro/cortexm3
  /bootloader-interface.o E:/em35x/hal/micro/cortexm3/button.o E:/em35x/hal/micro/
  cortexm3/buzzer.o E:/em35x/hal/micro/cortexm3/cstartup-iar-common.o E:/em35x/hal
  /micro/cortexm3/diagnostic.o E:/em35x/hal/micro/cortexm3/led.o E:/em35x/hal/micr
  o/cortexm3/mfg-token.o E:/em35x/hal/micro/cortexm3/micro-common.o E:/em35x/hal/m
  icro/cortexm3/micro.o E:/em35x/hal/micro/cortexm3/sleep.o E:/em35x/hal/micro/cor
  texm3/token-def.o E:/em35x/hal/micro/cortexm3/token.o E:/em35x/hal/micro/cortexm
  3/uart.o E:/em35x/hal/micro/generic/crc.o E:/em35x/hal/micro/generic/endian.o E:
  /em35x/hal/micro/generic/mem-util.o E:/em35x/hal/micro/generic/random.o E:/em35x
  /hal/micro/generic/sim-eeprom.o E:/em35x/app/util/serial/cli.o E:/em35x/app/util
  /serial/serial.o E:/em35x/hal/micro/cortexm3/em35x/mpu.o E:/em35x/hal/micro/cort
  exm3/faults.o E:/em35x/hal/micro/cortexm3/isr-stubs.o
  
     IAR ELF Linker V5.50.5.51995/W32 for ARM
     Copyright (C) 2007-2010 IAR Systems AB.
  Fatal error[Li001]: could not open file "E:\em35x\app\mfglib\mfg-sample.o"
  Fatal error detected, aborting.
  make: *** [mfg-sample-app.out] Error 3
  </code></pre>
  
  <p>(first it compiles the source files but at the end it cannot find the object files in the build folder)</p>
  
  <p>Now after I delete line 70 from the makefile which is</p>
  
  <pre><code>OBJ = $(SRC:.c=.o) E:/em35x/hal/micro/cortexm3/faults.o E:/em35x/hal/micro/cortexm3/isr-stubs.o
  </code></pre>
  
  <p>then the linker can find the previous compiled object files in the build directory and creates the .out file. And if I manually delete all the object files from the build directory (which the compiler created previously) and run the makefile again (line 70 is still deleted) then I get this error:</p>
  
  <pre><code>$ make
  make: *** No rule to make target `E:/em35x/build/mfg-sample-app-cortexm3-iar-em3
  57-em3xx-dev0680/mfg-sample.o', needed by `mfg-sample-app.out'.  Stop.
  </code></pre>
  
  <p>And if I add line 70 again which is :</p>
  
  <pre><code>OBJ = $(SRC:.c=.o) E:/em35x/hal/micro/cortexm3/faults.o E:/em35x/hal/micro/cortexm3/isr-stubs.o
  </code></pre>
  
  <p>then it compiles again but does not link because it cannot open the object files. (The first mentioned error again)</p>
  
  <p>I dont know what I am doing wrong. I have tried many things but cannot find my problem.</p>
  
  <p>Thanks</p>
  
  <p><strong>EDIT</strong>: I am using GNU Make 3.81</p>
  
  <p>have changed the second-to-last line to:</p>
  
  <pre><code>$(END_DIR)/%.o : %.c
  </code></pre>
  
  <p>and I also made changes to VPATH as suggested by Gilles but no luck.</p>
  
  <p>Now I get this erorr:</p>
  
  <pre><code>$ make
  make: *** No rule to make target `E:/em35x/build/mfg-sample-app-cortexm3-iar-em3
  57-em3xx-dev0680/mfg-sample.o', needed by `mfg-sample-app.out'.  Stop.
  </code></pre>
  
  <p>It is not compiling any .c file into a .o file</p>
  
  <p><strong>EDIT:</strong> Beta, I will be able to test you lines on Monday. I will then report the results, I want to resolve this issue it is driving me crazy. Thanks</p>
  
  <p><strong>EDIT:</strong></p>
  
  <p>Hi Beta,</p>
  
  <p>I am still getting the same error with the code you suggested. This is the error, if mfg-sample.o is not in the build folder (E:/em35x/build/mfg-sample-app-cortexm3-iar-em3
          57-em3xx-dev0680) :</p>
  
  <pre><code>tjoyia@TJ-PC /e/em35x/build/mfg-sample-app-cortexm3-iar-em357-em3xx-dev0680
  $ make
  make: *** No rule to make target `E:/em35x/build/mfg-sample-app-cortexm3-iar-em3
  57-em3xx-dev0680/mfg-sample.o', needed by `mfg-sample-app.out'.  Stop.
  </code></pre>
  
  <p>But if mfg-sample.o already exists in the build folder (after I complied mfg-sample.c to mfg-sample.o) then I get this message:</p>
  
  <pre><code>tjoyia@TJ-PC /e/em35x/build/mfg-sample-app-cortexm3-iar-em357-em3xx-dev0680
  $ make
  found E:/em35x/build/mfg-sample-app-cortexm3-iar-em357-em3xx-dev0680/mfg-sample.
  o, making mfg-sample-app.out
  </code></pre>
  
  <p><strong>EDIT:</strong></p>
  
  <p>Hi Beta,
  Yes, that worked.</p>
  
  <p>I got this message: </p>
  
  <pre><code>tjoyia@TJ-PC /e/em35x/build/mfg-sample-app-cortexm3-iar-em357-em3xx-dev0680
  $ make
  found E:/em35x/app/mfglib/mfg-sample.c, making E:/em35x/build/mfg-sample-app-cor
  texm3-iar-em357-em3xx-dev0680/mfg-sample.o
  found E:/em35x/build/mfg-sample-app-cortexm3-iar-em357-em3xx-dev0680/mfg-sample.
  o, making mfg-sample-app.out
  </code></pre>
  
  <p>So, what should I do now in my original makefile? I want to compile my whole project and link the object files.(all my .c files in different path locations into the build folder and then the linker should link the previous created .o files into the .out file)</p>
  
  <p><strong>EDIT:</strong></p>
  
  <p>Hi Beta,</p>
  
  <p>Ok I got it working, but what about the two .s79 files how I can get them also compiled into object files in the build directory? Why is VPATH not working and I think my dependcy file creation (.d) is not invoked how I can get the invoked. I want all the .h files (#include statements in the source files) get automatically recognized and depend on the object file.</p>
  
  <p>And after that I want to convert the .out files but its not getting invoked.</p>
  
  <p>Here is the problem:</p>
  
  <p>Do you know how I could add this to my makefile:</p>
  
  <p>ielftool.exe --srec --verbose E:\em35x\build\mfg-sample-app-cortexm3-iar-em357-em3xx-dev0680\mfg-sample-app.out E:\em35x\build\mfg-sample-app-cortexm3-iar-em357-em3xx-dev0680\mfg-sample-app.s37 </p>
  
  <p>It should convert the mfg-sample-app.out file into a mfg-sample-app.s37 after the .out file is created/linked from the object files.</p>