forked from iPodLinux-Community/podzillaz
-
Notifications
You must be signed in to change notification settings - Fork 0
/
module.mk
179 lines (155 loc) · 4.19 KB
/
module.mk
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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
PZPATH ?= ../..
default: all-check
ifdef IPOD
CROSS ?= arm-uclinux-elf
CC = $(CROSS)-gcc
CXX = $(CROSS)-g++
LD = $(CROSS)-ld
OBJCOPY = $(CROSS)-objcopy
TARGET = ipod
PIC =
MYCFLAGS = -O3 -fomit-frame-pointer -funroll-loops -mapcs -mcpu=arm7tdmi -DVERSION=\"$(VERSION)\" -Wall
else
CC ?= cc
CXX ?= c++
LD ?= ld
OBJCOPY ?= objcopy
TARGET = x11
ifeq ($(shell uname),Darwin)
PIC = -dynamic
MAKESO = ld -bundle /usr/lib/bundle1.o -flat_namespace `gcc -print-libgcc-file-name` -lSystemStubs -undefined suppress -bundle_loader $(PZPATH)/core/built-in.o
else
PIC = -fPIC -DPIC
MAKESO = cc -shared
endif
MYCFLAGS = -DVERSION=\"$(VERSION)\"
endif
include Makefile
include $(PZPATH)/.config
ifndef MODULE
$(error You must define MODULE.)
endif
MODULE := $(strip $(MODULE))
ifeq ($(MODULE_$(MODULE)),n)
all-check:
@echo " (Skipping $(MODULE).)"
@rm -f built-in.o
distfiles:
install:
else
all-check: all
distfiles: real-distfiles
install: real-install
endif
ifeq ($(MODULE_$(MODULE)),y)
STATIC := 1
endif
ifdef STATIC
obj-y := $(obj-y) $(obj-m)
obj-m =
endif
cobj-y := $(patsubst %.c,%.o,$(wildcard $(patsubst %.o,%.c,$(obj-y))))
ccobj-y := $(patsubst %.cc,%.o,$(wildcard $(patsubst %.o,%.cc,$(obj-y))))
cobj-m := $(patsubst %.c,%.o,$(wildcard $(patsubst %.o,%.c,$(obj-m))))
ccobj-m := $(patsubst %.cc,%.o,$(wildcard $(patsubst %.o,%.cc,$(obj-m))))
obj = $(obj-y) $(obj-m)
ifeq ($(strip $(obj)),)
ifeq ($(strip $(MODLIBS)),)
$(error You must specify some object files or libraries.)
else
ifneq ($(shell uname),Darwin)
WA = -whole-archive
NWA = -no-whole-archive
endif
ifndef STATIC
obj-m = LIBRARY
endif
endif
else
WA =
NWA =
endif
ifdef obj-y
built-in = built-in.o
endif
ifdef obj-m
ifeq ($(obj-m),LIBRARY)
obj-m =
endif
## Case for single-file
ifndef IPOD
finalmod = $(MODULE).so
$(MODULE).so: $(obj-m)
@echo " LD [SO] $(MODULE).so"
@$(MAKESO) $(LDFLAGS) -o $@ $(obj-m) $(MODLIBS)
else
finalmod = $(MODULE).mod.o
$(MODULE).mod.o: $(obj-m)
@echo " LD [M] $(MODULE).mod.o"
@$(LD) -Ur -d -o $(MODULE).mod.o $(obj-m) $(WA) $(MODLIBS) $(NWA)
endif
else
finalmod =
endif
#####
all: $(obj-y) $(built-in) $(obj-m) $(finalmod)
#####
ifdef obj-y
built-in.o: $(obj-y)
@echo " LD $(MODULE)"
ifdef IPOD
@$(LD) -r -o built-in.o.strong $(obj-y) -L$(dir $(shell $(CC) -print-file-name=libc.a)) $(WA) $(MODLIBS) $(NWA)
@$(OBJCOPY) --weaken built-in.o.strong built-in.o
@$(RM) -f built-in.o.strong
else
@$(LD) -r -o built-in.o $(obj-y) -L$(dir $(shell $(CC) -print-file-name=libc.a)) $(WA) $(MODLIBS) $(NWA)
endif
$(cobj-y): %.o: %.c $(PZPATH)/config.h
@echo " CC " $@
@$(CC) $(CFLAGS) $(MYCFLAGS) -c -o $@ $< -I$(PZPATH)/core -I$(PZPATH) `$(TTKCONF) --$(TARGET) --sdl --cflags` -D__PZ_BUILTIN_MODULE -D__PZ_MODULE_NAME=\"$(MODULE)\" -DPZ_MOD -I/sw/include -L/sw/lib
$(ccobj-y): %.o: %.cc $(PZPATH)/config.h
@echo " CXX " $@
@$(CXX) $(CFLAGS) $(MYCFLAGS) -c -o $@ $< -I$(PZPATH)/core `$(TTKCONF) --$(TARGET) --sdl --cflags` -D__PZ_BUILTIN_MODULE -D__PZ_MODULE_NAME=\"$(MODULE)\" -DPZ_MOD -I/sw/include -L/sw/lib
endif
#####
ifdef obj-m
$(cobj-m): %.o: %.c $(PZPATH)/config.h
@echo " CC [M] " $@
@$(CC) $(CFLAGS) $(MYCFLAGS) $(PIC) -c -o $@ $< -I$(PZPATH) -I$(PZPATH)/core `$(TTKCONF) --$(TARGET) --sdl --cflags` -D__PZ_MODULE_NAME=\"$(MODULE)\" -DPZ_MOD -I/sw/include -L/sw/lib
$(ccobj-m): %.o: %.cc $(PZPATH)/config.h
@echo " CXX [M]" $@
@$(CXX) $(CFLAGS) $(MYCFLAGS) $(PIC) -c -o $@ $< -I$(PZPATH) -I$(PZPATH)/core `$(TTKCONF) --$(TARGET) --sdl --cflags` -D__PZ_MODULE_NAME=\"$(MODULE)\" -DPZ_MOD -I/sw/include -L/sw/lib
endif
LIBRARY:
#####
#####
semiclean:
@rm -f $(obj) built-in.o
clean:
@rm -f $(MODULE).mod.o $(MODULE).so $(obj) built-in.o
real-distfiles:
@echo Module
ifneq ($(MODULE_$(MODULE)),y)
ifdef IPOD
@echo $(MODULE).mod.o
else
@echo $(MODULE).so
endif
endif
ifdef DATA
@for file in $(DATA); do \
echo $$file; \
done
endif
DESTDIR ?= /mnt/ipod
real-install:
@echo " INST $(MODULE)"
@rm -rf $(DESTDIR)/usr/lib/$(MODULE)
@install -d -m 755 $(DESTDIR)/usr/lib/$(MODULE)
@install -m 644 Module $(DESTDIR)/usr/lib/$(MODULE)/Module
ifneq ($(MODULE_$(MODULE)),y)
@install -m 755 $(MODULE).mod.o $(DESTDIR)/usr/lib/$(MODULE)/$(MODULE).mod.o
endif
@for file in $(DATA); do \
install -m 755 $$file $(DESTDIR)/usr/lib/$(MODULE)/; \
done