Source

LIME / lib / gcc.mk

##################################################################
# This mk file contains rules to handle various GCC versions in
# LIME (behaviour of -fdump-translation-unit is different)
#
#Copyright (C) 2008 NXP Semiconductors B.V.
#
#This file is part of LIME.
#
#LIME is free software: you can redistribute it and/or modify
#it under the terms of the GNU General Public License version 2
#as published by the Free Software Foundation; either version 2
#of the License, or (at your option) any later version.
#
#LIME is distributed in the hope that it will be useful,
#but WITHOUT ANY WARRANTY; without even the implied warranty of
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#GNU General Public License for more details.
#
#You should have received a copy of the GNU General Public License
#along with LIME.  If not, see <http://www.gnu.org/licenses/>.
##################################################################

ifeq ($(shell [ $(GCC_VERSION) -lt 30203 ] && echo yes),yes)
$(error UNSUPPORTED GCC version $(GCC_VERSION))
endif

ifeq ($(shell [ $(GCC_VERSION) -ge 30203 ] && [ $(GCC_VERSION) -lt 40100 ] && echo yes),yes)
%.c.original: %.c %.dep.h %.domains
	$(inform)
	$e$(GCC) $(LIME_CFLAGS) $(call dom2hdr,$*.dep.h,$*.domains) -O0 -fdump-tree-original-all -c $*.c -o /dev/null
	$e$(cp) $*.c.original $@
%.tree: %.c.original
	$(inform)
	$e$(cp) $< $@
%.c.tu: %.c %.dep.h %.domains
	$(inform)
	$e$(GCC) -D__inout__= $(LIME_CFLAGS) $(call dom2hdr,$*.dep.h,$*.domains) -O1 -fdump-translation-unit -c $*.c -o /dev/null
	$e[[ -r $@ ]] || $(mv) $(notdir $@) $@
%.tu: %.c.tu
	$(inform)
	$e$(cp) $< $@
endif

ifeq ($(shell [ $(GCC_VERSION) -ge 40100 ] && [ $(GCC_VERSION) -lt 40200 ] && echo yes),yes)
%.c.t02.original: %.c %.dep.h %.domains
	$(inform)
	$e$(GCC) $(LIME_CFLAGS) $(call dom2hdr,$*.dep.h,$*.domains) -O0 -fdump-tree-original-details-stats-blocks-vops-lineno-uid-raw -c $*.c -o /dev/null
	$e$(cp) $*.c.t02.original $@
%.tree: %.c.t02.original
	$(inform)
	$e$(cp) $< $@
%.c.t00.tu: %.c %.dep.h %.domains
	$(inform)
	$e$(GCC) $(LIME_CFLAGS) $(call dom2hdr,$*.dep.h,$*.domains) -O1 -fdump-translation-unit -c $*.c -o /dev/null
	$e[[ -r $@ ]] || $(mv) $(notdir $@) $@
%.tu: %.c.t00.tu
	$(inform)
	$e$(cp) $< $@
endif

ifeq ($(shell [ $(GCC_VERSION) -ge 40200 ] && echo yes),yes)
%.c.003t.original.raw: %.c %.dep.h %.domains
	$(inform)
	$e$(GCC) $(LIME_CFLAGS) $(call dom2hdr,$*.dep.h,$*.domains) -O0 -fdump-tree-original-details-stats-blocks-vops-lineno-uid-raw -c $*.c -o /dev/null
	$e$(cp) $*.c.003t.original $@
%.tree: %.c.003t.original.raw
	$(inform)
	$e$(cp) $< $@
%.c.003t.original: %.c %.dep.h
	$(inform)
	$e$(GCC) $(LIME_CFLAGS) $(call dom2hdr,$*.dep.h,$*.domains) -O0 -fdump-tree-original-details-stats-blocks-vops-lineno-uid -c $*.c -o /dev/null
%.esrap: %.c.003t.original
	$(inform)
	$e$(cp) $< $@
%.c.001t.tu: %.c %.dep.h
	$(inform)
	$e$(GCC) $(LIME_CFLAGS) $(call dom2hdr,$*.dep.h,$*.domains) -O1 -fdump-translation-unit -c $*.c -o /dev/null
	$e[[ -r $@ ]] || $(mv) $(notdir $@) $@
%.tu: %.c.001t.tu
	$(inform)
	$e$(cp) $< $@
endif




ifneq ($(GCC),)
%.mod: %.tu %.E
	$(inform)
	$e$(cparse) -vGCC="$(GCC_VERSION)" -vSRC=$(filter %.E,$^) -vOP="comps,edges,sched" -vFNAME=$(notdir $*.c) $(filter %.tu,$^) > $@ || $(fail)
ifeq ($(shell [ $(GCC_VERSION) -ge 30203 ] && [ $(GCC_VERSION) -lt 40100 ] && echo yes),yes)
%.syms: %.tu
	$(inform)
	$e$(cparse) -vOP="idents" -vFNAME=$(notdir $*.c) $< | $(awk) '/extern$$/ { print $$3 }' > $@
endif
ifeq ($(shell [ $(GCC_VERSION) -ge 40100 ] && echo yes),yes)
%.syms: %.tu
	$(inform)
	$e$(cparse) -vOP="idents" -vFNAME=$(notdir $*.c) $< | $(awk) '$$2=="extern" { print $$3 }' > $@
endif
else
ifneq ($(objdump),)
%.syms: %.obj
	$(inform)
	$e$(objdump) -t $< | $(awk) '$$2=="g" { print $$6 }' > $@
endif
endif



# unused for now, .mod.o generated directly from .mod.c
# object handling
ifeq ($(objcopy),)
# in the absence of objcopy, just compile to .mod.o, with redefinitions in .depx.h
%.mod.o: %.c %.depx.h %.domains
	$(inform)
	$E$(CC) $(LIME_CFLAGS) $(call dom2hdr,$*.depx.h,$*.domains) -c $*.c -o $@ 
else
# have binutils rename local symbols
%.mod.o: %.obj %.mv
	$(inform)
	$e$(objcopy) --redefine-syms $(filter %.mv,$^) $(filter %.obj,$^) $@
endif


# unused for now, .mod.o generated directly from .mod.c
#%.obj: %.c %.dep.h %.domains
#	$(CC) $(LIME_CFLAGS) $(call dom2hdr,$*.dep.h,$*.domains) -c $*.c -o $@