관리 메뉴

너와 나의 스토리

[Unix] Make 본문

Unix/실습

[Unix] Make

노는게제일좋아! 2019. 9. 27. 20:56
반응형

Make란?

  • Unix 계열에서 많이 사용하는 빌드 자동화 도구
  • Manifest 파일을 이용하여 과정을 자동화
    • Manifest: 특정한 목적 및 절차를 표현하는 명세서

 

 

Makefile의 구조

  • 목적파일(Target): 명령어가 수행되어 나온 결과를 저장할 파일
  • 의존성(Dependency): 목적파일을 만들기 위해 필요한 재료
  • 명령어(Command): 실행되어야 할 명령어들
  • 매크로(Macro): 코드를 단순화시키기 위한 방법

 

 

Manifest 형식

* 만약 tab 했는데도 tab 아니라고 오류나면 

  1. 해당 파일이 있는 곳으로 가서 마우스 우측 키 누름
  2. 파일을 텍스트 에디터로 연 다음 
  3. tab으로 수정

 

Makefile lines

  • dependency line
    • target: [전제조건]
  • command line
    • "tab" [@] command
  • macro definition
    • name = string
  • include statement
    • include filenames
  • comment

 

 

Makefile 작성

터미널에서 vi makefile 치고 (파일 만들고) 다음 코드 작성

all: diary_exe

diary_exe: memo.o calendar.o main.o //의존성
	gcc -o diary_exe memo.o calendar.o main.o   // 명령어 (tab 주의)
    
memo.o: diary.h memo.c
	gcc -c -o memo.o memo.c
    
calendar.o: diary.h calendar.c
	gcc -c -o calendar.o calendar.c
   
main.o: diary.h main.c
	gcc -c -o main.o main.c
   
clean:
	rm *.o diary_exe   // 더미타겟 (파일 생성 안함)

 

 

참고 - https://bowbowbow.tistory.com/12#make-makefile-%EC%9D%B4%EB%9E%80

반응형
Comments