Reduce flag duplication and make kconfig use HOST_CC.
[platform/upstream/toybox.git] / Makefile
1 # Makefile for toybox.
2 # Copyright 2006 Rob Landley <rob@landley.net>
3
4 CFLAGS  = -Wall -Wundef -Os -s
5 CC      = $(CROSS_COMPILE)gcc $(CFLAGS) -funsigned-char
6 HOST_CC = gcc $(CFLAGS) -funsigned-char
7
8 all: toybox
9
10 .PHONY: clean
11
12 include kconfig/Makefile
13
14 .config: Config.in toys/Config.in
15
16 # The long and roundabout sed is to make old versions of sed happy.  New ones
17 # have '\n' so can replace one line with two without all the branches and
18 # mucking about with hold space.
19 gen_config.h: .config
20         sed -n -e 's/^# CONFIG_\(.*\) is not set.*/\1/' \
21           -e 't notset' -e 'b tryisset' -e ':notset' \
22           -e 'h' -e 's/.*/#define CFG_& 0/p' \
23           -e 'g' -e 's/.*/#define USE_&(...)/p' -e 'd' -e ':tryisset' \
24           -e 's/^CONFIG_\(.*\)=y.*/\1/' -e 't isset' -e 'd' -e ':isset' \
25           -e 'h' -e 's/.*/#define CFG_& 1/p' \
26           -e 'g' -e 's/.*/#define USE_&(...) __VA_ARGS__/p' $< > $@
27
28 # Actual build
29
30 toyfiles = main.c toys/*.c lib/*.c
31 toybox: gen_config.h $(toyfiles) toys/toylist.h lib/lib.h toys.h
32         $(CC) $(CFLAGS) -I . $(toyfiles) -o toybox \
33                 -ffunction-sections -fdata-sections -Wl,--gc-sections
34
35 clean::
36         rm -f toybox gen_config.h
37
38 distclean: clean
39         rm -f .config