# Makefile for toybox.
# Copyright 2006 Rob Landley <rob@landley.net>
-CFLAGS = -Wall -Wundef -Wno-char-subscripts -Os
-CCFLAGS = $(CFLAGS) -funsigned-char
-CC = $(CROSS_COMPILE)gcc
-STRIP = $(CROSS_COMPILE)strip
-HOSTCC = gcc
+# If people set these on the make command line, use 'em
+# Note that CC defaults to "cc" so the one in configure doesn't get
+# used when scripts/make.sh and care called through "make".
-all: toybox
+HOSTCC?=cc
-.PHONY: clean
+export CROSS_COMPILE CFLAGS OPTIMIZE LDOPTIMIZE CC HOSTCC V
-include kconfig/Makefile
+all: toybox
-# defconfig is the "maximum sane config"; allyesconfig minus debugging and such.
-defconfig: allyesconfig
- @sed -i -r -e "s/^(CONFIG_TOYBOX_(DEBUG|FREE))=.*/# \1 is not set/" .config
+KCONFIG_CONFIG ?= .config
-.config: Config.in toys/Config.in
+toybox_stuff: $(KCONFIG_CONFIG) *.[ch] lib/*.[ch] toys/*.h toys/*/*.c scripts/*.sh
-# The long and roundabout sed is to make old versions of sed happy. New ones
-# have '\n' so can replace one line with two without all the branches and
-# mucking about with hold space.
-gen_config.h: .config
- sed -n -e 's/^# CONFIG_\(.*\) is not set.*/\1/' \
- -e 't notset' -e 'b tryisset' -e ':notset' \
- -e 'h' -e 's/.*/#define CFG_& 0/p' \
- -e 'g' -e 's/.*/#define USE_&(...)/p' -e 'd' -e ':tryisset' \
- -e 's/^CONFIG_\(.*\)=y.*/\1/' -e 't isset' -e 'd' -e ':isset' \
- -e 'h' -e 's/.*/#define CFG_& 1/p' \
- -e 'g' -e 's/.*/#define USE_&(...) __VA_ARGS__/p' $< > $@
+toybox generated/unstripped/toybox: toybox_stuff
+ scripts/make.sh
-# Development targets
-baseline: toybox_unstripped
- @cp toybox_unstripped toybox_old
+.PHONY: clean distclean baseline bloatcheck install install_flat \
+ uinstall uninstall_flat tests help toybox_stuff change \
+ list list_working list_pending
-bloatcheck: toybox_old toybox_unstripped
- @scripts/bloat-o-meter toybox_old toybox_unstripped
+include kconfig/Makefile
+-include .singlemake
+
+$(KCONFIG_CONFIG): $(KCONFIG_TOP)
+$(KCONFIG_TOP): generated/Config.in
+generated/Config.in: toys/*/*.c scripts/genconfig.sh
+ scripts/genconfig.sh
-# Get list of toys/*.c files from .config
+# Development targets
+baseline: generated/unstripped/toybox
+ @cp generated/unstripped/toybox generated/unstripped/toybox_old
-toysfiles = $(shell sed -nre 's/^CONFIG_(.*)=y/\1/;t skip;b;:skip;s/_.*//;p' .config | sort -u | tr A-Z a-z | grep -v '^toybox$$' | sed 's@\(.*\)@toys/\1.c@')
+bloatcheck: toybox_old generated/unstripped/toybox
+ @scripts/bloatcheck generated/unstripped/toybox_old generated/unstripped/toybox
-# Compile toybox from source
+install_flat:
+ scripts/install.sh --symlink --force
-toyfiles = main.c lib/*.c $(toysfiles)
-toybox_unstripped: gen_config.h $(toyfiles) toys/toylist.h lib/*.h toys.h
- $(CC) $(CCFLAGS) -I . $(toyfiles) -o toybox_unstripped \
- -ffunction-sections -fdata-sections -Wl,--gc-sections
+install:
+ scripts/install.sh --long --symlink --force
-toybox: toybox_unstripped
- $(STRIP) toybox_unstripped -o toybox
+uninstall_flat:
+ scripts/install.sh --uninstall
-instlist: toybox
- $(HOSTCC) $(CCFLAGS) -I . scripts/install.c -o instlist
+uninstall:
+ scripts/install.sh --long --uninstall
-install_flat: instlist
- @mkdir -p $(PREFIX)/
- @cp toybox $(PREFIX)/
- @for i in `./instlist`; do ln -s toybox "$(PREFIX)/$$i"; done
+change:
+ scripts/change.sh
clean::
- rm -f toybox toybox_old toybox_unstripped gen_config.h instlist
+ rm -rf toybox generated change .singleconfig*
distclean: clean
- rm -f .config*
+ rm -f toybox_old .config* .singlemake
+
+tests:
+ scripts/test.sh
help::
- @echo ' baseline - Create busybox_old for use by bloatcheck.'
+ @echo ' toybox - Build toybox.'
+ @echo ' COMMANDNAME - Build individual toybox command as a standalone binary.'
+ @echo ' list - List COMMANDNAMEs you can build standalone.'
+ @echo ' list_pending - List unfinished COMMANDNAMEs out of toys/pending.'
+ @echo ' change - Build each command standalone under change/.'
+ @echo ' baseline - Create toybox_old for use by bloatcheck.'
@echo ' bloatcheck - Report size differences between old and current versions'
+ @echo ' test_COMMAND - Run tests for COMMAND (test_ps, test_cat, etc.)'
+ @echo ' tests - Run test suite against all compiled commands.'
+ @echo ' export TEST_HOST=1 to test host command, VERBOSE=1'
+ @echo ' to show diff, VERBOSE=fail to stop after first failure.'
+ @echo ' clean - Delete temporary files.'
+ @echo " distclean - Delete everything that isn't shipped."
+ @echo ' install_flat - Install toybox into $$PREFIX directory.'
+ @echo ' install - Install toybox into subdirectories of $$PREFIX.'
+ @echo ' uninstall_flat - Remove toybox from $$PREFIX directory.'
+ @echo ' uninstall - Remove toybox from subdirectories of $$PREFIX.'
+ @echo ''
+ @echo 'example: CFLAGS="--static" CROSS_COMPILE=armv5l- make defconfig toybox install'
+ @echo ''