-
Notifications
You must be signed in to change notification settings - Fork 4
/
Makefile
80 lines (58 loc) · 1.77 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
-include Config.mk
################ Source files ##########################################
EXE := ${NAME}
SRCS := $(wildcard *.c)
OBJS := $(addprefix $O,$(SRCS:.c=.o))
################ Compilation ###########################################
.PHONY: all clean dist distclean maintainer-clean
all: Config.mk config.h ${EXE} ${DATAF}
run: ${EXE} ${DATAF}
@./${EXE}
${EXE}: ${OBJS}
@echo "Linking $@ ..."
@${LD} ${LDFLAGS} -o $@ $^ ${LIBS}
$O%.o: %.c
@echo " Compiling $< ..."
@[ -d $(dir $@) ] || mkdir -p $(dir $@)
@${CC} ${CFLAGS} -MMD -MT "$(<:.c=.s) $@" -o $@ -c $<
%.s: %.c
@echo " Compiling $< to assembly ..."
@${CC} ${CFLAGS} -S -o $@ -c $<
################ Installation ##########################################
.PHONY: install uninstall
ifdef BINDIR
EXEI := $(addprefix ${BINDIR}/,${EXE})
install: ${EXEI}
${EXEI}: ${EXE}
@echo "Installing $< as $@ ..."
@${INSTALLEXE} $< $@
uninstall:
@echo "Removing ${EXEI} ..."
@rm -f ${EXEI}
endif
################ Maintenance ###########################################
clean:
@[ ! -d ./$O ] || rm -rf ./$O
@rm -f ${EXE}
ifdef MAJOR
DISTVER := ${MAJOR}.${MINOR}
DISTNAM := ${NAME}-${DISTVER}
DISTTAR := ${DISTNAM}.tar.bz2
dist:
@echo "Generating ${DISTTAR} and ${DISTLSM} ..."
@mkdir .${DISTNAM}
@rm -f ${DISTTAR}
@cp -r * .${DISTNAM} && mv .${DISTNAM} ${DISTNAM}
@+${MAKE} -sC ${DISTNAM} maintainer-clean
@tar acf ${DISTTAR} ${DISTNAM} && rm -rf ${DISTNAM}
endif
distclean: clean
@rm -f Config.mk config.h config.status
maintainer-clean: distclean
${OBJS}: Makefile Config.mk config.h
Config.mk: Config.mk.in
config.h: config.h.in
Config.mk config.h: configure
@if [ -x config.status ]; then echo "Reconfiguring ..."; ./config.status; \
else echo "Running configure ..."; ./configure; fi
-include ${OBJS:.o=.d}