annotate scripts/make.sh @ 1108:fb8467436e6a draft

Tweak terminal_size to never set either to 0, and return true/false whether it could determine at least one coordinate. (If you set $COLUMNS but not $ROWS, we assume you're happy with the 80x25 default for the other.)
author Rob Landley <rob@landley.net>
date Thu, 07 Nov 2013 09:04:50 -0600
parents 370f15d1ece1
children 3570984a1015
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
233
d4176f3f3835 Zap toys/Config.in and instead create generated/Config.in from contents of
Rob Landley <rob@landley.net>
parents:
diff changeset
1 #!/bin/bash
d4176f3f3835 Zap toys/Config.in and instead create generated/Config.in from contents of
Rob Landley <rob@landley.net>
parents:
diff changeset
2
d4176f3f3835 Zap toys/Config.in and instead create generated/Config.in from contents of
Rob Landley <rob@landley.net>
parents:
diff changeset
3 # Grab default values for $CFLAGS and such.
d4176f3f3835 Zap toys/Config.in and instead create generated/Config.in from contents of
Rob Landley <rob@landley.net>
parents:
diff changeset
4
890
c7e7b159568d The host sort on many distros behaves stupidly, and sorts stuff in non-ascii order by default. Make it stop.
Rob Landley <rob@landley.net>
parents: 720
diff changeset
5 export LANG=c
233
d4176f3f3835 Zap toys/Config.in and instead create generated/Config.in from contents of
Rob Landley <rob@landley.net>
parents:
diff changeset
6 source ./configure
d4176f3f3835 Zap toys/Config.in and instead create generated/Config.in from contents of
Rob Landley <rob@landley.net>
parents:
diff changeset
7
1032
40d0c96a8e89 Add scripts/single.sh to build individual non-multiplexed standalone commands.
Rob Landley <rob@landley.net>
parents: 999
diff changeset
8 [ -z "$KCONFIG_CONFIG" ] && KCONFIG_CONFIG=".config"
40d0c96a8e89 Add scripts/single.sh to build individual non-multiplexed standalone commands.
Rob Landley <rob@landley.net>
parents: 999
diff changeset
9
40d0c96a8e89 Add scripts/single.sh to build individual non-multiplexed standalone commands.
Rob Landley <rob@landley.net>
parents: 999
diff changeset
10 if [ -z "$KCONFIG_CONFIG" ]
653
2986aa63a021 Move commands into "posix", "lsb", and "other" menus/directories.
Rob Landley <rob@landley.net>
parents: 595
diff changeset
11 then
1032
40d0c96a8e89 Add scripts/single.sh to build individual non-multiplexed standalone commands.
Rob Landley <rob@landley.net>
parents: 999
diff changeset
12 echo "No $KCONFIG_CONFIG (see "make help" for configuration options)."
653
2986aa63a021 Move commands into "posix", "lsb", and "other" menus/directories.
Rob Landley <rob@landley.net>
parents: 595
diff changeset
13 exit 1
2986aa63a021 Move commands into "posix", "lsb", and "other" menus/directories.
Rob Landley <rob@landley.net>
parents: 595
diff changeset
14 fi
2986aa63a021 Move commands into "posix", "lsb", and "other" menus/directories.
Rob Landley <rob@landley.net>
parents: 595
diff changeset
15
1032
40d0c96a8e89 Add scripts/single.sh to build individual non-multiplexed standalone commands.
Rob Landley <rob@landley.net>
parents: 999
diff changeset
16 echo "Make generated/config.h from $KCONFIG_CONFIG."
233
d4176f3f3835 Zap toys/Config.in and instead create generated/Config.in from contents of
Rob Landley <rob@landley.net>
parents:
diff changeset
17
d4176f3f3835 Zap toys/Config.in and instead create generated/Config.in from contents of
Rob Landley <rob@landley.net>
parents:
diff changeset
18 # This long and roundabout sed invocation is to make old versions of sed happy.
d4176f3f3835 Zap toys/Config.in and instead create generated/Config.in from contents of
Rob Landley <rob@landley.net>
parents:
diff changeset
19 # New ones have '\n' so can replace one line with two without all the branches
d4176f3f3835 Zap toys/Config.in and instead create generated/Config.in from contents of
Rob Landley <rob@landley.net>
parents:
diff changeset
20 # and tedious mucking about with hold space.
d4176f3f3835 Zap toys/Config.in and instead create generated/Config.in from contents of
Rob Landley <rob@landley.net>
parents:
diff changeset
21
346
d0bf1df83c04 Re-wordwrap and reorder the .config->config.h sed script. (No real changes, just one command/line in a clearer order.)
Rob Landley <rob@landley.net>
parents: 321
diff changeset
22 sed -n \
d0bf1df83c04 Re-wordwrap and reorder the .config->config.h sed script. (No real changes, just one command/line in a clearer order.)
Rob Landley <rob@landley.net>
parents: 321
diff changeset
23 -e 's/^# CONFIG_\(.*\) is not set.*/\1/' \
d0bf1df83c04 Re-wordwrap and reorder the .config->config.h sed script. (No real changes, just one command/line in a clearer order.)
Rob Landley <rob@landley.net>
parents: 321
diff changeset
24 -e 't notset' \
d0bf1df83c04 Re-wordwrap and reorder the .config->config.h sed script. (No real changes, just one command/line in a clearer order.)
Rob Landley <rob@landley.net>
parents: 321
diff changeset
25 -e 's/^CONFIG_\(.*\)=y.*/\1/' \
d0bf1df83c04 Re-wordwrap and reorder the .config->config.h sed script. (No real changes, just one command/line in a clearer order.)
Rob Landley <rob@landley.net>
parents: 321
diff changeset
26 -e 't isset' \
347
52e980b216d3 Convert non-bool config values (such as int) into config.h entries.
Rob Landley <rob@landley.net>
parents: 346
diff changeset
27 -e 's/^CONFIG_\([^=]*\)=\(.*\)/#define CFG_\1 \2/p' \
346
d0bf1df83c04 Re-wordwrap and reorder the .config->config.h sed script. (No real changes, just one command/line in a clearer order.)
Rob Landley <rob@landley.net>
parents: 321
diff changeset
28 -e 'd' \
d0bf1df83c04 Re-wordwrap and reorder the .config->config.h sed script. (No real changes, just one command/line in a clearer order.)
Rob Landley <rob@landley.net>
parents: 321
diff changeset
29 -e ':notset' \
d0bf1df83c04 Re-wordwrap and reorder the .config->config.h sed script. (No real changes, just one command/line in a clearer order.)
Rob Landley <rob@landley.net>
parents: 321
diff changeset
30 -e 'h' \
d0bf1df83c04 Re-wordwrap and reorder the .config->config.h sed script. (No real changes, just one command/line in a clearer order.)
Rob Landley <rob@landley.net>
parents: 321
diff changeset
31 -e 's/.*/#define CFG_& 0/p' \
d0bf1df83c04 Re-wordwrap and reorder the .config->config.h sed script. (No real changes, just one command/line in a clearer order.)
Rob Landley <rob@landley.net>
parents: 321
diff changeset
32 -e 'g' \
d0bf1df83c04 Re-wordwrap and reorder the .config->config.h sed script. (No real changes, just one command/line in a clearer order.)
Rob Landley <rob@landley.net>
parents: 321
diff changeset
33 -e 's/.*/#define USE_&(...)/p' \
d0bf1df83c04 Re-wordwrap and reorder the .config->config.h sed script. (No real changes, just one command/line in a clearer order.)
Rob Landley <rob@landley.net>
parents: 321
diff changeset
34 -e 'd' \
d0bf1df83c04 Re-wordwrap and reorder the .config->config.h sed script. (No real changes, just one command/line in a clearer order.)
Rob Landley <rob@landley.net>
parents: 321
diff changeset
35 -e ':isset' \
d0bf1df83c04 Re-wordwrap and reorder the .config->config.h sed script. (No real changes, just one command/line in a clearer order.)
Rob Landley <rob@landley.net>
parents: 321
diff changeset
36 -e 'h' \
d0bf1df83c04 Re-wordwrap and reorder the .config->config.h sed script. (No real changes, just one command/line in a clearer order.)
Rob Landley <rob@landley.net>
parents: 321
diff changeset
37 -e 's/.*/#define CFG_& 1/p' \
d0bf1df83c04 Re-wordwrap and reorder the .config->config.h sed script. (No real changes, just one command/line in a clearer order.)
Rob Landley <rob@landley.net>
parents: 321
diff changeset
38 -e 'g' \
d0bf1df83c04 Re-wordwrap and reorder the .config->config.h sed script. (No real changes, just one command/line in a clearer order.)
Rob Landley <rob@landley.net>
parents: 321
diff changeset
39 -e 's/.*/#define USE_&(...) __VA_ARGS__/p' \
1032
40d0c96a8e89 Add scripts/single.sh to build individual non-multiplexed standalone commands.
Rob Landley <rob@landley.net>
parents: 999
diff changeset
40 $KCONFIG_CONFIG > generated/config.h || exit 1
233
d4176f3f3835 Zap toys/Config.in and instead create generated/Config.in from contents of
Rob Landley <rob@landley.net>
parents:
diff changeset
41
674
7e846e281e38 New build infrastructure to generate FLAG_ macros and TT alias, #define FOR_commandname before #including toys.h to trigger it. Rename DEFINE_GLOBALS() to just GLOBALS() (because I could never remember if it was DECLARE_GLOBALS). Convert existing commands to use new infrastructure, and replace optflag constants with FLAG_ macros where appropriate.
Rob Landley <rob@landley.net>
parents: 664
diff changeset
42
7e846e281e38 New build infrastructure to generate FLAG_ macros and TT alias, #define FOR_commandname before #including toys.h to trigger it. Rename DEFINE_GLOBALS() to just GLOBALS() (because I could never remember if it was DECLARE_GLOBALS). Convert existing commands to use new infrastructure, and replace optflag constants with FLAG_ macros where appropriate.
Rob Landley <rob@landley.net>
parents: 664
diff changeset
43 echo "Extract configuration information from toys/*.c files..."
7e846e281e38 New build infrastructure to generate FLAG_ macros and TT alias, #define FOR_commandname before #including toys.h to trigger it. Rename DEFINE_GLOBALS() to just GLOBALS() (because I could never remember if it was DECLARE_GLOBALS). Convert existing commands to use new infrastructure, and replace optflag constants with FLAG_ macros where appropriate.
Rob Landley <rob@landley.net>
parents: 664
diff changeset
44 scripts/genconfig.sh
7e846e281e38 New build infrastructure to generate FLAG_ macros and TT alias, #define FOR_commandname before #including toys.h to trigger it. Rename DEFINE_GLOBALS() to just GLOBALS() (because I could never remember if it was DECLARE_GLOBALS). Convert existing commands to use new infrastructure, and replace optflag constants with FLAG_ macros where appropriate.
Rob Landley <rob@landley.net>
parents: 664
diff changeset
45
7e846e281e38 New build infrastructure to generate FLAG_ macros and TT alias, #define FOR_commandname before #including toys.h to trigger it. Rename DEFINE_GLOBALS() to just GLOBALS() (because I could never remember if it was DECLARE_GLOBALS). Convert existing commands to use new infrastructure, and replace optflag constants with FLAG_ macros where appropriate.
Rob Landley <rob@landley.net>
parents: 664
diff changeset
46 echo "Generate headers from toys/*/*.c..."
7e846e281e38 New build infrastructure to generate FLAG_ macros and TT alias, #define FOR_commandname before #including toys.h to trigger it. Rename DEFINE_GLOBALS() to just GLOBALS() (because I could never remember if it was DECLARE_GLOBALS). Convert existing commands to use new infrastructure, and replace optflag constants with FLAG_ macros where appropriate.
Rob Landley <rob@landley.net>
parents: 664
diff changeset
47
930
39ac9e0ad6ad Generate FLAG_longopt macros for --longopts with no corresponding short option.
Rob Landley <rob@landley.net>
parents: 892
diff changeset
48 # Create a list of all the commands toybox can provide. Note that the first
39ac9e0ad6ad Generate FLAG_longopt macros for --longopts with no corresponding short option.
Rob Landley <rob@landley.net>
parents: 892
diff changeset
49 # entry is out of order on purpose (the toybox multiplexer command must be the
39ac9e0ad6ad Generate FLAG_longopt macros for --longopts with no corresponding short option.
Rob Landley <rob@landley.net>
parents: 892
diff changeset
50 # first element of the array). The rest must be sorted in alphabetical order
674
7e846e281e38 New build infrastructure to generate FLAG_ macros and TT alias, #define FOR_commandname before #including toys.h to trigger it. Rename DEFINE_GLOBALS() to just GLOBALS() (because I could never remember if it was DECLARE_GLOBALS). Convert existing commands to use new infrastructure, and replace optflag constants with FLAG_ macros where appropriate.
Rob Landley <rob@landley.net>
parents: 664
diff changeset
51 # for fast binary search.
7e846e281e38 New build infrastructure to generate FLAG_ macros and TT alias, #define FOR_commandname before #including toys.h to trigger it. Rename DEFINE_GLOBALS() to just GLOBALS() (because I could never remember if it was DECLARE_GLOBALS). Convert existing commands to use new infrastructure, and replace optflag constants with FLAG_ macros where appropriate.
Rob Landley <rob@landley.net>
parents: 664
diff changeset
52
7e846e281e38 New build infrastructure to generate FLAG_ macros and TT alias, #define FOR_commandname before #including toys.h to trigger it. Rename DEFINE_GLOBALS() to just GLOBALS() (because I could never remember if it was DECLARE_GLOBALS). Convert existing commands to use new infrastructure, and replace optflag constants with FLAG_ macros where appropriate.
Rob Landley <rob@landley.net>
parents: 664
diff changeset
53 echo "generated/newtoys.h"
7e846e281e38 New build infrastructure to generate FLAG_ macros and TT alias, #define FOR_commandname before #including toys.h to trigger it. Rename DEFINE_GLOBALS() to just GLOBALS() (because I could never remember if it was DECLARE_GLOBALS). Convert existing commands to use new infrastructure, and replace optflag constants with FLAG_ macros where appropriate.
Rob Landley <rob@landley.net>
parents: 664
diff changeset
54
1032
40d0c96a8e89 Add scripts/single.sh to build individual non-multiplexed standalone commands.
Rob Landley <rob@landley.net>
parents: 999
diff changeset
55 echo "USE_TOYBOX(NEWTOY(toybox, NULL, TOYFLAG_STAYROOT))" > generated/newtoys.h
674
7e846e281e38 New build infrastructure to generate FLAG_ macros and TT alias, #define FOR_commandname before #including toys.h to trigger it. Rename DEFINE_GLOBALS() to just GLOBALS() (because I could never remember if it was DECLARE_GLOBALS). Convert existing commands to use new infrastructure, and replace optflag constants with FLAG_ macros where appropriate.
Rob Landley <rob@landley.net>
parents: 664
diff changeset
56 sed -n -e 's/^USE_[A-Z0-9_]*(/&/p' toys/*/*.c \
7e846e281e38 New build infrastructure to generate FLAG_ macros and TT alias, #define FOR_commandname before #including toys.h to trigger it. Rename DEFINE_GLOBALS() to just GLOBALS() (because I could never remember if it was DECLARE_GLOBALS). Convert existing commands to use new infrastructure, and replace optflag constants with FLAG_ macros where appropriate.
Rob Landley <rob@landley.net>
parents: 664
diff changeset
57 | sed 's/\(.*TOY(\)\([^,]*\),\(.*\)/\2 \1\2,\3/' | sort -k 1,1 \
7e846e281e38 New build infrastructure to generate FLAG_ macros and TT alias, #define FOR_commandname before #including toys.h to trigger it. Rename DEFINE_GLOBALS() to just GLOBALS() (because I could never remember if it was DECLARE_GLOBALS). Convert existing commands to use new infrastructure, and replace optflag constants with FLAG_ macros where appropriate.
Rob Landley <rob@landley.net>
parents: 664
diff changeset
58 | sed 's/[^ ]* //' >> generated/newtoys.h
1074
82c5eb459a91 Fix generated/oldtoys.h to contain option strings with USE() macros in them.
Rob Landley <rob@landley.net>
parents: 1051
diff changeset
59 sed -n -e 's/.*(NEWTOY(\([^,]*\), *\(\("[^"]*"[^,]*\)*\),.*/#define OPTSTR_\1\t\2/p' \
999
0af2375a8ef8 More grep cleanup, and make OPTSTR_command macros for use with OLDTOY()
Rob Landley <rob@landley.net>
parents: 965
diff changeset
60 generated/newtoys.h > generated/oldtoys.h
674
7e846e281e38 New build infrastructure to generate FLAG_ macros and TT alias, #define FOR_commandname before #including toys.h to trigger it. Rename DEFINE_GLOBALS() to just GLOBALS() (because I could never remember if it was DECLARE_GLOBALS). Convert existing commands to use new infrastructure, and replace optflag constants with FLAG_ macros where appropriate.
Rob Landley <rob@landley.net>
parents: 664
diff changeset
61
1076
1c15ba60aa64 Switch flag generation from shell to C.
Rob Landley <rob@landley.net>
parents: 1074
diff changeset
62 if [ ! -e generated/mkflags ]
1c15ba60aa64 Switch flag generation from shell to C.
Rob Landley <rob@landley.net>
parents: 1074
diff changeset
63 then
1c15ba60aa64 Switch flag generation from shell to C.
Rob Landley <rob@landley.net>
parents: 1074
diff changeset
64 $HOSTCC scripts/mkflags.c -o generated/mkflags || exit 1
1c15ba60aa64 Switch flag generation from shell to C.
Rob Landley <rob@landley.net>
parents: 1074
diff changeset
65 fi
1c15ba60aa64 Switch flag generation from shell to C.
Rob Landley <rob@landley.net>
parents: 1074
diff changeset
66
1c15ba60aa64 Switch flag generation from shell to C.
Rob Landley <rob@landley.net>
parents: 1074
diff changeset
67 echo generated/flags.h
1c15ba60aa64 Switch flag generation from shell to C.
Rob Landley <rob@landley.net>
parents: 1074
diff changeset
68
1c15ba60aa64 Switch flag generation from shell to C.
Rob Landley <rob@landley.net>
parents: 1074
diff changeset
69 # Parse files through C preprocessor twice, once to get flags for current
1c15ba60aa64 Switch flag generation from shell to C.
Rob Landley <rob@landley.net>
parents: 1074
diff changeset
70 # .config and once to get flags for allyesconfig
1c15ba60aa64 Switch flag generation from shell to C.
Rob Landley <rob@landley.net>
parents: 1074
diff changeset
71 for I in A B
1c15ba60aa64 Switch flag generation from shell to C.
Rob Landley <rob@landley.net>
parents: 1074
diff changeset
72 do
1c15ba60aa64 Switch flag generation from shell to C.
Rob Landley <rob@landley.net>
parents: 1074
diff changeset
73 (
1c15ba60aa64 Switch flag generation from shell to C.
Rob Landley <rob@landley.net>
parents: 1074
diff changeset
74 # define macros and select header files with option string data
712
a950dd960593 Cleanup i18n support (#ifdefectomy, move global init to process launch). Teach make.sh to emit "#define FLAG_x 0" for options inside disabled USE macros so we can unconditionally refer to them.
Rob Landley <rob@landley.net>
parents: 705
diff changeset
75
1076
1c15ba60aa64 Switch flag generation from shell to C.
Rob Landley <rob@landley.net>
parents: 1074
diff changeset
76 echo "#define NEWTOY(aa,bb,cc) aa $I bb"
1c15ba60aa64 Switch flag generation from shell to C.
Rob Landley <rob@landley.net>
parents: 1074
diff changeset
77 echo '#define OLDTOY(...)'
1c15ba60aa64 Switch flag generation from shell to C.
Rob Landley <rob@landley.net>
parents: 1074
diff changeset
78 if [ "$I" == A ]
1c15ba60aa64 Switch flag generation from shell to C.
Rob Landley <rob@landley.net>
parents: 1074
diff changeset
79 then
1c15ba60aa64 Switch flag generation from shell to C.
Rob Landley <rob@landley.net>
parents: 1074
diff changeset
80 cat generated/config.h
1c15ba60aa64 Switch flag generation from shell to C.
Rob Landley <rob@landley.net>
parents: 1074
diff changeset
81 else
1c15ba60aa64 Switch flag generation from shell to C.
Rob Landley <rob@landley.net>
parents: 1074
diff changeset
82 sed '/USE_.*([^)]*)$/s/$/ __VA_ARGS__/' generated/config.h
1c15ba60aa64 Switch flag generation from shell to C.
Rob Landley <rob@landley.net>
parents: 1074
diff changeset
83 fi
1c15ba60aa64 Switch flag generation from shell to C.
Rob Landley <rob@landley.net>
parents: 1074
diff changeset
84 cat generated/newtoys.h
1c15ba60aa64 Switch flag generation from shell to C.
Rob Landley <rob@landley.net>
parents: 1074
diff changeset
85
1c15ba60aa64 Switch flag generation from shell to C.
Rob Landley <rob@landley.net>
parents: 1074
diff changeset
86 # Run result through preprocessor, glue together " " gaps leftover from USE
1c15ba60aa64 Switch flag generation from shell to C.
Rob Landley <rob@landley.net>
parents: 1074
diff changeset
87 # macros, delete comment lines, print any line with a quoted optstring,
1c15ba60aa64 Switch flag generation from shell to C.
Rob Landley <rob@landley.net>
parents: 1074
diff changeset
88 # turn any non-quoted opstring (NULL or 0) into " " (because fscanf can't
1c15ba60aa64 Switch flag generation from shell to C.
Rob Landley <rob@landley.net>
parents: 1074
diff changeset
89 # handle "" with nothing in it).
1c15ba60aa64 Switch flag generation from shell to C.
Rob Landley <rob@landley.net>
parents: 1074
diff changeset
90
1094
370f15d1ece1 Don't use $CC without $CROSS_COMPILE because $HOSTCC could be something else entirely.
Rob Landley <rob@landley.net>
parents: 1076
diff changeset
91 ) | ${CROSS_COMPILE}${CC} -E - | \
1076
1c15ba60aa64 Switch flag generation from shell to C.
Rob Landley <rob@landley.net>
parents: 1074
diff changeset
92 sed -n -e 's/" *"//g;/^#/d;s/"/"/p' -e 's/ *$//;s/ [^" ]*$/ " "/p'
1c15ba60aa64 Switch flag generation from shell to C.
Rob Landley <rob@landley.net>
parents: 1074
diff changeset
93
1c15ba60aa64 Switch flag generation from shell to C.
Rob Landley <rob@landley.net>
parents: 1074
diff changeset
94 # Sort resulting line pairs and glue them together into triplets of
1c15ba60aa64 Switch flag generation from shell to C.
Rob Landley <rob@landley.net>
parents: 1074
diff changeset
95 # command "flags" "allflags"
1c15ba60aa64 Switch flag generation from shell to C.
Rob Landley <rob@landley.net>
parents: 1074
diff changeset
96 # to feed into mkflags C program that outputs actual flag macros
1c15ba60aa64 Switch flag generation from shell to C.
Rob Landley <rob@landley.net>
parents: 1074
diff changeset
97
1c15ba60aa64 Switch flag generation from shell to C.
Rob Landley <rob@landley.net>
parents: 1074
diff changeset
98 done | sort | sed -n 's/ A / /;t skip;d;:skip;h;n;s/[^ ]* B //;H;g;s/\n/ /;p' |\
1c15ba60aa64 Switch flag generation from shell to C.
Rob Landley <rob@landley.net>
parents: 1074
diff changeset
99 generated/mkflags > generated/flags.h || exit 1
712
a950dd960593 Cleanup i18n support (#ifdefectomy, move global init to process launch). Teach make.sh to emit "#define FLAG_x 0" for options inside disabled USE macros so we can unconditionally refer to them.
Rob Landley <rob@landley.net>
parents: 705
diff changeset
100
674
7e846e281e38 New build infrastructure to generate FLAG_ macros and TT alias, #define FOR_commandname before #including toys.h to trigger it. Rename DEFINE_GLOBALS() to just GLOBALS() (because I could never remember if it was DECLARE_GLOBALS). Convert existing commands to use new infrastructure, and replace optflag constants with FLAG_ macros where appropriate.
Rob Landley <rob@landley.net>
parents: 664
diff changeset
101 # Extract global structure definitions and flag definitions from toys/*/*.c
7e846e281e38 New build infrastructure to generate FLAG_ macros and TT alias, #define FOR_commandname before #including toys.h to trigger it. Rename DEFINE_GLOBALS() to just GLOBALS() (because I could never remember if it was DECLARE_GLOBALS). Convert existing commands to use new infrastructure, and replace optflag constants with FLAG_ macros where appropriate.
Rob Landley <rob@landley.net>
parents: 664
diff changeset
102
7e846e281e38 New build infrastructure to generate FLAG_ macros and TT alias, #define FOR_commandname before #including toys.h to trigger it. Rename DEFINE_GLOBALS() to just GLOBALS() (because I could never remember if it was DECLARE_GLOBALS). Convert existing commands to use new infrastructure, and replace optflag constants with FLAG_ macros where appropriate.
Rob Landley <rob@landley.net>
parents: 664
diff changeset
103 function getglobals()
7e846e281e38 New build infrastructure to generate FLAG_ macros and TT alias, #define FOR_commandname before #including toys.h to trigger it. Rename DEFINE_GLOBALS() to just GLOBALS() (because I could never remember if it was DECLARE_GLOBALS). Convert existing commands to use new infrastructure, and replace optflag constants with FLAG_ macros where appropriate.
Rob Landley <rob@landley.net>
parents: 664
diff changeset
104 {
7e846e281e38 New build infrastructure to generate FLAG_ macros and TT alias, #define FOR_commandname before #including toys.h to trigger it. Rename DEFINE_GLOBALS() to just GLOBALS() (because I could never remember if it was DECLARE_GLOBALS). Convert existing commands to use new infrastructure, and replace optflag constants with FLAG_ macros where appropriate.
Rob Landley <rob@landley.net>
parents: 664
diff changeset
105 for i in toys/*/*.c
7e846e281e38 New build infrastructure to generate FLAG_ macros and TT alias, #define FOR_commandname before #including toys.h to trigger it. Rename DEFINE_GLOBALS() to just GLOBALS() (because I could never remember if it was DECLARE_GLOBALS). Convert existing commands to use new infrastructure, and replace optflag constants with FLAG_ macros where appropriate.
Rob Landley <rob@landley.net>
parents: 664
diff changeset
106 do
7e846e281e38 New build infrastructure to generate FLAG_ macros and TT alias, #define FOR_commandname before #including toys.h to trigger it. Rename DEFINE_GLOBALS() to just GLOBALS() (because I could never remember if it was DECLARE_GLOBALS). Convert existing commands to use new infrastructure, and replace optflag constants with FLAG_ macros where appropriate.
Rob Landley <rob@landley.net>
parents: 664
diff changeset
107 NAME="$(echo $i | sed 's@.*/\(.*\)\.c@\1@')"
1076
1c15ba60aa64 Switch flag generation from shell to C.
Rob Landley <rob@landley.net>
parents: 1074
diff changeset
108 DATA="$(sed -n -e '/^GLOBALS(/,/^)/b got;b;:got' \
1c15ba60aa64 Switch flag generation from shell to C.
Rob Landley <rob@landley.net>
parents: 1074
diff changeset
109 -e 's/^GLOBALS(/struct '"$NAME"'_data {/' \
1c15ba60aa64 Switch flag generation from shell to C.
Rob Landley <rob@landley.net>
parents: 1074
diff changeset
110 -e 's/^)/};/' -e 'p' $i)"
712
a950dd960593 Cleanup i18n support (#ifdefectomy, move global init to process launch). Teach make.sh to emit "#define FLAG_x 0" for options inside disabled USE macros so we can unconditionally refer to them.
Rob Landley <rob@landley.net>
parents: 705
diff changeset
111
1076
1c15ba60aa64 Switch flag generation from shell to C.
Rob Landley <rob@landley.net>
parents: 1074
diff changeset
112 [ ! -z "$DATA" ] && echo -e "// $i\n\n$DATA\n"
674
7e846e281e38 New build infrastructure to generate FLAG_ macros and TT alias, #define FOR_commandname before #including toys.h to trigger it. Rename DEFINE_GLOBALS() to just GLOBALS() (because I could never remember if it was DECLARE_GLOBALS). Convert existing commands to use new infrastructure, and replace optflag constants with FLAG_ macros where appropriate.
Rob Landley <rob@landley.net>
parents: 664
diff changeset
113 done
7e846e281e38 New build infrastructure to generate FLAG_ macros and TT alias, #define FOR_commandname before #including toys.h to trigger it. Rename DEFINE_GLOBALS() to just GLOBALS() (because I could never remember if it was DECLARE_GLOBALS). Convert existing commands to use new infrastructure, and replace optflag constants with FLAG_ macros where appropriate.
Rob Landley <rob@landley.net>
parents: 664
diff changeset
114 }
7e846e281e38 New build infrastructure to generate FLAG_ macros and TT alias, #define FOR_commandname before #including toys.h to trigger it. Rename DEFINE_GLOBALS() to just GLOBALS() (because I could never remember if it was DECLARE_GLOBALS). Convert existing commands to use new infrastructure, and replace optflag constants with FLAG_ macros where appropriate.
Rob Landley <rob@landley.net>
parents: 664
diff changeset
115
7e846e281e38 New build infrastructure to generate FLAG_ macros and TT alias, #define FOR_commandname before #including toys.h to trigger it. Rename DEFINE_GLOBALS() to just GLOBALS() (because I could never remember if it was DECLARE_GLOBALS). Convert existing commands to use new infrastructure, and replace optflag constants with FLAG_ macros where appropriate.
Rob Landley <rob@landley.net>
parents: 664
diff changeset
116 echo "generated/globals.h"
7e846e281e38 New build infrastructure to generate FLAG_ macros and TT alias, #define FOR_commandname before #including toys.h to trigger it. Rename DEFINE_GLOBALS() to just GLOBALS() (because I could never remember if it was DECLARE_GLOBALS). Convert existing commands to use new infrastructure, and replace optflag constants with FLAG_ macros where appropriate.
Rob Landley <rob@landley.net>
parents: 664
diff changeset
117
7e846e281e38 New build infrastructure to generate FLAG_ macros and TT alias, #define FOR_commandname before #including toys.h to trigger it. Rename DEFINE_GLOBALS() to just GLOBALS() (because I could never remember if it was DECLARE_GLOBALS). Convert existing commands to use new infrastructure, and replace optflag constants with FLAG_ macros where appropriate.
Rob Landley <rob@landley.net>
parents: 664
diff changeset
118 GLOBSTRUCT="$(getglobals)"
7e846e281e38 New build infrastructure to generate FLAG_ macros and TT alias, #define FOR_commandname before #including toys.h to trigger it. Rename DEFINE_GLOBALS() to just GLOBALS() (because I could never remember if it was DECLARE_GLOBALS). Convert existing commands to use new infrastructure, and replace optflag constants with FLAG_ macros where appropriate.
Rob Landley <rob@landley.net>
parents: 664
diff changeset
119 (
7e846e281e38 New build infrastructure to generate FLAG_ macros and TT alias, #define FOR_commandname before #including toys.h to trigger it. Rename DEFINE_GLOBALS() to just GLOBALS() (because I could never remember if it was DECLARE_GLOBALS). Convert existing commands to use new infrastructure, and replace optflag constants with FLAG_ macros where appropriate.
Rob Landley <rob@landley.net>
parents: 664
diff changeset
120 echo "$GLOBSTRUCT"
7e846e281e38 New build infrastructure to generate FLAG_ macros and TT alias, #define FOR_commandname before #including toys.h to trigger it. Rename DEFINE_GLOBALS() to just GLOBALS() (because I could never remember if it was DECLARE_GLOBALS). Convert existing commands to use new infrastructure, and replace optflag constants with FLAG_ macros where appropriate.
Rob Landley <rob@landley.net>
parents: 664
diff changeset
121 echo
7e846e281e38 New build infrastructure to generate FLAG_ macros and TT alias, #define FOR_commandname before #including toys.h to trigger it. Rename DEFINE_GLOBALS() to just GLOBALS() (because I could never remember if it was DECLARE_GLOBALS). Convert existing commands to use new infrastructure, and replace optflag constants with FLAG_ macros where appropriate.
Rob Landley <rob@landley.net>
parents: 664
diff changeset
122 echo "extern union global_union {"
7e846e281e38 New build infrastructure to generate FLAG_ macros and TT alias, #define FOR_commandname before #including toys.h to trigger it. Rename DEFINE_GLOBALS() to just GLOBALS() (because I could never remember if it was DECLARE_GLOBALS). Convert existing commands to use new infrastructure, and replace optflag constants with FLAG_ macros where appropriate.
Rob Landley <rob@landley.net>
parents: 664
diff changeset
123 echo "$GLOBSTRUCT" | sed -n 's/struct \(.*\)_data {/ struct \1_data \1;/p'
7e846e281e38 New build infrastructure to generate FLAG_ macros and TT alias, #define FOR_commandname before #including toys.h to trigger it. Rename DEFINE_GLOBALS() to just GLOBALS() (because I could never remember if it was DECLARE_GLOBALS). Convert existing commands to use new infrastructure, and replace optflag constants with FLAG_ macros where appropriate.
Rob Landley <rob@landley.net>
parents: 664
diff changeset
124 echo "} this;"
7e846e281e38 New build infrastructure to generate FLAG_ macros and TT alias, #define FOR_commandname before #including toys.h to trigger it. Rename DEFINE_GLOBALS() to just GLOBALS() (because I could never remember if it was DECLARE_GLOBALS). Convert existing commands to use new infrastructure, and replace optflag constants with FLAG_ macros where appropriate.
Rob Landley <rob@landley.net>
parents: 664
diff changeset
125 ) > generated/globals.h
7e846e281e38 New build infrastructure to generate FLAG_ macros and TT alias, #define FOR_commandname before #including toys.h to trigger it. Rename DEFINE_GLOBALS() to just GLOBALS() (because I could never remember if it was DECLARE_GLOBALS). Convert existing commands to use new infrastructure, and replace optflag constants with FLAG_ macros where appropriate.
Rob Landley <rob@landley.net>
parents: 664
diff changeset
126
7e846e281e38 New build infrastructure to generate FLAG_ macros and TT alias, #define FOR_commandname before #including toys.h to trigger it. Rename DEFINE_GLOBALS() to just GLOBALS() (because I could never remember if it was DECLARE_GLOBALS). Convert existing commands to use new infrastructure, and replace optflag constants with FLAG_ macros where appropriate.
Rob Landley <rob@landley.net>
parents: 664
diff changeset
127 echo "generated/help.h"
965
0d20619388b3 Juhani Haverinen pointed out that python 3 doesn't work with config2help.py, so you python2 binary until finishing the C rewrite.
Rob Landley <rob@landley.net>
parents: 963
diff changeset
128 # Only recreate generated/help.h if python2 is installed. Does not work with 3.
1050
223df8e9c694 make.sh: Fix probing for python2.x and be verbose in error reporting
Elie De Brauwer <eliedebrauwer@gmail.com>
parents: 1037
diff changeset
129 PYTHON="$(which python2 || which python2.6 || which python2.7)"
223df8e9c694 make.sh: Fix probing for python2.x and be verbose in error reporting
Elie De Brauwer <eliedebrauwer@gmail.com>
parents: 1037
diff changeset
130 if [ ! -z "$(grep 'CONFIG_TOYBOX_HELP=y' $KCONFIG_CONFIG)" ];
674
7e846e281e38 New build infrastructure to generate FLAG_ macros and TT alias, #define FOR_commandname before #including toys.h to trigger it. Rename DEFINE_GLOBALS() to just GLOBALS() (because I could never remember if it was DECLARE_GLOBALS). Convert existing commands to use new infrastructure, and replace optflag constants with FLAG_ macros where appropriate.
Rob Landley <rob@landley.net>
parents: 664
diff changeset
131 then
1050
223df8e9c694 make.sh: Fix probing for python2.x and be verbose in error reporting
Elie De Brauwer <eliedebrauwer@gmail.com>
parents: 1037
diff changeset
132 if [ -z "$PYTHON" ];
223df8e9c694 make.sh: Fix probing for python2.x and be verbose in error reporting
Elie De Brauwer <eliedebrauwer@gmail.com>
parents: 1037
diff changeset
133 then
1051
626cc2108480 Allow shipped generated/help.h to still be used, until I rewrite the generator in C.
Rob Landley <rob@landley.net>
parents: 1050
diff changeset
134 echo "Python 2.x required to rebuild generated/help.h"
626cc2108480 Allow shipped generated/help.h to still be used, until I rewrite the generator in C.
Rob Landley <rob@landley.net>
parents: 1050
diff changeset
135 # exit 1
1050
223df8e9c694 make.sh: Fix probing for python2.x and be verbose in error reporting
Elie De Brauwer <eliedebrauwer@gmail.com>
parents: 1037
diff changeset
136 else
223df8e9c694 make.sh: Fix probing for python2.x and be verbose in error reporting
Elie De Brauwer <eliedebrauwer@gmail.com>
parents: 1037
diff changeset
137 echo "Extract help text from Config.in."
223df8e9c694 make.sh: Fix probing for python2.x and be verbose in error reporting
Elie De Brauwer <eliedebrauwer@gmail.com>
parents: 1037
diff changeset
138 "$PYTHON" scripts/config2help.py Config.in > generated/help.h || exit 1
223df8e9c694 make.sh: Fix probing for python2.x and be verbose in error reporting
Elie De Brauwer <eliedebrauwer@gmail.com>
parents: 1037
diff changeset
139 fi
674
7e846e281e38 New build infrastructure to generate FLAG_ macros and TT alias, #define FOR_commandname before #including toys.h to trigger it. Rename DEFINE_GLOBALS() to just GLOBALS() (because I could never remember if it was DECLARE_GLOBALS). Convert existing commands to use new infrastructure, and replace optflag constants with FLAG_ macros where appropriate.
Rob Landley <rob@landley.net>
parents: 664
diff changeset
140 fi
7e846e281e38 New build infrastructure to generate FLAG_ macros and TT alias, #define FOR_commandname before #including toys.h to trigger it. Rename DEFINE_GLOBALS() to just GLOBALS() (because I could never remember if it was DECLARE_GLOBALS). Convert existing commands to use new infrastructure, and replace optflag constants with FLAG_ macros where appropriate.
Rob Landley <rob@landley.net>
parents: 664
diff changeset
141
1032
40d0c96a8e89 Add scripts/single.sh to build individual non-multiplexed standalone commands.
Rob Landley <rob@landley.net>
parents: 999
diff changeset
142 # Extract a list of toys/*/*.c files to compile from the data in $KCONFIG_CONFIG
233
d4176f3f3835 Zap toys/Config.in and instead create generated/Config.in from contents of
Rob Landley <rob@landley.net>
parents:
diff changeset
143
654
04feab07416c Teach build to compare toys/*/*.c against .config symbol names instead of stopping at first _ when assembling list of files to build, and convert - to _. This lets us have commands like switch_root or nbd-client.
Rob Landley <rob@landley.net>
parents: 653
diff changeset
144 # 1) Get a list of C files in toys/* and glue them together into a regex we can
04feab07416c Teach build to compare toys/*/*.c against .config symbol names instead of stopping at first _ when assembling list of files to build, and convert - to _. This lets us have commands like switch_root or nbd-client.
Rob Landley <rob@landley.net>
parents: 653
diff changeset
145 # feed to grep that will match any one of them (whole word, not substring).
04feab07416c Teach build to compare toys/*/*.c against .config symbol names instead of stopping at first _ when assembling list of files to build, and convert - to _. This lets us have commands like switch_root or nbd-client.
Rob Landley <rob@landley.net>
parents: 653
diff changeset
146 TOYFILES="^$(ls toys/*/*.c | sed -n 's@^.*/\(.*\)\.c$@\1@;s/-/_/g;H;${g;s/\n//;s/\n/$|^/gp}')\$"
04feab07416c Teach build to compare toys/*/*.c against .config symbol names instead of stopping at first _ when assembling list of files to build, and convert - to _. This lets us have commands like switch_root or nbd-client.
Rob Landley <rob@landley.net>
parents: 653
diff changeset
147
04feab07416c Teach build to compare toys/*/*.c against .config symbol names instead of stopping at first _ when assembling list of files to build, and convert - to _. This lets us have commands like switch_root or nbd-client.
Rob Landley <rob@landley.net>
parents: 653
diff changeset
148 # 2) Grab the XXX part of all CONFIG_XXX entries, removing everything after the
233
d4176f3f3835 Zap toys/Config.in and instead create generated/Config.in from contents of
Rob Landley <rob@landley.net>
parents:
diff changeset
149 # second underline
654
04feab07416c Teach build to compare toys/*/*.c against .config symbol names instead of stopping at first _ when assembling list of files to build, and convert - to _. This lets us have commands like switch_root or nbd-client.
Rob Landley <rob@landley.net>
parents: 653
diff changeset
150 # 3) Sort the list, keeping only one of each entry.
04feab07416c Teach build to compare toys/*/*.c against .config symbol names instead of stopping at first _ when assembling list of files to build, and convert - to _. This lets us have commands like switch_root or nbd-client.
Rob Landley <rob@landley.net>
parents: 653
diff changeset
151 # 4) Convert to lower case.
04feab07416c Teach build to compare toys/*/*.c against .config symbol names instead of stopping at first _ when assembling list of files to build, and convert - to _. This lets us have commands like switch_root or nbd-client.
Rob Landley <rob@landley.net>
parents: 653
diff changeset
152 # 5) Remove any config symbol not recognized as a filename from step 1.
04feab07416c Teach build to compare toys/*/*.c against .config symbol names instead of stopping at first _ when assembling list of files to build, and convert - to _. This lets us have commands like switch_root or nbd-client.
Rob Landley <rob@landley.net>
parents: 653
diff changeset
153 # 6) Add "toys/*/" prefix and ".c" suffix.
233
d4176f3f3835 Zap toys/Config.in and instead create generated/Config.in from contents of
Rob Landley <rob@landley.net>
parents:
diff changeset
154
1032
40d0c96a8e89 Add scripts/single.sh to build individual non-multiplexed standalone commands.
Rob Landley <rob@landley.net>
parents: 999
diff changeset
155 TOYFILES=$(sed -nre 's/^CONFIG_(.*)=y/\1/p' < "$KCONFIG_CONFIG" \
654
04feab07416c Teach build to compare toys/*/*.c against .config symbol names instead of stopping at first _ when assembling list of files to build, and convert - to _. This lets us have commands like switch_root or nbd-client.
Rob Landley <rob@landley.net>
parents: 653
diff changeset
156 | sort -u | tr A-Z a-z | grep -E "$TOYFILES" | sed 's@\(.*\)@toys/\*/\1.c@')
233
d4176f3f3835 Zap toys/Config.in and instead create generated/Config.in from contents of
Rob Landley <rob@landley.net>
parents:
diff changeset
157
581
1e07220fd3b6 Probe available libraries to link --as-needed, avoiding "unknown libarary" errors.
Rob Landley <rob@landley.net>
parents: 572
diff changeset
158 echo "Library probe..."
1e07220fd3b6 Probe available libraries to link --as-needed, avoiding "unknown libarary" errors.
Rob Landley <rob@landley.net>
parents: 572
diff changeset
159
653
2986aa63a021 Move commands into "posix", "lsb", and "other" menus/directories.
Rob Landley <rob@landley.net>
parents: 595
diff changeset
160 # We trust --as-needed to remove each library if we don't use any symbols
2986aa63a021 Move commands into "posix", "lsb", and "other" menus/directories.
Rob Landley <rob@landley.net>
parents: 595
diff changeset
161 # out of it, this loop is because the compiler has no way to ignore a library
2986aa63a021 Move commands into "posix", "lsb", and "other" menus/directories.
Rob Landley <rob@landley.net>
parents: 595
diff changeset
162 # that doesn't exist, so we have to detect and skip nonexistent libraries
2986aa63a021 Move commands into "posix", "lsb", and "other" menus/directories.
Rob Landley <rob@landley.net>
parents: 595
diff changeset
163 # for it.
2986aa63a021 Move commands into "posix", "lsb", and "other" menus/directories.
Rob Landley <rob@landley.net>
parents: 595
diff changeset
164
581
1e07220fd3b6 Probe available libraries to link --as-needed, avoiding "unknown libarary" errors.
Rob Landley <rob@landley.net>
parents: 572
diff changeset
165 OPTLIBS="$(for i in util crypt m; do echo "int main(int argc, char *argv[]) {return 0;}" | ${CROSS_COMPILE}${CC} -xc - -o /dev/null -Wl,--as-needed -l$i > /dev/null 2>/dev/null && echo -l$i; done)"
1e07220fd3b6 Probe available libraries to link --as-needed, avoiding "unknown libarary" errors.
Rob Landley <rob@landley.net>
parents: 572
diff changeset
166
233
d4176f3f3835 Zap toys/Config.in and instead create generated/Config.in from contents of
Rob Landley <rob@landley.net>
parents:
diff changeset
167 echo "Compile toybox..."
d4176f3f3835 Zap toys/Config.in and instead create generated/Config.in from contents of
Rob Landley <rob@landley.net>
parents:
diff changeset
168
472
f59b4b6bde5e Add V=1 support to make.
Rob Landley <rob@landley.net>
parents: 364
diff changeset
169 do_loudly()
f59b4b6bde5e Add V=1 support to make.
Rob Landley <rob@landley.net>
parents: 364
diff changeset
170 {
f59b4b6bde5e Add V=1 support to make.
Rob Landley <rob@landley.net>
parents: 364
diff changeset
171 [ ! -z "$V" ] && echo "$@"
f59b4b6bde5e Add V=1 support to make.
Rob Landley <rob@landley.net>
parents: 364
diff changeset
172 "$@"
f59b4b6bde5e Add V=1 support to make.
Rob Landley <rob@landley.net>
parents: 364
diff changeset
173 }
f59b4b6bde5e Add V=1 support to make.
Rob Landley <rob@landley.net>
parents: 364
diff changeset
174
512
9bcc288a1c54 Fix from Georgi Chorbadzhiyski to make cross compiling more robust.
Rob Landley <rob@landley.net>
parents: 472
diff changeset
175 do_loudly ${CROSS_COMPILE}${CC} $CFLAGS -I . -o toybox_unstripped $OPTIMIZE \
581
1e07220fd3b6 Probe available libraries to link --as-needed, avoiding "unknown libarary" errors.
Rob Landley <rob@landley.net>
parents: 572
diff changeset
176 main.c lib/*.c $TOYFILES -Wl,--as-needed $OPTLIBS || exit 1
512
9bcc288a1c54 Fix from Georgi Chorbadzhiyski to make cross compiling more robust.
Rob Landley <rob@landley.net>
parents: 472
diff changeset
177 do_loudly ${CROSS_COMPILE}${STRIP} toybox_unstripped -o toybox || exit 1
364
6df3ac5165fa The "strip" in gcc 4.4 doesn't set the executable bit on its output, despite what SUSv4 says it should do, so cope with buggy FSF tools.
Rob Landley <rob@landley.net>
parents: 347
diff changeset
178 # gcc 4.4's strip command is buggy, and doesn't set the executable bit on
6df3ac5165fa The "strip" in gcc 4.4 doesn't set the executable bit on its output, despite what SUSv4 says it should do, so cope with buggy FSF tools.
Rob Landley <rob@landley.net>
parents: 347
diff changeset
179 # its output the way SUSv4 suggests it do so.
472
f59b4b6bde5e Add V=1 support to make.
Rob Landley <rob@landley.net>
parents: 364
diff changeset
180 do_loudly chmod +x toybox || exit 1