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