Makefile revision f7bb55bb14128a2b9367e2e089e9930c456f801f
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
49# The following still depends on toys/help.h even when it's not there, so *.h
50# isn't sufficient by itself.
51
52toybox_unstripped: gen_config.h $(toyfiles) toys/toylist.h toys/help.h toys/*.h lib/*.h toys.h
53	$(CC) $(CCFLAGS) -I . $(toyfiles) -o toybox_unstripped $(OPTIMIZE)
54
55toybox: toybox_unstripped
56	$(STRIP) toybox_unstripped -o toybox
57
58toys/help.c: toys/help.h
59
60toys/help.h: Config.in toys/Config.in scripts/config2help.py
61	scripts/config2help.py Config.in > toys/help.h
62
63instlist: toybox
64	$(HOSTCC) $(CCFLAGS) -I . scripts/install.c -o instlist
65
66install_flat: instlist
67	@mkdir -p $(PREFIX)/
68	@cp toybox $(PREFIX)/
69	@for i in `./instlist`; do ln -s toybox "$(PREFIX)/$$i"; done
70
71clean::
72	rm -f toybox toybox_unstripped gen_config.h instlist
73
74distclean: clean
75	rm -f toybox_old .config* toys/help.h
76
77test: tests
78
79tests:
80	scripts/testall.sh
81
82help::
83	@echo  '  baseline        - Create busybox_old for use by bloatcheck.'
84	@echo  '  bloatcheck      - Report size differences between old and current versions'
85