git
Build automation software
Makefile
宋劲杉. Linux C 编程一站式学习
Works but not good.
$ gcc main.c stack.c maze.c -o main
Two-step approach.
$ gcc -c main.c
$ gcc -c stack.c
$ gcc -c maze.c
$ gcc main.o stack.o maze.o -o main
Better practice. Using Makefile
main: main.o stack.o maze.o
gcc main.o stack.o maze.o -o main
main.o: main.c main.h stack.h maze.h
gcc -c main.c
stack.o: stack.c stack.h main.h
gcc -c stack.c
maze.o: maze.c maze.h main.h
gcc -c maze.c
Type make
Makefile
rulestarget ... : prerequisites ...
command1 command2 ...
all: main
main: main.o stack.o maze.o
gcc main.o stack.o maze.o -o main
main.o: main.c main.h stack.h maze.h
gcc -c main.c
stack.o: stack.c stack.h main.h
gcc -c stack.c
maze.o: maze.c maze.h main.h
gcc -c maze.c
clean:
@echo "cleanning project"
-rm main *.o
@echo "clean completed"
.PHONY: clean
main.o: main.h stack.h maze.h
main.o: main.c
gcc -c main.c
all: main
main: main.o stack.o maze.o
gcc main.o stack.o maze.o -o main
main.o: main.h stack.h maze.h
stack.o: stack.h main.h
maze.o: maze.h main.h
clean:
-$(RM) main *.o
.PHONY: clean
make -p
to show.
LINK.o = $(CC) $(LDFLAGS) $(TARGET_ARCH)
OUTPUT_OPTION = -o $@
CC = cc
LD = ld
COMPILE.c = $(CC) $(CFLAGS) $(CPPFLAGS) $(TARGET_ARCH) -c
%.o: %.c
$(COMPILE.c) $(OUTPUT_OPTION) $<
%.o: %.c
Pattern Rule
Multiple target. prerequisites centric rules.
all: main
main: main.o stack.o maze.o
gcc main.o stack.o maze.o -o main
main.o stack.o maze.o: main.h
main.o maze.o: maze.h
main.o stack.o: stack.h
clean:
-$(RM) main *.o
.PHONY: clean
Define using = := += ?=
$@
the target$<
the first prerequisite$?
updated prerequisites$^
all prerequisitesVariables used by implicit rules.
CC = cc
CFLAGS =
CPPFLAGS =
LD = ld
LDFLAGS =
TARGET_ARCH =
OUTPUT_OPTION = -o $@
LINK.o = $(CC) $(LDFLAGS) $(TARGET_ARCH)
COMPILE.c = $(CC) $(CFLAGS) $(CPPFLAGS) $(TARGET_ARCH) -c
RM = rm -f
Makefile Using variables.
MAINTARGET := main
SOURCE := main.c stack.c maze.c
OBJS := ${SOURCE:.c=.o}
all: $(MAINTARGET)
$(MAINTARGET): $(OBJS)
$(LINK.o) $^ $(OUTPUT_OPTION)
clean:
-$(RM) $(MAINTARGET) $(OBJS)
.PHONY: clean
main.o stack.o maze.o: main.h
main.o maze.o: maze.h
main.o stack.o: stack.h
make
options-n
just print, no run-C dir
Change to directory dir before anything else.make CFLAGS+=-g
define variablesdiff
and patch
$ diff -u mmm.c maze.c
$ diff -u mmm.c maze.c > pp.patch
$ patch -b < pp.patch
git
Popular version control systems.
git
- the simple guidegit
commands
* init * status * diff
* add * commit * log
* tag * checkout * branch
* merge * clone * fetch
* pull * push * remote
just a simple guide for getting started with git. no deep shit ;)