Upload
robyn-melton
View
215
Download
1
Embed Size (px)
Citation preview
1
Linux Command
Advanced Compiler Laboratory 2
Simple linux cmds
ls List information about FILEs, by default the cur
rent directory. pwd
Print Working Directory cd
Change Directory - change the current working directory to a specific Folder.
Advanced Compiler Laboratory 3
Simple linux cmds
cp Copy one or more files to another location
mv Move or rename files or directories.
rm Remove files (delete/unlink)
touch Change file timestamps, change the access and/or m
odification times of the specified files.
Advanced Compiler Laboratory 4
Simple linux cmds
mkdir Create new folder(s), if they do not already exi
st. rmdir
Remove folder(s), if they are empty. cat
Display the contents of a file (concatenate)
Advanced Compiler Laboratory 5
Simple linux cmds
passwd Modify a user password.
chmod Change access permissions
History Command Line history
man Display helpful information about commands.
Advanced Compiler Laboratory 6
make
Definition make is utility to maintain groups of
programs
Object If some file is modified, make detects it
and update files related with modified one.
It can use to command based programs
Advanced Compiler Laboratory 7
make basic rules
3 components target, dependency, command
file format file name: Makefile format :
target: dependency[tab] comand
Advanced Compiler Laboratory 8
make example
make 를 사용하지 않을때 $gcc –c main.c $gcc –c add.c $gcc –c sub.c $gcc –o test main.o add.o sub.o
혹은 , gcc –o test main.c add.c sub.c
Advanced Compiler Laboratory 9
make example
test : main.o add.o sub.ogcc –o test main.o add.o sub.o
main.o: addsub.h main.cgcc –c main.c
add.o: add.cgcc –c add.c
sub.o: sub.cgcc –c sub.c
command 앞에는 반드시 [tab] 을 사용할 것
Advanced Compiler Laboratory 10
make example
어느 때 어떤 target 이 다시 컴파일 될 것인가 ? main.c 가 바뀌었을 경우
add.c 혹은 sub.c 가 바뀌었을 경우
addsub.h 가 바뀌었을 경우
Advanced Compiler Laboratory 11
label
clean:rm *.o test
레이블로 사용될 때는 의존관계 부분이 없어도 된다 .
실행 방법 make clean
Advanced Compiler Laboratory 12
macro
CC=gccSRC=main.c add.c sub.cmain: ${SRC}
${CC} –o test ${SRC}
Advanced Compiler Laboratory 13
미리 정해져 있는 매크로
make –p 를 통하여 모든 값들을 확인 가능 ASFLAGS = <- as 명령어의 옵션 세팅 AS = as CFLAGS = <- gcc 의 옵션 세팅 CC = cc (= gcc) CPPFLAGS = <- g++ 의 옵션 CXX = g++ LDLFAGS = <- ld 의 옵션 세팅 LD = ld LFLAGS = <- lex 의 옵션 세팅 LEX = lex YFLAGS = <- yacc 의 옵션 세팅 YACC = yacc
Advanced Compiler Laboratory 14
확장자 규칙
확장자 규칙 target 에 확장자 규칙을 적용 확장자를 보고 그에 따라 적절한 연산을 수행시키는
규칙 .SUFFIX 매크로
make 파일에서 주의 깊게 처리할 파일들의 확장자 등록
.c.o .c 를 확장자로 가지는 파일을 .o 를 확장자로 갖는
파일로 바꾸는 규칙을 직접 정의
Advanced Compiler Laboratory 15
확장자 규칙의 예
.SUFFIXES : .c .o OBJECTS = main.o add.o sub.o CC = gcc CFLAGS = -g -c TARGET = test $(TARGET) : $(OBJECTS) $(CC) -o $(TARGET) $(OBJECTS) .c.o : $(CC) $(CFLAGS) $< clean : rm -rf $(OBJECTS) $(TARGET) core main.o : addsub.h main.c add.o : addsub.h add.c sub.o : addsub.h sub.c
Advanced Compiler Laboratory 16
확장자 규칙의 예
CC=gccOBJS= main.o add.o sub.otest3:${OBJS}
${CC} –o $@ ${OBJS} .c.o:
gcc –c $<
Advanced Compiler Laboratory 17
매크로 치환
$(MACRO_NAME:OLD=NEW) SRC=main.c OBJ=$(SRC:.c=.o)
참고 : 긴 명령어를 여러 라인으로 표현시 \ 사용OBJS = shape.o \
pen.o\marker.o
Advanced Compiler Laboratory 18
Example
만들었던 Makefile 을 macro 와 확장자 규칙을 이용하여 다시 바꾸어 보자 .
Advanced Compiler Laboratory 19
의존 관계 생성
gccmakedep 어떤 파일의 의존 관계를 자동으로 조사해서
Makefile 의 뒷부분에 자동으로 붙여주는 유틸리티 .SUFFIXES : .c .o
CFLAGS = -O2 -g OBJS = main.o add.o sub.oSRCS = $(OBJS:.o=.c) test : $(OBJS) $(CC) -o test $(OBJS) dep : gccmakedep $(SRCS)
Advanced Compiler Laboratory 20
Recursive Make
파일들이 여러 directory 에 나누어져 있고 각 sub-directory 에 makefile 이 존재 한다면 ?
subsystem:cd subdir;$(MAKE)
subsystem:$(MAKE) –C subdir
Advanced Compiler Laboratory 21
Example
Recursive Makefile 을 작성해 보자 .