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
|
# MinGW cross compiling environment
# see doc/README for further information
JOBS := 1
TARGET := i386-mingw32msvc
SOURCEFORGE_MIRROR := kent.dl.sourceforge.net
VERSION := 2.5
PREFIX := $(PWD)/usr
PKG_DIR := $(PWD)/pkg
TMP_DIR = $(PWD)/tmp-$(1)
TOP_DIR := $(patsubst %/,%,$(dir $(word $(words $(MAKEFILE_LIST)),$(MAKEFILE_LIST))))
PATH := $(PREFIX)/bin:$(PATH)
SHELL := bash
SED := $(shell gsed --help >/dev/null 2>&1 && echo g)sed
INSTALL := $(shell ginstall --help >/dev/null 2>&1 && echo g)install
# unset any environment variables which might cause trouble
AR =
CC =
CFLAGS =
CPP =
CPPFLAGS =
CROSS =
CXX =
CXXCPP =
CXXFLAGS =
EXEEXT =
LD =
LDFLAGS =
LIBS =
NM =
PKG_CONFIG =
RANLIB =
STRIP =
SHORT_PKG_VERSION = \
$(word 1,$(subst ., ,$($(1)_VERSION))).$(word 2,$(subst ., ,$($(1)_VERSION)))
PKG_RULES := $(patsubst $(TOP_DIR)/src/%.mk,%,$(wildcard $(TOP_DIR)/src/*.mk))
include $(TOP_DIR)/src/*.mk
CHECK_ARCHIVE = \
$(if $(filter %.tgz, $(1)),tar tfz '$(1)' >/dev/null 2>&1, \
$(if $(filter %.tar.gz, $(1)),tar tfz '$(1)' >/dev/null 2>&1, \
$(if $(filter %.tar.bz2,$(1)),tar tfj '$(1)' >/dev/null 2>&1, \
$(if $(filter %.zip, $(1)),unzip -t '$(1)' >/dev/null 2>&1, \
$(error Unknown archive format: $(1))))))
UNPACK_ARCHIVE = \
$(if $(filter %.tgz, $(1)),tar xvzf '$(1)', \
$(if $(filter %.tar.gz, $(1)),tar xvzf '$(1)', \
$(if $(filter %.tar.bz2,$(1)),tar xvjf '$(1)', \
$(if $(filter %.zip, $(1)),unzip '$(1)', \
$(error Unknown archive format: $(1))))))
UNPACK_PKG_ARCHIVE = \
$(call UNPACK_ARCHIVE,$(PKG_DIR)/$($(1)_FILE))
.PHONY: all
all: $(PKG_RULES)
define PKG_RULE
.PHONY: $(1)
$(1): $(PREFIX)/installed-$(1)
$(PREFIX)/installed-$(1): $(TOP_DIR)/src/$(1).mk $(addprefix $(PREFIX)/installed-,$($(1)_DEPS))
[ -d '$(PREFIX)' ] || mkdir -p '$(PREFIX)'
[ -d '$(PKG_DIR)' ] || mkdir -p '$(PKG_DIR)'
cd '$(PKG_DIR)' && ( \
$(call CHECK_ARCHIVE,$($(1)_FILE)) || \
$(if $($(1)_URL_2), \
wget -T 30 -t 3 -c -O '$($(1)_FILE)' '$($(1)_URL)' || \
wget -c -O '$($(1)_FILE)' '$($(1)_URL_2)', \
wget -c -O '$($(1)_FILE)' '$($(1)_URL)'))
$(if $(value $(1)_BUILD),
rm -rf '$(2)'
mkdir -p '$(2)'
cd '$(2)' && $(call UNPACK_PKG_ARCHIVE,$(1))
cd '$(2)/$($(1)_SUBDIR)'
$$(call $(1)_BUILD,$(2)/$($(1)_SUBDIR))
rm -rfv '$(2)'
,)
touch '$$@'
endef
$(foreach PKG,$(PKG_RULES),$(eval $(call PKG_RULE,$(PKG),$(call TMP_DIR,$(PKG)))))
.PHONY: strip
strip:
rm -rf \
'$(PREFIX)/include' \
'$(PREFIX)/info' \
'$(PREFIX)/lib/libiberty.a' \
'$(PREFIX)/man' \
'$(PREFIX)/share' \
'$(PREFIX)/$(TARGET)/etc' \
'$(PREFIX)/$(TARGET)/doc' \
'$(PREFIX)/$(TARGET)/info' \
'$(PREFIX)/$(TARGET)/lib'/*.def \
'$(PREFIX)/$(TARGET)/man' \
'$(PREFIX)/$(TARGET)/sbin' \
'$(PREFIX)/$(TARGET)/share'
-strip -Sx \
'$(PREFIX)/bin'/* \
'$(PREFIX)/libexec/gcc/$(TARGET)'/*/* \
'$(PREFIX)/$(TARGET)/bin'/*
-$(TARGET)-strip -S \
'$(PREFIX)/lib/gcc/$(TARGET)'/*/*.a \
'$(PREFIX)/lib/gcc/$(TARGET)'/*/*.o \
'$(PREFIX)/$(TARGET)/lib'/*.a \
'$(PREFIX)/$(TARGET)/lib'/*.o
.PHONY: clean
clean:
rm -rf $(call TMP_DIR,*) $(PREFIX)/*
.PHONY: clean-pkg
clean-pkg:
rm -f $(patsubst %,'%', \
$(filter-out \
$(foreach PKG,$(PKG_RULES),$(PKG_DIR)/$($(PKG)_FILE)), \
$(wildcard $(PKG_DIR)/*)))
.PHONY: update
define UPDATE
$(if $(2), \
$(info $(1): $(2)) \
$(if $(filter $(2),$($(1)_VERSION)), \
, \
$(SED) 's/^\([^ ]*_VERSION *:=\).*/\1 $(2)/' -i '$(TOP_DIR)/src/$(1).mk'), \
$(error Unable to update version number: $(1)))
endef
update:
$(foreach PKG,$(PKG_RULES),$(call UPDATE,$(PKG),$(shell $($(PKG)_UPDATE))))
.PHONY: dist
dist:
rm -rf 'mingw_cross_env-$(VERSION)'
mkdir 'mingw_cross_env-$(VERSION)'
mkdir 'mingw_cross_env-$(VERSION)/doc'
mkdir 'mingw_cross_env-$(VERSION)/src'
(cd '$(TOP_DIR)' && hg log -v --style changelog) >'mingw_cross_env-$(VERSION)/doc/ChangeLog'
( \
$(SED) -n '1,/<!-- begin of package list -->/ p' '$(TOP_DIR)/doc/README.html' && \
($(foreach PKG,$(PKG_RULES), \
echo ' <tr><td><a href="$($(PKG)_WEBSITE)">$(PKG)</a></td><td>$($(PKG)_VERSION)</td></tr>';)) && \
$(SED) -n '/<!-- end of package list -->/,$$ p' '$(TOP_DIR)/doc/README.html' \
) >'$(TOP_DIR)/README.html'
cp -p '$(TOP_DIR)/README.html' 'mingw_cross_env-$(VERSION)/doc/'
cd 'mingw_cross_env-$(VERSION)/doc' && lynx -dump -width 75 -nolist -force_html README.html >README
cp -p '$(TOP_DIR)/Makefile' 'mingw_cross_env-$(VERSION)/'
cp -p '$(TOP_DIR)/src'/*.mk 'mingw_cross_env-$(VERSION)/src/'
tar cvf - 'mingw_cross_env-$(VERSION)' | gzip -9 >'mingw_cross_env-$(VERSION).tar.gz'
rm -rf 'mingw_cross_env-$(VERSION)'
|