39,11 → 39,10 |
in-local:= $$(subst $$(srctree)/,,$$<) |
out-local:= $$(subst install-,,$$(subst $$(objtree)/,,$$@)) |
in-objs:= $$(filter %.o,$$^) |
in-objs-local:= $$(filter %.o,$$(subst $$(objtree)/,,$$^)) |
|
# The rule patterns, in quiet and in verbose form. The verbose form is |
# used also for the actual command. |
quiet_ar_cmd := ' AR\\t$(out-local) $(in-objs-local)' |
quiet_ar_cmd := ' AR\\t$(out-local)' |
ar_cmd := $(ar) cr $$@ $(in-objs) |
|
quiet_cc_cmd := ' CC\\t$(in-local)' |
59,9 → 58,14 |
"$$(subst $$(srctree),$$(objtree),$$(<:.c=.o))\ |
$$@" $$< > $$@ 2>/dev/null |
|
quiet_ld-r_cmd := ' LD\\t$(out-local) $(in-objs-local)' |
ld-r_cmd := $(ld) $$(ldflags-$$(dir $$@)) -r $(in-objs) -o $$@ |
quiet_ld-r_cmd := ' LD [R]\\t$(out-local)' |
ld-r_cmd := $(ld) $$(ldflags-$$(dir $$@)) $$(ldflags-$$@)\ |
-r $(in-objs) -o $$@ |
|
quiet_ld_cmd := ' LD\\t$(out-local)' |
ld_cmd := $(ld) $$(ldflags-$$(dir $$@)) $$(startup-$$@) $(in-objs)\ |
$$(ldflags-$$@) -o $$@ |
|
quiet_rm_cmd := ' RM\\t$$(subst clean-,,$$(subst distclean-,,$(out-local)))' |
rm_cmd := -$(rm) $$(subst clean-,,$$(subst distclean-,,$$@)) |
|
78,10 → 82,16 |
endef |
|
# Remove duplicate slashes, ../'s, trailing slashes and so on from paths. |
define clean-path |
$(dir $(abspath $(1)))$(notdir $(abspath $(1))) |
endef |
clean-path=$(dir $(abspath $(1)))$(notdir $(abspath $(1))) |
|
# Canonicalize a path, converting .. and . $(1) is the current directory, |
# and $(2) are the paths to be converted. |
to-local-path=$(subst $(1)/,,$(abspath $(addprefix $(1)/,$(2)))) |
|
# Keep only paths in $(1) that start with ./ (i.e., that are relative to the |
# current directory.) |
keep-local=$(foreach p, $(1),$(if $(subst ./,,$(dir $(p))),,$(p))) |
|
# Adjust the paths for all the prerequisites of a target. Given a list |
# of objects, with relative or absolute path, figure out the right paths |
# in the build directory. Leave the output in $(target-objs). |
99,18 → 109,19 |
$$(call clean-path,$$(dir))) |
endef |
|
# Produce targets for a given library. |
define lib-templ |
lib:=$(1) |
lib-target:=$$(objdir)/$$(lib) |
# Produce targets for a given library/application. |
define libapp-templ |
libapp:=$(1) |
is-app:=$(strip $(2)) |
libapp-target:=$$(objdir)/$$(libapp) |
|
# Get a list of all the prerequisites needed to build the library. |
# Get a list of all the prerequisites needed to build the library/application. |
$$(eval $$(call all-prerequisites-templ,\ |
$$(patsubst %/,%/obj.o,$$($$(lib)-objs)))) |
$$(patsubst %/,%/obj.o,$$($$(libapp)-objs)))) |
|
$$(foreach flag,$(flags),$$(eval $$(call flags-per-target,$$(flag),$$(lib)))) |
$$(foreach flag,$(flags),$$(eval $$(call flags-per-target,$$(flag),$$(libapp)))) |
$$(foreach obj,$$(target-objs),\ |
$$(eval $$(call flags-per-objects,$$(obj),$$(lib)))) |
$$(eval $$(call flags-per-objects,$$(obj),$$(libapp)))) |
|
# Produce the real target, in $(objtree), and the user-friendly target, |
# with a relative path to $(srctree). Note that even when the two trees |
117,25 → 128,33 |
# are equal we define two targets; a possible optimization could be to |
# use relative paths for the object tree in this case, but the code can |
# become even less readable than it is now... |
$$(lib-target): $$(target-objs) |
ifeq ($$(is-app),true) |
startup-$$(libapp-target):= $$($$(libapp)-startup) |
$$(libapp-target): $$(target-objs) |
$(call cmd,ld) |
else |
$$(libapp-target): $$(target-objs) |
$(call cmd,ar) |
short-lib-taget:=$$(subst $$(srctree)/,,$$(curdir)/$$(lib)) |
.PHONY: $$(short-lib-target) |
$$(short-lib-target): $$(lib-target) |
endif |
short-libapp-taget:=$$(subst $$(srctree)/,,$$(curdir)/$$(libapp)) |
.PHONY: $$(short-libapp-target) |
$$(short-libapp-target): $$(libapp-target) |
|
# Update the $(subdirs) for $(curdir) and its target list. |
subdirs+=$$(filter %/,$$($$(lib)-objs)) |
curdir-targets+=$$(lib-target) |
subdirs+=$$(filter %/,$$($$(libapp)-objs)) |
curdir-targets+=$$(libapp-target) |
|
.PHONY: clean-$$(lib-target) |
clean-$$(lib-target): |
.PHONY: clean-$$(libapp-target) |
clean-$$(libapp-target): |
$(call cmd,rm) |
curdir-clean-targets+= clean-$$(lib-target) |
curdir-clean-targets+= clean-$$(libapp-target) |
|
.PHONY: install-$$(lib-target) |
install-$$(lib-target): $$(lib-target) |
ifneq ($$(is-app),true) |
.PHONY: install-$$(libapp-target) |
install-$$(libapp-target): $$(libapp-target) |
$(call cmd,install) |
curdir-install-targets+= install-$$(lib-target) |
curdir-install-targets+= install-$$(libapp-target) |
endif |
endef |
|
# Produce the needed code for a given object. |
166,6 → 185,12 |
curdir-clean-targets+= clean-$$(obj-target) |
curdir-distclean-targets+= distclean-$$(obj-dep) |
|
ifneq ($$(filter $$(obj),$$(install-objs)),) |
.PHONY: install-$$(obj-target) |
install-$$(obj-target): $$(obj-target) |
$(call cmd,install) |
curdir-install-targets+= install-$$(obj-target) |
endif |
endef |
|
# Handle the flags for the current directory. for each *FLAGS variable |
216,10 → 241,12 |
$$(flag)-$$(curdir)/$$(target):=$$($$(flag)-$$(curdir)) \ |
$$($$(target)-$$(flag)) $$(extra-$$(flag)-$$(curdir)/$$(target)) |
|
ifneq ($$(target),install-objs) |
# Those are the flags coming from the upper directories, they are set for |
# obj.o targets, we must export them to our children, so we leave them here. |
exported-$$(flag)-$$(curdir)/$$(target):= $$($$(target)-$$(flag)) \ |
$$(extra-$$(flag)-$$(curdir)/$$(target)) |
endif |
$$(target)-$$(flag):= |
endef |
|
237,8 → 264,10 |
$$($$(this-obj)-$$(flag)) |
$$(this-obj)-$$(flag):= |
|
#to-print+= [ $$(flag)-$$(curdir)/$$(this-obj) = $$($$(flag)-$$(curdir)/$$(this-obj)) ] RET |
ifeq ($(3),install-objs) |
to-print+= [ $(2) $(3) ] RET |
endif |
endif |
# Pass the right flags to the subdirs we use to build $(target). |
ifeq ($$(notdir $(2)),obj.o) |
extra-$$(flag)-$(2):= $$(exported-$$(flag)-$$(curdir)/$$(target)) |
312,6 → 341,8 |
curdir-distclean-targets:= |
curdir-install-targets:= |
|
install-objs:= |
|
# If the output directory does not exist every target that actually |
# needs it will have to create it. |
ifneq ($(objtree),$(srctree)) |
340,6 → 371,7 |
subdirs:=$$(filter %/, $$(targets)) |
objs:=$$(filter %.o, $$(targets)) |
libs:=$$(filter %.a, $$(targets)) |
apps:=$$(filter-out $$(subdirs) $$(objs) $$(libs),$$(targets)) |
|
$$(eval $$(call all-prerequisites-templ, $$(subdirs))) |
subdir-targets:= $$(target-objs) |
372,9 → 404,13 |
|
# Produce the needed targets for each library. |
ifneq ($$(strip $$(libs)),) |
$$(foreach lib,$$(libs),$$(eval $$(call lib-templ,$$(lib)))) |
$$(foreach lib,$$(libs),$$(eval $$(call libapp-templ,$$(lib),false))) |
endif |
|
ifneq ($$(strip $$(apps)),) |
$$(foreach app,$$(apps),$$(eval $$(call libapp-templ,$$(app),true))) |
endif |
|
# Produce a target for each local object. Build the list of all the |
# targets specified by the current subdir. It is given by all the local |
# objects in $(targets) or in a library contained in it. Non-local |
387,16 → 423,35 |
# First build a relative path for all the .o files in the targets (the |
# default one and the library ones,) taking care of not being confused |
# by relative directory specifications. |
all-local-objs-paths:=$$(subst $$(curdir)/,,\ |
$$(abspath $$(addprefix $$(curdir)/,\ |
$$(objs) $$(foreach lib,$$(libs),$$(filter %.o,$$($$(lib)-objs)))))) |
#all-local-objs-paths:=$$(subst $$(curdir)/,,\ |
# $$(abspath $$(addprefix $$(curdir)/,\ |
# $$(objs) $$(install-objs)\ |
# $$(foreach lib,$$(libs),$$(filter %.o,$$($$(lib)-objs)))\ |
# $$(foreach app,$$(apps),$$(filter %.o,$$($$(app)-objs)))))) |
all-local-objs-paths:=$$(call to-local-path,$$(curdir),\ |
$$(objs)\ |
$$(foreach lib,$$(libs),$$(filter %.o,$$($$(lib)-objs)))\ |
$$(foreach app,$$(apps),$$(filter %.o,$$($$(app)-objs)))) |
|
all-local-install-objs-paths:=$$(call to-local-path,$$(curdir),\ |
$$(install-objs)) |
|
# Then keep only those with a dir equal to ./ A local object is not |
# allowed to be specified with a path specifying a directory different |
# from the current one. |
all-local-objs:=$$(foreach obj, $$(all-local-objs-paths), \ |
$$(if $$(subst ./,,$$(dir $$(obj))),,$$(obj))) |
# from the current one. Objects to be installed are only taken into |
# account if they're local to the current directory. |
#all-local-objs:=$$(foreach obj, $$(all-local-objs-paths),\ |
# $$(if $$(subst ./,,$$(dir $$(obj))),,$$(obj))) |
all-local-install-objs:=$$(call keep-local,$$(all-local-install-objs-paths)) |
all-local-objs:=$$(call keep-local,$$(all-local-objs-paths))\ |
$$(all-local-install-objs) |
|
$$(eval $$(call all-prerequisites-templ,$$(all-local-install-objs))) |
$$(foreach flag,$(flags),\ |
$$(eval $$(call flags-per-target,$$(flag),install-objs))) |
$$(foreach obj,$$(target-objs),\ |
$$(eval $$(call flags-per-objects,$$(obj),install-objs))) |
|
# Produce one target per object, and the rules to build them along with |
# their dependencies. |
ifneq ($$(strip $$(all-local-objs)),) |
452,57 → 507,11 |
|
.DEFAULT_GOAL:= all |
|
include shark.cfg |
|
installdir:=$(objtree)/.lib |
|
# Handle Shark configuration. Really insane, indeed. |
options:=TSC APIC BIOS TRACER FG FB COMPILER |
define strip-in-place |
$(1):=$(strip $($(1))) |
endef |
$(foreach cfgopt,$(options),$(eval $(call strip-in-place,$(cfgopt)))) |
# Include all the Shark specific configuration... |
include $(if $(S),$(S)/)Rules.mk |
|
cpp-tsc-TRUE:= -D__TSC__ |
cpp-apic-TRUE:= -D__APIC__ |
cpp-bios-VM86:= -DVM86 |
cpp-tracer-NEW:= -D__NEW_TRACER__ |
cpp-tracer-OLD:= -D__OLD_TRACER__ |
cpp-fg-FORCE_PXC:= -D__FORCE_PXC__ |
cpp-fb-VESA:= -DCONFIG_FB_VESA -DCONFIG_LOGO |
cpp-fb-FINDPCI:= -DCONFIG_FB_RIVA -DCONFIG_FB_RADEON -DCONFIG_FB_MATROX \ |
-DCONFIG_LOGO -DCONFIG_FB_MATROX_G100 \ |
-DCONFIG_FB_MATROX_MILLENIUM -DCONFIG_FB_MATROX_MYSTIQUE |
cpp-fb-VGA16:= -DCONFIG_FB_VGA16 |
|
include-dirs:= \ |
-I$(srctree)/include -I$(srctree)/modules \ |
-I$(srctree)/arch/$(ARCH)/include/arch \ |
-I$(srctree)/libc/arch/$(ARCH)/include \ |
-I$(srctree)/tracer/include |
|
config:= -D__LINUX__ \ |
$(cpp-tsc-$(TSC)) $(cpp-apic-$(APIC)) $(cpp-bios-$(BIOS)) \ |
$(cpp-tracer-$(TRACER)) $(cpp-fg-$(FG)) $(cpp-fb-$(FB)) |
|
exported-cppflags:= $(include-dirs) $(config) |
exported-aflags:= -x assembler-with-cpp $(include-dirs) $(config) |
|
cc-compiler-GCC4:= -Wimplicit-function-declaration -Wno-attributes \ |
-Wno-pointer-sign -Wall -O -fno-builtin -nostdinc \ |
-minline-all-stringops -fno-stack-protector |
cc-compiler-GCC3:= -Wimplicit-function-declaration -Wall -O \ |
-fno-builtin -nostdinc -minline-all-stringops |
cc-compiler-DJGPP:= -Wimplicit-function-declaration -Wall -O \ |
-fno-builtin -nostdinc -minline-all-stringops |
|
exported-cflags:= $(cc-compiler-$(COMPILER)) |
|
fs-YES:= fs/ |
|
targets:= libgkern.a drivers/ libc/ ports/ tracer/ $(fs-$(SHARK_FS)) |
libgkern.a-objs:= arch/$(ARCH)/ kernel/ modules/ |
|
# Let the good times roll... |
$(eval $(call recurse-templ,$(srctree))) |
|