Makefile
changeset 120 02e37d9e96a9
parent 112 b78f14613a6c
child 123 032aaa29f498
equal deleted inserted replaced
119:6be785b8cc85 120:02e37d9e96a9
     9 all: main_target
     9 all: main_target
    10 
    10 
    11 DIST ?= win32
    11 DIST ?= win32
    12 
    12 
    13 src := $(abspath $(dir $(lastword $(MAKEFILE_LIST))))
    13 src := $(abspath $(dir $(lastword $(MAKEFILE_LIST))))
    14 HGREMOTE ?= REMOTE_HG_DISABLED
    14 WORKSPACE ?= $(abspath $(src)/..)
    15 HGROOT ?= $(abspath $(src)/..)
       
    16 GITROOT := $(HGROOT)
       
    17 CPUS := `cat /proc/cpuinfo | grep -e 'processor\W*:\W*[[:digit:]]*' | nl -n ln | tail -n1 | cut -f1`
    15 CPUS := `cat /proc/cpuinfo | grep -e 'processor\W*:\W*[[:digit:]]*' | nl -n ln | tail -n1 | cut -f1`
    18 
    16 
    19 distfiles = $(src)/distfiles
    17 distfiles = $(src)/distfiles
    20 sfmirror = downloads
    18 sfmirror = downloads
    21 tmp := $(shell rm -rf $${TMPDIR:-/tmp}/beremiz_dist_build_tmp.* ; mktemp -d -t beremiz_dist_build_tmp.XXXXXXXXXX)
    19 tmp := $(shell rm -rf $${TMPDIR:-/tmp}/beremiz_dist_build_tmp.* ; mktemp -d -t beremiz_dist_build_tmp.XXXXXXXXXX)
    22 
    20 
    23 define hg_get_archive
    21 define hg_get_archive
    24 	test -d $(HGROOT)/`basename $(1)` || hg --cwd $(HGROOT) clone $(HGREMOTE)`basename $(1)`;\
    22 	hg -R $(WORKSPACE)/`basename $(1)` archive $(2) $(1);\
    25 	hg -R $(HGROOT)/`basename $(1)` archive $(2) $(1);\
    23 	hg -R $(WORKSPACE)/`basename $(1)` id -i | sed 's/\+//' > $(1)/revision;
    26 	hg -R $(HGROOT)/`basename $(1)` id -i | sed 's/\+//' > $(1)/revision;
       
    27 endef
    24 endef
    28 
    25 
    29 define get_src_hg
    26 define get_src_hg
    30 	rm -rf $(1);\
    27 	rm -rf $(1);\
    31 	$(call hg_get_archive, $(1), $(2))
    28 	$(call hg_get_archive, $(1), $(2))
    32 endef
    29 endef
    33 
    30 
    34 define get_src_git
    31 define get_src_git
    35 	rm -rf $(1)
       
    36 	test -d $(GITROOT)/`basename $(1)` || git clone $(3) $(GITROOT)/`basename $(1)`
       
    37 	mkdir $(1)
       
    38 	(cd $(GITROOT)/`basename $(1)`; git archive --format=tar $(2)) | tar -C $(1) -x
       
    39 endef
    32 endef
    40 
    33 
    41 define get_src_http
    34 define get_src_http
    42 	dld=$(distfiles)/`echo $(2) | tr ' ()' '___'`;( ( [ -f $$dld ] || wget $(1)/$(2) -O $$dld ) && ( [ ! -f $$dld.md5 ] && (cd $(distfiles);md5sum `basename $$dld`) > $$dld.md5 || (cd $(distfiles);md5sum -c `basename $$dld.md5`) ) ) &&
    35 	dld=$(distfiles)/`echo $(2) | tr ' ()' '___'`;( ( [ -f $$dld ] || wget $(1)/$(2) -O $$dld ) && ( [ ! -f $$dld.md5 ] && (cd $(distfiles);md5sum `basename $$dld`) > $$dld.md5 || (cd $(distfiles);md5sum -c `basename $$dld.md5`) ) ) &&
    43 endef
    36 endef
    44 
    37 
    45 get_src_pypi=$(call get_src_http,https://pypi.python.org/packages/$(1),$(2))
       
    46 
       
    47 get_src_sf=$(call get_src_http,https://$(sfmirror).sourceforge.net/project/$(1),$(2))
       
    48 
       
    49 ifneq ("$(DIST)","")
    38 ifneq ("$(DIST)","")
    50 include $(src)/$(DIST).mk
    39 include $(src)/$(DIST).mk
    51 endif
    40 endif
    52 
    41 
    53 OWN_PROJECTS=beremiz matiec canfestival Modbus
    42 FROM_SOURCE_PROJECTS=beremiz matiec $(DIST_FROM_SOURCE_PROJECTS)
    54 
    43 
    55 define get_revision
    44 define get_revision
    56 $(1)_revision?=$(lastword $(shell grep $(1) $(src)/revisions.txt))
    45 $(1)_revision?=$(lastword $(shell grep $(1) $(src)/revisions.txt))
    57 endef
    46 endef
    58 $(foreach project,$(OWN_PROJECTS),$(eval $(call get_revision,$(project))))
    47 $(foreach project,$(FROM_SOURCE_PROJECTS),$(eval $(call get_revision,$(project))))
       
    48 
       
    49 tar_opts=--absolute-names --exclude=.hg --exclude=.git --exclude=.*.pyc --exclude=.*.swp --exclude=__pycache__
    59 
    50 
    60 define get_revisionid
    51 define get_revisionid
    61 ifeq ($(origin $(1)_revisionid), undefined)
    52 $(1)_revisionid ?=\
    62 $(1)_revisionid?=$(shell hg -R $(HGROOT)/$(1) id -i -r $($(1)_revision))
    53 	$(if $(filter local, $($(1)_revision)),\
    63 endif
    54 		$(shell tar $(tar_opts) -P -c $(WORKSPACE)/$(1) | sha1sum | cut -d ' ' -f 1),\
       
    55 		$(1)_revisionid?=$$(shell hg -R $(WORKSPACE)/$(1) id -i -r $($(1)_revision)))
    64 endef
    56 endef
    65 $(foreach project,$(OWN_PROJECTS),$(eval $(call get_revisionid,$(project))))
    57 $(foreach project,$(FROM_SOURCE_PROJECTS),$(eval $(call get_revisionid,$(project))))
    66 
    58 
    67 sources:
    59 sources:
    68 	mkdir -p sources
    60 	mkdir -p sources
    69 
    61 
    70 define make_src_rule
    62 define make_src_rule
    71 sources/$(1)_src: sources/$(1)_$($(1)_revisionid)
    63 sources/$(1)_src: sources/$(1)_$($(1)_revisionid)
    72 	touch $$@
    64 	touch $$@
    73 
    65 
    74 sources/$(1)_$($(1)_revisionid): | sources
    66 sources/$(1)_$($(1)_revisionid): | sources
       
    67 	rm -rf sources/$(1)*
       
    68 ifeq ($($(1)_revision),local)
       
    69 	echo "Copy local source code for $(1)_$($(1)_revisionid)"
       
    70 	tar -C $(WORKSPACE) $(tar_opts) -P -c $(1) | tar -C sources -x
       
    71 else
    75 	echo "Checkout HG source $(1)_$($(1)_revisionid)"
    72 	echo "Checkout HG source $(1)_$($(1)_revisionid)"
    76 	rm -rf sources/$(1)*
       
    77 	$(call get_src_hg,sources/$(1),-r $($(1)_revisionid))
    73 	$(call get_src_hg,sources/$(1),-r $($(1)_revisionid))
       
    74 endif
    78 	touch $$@
    75 	touch $$@
    79 endef
    76 endef
    80 $(foreach project,$(OWN_PROJECTS),$(eval $(call make_src_rule,$(project))))
    77 $(foreach project,$(FROM_SOURCE_PROJECTS),$(eval $(call make_src_rule,$(project))))
    81 
    78 
    82 own_sources: $(foreach project,$(OWN_PROJECTS), sources/$(project)_src)
    79 own_sources: $(foreach project,$(FROM_SOURCE_PROJECTS), sources/$(project)_src)
    83 	touch $@
    80 	touch $@
    84 
    81 
    85 all_sources: own_sources sources/open62541_src
    82 all_sources: own_sources sources/open62541_src
    86 	touch $@
    83 	touch $@
    87 
    84 
    91 	tar -xzf $$dld
    88 	tar -xzf $$dld
    92 	mv open62541-1.3.2 sources/open62541
    89 	mv open62541-1.3.2 sources/open62541
    93 	
    90 	
    94 
    91 
    95 define show_revision_details
    92 define show_revision_details
    96 echo -n $(1) "revision is: "; hg -R $(HGROOT)/$(1) id -r $($(1)_revisionid);
    93 	$(if $(filter local, $($(1)_revision)),\
       
    94 		echo -n $(1) "state is: "; test -d .hg \
       
    95 			&& (hg -R $(WORKSPACE)/$(1) id; echo; hg -R $(WORKSPACE)/$(1) st) \
       
    96 			|| (git -C $(WORKSPACE)/$(1) show --pretty=format:'%P' -s; echo; git -C $(WORKSPACE)/$(1) status --porcelain);,\
       
    97 		echo -n $(1) "revision is: "; hg -R $(WORKSPACE)/$(1) id -r $($(1)_revisionid); )
    97 endef
    98 endef
    98 
    99 
    99 revisions.txt: $(src)/revisions.txt own_sources
   100 revisions.txt: $(src)/revisions.txt own_sources
   100 	echo "Generate revisions.txt"
   101 	echo "Generate revisions.txt"
   101 	echo "\n******* PACKAGE REVISIONS ********\n" > revisions.txt
   102 	echo "\n******* PACKAGE REVISIONS ********\n" > revisions.txt
   102 	(echo -n "beremiz_public_dist revision is: "; hg -R $(src) id;) >> revisions.txt
   103 	(echo -n "beremiz_public_dist revision is: "; test -d .hg && (hg -R $(src) id ; echo; hg -R $(src) st) || (git -C $(src) show --pretty=format:'%P' -s; echo; git -C $(src) status --porcelain)) >> revisions.txt
   103 	($(foreach project,$(OWN_PROJECTS),$(call show_revision_details,$(project)))) >> revisions.txt
   104 	($(foreach project,$(FROM_SOURCE_PROJECTS),$(call show_revision_details,$(project)))) >> revisions.txt
   104 	bash -c 'hg -R $(src) st | ( if read ; then echo -e "\n******* beremiz_public_dist IS MODIFIED ********\n" ; hg -R $(src) st ; fi ) >> revisions.txt'
       
   105 
   105 
   106 
   106 
   107 
   107