Skip to content

Commit 0a02ce7

Browse files
author
Linus Torvalds
committed
Clean up the Makefile a bit.
This introduces the concept of git "library" objects that the real programs use, and makes it easier to add such things to a "libgit.a". This will also make it trivial to split the current "read-cache.o" into more aptly named pieces (it does a lot more than just read the index file).
1 parent 839a7a0 commit 0a02ce7

File tree

1 file changed

+39
-32
lines changed

1 file changed

+39
-32
lines changed

Makefile

Lines changed: 39 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
CFLAGS=-g -O3 -Wall
1111

1212
CC=gcc
13+
AR=ar
1314

1415

1516
PROG= update-cache show-diff init-db write-tree read-tree commit-tree \
@@ -21,60 +22,66 @@ all: $(PROG)
2122
install: $(PROG)
2223
install $(PROG) $(HOME)/bin/
2324

24-
LIBS= -lssl -lz
25+
LIB_OBJS=read-cache.o object.o commit.o tree.o blob.o
26+
LIB_FILE=libgit.a
27+
28+
$(LIB_FILE): $(LIB_OBJS)
29+
$(AR) rcs $@ $(LIB_OBJS)
30+
31+
LIBS= $(LIB_FILE) -lssl -lz
2532

2633
init-db: init-db.o
2734

28-
update-cache: update-cache.o read-cache.o
29-
$(CC) $(CFLAGS) -o update-cache update-cache.o read-cache.o $(LIBS)
35+
update-cache: update-cache.o $(LIB_FILE)
36+
$(CC) $(CFLAGS) -o update-cache update-cache.o $(LIBS)
3037

31-
show-diff: show-diff.o read-cache.o
32-
$(CC) $(CFLAGS) -o show-diff show-diff.o read-cache.o $(LIBS)
38+
show-diff: show-diff.o $(LIB_FILE)
39+
$(CC) $(CFLAGS) -o show-diff show-diff.o $(LIBS)
3340

34-
write-tree: write-tree.o read-cache.o
35-
$(CC) $(CFLAGS) -o write-tree write-tree.o read-cache.o $(LIBS)
41+
write-tree: write-tree.o $(LIB_FILE)
42+
$(CC) $(CFLAGS) -o write-tree write-tree.o $(LIBS)
3643

37-
read-tree: read-tree.o read-cache.o
38-
$(CC) $(CFLAGS) -o read-tree read-tree.o read-cache.o $(LIBS)
44+
read-tree: read-tree.o $(LIB_FILE)
45+
$(CC) $(CFLAGS) -o read-tree read-tree.o $(LIBS)
3946

40-
commit-tree: commit-tree.o read-cache.o
41-
$(CC) $(CFLAGS) -o commit-tree commit-tree.o read-cache.o $(LIBS)
47+
commit-tree: commit-tree.o $(LIB_FILE)
48+
$(CC) $(CFLAGS) -o commit-tree commit-tree.o $(LIBS)
4249

43-
cat-file: cat-file.o read-cache.o
44-
$(CC) $(CFLAGS) -o cat-file cat-file.o read-cache.o $(LIBS)
50+
cat-file: cat-file.o $(LIB_FILE)
51+
$(CC) $(CFLAGS) -o cat-file cat-file.o $(LIBS)
4552

46-
fsck-cache: fsck-cache.o read-cache.o object.o commit.o tree.o blob.o
47-
$(CC) $(CFLAGS) -o fsck-cache fsck-cache.o read-cache.o object.o commit.o tree.o blob.o $(LIBS)
53+
fsck-cache: fsck-cache.o $(LIB_FILE) object.o commit.o tree.o blob.o
54+
$(CC) $(CFLAGS) -o fsck-cache fsck-cache.o $(LIBS)
4855

49-
checkout-cache: checkout-cache.o read-cache.o
50-
$(CC) $(CFLAGS) -o checkout-cache checkout-cache.o read-cache.o $(LIBS)
56+
checkout-cache: checkout-cache.o $(LIB_FILE)
57+
$(CC) $(CFLAGS) -o checkout-cache checkout-cache.o $(LIBS)
5158

52-
diff-tree: diff-tree.o read-cache.o
53-
$(CC) $(CFLAGS) -o diff-tree diff-tree.o read-cache.o $(LIBS)
59+
diff-tree: diff-tree.o $(LIB_FILE)
60+
$(CC) $(CFLAGS) -o diff-tree diff-tree.o $(LIBS)
5461

55-
rev-tree: rev-tree.o read-cache.o object.o commit.o tree.o blob.o
56-
$(CC) $(CFLAGS) -o rev-tree rev-tree.o read-cache.o object.o commit.o tree.o blob.o $(LIBS)
62+
rev-tree: rev-tree.o $(LIB_FILE) object.o commit.o tree.o blob.o
63+
$(CC) $(CFLAGS) -o rev-tree rev-tree.o $(LIBS)
5764

58-
show-files: show-files.o read-cache.o
59-
$(CC) $(CFLAGS) -o show-files show-files.o read-cache.o $(LIBS)
65+
show-files: show-files.o $(LIB_FILE)
66+
$(CC) $(CFLAGS) -o show-files show-files.o $(LIBS)
6067

61-
check-files: check-files.o read-cache.o
62-
$(CC) $(CFLAGS) -o check-files check-files.o read-cache.o $(LIBS)
68+
check-files: check-files.o $(LIB_FILE)
69+
$(CC) $(CFLAGS) -o check-files check-files.o $(LIBS)
6370

64-
ls-tree: ls-tree.o read-cache.o
65-
$(CC) $(CFLAGS) -o ls-tree ls-tree.o read-cache.o $(LIBS)
71+
ls-tree: ls-tree.o $(LIB_FILE)
72+
$(CC) $(CFLAGS) -o ls-tree ls-tree.o $(LIBS)
6673

67-
merge-base: merge-base.o read-cache.o object.o commit.o tree.o blob.o
68-
$(CC) $(CFLAGS) -o merge-base merge-base.o read-cache.o object.o commit.o tree.o blob.o $(LIBS)
74+
merge-base: merge-base.o $(LIB_FILE) object.o commit.o tree.o blob.o
75+
$(CC) $(CFLAGS) -o merge-base merge-base.o $(LIBS)
6976

70-
merge-cache: merge-cache.o read-cache.o
71-
$(CC) $(CFLAGS) -o merge-cache merge-cache.o read-cache.o $(LIBS)
77+
merge-cache: merge-cache.o $(LIB_FILE)
78+
$(CC) $(CFLAGS) -o merge-cache merge-cache.o $(LIBS)
7279

7380
read-cache.o: cache.h
7481
show-diff.o: cache.h
7582

7683
clean:
77-
rm -f *.o $(PROG)
84+
rm -f *.o $(PROG) $(LIB_FILE)
7885

7986
backup: clean
8087
cd .. ; tar czvf dircache.tar.gz dir-cache

0 commit comments

Comments
 (0)