OSDN Git Service

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