More cross compiling infrastructure.
[platform/upstream/toybox.git] / Makefile
1 # Makefile for toybox.
2 # Copyright 2006 Rob Landley <rob@landley.net>
3
4 CFLAGS  := $(CFLAGS) -Wall -Wundef -Wno-char-subscripts -Os
5 CCFLAGS = $(CFLAGS) -funsigned-char
6 CC      = $(CROSS_COMPILE)gcc
7 STRIP   = $(CROSS_COMPILE)strip
8 HOSTCC  = gcc
9
10 # A synonym.
11 CROSS_COMPILE = $(CROSS)
12
13 all: toybox
14
15 .PHONY: clean
16
17 include kconfig/Makefile
18
19 # defconfig is the "maximum sane config"; allyesconfig minus debugging and such.
20 defconfig: allyesconfig
21         @sed -i -r -e "s/^(CONFIG_TOYBOX_(DEBUG|FREE))=.*/# \1 is not set/" .config
22
23 .config: Config.in toys/Config.in
24
25 # The long and roundabout sed is to make old versions of sed happy.  New ones
26 # have '\n' so can replace one line with two without all the branches and
27 # mucking about with hold space.
28 gen_config.h: .config
29         sed -n -e 's/^# CONFIG_\(.*\) is not set.*/\1/' \
30           -e 't notset' -e 'b tryisset' -e ':notset' \
31           -e 'h' -e 's/.*/#define CFG_& 0/p' \
32           -e 'g' -e 's/.*/#define USE_&(...)/p' -e 'd' -e ':tryisset' \
33           -e 's/^CONFIG_\(.*\)=y.*/\1/' -e 't isset' -e 'd' -e ':isset' \
34           -e 'h' -e 's/.*/#define CFG_& 1/p' \
35           -e 'g' -e 's/.*/#define USE_&(...) __VA_ARGS__/p' $< > $@
36
37 # Development targets
38 baseline: toybox_unstripped
39         @cp toybox_unstripped toybox_old
40
41 bloatcheck: toybox_old toybox_unstripped
42         @scripts/bloat-o-meter toybox_old toybox_unstripped
43
44 # Get list of toys/*.c files from .config
45
46 toysfiles = $(shell sed -nre 's/^CONFIG_(.*)=y/\1/;t skip;b;:skip;s/_.*//;p' .config | sort -u | tr A-Z a-z | grep -v '^toybox$$' | sed 's@\(.*\)@toys/\1.c@')
47
48 # Compile toybox from source
49
50 toyfiles = main.c lib/*.c $(toysfiles)
51 toybox_unstripped: gen_config.h $(toyfiles) toys/toylist.h lib/*.h toys.h
52         $(CC) $(CCFLAGS) -I . $(toyfiles) -o toybox_unstripped \
53                 -ffunction-sections -fdata-sections -Wl,--gc-sections
54
55 toybox: toybox_unstripped
56         $(STRIP) toybox_unstripped -o toybox
57
58 instlist: toybox
59         $(HOSTCC) $(CCFLAGS) -I . scripts/install.c -o instlist
60
61 install_flat: instlist
62         @mkdir -p $(PREFIX)/
63         @cp toybox $(PREFIX)/
64         @for i in `./instlist`; do ln -s toybox "$(PREFIX)/$$i"; done
65
66 clean::
67         rm -f toybox toybox_old toybox_unstripped gen_config.h instlist
68
69 distclean: clean
70         rm -f .config*
71
72 help::
73         @echo  '  baseline        - Create busybox_old for use by bloatcheck.'
74         @echo  '  bloatcheck      - Report size differences between old and current versions'