Commit f99e6d1e authored by Kai Germaschewski's avatar Kai Germaschewski

kbuild: Add rules for compiling programs on the host

At a couple of places, we need to build programs which run on the
compile host during building the kernel.

Add a new variable "host-progs" to declare such programs. Rules.make will
automatically provide rules to compile these programs with appropriate
command lines etc.

Compared to having explicit rules spread around for doing so, this has
the following advantages:

o shorter
o automatically figures out dependencies and handles changing command
  lines
o Nicer output in quiet mode ;-)

Compiling host programs from multiple sources is also possible, analogous
to multi-part objects. E.g. scripts/Makefile has

	host-progs := tkparse
	tkparse-objs := tkparse.o tkcond.o tkgen.o
parent f56dec02
......@@ -224,6 +224,36 @@ $(multi-used-y) : %.o: $(multi-objs-y) FORCE
$(multi-used-m) : %.o: $(multi-objs-m) FORCE
$(call if_changed,cmd_link_multi)
# Compile programs on the host
# FIXME: handle dependencies
# ===========================================================================
host-progs-single := $(foreach m,$(host-progs),$(if $($(m)-objs),,$(m)))
host-progs-multi := $(foreach m,$(host-progs),$(if $($(m)-objs),$(m)))
host-progs-multi-objs := $(foreach m,$(host-progs-multi),$($(m)-objs))
quiet_cmd_host_cc__c = HOSTCC $(RELDIR)/$@
cmd_host_cc__c = $(HOSTCC) -Wp,-MD,.$(subst /,_,$@).d \
$(HOSTCFLAGS) $(HOST_EXTRACFLAGS) -o $@ $<
$(host-progs-single): %: %.c FORCE
$(call if_changed_dep,host_cc__c)
quiet_cmd_host_cc_o_c = HOSTCC $(RELDIR)/$@
cmd_host_cc_o_c = $(HOSTCC) -Wp,-MD,.$(subst /,_,$@).d \
$(HOSTCFLAGS) $(HOST_EXTRACFLAGS) -c -o $@ $<
$(host-progs-multi-objs): %.o: %.c FORCE
$(call if_changed_dep,host_cc_o_c)
quiet_cmd_host_cc__o = HOSTLD $(RELDIR)/$@
cmd_host_cc__o = $(HOSTCC) $(HOSTLDFLAGS) -o $@ $($@-objs) \
$(HOST_LOADLIBES)
$(host-progs-multi): %: $(host-progs-multi-objs) FORCE
$(call if_changed,cmd_host_cc__o)
# Descending when making module versions
# ---------------------------------------------------------------------------
......
......@@ -56,6 +56,8 @@ EXTRA_CFLAGS=-g
fore_200e-objs := fore200e.o $(FORE200E_FW_OBJS)
host-progs := fore200e_mkfirm
include $(TOPDIR)/Rules.make
......@@ -80,9 +82,6 @@ fore200e_sba_fw.c: $(patsubst "%", %, $(CONFIG_ATM_FORE200E_SBA_FW)) \
echo 'endif' \
) >.$@.fw
fore200e_mkfirm: fore200e_mkfirm.c
$(HOSTCC) $(HOSTCFLAGS) $< -o $@
# deal with the various suffixes of the binary firmware images
%.bin %.bin1 %.bin2: %.data
objcopy -Iihex $< -Obinary $@.gz
......
......@@ -214,17 +214,12 @@ obj-$(CONFIG_AGP) += agp/
obj-$(CONFIG_DRM) += drm/
obj-$(CONFIG_PCMCIA) += pcmcia/
include $(TOPDIR)/Rules.make
fastdep:
host-progs := conmakehash
conmakehash: conmakehash.c
$(HOSTCC) $(HOSTCFLAGS) -o conmakehash conmakehash.c
include $(TOPDIR)/Rules.make
consolemap_deftbl.c: $(FONTMAPFILE) conmakehash
./conmakehash $(FONTMAPFILE) > consolemap_deftbl.c
consolemap_deftbl.o: consolemap_deftbl.c $(TOPDIR)/include/linux/types.h
./conmakehash $< > $@
.DELETE_ON_ERROR:
......
......@@ -16,19 +16,21 @@ soundmodem-$(CONFIG_SOUNDMODEM_PSK4800) += sm_psk4800.o
soundmodem-$(CONFIG_SOUNDMODEM_FSK9600) += sm_fsk9600.o
soundmodem-objs := $(soundmodem-y)
host-progs := gentbl
HOST_LOADLIBES := -lm
include $(TOPDIR)/Rules.make
# Dependencies on generates files need to be listed explicitly
sm_%.o: sm_tbl_%.h
TBLHDR := sm_tbl_afsk1200.h sm_tbl_afsk2400_7.h sm_tbl_afsk2400_8.h \
sm_tbl_afsk2666.h sm_tbl_psk4800.h sm_tbl_hapn4800.h \
sm_tbl_fsk9600.h
$(TBLHDR): gentbl
./gentbl
sm_afsk1200.o: sm_tbl_afsk1200.h
sm_afsk2400_7.o: sm_tbl_afsk2400_7.h
sm_afsk2400_8.o: sm_tbl_afsk2400_8.h
sm_afsk2666.o: sm_tbl_afsk2666.h
sm_psk4800.o: sm_tbl_psk4800.h
sm_hapn4800.o: sm_tbl_hapn4800.h
sm_fsk9600.o: sm_tbl_fsk9600.h
gentbl: gentbl.c
$(HOSTCC) $(HOSTCFLAGS) $< -o $@ -lm
sm_tbl_%: gentbl
./gentbl
......@@ -30,12 +30,11 @@ ifndef CONFIG_X86
obj-y += syscall.o
endif
host-progs := gen-devlist
include $(TOPDIR)/Rules.make
names.o: names.c devlist.h classlist.h
names.o: devlist.h classlist.h
devlist.h classlist.h: pci.ids gen-devlist
./gen-devlist <pci.ids
gen-devlist: gen-devlist.c
$(HOSTCC) $(HOSTCFLAGS) -o gen-devlist gen-devlist.c
......@@ -124,14 +124,13 @@ obj-$(CONFIG_FBCON_HGA) += fbcon-hga.o
obj-$(CONFIG_FBCON_STI) += fbcon-sti.o
obj-$(CONFIG_FBCON_ACCEL) += fbcon-accel.o
host-progs := ../conmakehash
include $(TOPDIR)/Rules.make
clean:
rm -f core *.o *.a *.s
../conmakehash: ../conmakehash.c
$(HOSTCC) $(HOSTCFLAGS) -o ../conmakehash ../conmakehash.c
promcon_tbl.c: prom.uni ../char/conmakehash
../char/conmakehash prom.uni | \
sed -e '/#include <[^>]*>/p' -e 's/types/init/' \
......
......@@ -7,12 +7,11 @@ export-objs := zorro.o
obj-$(CONFIG_ZORRO) += zorro.o names.o
obj-$(CONFIG_PROC_FS) += proc.o
host-progs := gen_devlist
include $(TOPDIR)/Rules.make
names.o: names.c devlist.h
names.o: devlist.h
devlist.h: zorro.ids gen-devlist
./gen-devlist <zorro.ids
gen-devlist: gen-devlist.c
$(HOSTCC) $(HOSTCFLAGS) -o gen-devlist gen-devlist.c
......@@ -8,12 +8,11 @@ khttpd-objs := main.o accept.o datasending.o logging.o misc.o rfc.o \
rfc_time.o security.o sockets.o sysctl.o userspace.o \
waitheaders.o
host-progs := make_times_h
include $(TOPDIR)/Rules.make
rfc_time.o: times.h
make_times_h: make_times_h.c
$(HOSTCC) $(HOSTCFLAGS) -o make_times_h make_times_h.c
times.h: make_times_h
./make_times_h
......@@ -9,12 +9,6 @@ CHMOD_FILES := docgen gen-all-syms kernel-doc mkcompile_h makelst
all: fixdep split-include $(CHMOD_FILES)
fixdep: fixdep.c
$(HOSTCC) $(HOSTCFLAGS) -o $@ $<
split-include: split-include.c
$(HOSTCC) $(HOSTCFLAGS) -o $@ $<
$(CHMOD_FILES): FORCE
@chmod a+x $@
......@@ -43,23 +37,15 @@ kconfig.tk: $(TOPDIR)/arch/$(ARCH)/config.in tkparse $(HEADER) $(TAIL) FORCE
) > $@
chmod 755 $@
tkparse: tkparse.o tkcond.o tkgen.o
$(HOSTCC) -o $@ $^
tkparse.o tkcond.o tkgen.o: %.o: %.c
$(HOSTCC) $(HOSTCFLAGS) -c -o $@ $<
# DocBook stuff
# ---------------------------------------------------------------------------
doc-progs: docproc
docproc: docproc.c
$(HOSTCC) $(HOSTCFLAGS) -o $@ $<
include $(TOPDIR)/Rules.make
# ---------------------------------------------------------------------------
# we don't have automatic deps for host programs
host-progs := fixdep split-include docproc tkparse
tkparse.o tkcond.o tkgen.o: tkparse.h
tkparse-objs := tkparse.o tkcond.o tkgen.o
include $(TOPDIR)/Rules.make
HOSTCFLAGS += -DLOCALE
LIBS = -lncurses
HOST_EXTRACFLAGS := -DLOCALE
HOST_LOADLIBES := -lncurses
ifeq (/usr/include/ncurses/ncurses.h, $(wildcard /usr/include/ncurses/ncurses.h))
HOSTCFLAGS += -I/usr/include/ncurses -DCURSES_LOC="<ncurses.h>"
HOST_EXTRACFLAGS += -I/usr/include/ncurses -DCURSES_LOC="<ncurses.h>"
else
ifeq (/usr/include/ncurses/curses.h, $(wildcard /usr/include/ncurses/curses.h))
HOSTCFLAGS += -I/usr/include/ncurses -DCURSES_LOC="<ncurses/curses.h>"
HOST_EXTRACFLAGS += -I/usr/include/ncurses -DCURSES_LOC="<ncurses/curses.h>"
else
ifeq (/usr/include/ncurses.h, $(wildcard /usr/include/ncurses.h))
HOSTCFLAGS += -DCURSES_LOC="<ncurses.h>"
HOST_EXTRACFLAGS += -DCURSES_LOC="<ncurses.h>"
else
HOSTCFLAGS += -DCURSES_LOC="<curses.h>"
HOST_EXTRACFLAGS += -DCURSES_LOC="<curses.h>"
endif
endif
endif
host-progs := lxdialog
OBJS = checklist.o menubox.o textbox.o yesno.o inputbox.o \
util.o lxdialog.o msgbox.o
%.o: %.c
$(HOSTCC) $(HOSTCFLAGS) -c -o $@ $<
lxdialog-objs := checklist.o menubox.o textbox.o yesno.o inputbox.o \
util.o lxdialog.o msgbox.o
all: ncurses lxdialog
lxdialog: $(OBJS)
$(HOSTCC) -o lxdialog $(OBJS) $(LIBS)
include $(TOPDIR)/Rules.make
ncurses:
@echo "main() {}" > lxtemp.c
@if $(HOSTCC) -lncurses lxtemp.c ; then \
@if $(HOSTCC) lxtemp.c $(HOST_LOADLIBES); then \
rm -f lxtemp.c a.out; \
else \
rm -f lxtemp.c; \
......
......@@ -95,6 +95,7 @@ sb_lib-objs := sb_common.o sb_audio.o sb_midi.o sb_mixer.o sb_ess.o
vidc_mod-objs := vidc.o vidc_fill.o
wavefront-objs := wavfront.o wf_midi.o yss225.o
host-progs := bin2hex hex2hex
include $(TOPDIR)/Rules.make
......@@ -104,16 +105,6 @@ include $(TOPDIR)/Rules.make
# of what name was used to build them. If the name changes, they
# will be forced to be remade.
#
# First make the utilities.
bin2hex: bin2hex.c
$(HOSTCC) $(HOSTCFLAGS) -o bin2hex bin2hex.c
hex2hex: hex2hex.c
$(HOSTCC) $(HOSTCFLAGS) -o hex2hex hex2hex.c
# Turtle Beach Maui / Tropez
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment