-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
131 lines (105 loc) · 3.43 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
128
129
130
131
# Package-related substitution variables
export package = luawrapper
export version = 0.1
export tarname = $(package)
export distdir = $(tarname)-$(version)
# Prefix-related substitution variables
export prefix = /usr/local
export exec_prefix = $(prefix)
export libdir = $(exec_prefix)/lib
# related substitution variables
export CC ?= gcc
export CFLAGS ?= -Os
export CPPFLAGS ?=
export AR ?= ar
export Q ?= @
CPPFLAGS += \
-I. \
-Iinclude/ \
-Isrc/libelf/common/ \
-Isrc/libelf/ \
-Isrc/lua/
luawrapper_gen_src := \
src/libelf/libelf_msize.c \
src/libelf/libelf_fsize.c \
src/libelf/libelf_convert.c
.SECONDARY: $(luawrapper_gen_src)
luawrapper_src := \
$(shell find src -name *.c) \
$(luawrapper_gen_src)
luawrapper_objects := $(luawrapper_src:.c=.o)
luawrapper_clean_files := \
$(luawrapper_gen_src) \
native-elf-format.h \
luawrapper.a \
$(luawrapper_objects) \
$(luawrapper_src:.c=.d)
all: luawrapper.a examples
native-elf-format.h:
@echo generate platform dependant header $@
$(Q) LANG=C src/libelf/common/native-elf-format > $@
-include $(luawrapper_src:.c=.d)
%.d: %.c
$(Q) set -e; rm -f $@; \
$(CC) -MM -MG $(CPPFLAGS) $< | \
sed 's,\(^[^:]*\):,$(dir $@)\1 $@ : ,g' > $@; \
# TODO tester $?
luawrapper.a: $(luawrapper_objects)
@echo creation of $@
$(Q) $(AR) cr $@ $^
src/libelf/libelf_%.c: src/libelf/libelf_%.m4
@echo "generate m4 generated $@ for luawrapper"
$(Q) (cd src/libelf/; m4 -D SRCDIR=. $(notdir $^) > $(notdir $@))
examples: luawrapper.a
$(MAKE) -C examples
clean:
$(Q) -rm -f $(luawrapper_clean_files) &>/dev/null
$(MAKE) -C examples clean
check: all
$(MAKE) -C examples check
install:
install -d $(DESTDIR)$(libdir)
install -m 0755 luawrapper.a $(DESTDIR)$(libdir)
uninstall:
-rm $(DESTDIR)$(libdir)/luawrapper.a &>/dev/null
dist: $(distdir).tar.gz
$(distdir).tar.gz: FORCE $(distdir)
tar chof - $(distdir) | gzip -9 -c >$(distdir).tar.gz
rm -rf $(distdir)
$(distdir):
mkdir -p $(distdir)/src/libelf/common
mkdir -p $(distdir)/src/lua
mkdir -p $(distdir)/include
mkdir -p $(distdir)/examples/both_dep
mkdir -p $(distdir)/examples/lua_dep
mkdir -p $(distdir)/examples/no_dep
cp Makefile $(distdir)
cp build_wrapper.sh $(distdir)
cp include/lw_dependencies.h $(distdir)/include
cp src/luawrapper.c $(distdir)/src
cp src/lua/*.c $(distdir)/src/lua
cp src/lua/*.h $(distdir)/src/lua
cp src/libelf/*.c $(distdir)/src/libelf
cp src/libelf/*.h $(distdir)/src/libelf
cp src/libelf/*.m4 $(distdir)/src/libelf
cp src/libelf/common/*.h $(distdir)/src/libelf/common
cp src/libelf/common/native-elf-format $(distdir)/src/libelf/common
cp examples/Makefile $(distdir)/examples
cp examples/examples.mk $(distdir)/examples
cp examples/both_dep/*.c $(distdir)/examples/both_dep
cp examples/both_dep/*.lua $(distdir)/examples/both_dep
cp examples/no_dep/*.c $(distdir)/examples/no_dep
cp examples/no_dep/*.lua $(distdir)/examples/no_dep
cp examples/lua_dep/*.c $(distdir)/examples/lua_dep
cp examples/lua_dep/*.lua $(distdir)/examples/lua_dep
distcheck: $(distdir).tar.gz
gzip -cd $+ | tar xvf -
$(MAKE) -C $(distdir) all check
$(MAKE) -C $(distdir) DESTDIR=$${PWD}/$(distdir)/_inst install uninstall
$(MAKE) -C $(distdir) clean
rm -rf $(distdir)
@echo "*** Package $(distdir).tar.gz is ready for distribution."
FORCE:
-rm -rf $(distdir) &>/dev/null
-rm $(distdir).tar.gz &>/dev/null
.PHONY: FORCE all examples clean check dist distcheck install uninstall