Makefile revision 064d1b1e5d29f79060c47769da92d51f89bc9edd
1# Makefile for toybox.
2# Copyright 2006 Rob Landley <rob@landley.net>
3
4CFLAGS  := $(CFLAGS) -Wall -Wundef -Wno-char-subscripts
5CCFLAGS = $(CFLAGS) -funsigned-char
6OPTIMIZE = -Os -ffunction-sections -fdata-sections -Wl,--gc-sections
7CC      = $(CROSS_COMPILE)gcc
8STRIP   = $(CROSS_COMPILE)strip
9HOSTCC  = gcc
10
11# A synonym.
12CROSS_COMPILE = $(CROSS)
13
14all: toybox
15
16.PHONY: clean
17
18include 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.
29gen_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
39baseline: toybox_unstripped
40	@cp toybox_unstripped toybox_old
41
42bloatcheck: 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
46toyfiles = main.c lib/*.c \
47	$(shell scripts/cfg2files.sh < .config | sed 's@\(.*\)@toys/\1.c@')
48
49toybox_unstripped: gen_config.h $(toyfiles) toys/toylist.h lib/*.h toys.h
50	$(CC) $(CCFLAGS) -I . $(toyfiles) -o toybox_unstripped $(OPTIMIZE)
51
52toybox: toybox_unstripped
53	$(STRIP) toybox_unstripped -o toybox
54
55toys/help.c: toys/help.h
56
57toys/help.h: Config.in toys/Config.in scripts/config2help.py
58	scripts/config2help.py Config.in > toys/help.h
59
60instlist: toybox
61	$(HOSTCC) $(CCFLAGS) -I . scripts/install.c -o instlist
62
63install_flat: instlist
64	@mkdir -p $(PREFIX)/
65	@cp toybox $(PREFIX)/
66	@for i in `./instlist`; do ln -s toybox "$(PREFIX)/$$i"; done
67
68clean::
69	rm -f toybox toybox_unstripped gen_config.h instlist
70
71distclean: clean
72	rm -f toybox_old .config*
73
74test: tests
75
76tests:
77	scripts/testall.sh
78
79help::
80	@echo  '  baseline        - Create busybox_old for use by bloatcheck.'
81	@echo  '  bloatcheck      - Report size differences between old and current versions'
82