Ubuntu makefile操作

網上很多講解了Makefile檔案的具體寫法 缺沒有寫一開始怎麼執行操作 初學者可能不是很懂

我是分別在Ubuntu的Desktop中分別新增了下面的程式碼檔案

func1.c

#include "head.h"
#include "head1.h"
void f1()
{
struct student1 stu;
stu.id = 10101;
strcpy(stu.name,"ygt1");
stu.sex = 'm';
printf("id = %d\t name = %s\t sex = %c\n",stu.id,stu.name,stu.sex);
}

func2.c

#include "head.h"
#include "head2.h"
void f2()
{
struct student2 stu;
stu.id = 10102;
strcpy(stu.name,"ygt2");
stu.sex = 'm';
printf("id = %d\t name = %s\t sex = %c\n",stu.id,stu.name,stu.sex);
}

func3.c

#include "head.h"
#include "head3.h"
void f3()
{
struct student3 stu;
stu.id = 10103;
strcpy(stu.name,"ygt3");
stu.sex = 'm';
printf("id = %d\t name = %s\t sex = %c\n",stu.id,stu.name,stu.sex);
}

func4.c

#include "head.h"
#include "head4.h"
void f4()
{
struct student4 stu;
stu.id = 10104;
strcpy(stu.name,"ygt4");
stu.sex = 'm';
printf("id = %d\t name = %s\t sex = %c\n",stu.id,stu.name,stu.sex);
}

func5.c

#include "head.h"
#include "head5.h"
void f5()
{
struct student5 stu;
stu.id = 10105;
strcpy(stu.name,"ygt5");
stu.sex = 'm';
printf("id = %d\t name = %s\t sex = %c\n",stu.id,stu.name,stu.sex);
}

main.c

#include "head.h"
extern void f1();
extern void f2();
extern void f3();
extern void f4();
extern void f5();
int main()
{
f1();
f2();
f3();
f4();
f5();
printf("the end\n");
return 0;
}

head1.h

struct student1
{
int id;
char name[20];
char sex;	
};

head2.h

struct student2
{
int id;
char name[20];
char sex;	
};

head3.h

struct student3
{
int id;
char name[20];
char sex;	
};

head4.h

struct student4
{
int id;
char name[20];
char sex;	
};

head5.h

struct student5
{
int id;
char name[20];
char sex;	
};

head.h

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

在同樣的目錄下建立Makefile檔案

exefile: main.o func1.o func2.o func3.o func4.o func5.o 
gcc -o exefile main.o func1.o func2.o func3.o func4.o func5.o
main.o:main.c head.h 
gcc -c main.c
func1.o:func1.c head.h head1.h
gcc -c func1.c
func2.o:func2.c head.h head2.h
gcc -c func2.c
func3.o:func3.c head.h head3.h
gcc -c func3.c
func4.o:func4.c head.h head4.h
gcc -c func4.c
func5.o:func5.c head.h head5.h
gcc -c func5.c
clean:
rm -f *.o exefile

都建立完了之後呢 要在終端中輸入指令進行執行了  需要先進入檔案所在的路徑 然後make