Skip to content

Commit b001a0e

Browse files
committed
General update and clean-up
- Use published `prebuild-install` - Updated source code versions - Generated files on root folder - Incremented number of binaries symlinks - Code clean-up
1 parent efcf6ae commit b001a0e

File tree

10 files changed

+174
-120
lines changed

10 files changed

+174
-120
lines changed

.gitignore

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
1+
build/
12
deps/
2-
obj/
33
node_modules/
4-
out/
54
npm-debug.log
65
prebuilds/
6+
7+
lib/
8+
libexec/
9+
share/
10+
*-nodeos-linux-musl/

index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
module.exports = __dirname + '/out'
1+
module.exports = __dirname

package.json

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,35 @@
33
"version": "0.0.1",
44
"description": "Cross-toolchain to build NodeOS based on Compressed Linux From Scratch Embedded",
55
"bin": {
6+
"addr2line": "bin/addr2line",
67
"ar": "bin/ar",
78
"as": "bin/as",
8-
"c++": "bin/c++",
9-
"g++": "bin/g++",
10-
"gcc": "bin/gcc",
9+
"c++filt": "bin/c++filt",
10+
"elfedit": "bin/elfedit",
11+
"gprof": "bin/gprof",
1112
"ld": "bin/ld",
1213
"ld.bfd": "bin/ld.bfd",
1314
"nm": "bin/nm",
1415
"objcopy": "bin/objcopy",
1516
"objdump": "bin/objdump",
1617
"ranlib": "bin/ranlib",
17-
"strip": "bin/strip"
18+
"readelf": "bin/readelf",
19+
"size": "bin/size",
20+
"strings": "bin/strings",
21+
"strip": "bin/strip",
22+
"c++": "bin/c++",
23+
"cpp": "bin/cpp",
24+
"g++": "bin/g++",
25+
"gcc": "bin/gcc",
26+
"gcov": "bin/gcov",
27+
"gcov-tool": "bin/gcov-tool"
1828
},
1929
"scripts": {
2030
"BigRedButton": "scripts/BigRedButton",
21-
"build": "scripts/preinstall && scripts/build && scripts/postinstall",
31+
"build": "scripts/preinstall && scripts/build",
2232
"install": "prebuild-install --download https://github.com/NodeOS/nodeos-cross-toolchain/releases/download/v{version}/{platform}-{arch}.tar.gz || npm run build",
33+
"postinstall": "scripts/postinstall",
34+
"prepublish": "rm -rf bin/*-nodeos-linux-musl-* && truncate --size 0 bin/*",
2335
"test": "scripts/test",
2436
"unbuild": "scripts/unbuild"
2537
},
@@ -34,13 +46,14 @@
3446
"linux",
3547
"binutils"
3648
],
37-
"author": "Jesús Leganés Combarro \"piranna\" <piranna@gmail.com>",
49+
"author": "Jesús Leganés Combarro 'piranna' <piranna@gmail.com>",
3850
"license": "MIT",
3951
"dependencies": {
40-
"prebuild": "piranna/prebuild-install#WIP_aux"
52+
"prebuild-install": "^1.0.2"
4153
},
42-
"devDpendencies": {
43-
"download-manager": "^0.0.15",
44-
"fs-extra": "^0.26.5"
54+
"devDependencies": {
55+
"download-manager": "^0.0.20",
56+
"fs-extra": "^0.30.0",
57+
"prebuild": "^4.2.1"
4558
}
4659
}

scripts/BigRedButton

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,15 @@
11
#!/usr/bin/env bash
22

3-
. scripts/adjustEnvVars.sh
3+
source scripts/adjustEnvVars.sh
4+
5+
6+
#
7+
# Define steps paths
8+
#
9+
10+
PRODUCTS=(bin lib libexec share *-nodeos-linux-musl)
11+
PREBUILD=prebuilds/linux-$NODE_ARCH.tar.gz
12+
413

514
#
615
# Build cross toolchain for all supported platforms
@@ -9,12 +18,16 @@
918
PLATFORM=pc_qemu_32 npm run build || exit 1
1019
PLATFORM=pc_qemu_64 npm run build || exit 2
1120

21+
1222
#
1323
# Pack toolchain in a node-gyp compatible way
1424
#
1525

16-
mkdir -p prebuilds &&
17-
tar -cf - out | gzip > prebuilds/linux-$NODE_ARCH.tar.gz || exit 3
26+
STEP_DIR=$PREBUILD
27+
28+
mkdir -p prebuilds &&
29+
tar -cf - ${PRODUCTS[@]} | gzip > $PREBUILD || err 3
30+
1831

1932
#
2033
# Upload release to GitHub

scripts/adjustEnvVars.sh

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -139,22 +139,20 @@ fi
139139

140140

141141
# Auxiliar variables
142-
OBJECTS=`pwd`/obj/$CPU
143-
OUT_DIR=`pwd`/out/$CPU
144-
145-
if [[ $TOOLS ]]; then
146-
TOOLS=`realpath -s $TOOLS`
147-
fi
148-
PATH=$TOOLS/bin:/bin:/usr/bin
142+
OBJECTS=`pwd`/build/$CPU
149143

