next up previous contents
Next: Using several files Up: Make without Makefile Previous: Case 2: no makefile,   Contents

Case 3: no makefile, change the source code

Now we edit the source code so it says:
#include <stdio.h>

int main(int argc, char* argv)
{ printf("I am the main program\n");
  printf("I depend on nothing\n");
  printf("change 1 applied\n");
}
Notice that, after the edit we made, mainprog exists but is older than mainprog.c:
bash-2.05b# ls -l
total 20
-rwxr-xr-x    1 root     root        11593 Mar  9 05:28 mainprog
-rw-r--r--    1 root     root          157 Mar  9 05:34 mainprog.c
-rw-r--r--    1 root     root          125 Mar  9 05:07 mainprog.c~
So we ask to bring mainprog ``up to date'' again:
bash-2.05b# make mainprog
cc     mainprog.c   -o mainprog
bash-2.05b# ls -l
total 20
-rwxr-xr-x    1 root     root        11625 Mar  9 05:36 mainprog
-rw-r--r--    1 root     root          157 Mar  9 05:34 mainprog.c
-rw-r--r--    1 root     root          125 Mar  9 05:07 mainprog.c~
bash-2.05b# ./mainprog
I am the main program
I depend on nothing
change 1 applied
So if you are just using one C file you can use make to automatically call the compiler.

root 2004-03-15