210 likes | 367 Views
Linux Command. Simple linux cmds. ls List information about FILEs, by default the current directory. pwd Print Working Directory cd Change Directory - change the current working directory to a specific Folder. Simple linux cmds. cp Copy one or more files to another location mv
E N D
Simple linux cmds • ls • List information about FILEs, by default the current directory. • pwd • Print Working Directory • cd • Change Directory - change the current working directory to a specific Folder.
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 modification times of the specified files.
Simple linux cmds • mkdir • Create new folder(s), if they do not already exist. • rmdir • Remove folder(s), if they are empty. • cat • Display the contents of a file (concatenate)
Simple linux cmds • passwd • Modify a user password. • chmod • Change access permissions • History • Command Line history • man • Display helpful information about commands.
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
make basic rules • 3 components • target, dependency, command • file format • file name: Makefile • format : target: dependency [tab] comand
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
make example test : main.o add.o sub.o gcc –o test main.o add.o sub.o main.o: addsub.h main.c gcc –c main.c add.o: add.c gcc –c add.c sub.o: sub.c gcc –c sub.c command 앞에는 반드시 [tab]을 사용할 것
make example • 어느 때 어떤 target이 다시 컴파일 될 것인가? • main.c가 바뀌었을 경우 • add.c 혹은 sub.c가 바뀌었을 경우 • addsub.h가 바뀌었을 경우
label clean: rm *.o test • 레이블로 사용될 때는 의존관계 부분이 없어도 된다. • 실행 방법 • make clean
macro CC=gcc SRC=main.c add.c sub.c main: ${SRC} ${CC} –o test ${SRC}
미리 정해져 있는 매크로 • 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
확장자 규칙 • 확장자 규칙 • target에 확장자 규칙을 적용 • 확장자를 보고 그에 따라 적절한 연산을 수행시키는 규칙 • .SUFFIX 매크로 • make 파일에서 주의 깊게 처리할 파일들의 확장자 등록 • .c.o • .c를 확장자로 가지는 파일을 .o를 확장자로 갖는 파일로 바꾸는 규칙을 직접 정의
확장자 규칙의 예 • .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
확장자 규칙의 예 CC=gcc OBJS= main.o add.o sub.o test3:${OBJS} ${CC} –o $@ ${OBJS} .c.o: gcc –c $<
매크로 치환 • $(MACRO_NAME:OLD=NEW) • SRC=main.c • OBJ=$(SRC:.c=.o) • 참고: 긴 명령어를 여러 라인으로 표현시 \사용 OBJS = shape.o \ pen.o\ marker.o
Example • 만들었던 Makefile을 macro와 확장자 규칙을 이용하여 다시 바꾸어 보자.
의존 관계 생성 • gccmakedep • 어떤 파일의 의존 관계를 자동으로 조사해서 Makefile의 뒷부분에 자동으로 붙여주는 유틸리티 .SUFFIXES : .c .o CFLAGS = -O2 -g OBJS = main.o add.o sub.o SRCS = $(OBJS:.o=.c) test : $(OBJS) $(CC) -o test $(OBJS) dep : gccmakedep $(SRCS)
Recursive Make • 파일들이 여러 directory에 나누어져 있고 각 sub-directory에 makefile이 존재 한다면? subsystem: cd subdir;$(MAKE) subsystem: $(MAKE) –C subdir
Example • Recursive Makefile 을 작성해 보자.