title: how to run make for a local subdirectory
body: <p>I am trying to port an existing code into a larger project. The larger project has a main Makefile with Makefiles in each sub-directory. I am sure the path below tells you all about how it is setup. I want to port my code to </p>
  
  <pre><code>/WORKING_DIRECTORY/Drivers/Char/example
  </code></pre>
  
  <p>And here is the content: </p>
  
  <pre><code>sansari@ubuntu:~/WORKING_DIRECTORY/drivers/char/examples$ ls
  hello1.c  Makefile
  </code></pre>
  
  <p>My question is 1- Should modify this local Makefile or the main one? I am setting up to modify this one, but I am not sure. </p>
  
  <p>2- My other question is if I modify this local file, can I just run make from here and validate my configuration instead of running make for the entire project? I know that make only updates the files that are changed; however I feel better when I clean the build environment before each make. I have run into situations, which this alone fixed my issue. </p>
  
  <p>Just as background, I did try to include the make file of my target project, the one I am trying to import here with -f command. What I did was: <code>make -f Makefile -f ../mytarget/core/Makefile</code>
  But I ran into some issues with make not doing some of the normal things it does in the primary project. For instance, there was an include statement with a relative path to a header file, which make gave me an error about not seeing it. So now I am abandoning that strategy for the time being. </p>
  
  <p>@Ahmad Masoud - Hey man, thanks. <a href="http://pastebin.com/mqrFX7i3" rel="nofollow">Here</a> is the Makefile. Hey man, the link is exactly what I needed. I think it will address my other questions also. You see, I cross compiled this code, and when I flashed my phone, I get the following for </p>
  
  <pre><code>uname -r:  1|root@hltespr:/lib/modules # uname -r
  uname -r
  3.4.0-g7e6fbf7-dirty
  </code></pre>
  
  <p>And I have been wondering what "dirty" means and where it comes from. If you know please tell me. The link you sent, states that perhaps make would insert the Linux kernel version there? I ask this since, modprobe does not work when I try to load my module. Instead insmod works, and I can validate that my module is in. My main issue now is that I don't know how to execute the file to make sure it runs. I only know how to run the file using modprobe, and I can not use it. It gives me the following error: </p>
  
  <pre><code>1|root@hltespr:/ # modprobe /lib/modules/hello1.ko
  modprobe /lib/modules/hello1.ko
  modprobe: can't change directory to '3.4.0-g7e6fbf7-dirty': No such file or directory
  </code></pre>
  
  <p>Update as of 06/20/15 -I put in <code>include /home/sansari/mytree2/tbt/makefile</code> in my module's make file. I get the following error: <code>makefile:3: *** missing separator.  Stop.</code></p>
  
  <p>@Ahmad - This is an update as of 062415. Thanks for the info. My goal is to get make to look into this external directory, collect all the source files and build them for me. What would you suggest? I am stuck because as it stands, I know make looks into my examples directory, but no other changes I make to that local make file in the examples directory shows up in make. For instance I tried adding ($warning ....) and @echo messages, but even they do not show up.</p>
  
  <p>Update on 070215- Thanks for the previous comments and support. I feel I really should reopen this thread since I did not explain the goal in detail, and now I feel I can describe it better, and hopefully the resolution will help other. I issue the command: </p>
  
  <pre><code>TARGET=msm8974 PLATFORM=msm8974 make  drivers/char/examples
  </code></pre>
  
  <p>But I get a message stating: Nothing to be done, while I have added a number of tasks to do. Below is my make file, and I'll elaborate on what I have added right after: </p>
  
  <pre><code>lib_tbt := ../../../m/shahin/tbt
  lib_daemon := ../../../m/shahin/daemon
  lib_lib := ../../../m/shahin/lib
  lib_tasks := ../../../m/shahin/tasks
  lib_tbt_driver := ../../../m/shahin/tbt_driver
  lib_tbt_make := ../../../m/shahin/tbt/make
  lib_tbt_msm_common := ../../../m/shahin/tbt/platform/msm8974/common
  lib_tbt_msm8974 := ../../../m/shahin/tbt/platform/msm8974
  lib_asm_generic = ../../../m/shahin/tbt/platform/msm8974/include/asm-generic
  $(warning This is what is in lib_asm_generic $(lib_asm_generic))
  #include $(lib_tbt_make)/macros.mk
  .PHONY: all $(lib_tbt)
  $(lib_tbt) $(lib_daemon) $(lib_lib) $(lib_tasks) $(lib_tbt_driver) $(lib_tbt_make) $(lib_tbt_msm_common) $(lib_tbt_msm8974) $(lib_asmgeneric) :
          $(MAKE) --directory=$@
          $(lib_*): $(MAKE) --directory=$@
  obj-$(CONFIG_EXAMPLES)          += hello1.o
  _
  </code></pre>
  
  <p>Initially I only had the <code>obj-$(CONFIG_EXAMPLES)          += hello1.o</code>statement in my make file. I then proceeded to add the directory variables at the top of my makefile and added the <code>$(lib_*): $(MAKE) --directory=$@</code> directing make to compile what is in the directory. I believe that is what it does. Please let me know if I am mistaken. And although this same make file proceeds to create object files when I put it a different directory within my project, it won't do so when it is in a device driver directory. And I do not understand why. The other directory is the /external directory and it is at the top of the tree. But that should not matter right. What I have done was to first make sure I can compile a hello program in my device driver directory called /examples. I now want to add more source code to this section. I believe the correct term is module? I also want to know if I should copy of the source files to the /examples directory or referencing them via the path is ok. That is should I move the source code directory under /examples directory or not?</p>