150144
MAKE1="make ${SILENT:=--silent LIBTOOLFLAGS=--silent V=}"
151145
MAKE="$MAKE1 --jobs=$JOBS"
152146

153147

148+
function rmStep(){
149+
rm -rf "$@"
150+
rmdir -p --ignore-fail-on-non-empty `dirname "$@"`
151+
}
152+
154153
# Clean object dir and return the input error
155154
function err(){
156155
echo -e "${RED}Error compiling '${OBJ_DIR}'${CLR}"
157-
rm -rf $OBJ_DIR
158-
rmdir -p --ignore-fail-on-non-empty `dirname $OBJ_DIR`
156+
rmStep $OBJ_DIR
159157
exit $1
160158
}

scripts/build

Lines changed: 82 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -10,36 +10,56 @@ unset CFLAGS
1010

1111

1212
DEPS=`pwd`/deps
13-
TOOLS=`pwd`/out
13+
OUT_DIR=`pwd`
1414

1515
source scripts/adjustEnvVars.sh || exit $?
1616

1717

18-
mkdir -p $TOOLS/$TARGET &&
19-
ln -sfn . $TOOLS/$TARGET/usr || exit 1
18+
mkdir -p $TARGET &&
19+
ln -sfn . $TARGET/usr || exit 1
2020

2121
if [[ $BITS = 64 ]]; then
22-
ln -sfn lib $TOOLS/$TARGET/lib64 || exit 2
22+
ln -sfn lib $TARGET/lib64 || exit 2
2323
fi
2424

2525

26+
# Clean object dir and return the input error
27+
function err(){
28+
rmStep $STEP_DIR
29+
exit $1
30+
}
31+
32+
33+
#
34+
# Define steps paths
35+
#
36+
37+
KERNEL_HEADERS=$OUT_DIR/$TARGET/include/linux
38+
OBJ_BINUTILS=$OBJECTS/binutils
39+
OBJ_GCC_STATIC=$OBJECTS/gcc_static
40+
OBJ_MUSL=$OBJECTS/musl
41+
OBJ_GCC_FINAL=$OBJECTS/gcc_final
42+
43+
2644
#
2745
# Linux kernel headers
2846
#
2947

3048
SRC_DIR=$DEPS/linux
31-
OBJ_DIR=$TOOLS/$TARGET/include/linux
49+
STEP_DIR=$KERNEL_HEADERS
3250

33-
if [[ ! -d $OBJ_DIR ]]; then
51+
if [[ ! -d $STEP_DIR ]]; then
3452
echo -e "${WHT}Extracting Linux headers${CLR}"
3553

54+
rmStep $OBJ_BINUTILS
55+
3656
(
3757
cd $SRC_DIR
3858

3959
# Extract headers
40-
$MAKE mrproper &&
41-
$MAKE ARCH=$ARCH headers_check &&
42-
$MAKE ARCH=$ARCH INSTALL_HDR_PATH=$TOOLS/$TARGET headers_install || exit 10
60+
$MAKE mrproper &&
61+
$MAKE ARCH=$ARCH headers_check &&
62+
$MAKE ARCH=$ARCH INSTALL_HDR_PATH=$OUT_DIR/$TARGET headers_install || exit 10
4363
) || err $?
4464

4565
echo -e "${GRN}Successfully extracted Linux headers${CLR}"
@@ -51,25 +71,26 @@ fi
5171
#
5272

5373
SRC_DIR=$DEPS/binutils
54-
OBJ_DIR=$OBJECTS/binutils
74+
STEP_DIR=$OBJ_BINUTILS
5575

56-
if [[ ! -d $OBJ_DIR ]]; then
76+
if [[ ! -d $STEP_DIR ]]; then
5777
echo -e "${WHT}Compiling binutils${CLR}"
5878

59-
mkdir -p $OBJ_DIR || exit 20
79+
rmStep $OBJ_GCC_STATIC
6080

