forked from zakkak/turnin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
127 lines (112 loc) · 3.11 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
###############################################################################
#
# Copyright 1993 Paul Eggert
# Copyright 2014 Foivos S. Zakkak <foivos@zakkak.net> and
# Antonios A. Chariton <daknob.mac@gmail.com>
#
# This program is free software: you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the Free
# Software Foundation, either version 3 of the License, or (at your option)
# any later version.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
# more details.
#
# You should have received a copy of the GNU General Public License along with
# this program. If not, see <http://www.gnu.org/licenses/>.
#
###############################################################################
CC := gcc
CFLAGS := -Wall -I./src
LDFLAGS := -lcrypto
EUID := $(shell id -u -r)
DESTDIR ?=/usr
SOURCES := $(wildcard src/*.c)
SOURCES += obj/version.c # This is automatically generated
HEADERS := $(wildcard src/*.h)
OBJECTS := ${SOURCES:src/%=obj/%}
OBJECTS := ${OBJECTS:%.c=%.o}
GIT:=$(shell which git)
.PHONY: check install uninstall clean
all: check turnin
# Check for root
check:
ifneq ($(EUID),0)
@echo "Please run as root user"
@exit 1
endif
obj/version.c: src/version.sed.me
ifdef GIT
@if [ -d .git ]; then\
echo ' SED version.sed.me';\
mkdir -p $(dir $@);\
sed -r 's/^(char \*turninversion = ").*(";)/\1'`git describe`'\2/' $< > $@;\
else\
rm -f $@;\
mkdir -p $(dir $@);\
cp $< $@;\
fi;
else
@rm -f $@
@mkdir -p $(dir $@)
@cp $< $@
endif
# Conditionally add dependencies rule
ifneq ($(MAKECMDGOALS),clean)
ifneq ($(MAKECMDGOALS),distclean)
-include $(OBJECTS:obj/%.o=dep/%.d)
endif
endif
dep/%.d: src/%.c $(HEADERS)
@mkdir -p $(dir $@)
@echo ' DEP' $@
@$(CC) $(CFLAGS) -M $< | \
sed 's,[a-zA-Z0-9_\.]*.o:,$(<:src/%.c=obj/%.o):,' > $@
%.o: %.c $(HEADERS)
@mkdir -p $(dir $@)
@echo ' CC ' $@
@$(CC) $(CFLAGS) -c $< -o $@
obj/%.o: src/%.c dep/%.d $(HEADERS)
@mkdir -p $(dir $@)
@echo ' CC ' $@
@$(CC) $(CFLAGS) -c $< -o $@
turnin: check $(OBJECTS)
@echo ' LD ' $@
@$(CC) $(CFLAGS) $(OBJECTS) -o turnin $(LDFLAGS)
install: check turnin uninstall $(DESTDIR)/bin/verify-turnin
@echo ' INST'
mkdir -p $(DESTDIR)/bin/
cp -p turnin $(DESTDIR)/bin/
chmod ug+s $(DESTDIR)/bin/turnin
mkdir -p $(DESTDIR)/share/man/man1/
cp -p man/turnin.1 $(DESTDIR)/share/man/man1/
chmod 755 $(DESTDIR)/bin/verify-turnin
$(DESTDIR)/bin/verify-turnin: scripts/verify-turnin.sed.me
ifdef GIT
@if [ -d .git ]; then\
echo ' SED verify-turnin.sed.me';\
mkdir -p $(dir $@);\
sed -r 's/^(VER = ").*(")/\1'`git describe`'\2/' $< > $@;\
else\
rm -rf $@;\
mkdir -p $(dir $a);\
cp $< $@;\
fi;
else
@rm -rf $@
@mkdir -p $(dir $@)
@cp $< $@
endif
uninstall: check
-rm -f \
$(DESTDIR)/bin/turnin \
$(DESTDIR)/bin/verify-turnin \
$(DESTDIR)/share/man/man1/turnin.1
clean:
@echo ' CLN'
rm -rf obj dep
distclean: clean
@echo ' CLN dist'
rm -f turnin