Source

LIME / lib / main.mk

Full commit
##################################################################
# This mk file contains rules (no configuration or command defines)
# that drive the LIME flow
#
#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/>.
##################################################################
include $(rlib)/LIME.mk
include $(rlib)/literate.mk
include $(rlib)/gcc.mk

######### compilation stuff

%.domains: %.c
	$(inform)
	$e(\
		$(call c2dom,$<);\
		for x in $(syshdr); do\
			echo $$x | sed -ne 's,$(rinc)/\(.*\).h,\1,p';\
		done;\
	) | $(uniq) >$@

%.sdomains: 
	$(inform)
	$e(\
		$(echo) LIME;\
		for x in $(syshdr); do\
			echo $$x | sed -ne 's,$(rinc)/\(.*\).h,\1,p';\
		done;\
	) | $(uniq) >$@

# in case a component does not specify diversity,
# just create an empty one
%.diversity:
	$(inform)
	$e$(touch) $@ 

%.div: $(DIVERSITY) %.diversity
	$(inform)
	$e(\
	  $(echo) CLONE_INDEX=CLONE_$(notdir $*);\
	  $(echo) CLONE_$(notdir $*)=$(subst $(basename $(notdir $(if $(shell readlink $*.c),\
	  							      $(shell readlink $*.c),\
								      $*.c))),\
						$(if $(shell readlink $*.c),,0),\
						$(notdir $*));\
	  if test -s "$(filter %.diversity,$^)"; then\
	  	$(echo) "# Locally-set parameters take precedence";\
	  	$(cat) $(filter %.diversity,$^);\
	  fi;\
	  if test -n "$(filter-out %.diversity,$^)"; then\
	  	$(echo) "# Globally-set parameters as a default";\
	  	$(awk) -vMODULE=$* -vFS="=" '/^#/ { next }\
			{ split($$1,path,"[.]");\
			  if (!path[1]) next;\
			  if (MODULE !~ "^" path[1] "$$") next;\
			  print path[2] "=" $$2\
			}' $(filter-out %.diversity,$^);\
	  fi;\
	) > $@


%.E: %.c %.dep.h %.domains
	$(inform)
	$e$(CC) $(LIME_CFLAGS) $(call dom2hdr,$*.dep.h,$*.domains) -c $*.c -E -o $@

# break cyclical dependency of .E by first processing incomplete module
%.E0: %.c %.domains
	$(inform)
	$e$(CC) $(LIME_CFLAGS) $(call dom2hdr,ctype.h,$*.domains) -c $*.c -E -o $@

%.forwards: %.E0
	$(inform)
	$e$(fwdecl) $^ > $@

%.simps: %.sdomains
	$(inform)
	$e(\
	$(call dom2imp,$*.sdomains);\
	) | $(uniq) > $@

%.imps: %.forwards %.domains
	$(inform)
	$e(\
	$(call dom2imp,$*.domains);\
	if test -s $*.forwards -a -n "$(types)"; then\
		$(typeq) -vFILE=$*.forwards $(types) $(redir);\
	fi;\
	) | $(uniq) > $@

%.simports: %.simps
	$(inform)
	$e$(call imps2imp,$<) > $@

%.imports: %.imps
	$(inform)
	$e$(call imps2imp,$<) > $@

%.pdepx.h: %.div %.ren %.imports
	$(inform)
	$e(\
	$(call nvp2cpp.awk,$(filter-out %.imports,$^));\
	$(call imp2hdrp,$*.imports,TARGET);\
	) > $@

%.depx.h: %.div %.ren %.imports
	$(inform)
	$e(\
	$(call nvp2cpp.awk,$(filter-out %.imports,$^));\
	$(call imp2hdr,$*.imports);\
	) > $@

%.deps.h: %.div %.simports
	$(inform)
	$e(\
	$(call nvp2cpp.awk,$(filter-out %.simports,$^));\
	$(call imp2hdr,$*.simports);\
	) > $@

%.dep.h: %.div %.imports
	$(inform)
	$e(\
	$(call nvp2cpp.awk,$(filter-out %.imports,$^));\
	$(call imp2hdr,$*.imports);\
	) > $@


%.ren: %.syms
	$(inform)
	$e( $(echo) "# Rename standard local names";\
	  $(awk) -vMODULE=$* '/^[a-z$$A-Z_][a-z$$A-Z_0-9]*$$/ { print $$0 "=" MODULE "_" $$0 }' $(filter %.syms,$^);\
	) > $@

%.mv: %.syms
	$(inform)
	$e$(awk) -vMODULE=$* '/^[a-z$$A-Z_][a-z$$A-Z_0-9]*$$/ { print $$0, MODULE "_" $$0 }' $< > $@

# generate preprocessed source
%.mod.c: %.c %.depx.h %.domains
	$(inform)
	$E$(CC) $(CFLAGS) $(call dom2hdr,$*.depx.h,$*.domains) $(FLAGS) -E $*.c -o $@ 

# simply compile now
%.mod.o: %.mod.c
	$(inform)
	$E$(CC) $(CFLAGS) -o $@ -c $<


# header handling
LIME%.c: LIME%.h
	$(inform)
	$e(\
	$(echo) '#include <ctype.h>';\
	$(echo) '#include "$(filter %.h,$^)"';\
	) > $@

%.c: %.h
	$(inform)
	$e(\
	$(echo) '#include LIME';\
	$(echo) '#include <ctype.h>';\
	$(echo) '#include "$(filter %.h,$^)"';\
	) > $@

%.types: %.tu %.E
	$(inform)
	$e$(cparse) -vDIR=$(dir $*) -vSRC=$(filter %.E,$^) -vOP="types,typedefs" -vFNAME=$(notdir $(basename $*.c).h) $(filter %.tu,$^) |\
		$(xmlnorm) -vRoot=$(subst .,,$(suffix $@)) $(xml_opts) > $@ || $(fail)
	$e$(cat) $@ | $(call xmllint,types) $(quiet) && $(echo) VALIDATED
	$e$(rm) -f $*.c

#GXF
%.module: %.mod %.imports
	$(inform)
	$e$(composer) -vroot="@" $(filter-out %.imports,$^) $(call imp2type,$*.imports) > $@ || $(fail)

#%.graph.xml: %.graph
#	$(inform)
#	$e$(en2xml) $< >$@ || $(fail)

# Special rule for self-contained .graph files, which must include gxf.dtd,
# skip validation to allow xmlnorm to do its job...
%.graph.xml: %.graph
	$(inform)
	$e$(en2xml) -vtarget=$@ -vRoot='gxf@id="$*"' $(xml_opts) $< >$@ || $(fail)
	$e$(call get,$(dtd_root)/gxf.xsl,gxf.xsl)
	#$e$(cat) $@ | $(call xmllint,$(subst .,,gxf)) $(quiet) && $(echo) VALIDATED

%.xml: %
	$(inform)
	$e$(en2xml) -vRoot='$(subst .,,$(suffix $<))' $(xml_opts) $< >$@ || $(fail)
	$e$(call get,$(dtd_root)/$(subst .,,$(suffix $<)).xsl,$(subst .,,$(suffix $<)).xsl)
	$e$(cat) $@ | $(call xmllint,$(subst .,,$(suffix $<))) $(quiet) && $(echo) VALIDATED

$(app).0.gxf: $(modules) $(graphs)
	$(inform)
	$e$(xmlnorm) -vRoot='$(subst .,,$(suffix $@))@id="$(app)"' $(xml_opts) $^ > $@ || $(fail)
	$e$(echo) -n .

%.01.gxf: %.0.gxf
	$(inform)
	$e$(cat) $< | $(call xmllint,$(subst .,,$(suffix $<))) > $@ || $(fail)
	$e$(echo) -n VALIDATED

%.1.gxf: %.01.gxf
	$(inform)
	$e$(incarnator) -vRoot='$(subst .,,$(suffix $<))@id="$*"' $(xml_opts) $< > $@ || $(fail)
	$e$(echo) -n .

%.2.gxf: %.1.gxf
	$(inform)
	$e$(replicator) -vRoot='$(subst .,,$(suffix $<))@id="$*"' $(xml_opts) $< > $@ || $(fail)
	$e$(echo) -n .

%.3.gxf: %.2.gxf
	$(inform)
	$e$(incarnator) -vRoot='$(subst .,,$(suffix $<))@id="$*"' $(xml_opts) $< > $@ || $(fail)
	$e$(echo) -n .

# Duplicated rule because of circular dependency;-)
%.dot: %.3.gxf
	$(inform)
	$e$(gxf2dot) -vstem=$*.gxf $^ | $(sed) -e 's,\.3\.gxf,\.gxf,g' > $@ || $(fail)
%-full.dot: %.3.gxf
	$(inform)
	$e$(gxf2dot) -vstem=$*-full.gxf -vnode_detail=1 -vedge_detail=1 $< | $(sed) -e 's,\.3\.gxf,\.gxf,g' > $@ || $(fail)

%.gxf: %.3.gxf %.map %-full.map
	$(inform)
	$e$(cat) $< | $(call xmllint,$(subst .,,$(suffix $<))) > $@ || $(fail)
	$e$(call get,$(dtd_root)/gxf.xsl,gxf.xsl)
	$e$(echo) VALIDATED

%.dot: %.gxf
	$(inform)
	$e$(gxf2dot) -vstem=$*.gxf $^ > $@ || $(fail)

%-full.dot: %.gxf
	$(inform)
	$e$(gxf2dot) -vstem=$*-full.gxf -vnode_detail=1 -vedge_detail=1 $< >$@ || $(fail)

%-alt.dot: %.gxf
	$(inform)
	$e$(gxf2dot) -vstem=$*-alt.gxf -vOP=dot2 -vnode_detail=1 -vedge_detail=1 $< >$@ || $(fail)

.PRECIOUS: $(graphs)