6181
(
62-
cd $OBJ_DIR
82+
mkdir -p $STEP_DIR &&
83+
cd $STEP_DIR || exit 20
6384

6485
# Configure
65-
$SRC_DIR/configure \
66-
--silent \
67-
--prefix=$TOOLS \
68-
--target=$TARGET \
69-
--with-sysroot=$TOOLS/$TARGET \
70-
--disable-werror \
71-
--disable-nls \
72-
--disable-multilib || exit 21
86+
$SRC_DIR/configure \
87+
--silent \
88+
--prefix=$OUT_DIR \
89+
--target=$TARGET \
90+
--with-sysroot=$OUT_DIR/$TARGET \
91+
--disable-werror \
92+
--disable-nls \
93+
--disable-multilib || exit 21
7394

7495
# Compile
7596
$MAKE configure-host && $MAKE || exit 22
@@ -87,27 +108,25 @@ fi
87108
#
88109

89110
SRC_DIR=$DEPS/gcc
90-
OBJ_DIR=$OBJECTS/gcc
111+
STEP_DIR=$OBJ_GCC_STATIC
91112

92-
if [[ ! -d $OBJ_DIR ]]; then
113+
if [[ ! -d $STEP_DIR ]]; then
93114
echo -e "${WHT}Compiling GCC static${CLR}"
94115

95-
mkdir -p $OBJ_DIR || exit 30
96-
97-
# Remove old musl object files
98-
rm -rf $OBJECTS/musl || exit 31
116+
rmStep $OBJ_MUSL
99117

100118
(
101-
cd $OBJ_DIR
119+
mkdir -p $STEP_DIR &&
120+
cd $STEP_DIR || exit 30
102121

103122
# Configure
104123
$SRC_DIR/configure \
105124
--silent \
106-
--prefix=$TOOLS \
125+
--prefix=$OUT_DIR \
107126
--build=$HOST \
108127
--host=$HOST \
109128
--target=$TARGET \
110-
--with-sysroot=$TOOLS/$TARGET \
129+
--with-sysroot=$OUT_DIR/$TARGET \
111130
--disable-nls \
112131
--disable-shared \
113132
--disable-target-libsanitizer \
@@ -139,7 +158,7 @@ if [[ ! -d $OBJ_DIR ]]; then
139158

140159
# Remove object files to allow generation of final version
141160
# [ToDo] Check if we can be able to generate them on different folders
142-
rm -rf $OBJ_DIR || exit 35
161+
# rm -rf $STEP_DIR || exit 35
143162

144163
echo -e "${GRN}Successfully compiled GCC static${CLR}"
145164
fi
@@ -150,15 +169,18 @@ fi
150169
#
151170

152171
SRC_DIR=$DEPS/musl
153-
OBJ_DIR=$OBJECTS/musl
172+
STEP_DIR=$OBJ_MUSL
154173

155-
if [[ ! -d $OBJ_DIR ]]; then
174+
if [[ ! -d $STEP_DIR ]]; then
156175
echo -e "${WHT}Compiling musl${CLR}"
157176

158-
mkdir -p $OBJ_DIR || exit 40
177+
rmStep $OBJ_GCC_FINAL
159178

160179
(
161-
# cd $OBJ_DIR
180+
PATH=`pwd`/bin:$PATH # Use the just generated cross-compiler ONLY for musl
181+
182+
mkdir -p $STEP_DIR || exit 40
183+
# cd $STEP_DIR
162184
cd $SRC_DIR && $MAKE clean # musl don't support out-of-tree builds yet
163185

164186
# Configure
@@ -173,7 +195,7 @@ if [[ ! -d $OBJ_DIR ]]; then
173195
CROSS_COMPILE="$TARGET-" $MAKE || exit 42
174196

175197
# Install
176-
DESTDIR=$TOOLS/$TARGET $MAKE install || exit 43
198+
DESTDIR=$OUT_DIR/$TARGET $MAKE install || exit 43
177199
) || err $?
178200

179201
echo -e "${GRN}Successfully compiled musl${CLR}"
@@ -185,24 +207,23 @@ fi
185207
#
186208

187209
SRC_DIR=$DEPS/gcc
188-
OBJ_DIR=$OBJECTS/gcc
210+
STEP_DIR=$OBJ_GCC_FINAL
189211

190-
if [[ ! -d $OBJ_DIR ]]; then
212+
if [[ ! -d $STEP_DIR ]]; then
191213
echo -e "${WHT}Compiling GCC final${CLR}"
192214

193-
mkdir -p $OBJ_DIR || exit 50
194-
195215
(
196-
cd $OBJ_DIR
216+
mkdir -p $STEP_DIR &&
217+
cd $STEP_DIR || exit 50
197218

198219
# Configure
199220
$SRC_DIR/configure \
200221
--silent \
201-
--prefix=$TOOLS \
222+
--prefix=$OUT_DIR \
202223
--build=$HOST \
203224
--host=$HOST \
204225
--target=$TARGET \
205-
--with-sysroot=$TOOLS/$TARGET \
226+
--with-sysroot=$OUT_DIR/$TARGET \
206227
--disable-nls \
207228
--disable-static \
208229
--enable-c99 \
@@ -230,4 +251,21 @@ if [[ ! -d $OBJ_DIR ]]; then
230251
fi
231252

232253

233-
rm -rf $TOOLS/include || exit 60
254+
#
255+
# Remove empty includes and generated docs
256+
#
257+
258+
rm -rf include &&
259+
rm -rf {,share}/{info,man,doc} || exit 60
260+
261+
262+
#
263+
# Strip libraries and binaries
264+
#
265+
266+
strip --strip-debug {,$TARGET/}lib/* &>> /dev/null
267+
strip --strip-unneeded {,$TARGET/}bin/* &>> /dev/null
268+
269+
strip --strip-unneeded libexec/gcc/$TARGET/*/*{,/*} &>> /dev/null
270+
271+
exit 0 # Ignore errors from `strip`

0 commit comments

Comments
 (0)