-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathGNUmakefile
82 lines (66 loc) · 1.92 KB
/
GNUmakefile
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
# Usage: make [var=value]...
# Compile host binaries and (if crossprefix set) cross-compile as well.
#
# Some variables with example values:
# crossprefix=i486-openwrt-linux-uclibc-
# crossbindir=/bin
# crosshost=wrt
# bindir=/usr/sbin
# DESTDIR=$PWD/_installroot
#
# Some interesting targets:
# all (default)
# clean
# install
# cross-install
prefix = /usr
execprefix = $(prefix)
bindir = $(execprefix)/bin
INSTALL = install
crossbindir = /bin
crosshost = need-to-set-crosshost-first
crossprefix =
crossCC = $(crossprefix)gcc
crossNM = $(crossprefix)nm
crossOBJDUMP = $(crossprefix)objdump
crossSTRIP = $(crossprefix)strip
CC = gcc
NM = nm
OBJDUMP = objdump
STRIP = strip
CLEANFILES =
DUMMY1 := $(shell ./update-git-version.sh)
CLEANFILES += git-version.h
DUMMY2 := $(shell ./update-usage-msg.sh)
CLEANFILES += usage-msg.h
BASE = send-echo-request
export BASE
crossbuild := cross-$(notdir $(crossprefix))build
hostbuild := host-build
.PHONY: all
all:
mkdir -p $(hostbuild)
$(MAKE) -f rules.mk outdir=$(hostbuild) CC=$(CC) NM=$(NM) OBJDUMP=$(OBJDUMP) STRIP=$(STRIP)
ifneq ($(crossprefix),)
mkdir -p $(crossbuild)
$(MAKE) -f rules.mk outdir=$(crossbuild) CC=$(crossCC) NM=$(crossNM) OBJDUMP=$(crossOBJDUMP) STRIP=$(crossSTRIP)
endif
.PHONY: clean
clean:
rm -f $(CLEANFILES)
rm -rf $(crossbuild) $(hostbuild)
.PHONY: install
install: all
$(INSTALL) -c -m 0755 -d $(DESTDIR)$(bindir)
$(INSTALL) -cp -m 0755 $(hostbuild)/$(BASE).exe $(DESTDIR)$(bindir)/$(BASE)
.PHONY: uninstall
uninstall:
rm -f $(DESTDIR)$(bindir)/$(BASE)
# Remove the target file first to work around OpenWRT "text file busy" error.
.PHONY: cross-install
cross-install: all
ssh $(crosshost) rm -f $(crossbindir)/$(BASE)
scp $(crossbuild)/$(BASE).stripped $(crosshost):$(crossbindir)/$(BASE)
.PHONY: cross-uninstall
cross-uninstall:
ssh $(crosshost) rm -f $(crossbindir)/$(BASE)