forked from h0tw1r3/pixelserv
-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathMakefile
151 lines (126 loc) · 6.48 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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
# basic setup
DISTNAME := pixelserv
CC := gcc
OPTS := -DDROP_ROOT -DIF_MODE
SRCS := util.c socket_handler.c pixelserv.c
# debug flags
CFLAGS_D := $(CFLAGS) -g -Wall
LDFLAGS_D := $(LDFLAGS)
# performance flags
CFLAGS_P := $(CFLAGS) -O3 -s -Wall -ffunction-sections -fdata-sections -fno-strict-aliasing
LDFLAGS_P := $(LDFLAGS) -Wl,--gc-sections
# aggressive strip command
# note that this breaks the x86 build on x86-64 for some reason
#STRIP := strip -s -R .note -R .comment -R .gnu.version -R .gnu.version_r
# Less aggressive, works for RPi
STRIP := strip -s -R .note -R .comment -R .gnu.version
# agressive UPX compress
UPX := upx -9
# packaging macros
PFILES := LICENSE README.md
PVERSION := $(shell grep VERSION util.h | awk '{print $$NF}' | sed 's|\"||g')
PCMD := zip -j
# x86 environment
CC32 := $(CC) -m32
# x86_64 environment
CC64 := $(CC) -m64
# MIPS environment
# I set my path ahead of time, so I've commented out the path command macro below
MIPSTOOLS := /opt/brcm/hndtools-mipsel-uclibc/bin:/opt/brcm/hndtools-mipsel-linux/bin
#MIPSPATH := PATH=$(MIPSTOOLS):$(PATH)
MIPSREFIX := mipsel-uclibc-
MIPSCC := $(MIPSREFIX)$(CC)
MIPSSTRIP := $(MIPSREFIX)$(STRIP)
# ARM environment
ARMTOOLS := /usr/local/x-tools/arm-unknown-linux-gnueabihf/bin
#ARMPATH := PATH=$(ARMTOOLS):$(PATH)
ARMPREFIX := arm-unknown-linux-gnueabihf-
ARMCC := $(ARMPREFIX)$(CC)
ARMSTRIP := $(ARMPREFIX)$(STRIP)
# RPi environment
RPITOOLS := /usr/bin
#RPIPATH := PATH=$(RPITOOLS):$(PATH)
RPIPREFIX := arm-linux-gnueabihf-
RPICC := $(RPIPREVIX)$(CC)
RPIOPTS := -lrt
RPISTRIP := $(RPIPREFIX)$(STRIP)
# tomatoware environment uses basic setup options because it compiles native
# targets - notes:
# - for each platform, there should be 4 versions: dynamic performance, dynamic debug, static performance, static debug
# - static is not built for x86* targets because it causes glibc-related complaints
# - mips version could be K24 or K26 depending on environment
# - tomatoware is not included in the 'all' target, because it's for compiling natively on a router
.PHONY: all clean distclean printver x86 x86_x64 mips arm tomatoware rpi
all: x86 x86_64 mips #arm rpi
@echo "=== Built all x86 and cross-compiler targets ==="
clean:
@echo "=== Cleaning intermediate build products ==="
rm -rf ./*.o
distclean: clean
@echo "=== Cleaning deployment products ==="
rm -rf ./dist
dist:
@echo "=== Creating deployment directory ==="
mkdir -p dist
printver:
@echo "=== Building $(DISTNAME) version $(PVERSION) ==="
x86: printver dist
@echo "=== Building x86 ==="
$(CC32) $(CFLAGS_D) $(LDFLAGS_D) $(OPTS) $(SRCS) -o dist/$(DISTNAME)[email protected]
$(CC32) $(CFLAGS_P) $(LDFLAGS_P) $(OPTS) $(SRCS) -o dist/$(DISTNAME)[email protected]
# $(CC32) $(CFLAGS_D) -static $(LDFLAGS_D) $(OPTS) $(SRCS) -o dist/$(DISTNAME)[email protected]
# $(CC32) $(CFLAGS_P) -static $(LDFLAGS_P) $(OPTS) $(SRCS) -o dist/$(DISTNAME)[email protected]
$(STRIP) dist/$(DISTNAME)[email protected].*
$(UPX) dist/$(DISTNAME)[email protected].*
rm -f dist/$(DISTNAME).$(PVERSION)[email protected]
$(PCMD) dist/$(DISTNAME).$(PVERSION)[email protected] $(PFILES) dist/$(DISTNAME).$@.*
x86_64: printver dist
@echo "=== Building x86-64 ==="
$(CC64) $(CFLAGS_D) $(LDFLAGS_D) $(OPTS) $(SRCS) -o dist/$(DISTNAME)[email protected]
$(CC64) $(CFLAGS_P) $(LDFLAGS_P) $(OPTS) $(SRCS) -o dist/$(DISTNAME)[email protected]
# $(CC64) $(CFLAGS_D) -static $(LDFLAGS_D) $(OPTS) $(SRCS) -o dist/$(DISTNAME)[email protected]
# $(CC64) $(CFLAGS_P) -static $(LDFLAGS_P) $(OPTS) $(SRCS) -o dist/$(DISTNAME)[email protected]
$(STRIP) dist/$(DISTNAME)[email protected].*
$(UPX) dist/$(DISTNAME)[email protected].*
rm -f dist/$(DISTNAME).$(PVERSION)[email protected]
$(PCMD) dist/$(DISTNAME).$(PVERSION)[email protected] $(PFILES) dist/$(DISTNAME).$@.*
mips: printver dist
@echo "=== Building MIPS ==="
$(MIPSPATH) $(MIPSCC) $(CFLAGS_D) $(LDFLAGS_D) $(OPTS) $(SRCS) -o dist/$(DISTNAME)[email protected]
$(MIPSPATH) $(MIPSCC) $(CFLAGS_P) $(LDFLAGS_P) $(OPTS) $(SRCS) -o dist/$(DISTNAME)[email protected]
$(MIPSPATH) $(MIPSCC) $(CFLAGS_D) -static $(LDFLAGS_D) $(OPTS) $(SRCS) -o dist/$(DISTNAME)[email protected]
$(MIPSPATH) $(MIPSCC) $(CFLAGS_P) -static $(LDFLAGS_P) $(OPTS) $(SRCS) -o dist/$(DISTNAME)[email protected]
$(MIPSPATH) $(MIPSSTRIP) dist/$(DISTNAME)[email protected].*
$(UPX) dist/$(DISTNAME)[email protected].*
rm -f dist/$(DISTNAME).$(PVERSION)[email protected]
$(PCMD) dist/$(DISTNAME).$(PVERSION)[email protected] $(PFILES) dist/$(DISTNAME).$@.*
arm: printver dist
@echo "=== Building ARM ==="
$(ARMPATH) $(ARMCC) $(CFLAGS_D) $(LDFLAGS_D) $(OPTS) $(SRCS) -o dist/$(DISTNAME)[email protected]
$(ARMPATH) $(ARMCC) $(CFLAGS_P) $(LDFLAGS_P) $(OPTS) $(SRCS) -o dist/$(DISTNAME)[email protected]
$(ARMPATH) $(ARMCC) $(CFLAGS_D) -static $(LDFLAGS_D) $(OPTS) $(SRCS) -o dist/$(DISTNAME)[email protected]
$(ARMPATH) $(ARMCC) $(CFLAGS_P) -static $(LDFLAGS_P) $(OPTS) $(SRCS) -o dist/$(DISTNAME)[email protected]
$(ARMPATH) $(ARMSTRIP) dist/$(DISTNAME)[email protected].*
$(UPX) dist/$(DISTNAME)[email protected].*
rm -f dist/$(DISTNAME).$(PVERSION)[email protected]
$(PCMD) dist/$(DISTNAME).$(PVERSION)[email protected] $(PFILES) dist/$(DISTNAME).$@.*
tomatoware: printver dist
@echo "=== Building tomatoware ==="
$(CC) $(CFLAGS_D) $(LDFLAGS_D) $(OPTS) $(SRCS) -o dist/$(DISTNAME)[email protected]
$(CC) $(CFLAGS_P) $(LDFLAGS_P) $(OPTS) $(SRCS) -o dist/$(DISTNAME)[email protected]
$(CC) $(CFLAGS_D) -static $(LDFLAGS_D) $(OPTS) $(SRCS) -o dist/$(DISTNAME)[email protected]
$(CC) $(CFLAGS_P) -static $(LDFLAGS_P) $(OPTS) $(SRCS) -o dist/$(DISTNAME)[email protected]
$(STRIP) dist/$(DISTNAME)[email protected].*
$(UPX) dist/$(DISTNAME)[email protected].*
rm -f dist/$(DISTNAME).$(PVERSION)[email protected]
$(PCMD) dist/$(DISTNAME).$(PVERSION)[email protected] $(PFILES) dist/$(DISTNAME).$@.*
rpi: printver dist
@echo "=== Building for Raspberry Pi ==="
$(RPIPATH) $(RPICC) $(CFLAGS_D) $(LDFLAGS_D) $(OPTS) $(RPIOPTS) $(SRCS) -o dist/$(DISTNAME)[email protected]
$(RPIPATH) $(RPICC) $(CFLAGS_P) $(LDFLAGS_P) $(OPTS) $(RPIOPTS) $(SRCS) -o dist/$(DISTNAME)[email protected]
# $(RPIPATH) $(RPICC) $(CFLAGS_D) -static $(LDFLAGS_D) $(OPTS) $(RPIOPTS) $(SRCS) -o dist/$(DISTNAME)[email protected]
# $(RPIPATH) $(RPICC) $(CFLAGS_P) -static $(LDFLAGS_P) $(OPTS) $(RPIOPTS) $(SRCS) -o dist/$(DISTNAME)[email protected]
$(RPIPATH) $(RPISTRIP) dist/$(DISTNAME)[email protected].*
$(UPX) dist/$(DISTNAME)[email protected].*
rm -f dist/$(DISTNAME).$(PVERSION)[email protected]
$(PCMD) dist/$(DISTNAME).$(PVERSION)[email protected] $(PFILES) dist/$(DISTNAME).$@.*