Taking threads directory for example, there is a directory called arch, within which there are dec-alpha-osf , dec-mips-ultrix , sun-sparc-sunos , unknown-i386-linux . I’m using Linux, so just look at unknown-i386-linux . The bin stores the executable file (nachos), the depends stores dependence files (like xxxx.d), and the objects stores object files (like xxxx.o).
In threads directory, when make, there will be a link file named nachos linked to arch/unknown-i386-linux/bin/nachos .
Makefile.common
The most complex file. First it includes Makefile.dep, then vpath tells gnu make where to look for certain files.
$(depends_dir)/%.d: %.cc @echo ">>> Building dependency file for "$<"<<<" @$(SHELL) -ec '$(CC) -MM $(CFLAGS)$< \ | sed '\''s@$*.o[ ]*:@$(depends_dir)/$(notdir$@)$(obj_dir)/&@g'\'' > $@'
$(depends_dir)/%.d: %.c @echo ">>> Building dependency file for"$<"<<<" @$(SHELL) -ec '$(CC) -MM $(CFLAGS)$< \ | sed '\''s@$*.o[ ]*:@$(depends_dir)/$(notdir$@)$(obj_dir)/&@g'\'' > $@'
$(depends_dir)/%.d: %.s @echo ">>> Building dependency file for"$<"<<<" @$(SHELL) -ec '$(CPP) -MM $(CPPFLAGS)$< \ | sed '\''s@$*.o[ ]*:@$(depends_dir)/$(notdir$@)$(obj_dir)/&@g'\'' > $@'
lab2
Preparation
If you want to modify some files, you’d better do it in other directory with the files associated with Makefile and Makefile.local copied, then it will compile the file you modified dependently first.
So copy Makefile , Makefile.localscheduler.cc , scheduler.h and arch in threads to lab2, and in arch just keep the unknown-i386-linux and within make the three folders empty.
Method 1
Change Makefile.local to make sure the changed or to be changed .h files will found when compiling:
INCPATH += -I../lab2 -I../threads -I../machine
Because I put lab2 in front of threads, so it will go to lab2 first then to the threads directory.
Use touch to change the modification time of file scheduler.h (It won’t change the contents), then make :
../Makefile.dep:29: Linux >>> Building dependency file for scheduler.cc <<< ../Makefile.dep:29: Linux >>> Compiling scheduler.cc <<< g++ -m32 -g -Wall -Wshadow -m32 -I../lab2 -I../threads -I../machine -DTHREADS -DHOST_i386 -DHOST_LINUX -DCHANGED -c -o arch/unknown-i386-linux/objects/scheduler.o scheduler.cc
Only scheduler.cc is recompiled, while others not associated with scheduler.h are not recompiled.
If touch scheduler.h in threads?
root@iZbp1iqmvkj69470qn1vpvZ:~/OS/lab2# touch ../threads/scheduler.h root@iZbp1iqmvkj69470qn1vpvZ:~/OS/lab2# make ../Makefile.dep:29: Linux >>> Building dependency file for ../machine/timer.cc <<< >>> Building dependency file for ../machine/sysdep.cc <<< >>> Building dependency file for ../machine/interrupt.cc <<< >>> Building dependency file for ../threads/synchtest.cc <<< >>> Building dependency file for ../threads/threadtest.cc <<< >>> Building dependency file for ../threads/thread.cc <<< >>> Building dependency file for ../threads/system.cc <<< >>> Building dependency file for ../threads/synch.cc <<< >>> Building dependency file for scheduler.cc <<< >>> Building dependency file for ../threads/main.cc <<< ../Makefile.dep:29: Linux >>> Compiling ../threads/main.cc <<< g++ -m32 -g -Wall -Wshadow -m32 -I../lab2 -I../threads -I../machine -DTHREADS -DHOST_i386 -DHOST_LINUX -DCHANGED -c -o arch/unknown-i386-linux/objects/main.o ../threads/main.cc
We see that all source files associated with scheduler.h in directory machine and threads are all recompiled.
If a file doesn’t include scheduler.h , but it includes a file that includes scheduler.h , it will be recompiled too. So we can use grep to find them, and copy them to lab2.
In threads directory, type grep scheduler.h * , and get:
grep: arch: Is a directory Binary file nachos matches scheduler.cc:#include "scheduler.h" scheduler.h:// scheduler.h system.h:#include "scheduler.h"
We see system.h includes scheduler.h , so we look into system.h by grep system.h * :
Well I get this result, because I didn’t compile it first after I copy all these files, but if I do it a second time:
root@iZbp1iqmvkj69470qn1vpvZ:~/OS/lab2# touch ../threads/scheduler.h root@iZbp1iqmvkj69470qn1vpvZ:~/OS/lab2# make ../Makefile.dep:29: Linux make: 'arch/unknown-i386-linux/bin/nachos' is up to date.
It shows that it has nothing to do with the file in scheduler.h in threads directory if we change anything in scheduler.h in the current directory, lab2 .