]> git.donarmstrong.com Git - dactyl.git/blob - common/Makefile
955d358a7b9acb1925afca94585634387b0b8ca5
[dactyl.git] / common / Makefile
1 #### configuration
2
3 TOP           = $(shell pwd)
4 OS            = $(shell uname -s)
5 BUILD_DATE    = $(shell date "+%Y/%m/%d %H:%M:%S")
6 BASE          = $(TOP)/../common
7 GOOGLE_PROJ   = dactyl
8 GOOGLE        = https://$(GOOGLE_PROJ).googlecode.com/files
9 VERSION      ?= $(shell sed -n 's/.*em:version\(>\|="\)\(.*\)["<].*/\2/p' $(TOP)/install.rdf | sed 1q)
10 UUID         := $(shell sed -n 's/.*em:id\(>\|="\)\(.*\)["<].*/\2/p' $(TOP)/install.rdf | sed 1q)
11 MANGLE       := $(shell date '+%s' | awk '{ printf "%x", $$1 }')
12 MOZMILL       = mozmill
13 HOSTAPP_PATH  = $(shell which $(HOSTAPP))
14 TEST_DIR      = $(BASE)/tests/functional
15 TEST_LOG      = $(TEST_DIR)/log
16
17 IDNAME       := $(shell echo "$(NAME)" | tr a-z A-Z)
18
19 LOCALEDIR     = locale
20 DOC_FILES     = $(wildcard $(LOCALEDIR)/*/*.xml)
21
22 export VERSION BUILD_DATE
23 MAKE_JAR      = sh $(BASE)/make_jar.sh
24
25 # TODO: specify source files manually?
26 JAR_BASES     = $(TOP) $(BASE)
27 JAR_DIRS      = content skin locale modules
28 JAR_TEXTS     = js jsm css dtd xml xul html xhtml xsl properties
29 JAR_BINS      = png
30
31 CHROME        = $(MANGLE)/
32 JAR           = $(CHROME)$(NAME).jar
33
34 XPI_BASES     = $(JAR_BASES) $(TOP)/..
35 XPI_FILES     = bootstrap.js TODO AUTHORS Donors NEWS LICENSE.txt
36 XPI_DIRS      = components $(MANGLE) defaults
37 XPI_TEXTS     = js jsm $(JAR_TEXTS)
38 XPI_BINS      = $(JAR_BINS)
39
40 XPI_NAME      = $(NAME)-$(VERSION)
41 XPI           =  ../downloads/$(XPI_NAME).xpi
42 XPI_PATH      = $(TOP)/$(XPI:%.xpi=%)
43
44 RDF           = ../downloads/update.rdf
45 RDF_IN        = $(RDF).in
46
47 BUILD_DIR     = build.$(VERSION).$(OS)
48
49 AWK       ?= awk
50 B64ENCODE ?= base64
51 CURL      ?= curl
52 SED       := $(shell if [ "xoo" = x$$(echo foo | sed -E 's/f(o)/\1/' 2>/dev/null) ]; \
53                      then echo sed -E; else echo sed -r;                             \
54                      fi)
55
56 .SILENT:
57
58 #### rules
59
60 TARGETS = all help info jar xpi install clean distclean install installxpi test $(CHROME) $(JAR)
61 $(TARGETS:%=\%.%):
62         echo MAKE $* $(@:$*.%=%)
63         $(MAKE) -C $* $(@:$*.%=%)
64
65 .PHONY: $(TARGETS)
66 all: help
67
68 help:
69         @echo "$(NAME) $(VERSION) build"
70         @echo
71         @echo "  make help       - display this help"
72         @echo "  make info       - show some info about the system"
73         @echo "  make jar        - build a JAR ($(JAR))"
74         @echo "  make xpi        - build an XPI ($(XPI_NAME))"
75         @echo "  make installxpi - build an XPI and install it to your profile"
76         @echo "  make install    - installs this source tree directly to your $(HOSTAPP) profile"
77         @echo '                    set $$PROFILE to select a profile by name and $$PROFILEPATHS'
78         @echo '                    to change the directory where profiles are searched'
79         @echo "  make release    - updates update.rdf (this is not for you)"
80         @echo "  make dist       - uploads to Google Code (this is not for you)"
81         @echo "  make clean      - clean up"
82         @echo "  make distclean  - clean up more"
83         @echo "  make test       - run functional tests"
84         @echo
85         @echo "running some commands with V=1 will show more build details"
86
87 info:
88         @echo "version             $(VERSION)"
89         @echo "release file        $(XPI)"
90         @echo "doc files           $(DOC_FILES)"
91         @echo "xpi files           $(XPI_FILES)"
92
93 jar: $(JAR)
94
95 release: $(XPI) $(RDF)
96
97 # This is not for you!
98 dist: $(XPI)
99         @echo DIST $(XPI) $(GOOGLE)
100         set -e;                                                                 \
101                                                                                 \
102         proj=$$(echo -n $(NAME) | sed 's/\(.\).*/\1/' | tr a-z A-Z);            \
103         proj="$$proj$$(echo $(NAME) | sed 's/.//')";                            \
104         [ -z "$$summary" ] && summary="$$proj $(VERSION) Release";              \
105         labels="Project-$$proj,$(labels)";                                      \
106         [ -n "$(featured)" ] && labels="$$labels,Featured";                     \
107                                                                                 \
108         IFS=,; for l in $$labels; do                                            \
109                 set -- "$$@" --form-string "label=$$l";                         \
110         done;                                                                   \
111         auth=$$(echo -n "$(GOOGLE_USER):$(GOOGLE_PASS)" | $(B64ENCODE));        \
112         $(CURL) "$$@" --form-string "summary=$$summary"                         \
113                 -F "filename=@$(XPI)"                                           \
114                 -H "Authorization: Basic $$auth"                                \
115                 -i "$(GOOGLE)" | sed -n '/^Location/{p;q;}'
116
117 install:
118         export dir;                                                             \
119         for dir in $(PROFILEPATHS); do                                          \
120                 test -f "$$dir/profiles.ini" && break;                          \
121         done;                                                                   \
122                                                                                 \
123         profile=$$(sed 's/^$$/\#/' "$$dir/profiles.ini" |                       \
124                 awk -v"profile=$(PROFILE)"                                      \
125                         'BEGIN { RS="#" }                                       \
126                         index($$0, "\nName=" profile "\n") { print; exit }      \
127                         !profile && /\nName=default\n/ { args["name=default"] = $$0 }   \
128                         !profile && /\nDefault=1/ { args["default=1"] = $$0 }   \
129                         END {                                                   \
130                                 if (args["default=1"]) print args["default=1"]; \
131                                 else print args["name=default"]                 \
132                         }' |                                                    \
133                 awk -F= '{ args[$$1] = $$2 }                                    \
134                 END {                                                           \
135                         if (args["IsRelative"]) print ENVIRON["dir"] "/" args["Path"];  \
136                         else print args["Path"]                                 \
137                 }');                                                            \
138                                                                                 \
139         if ! test -d "$$profile"; then                                          \
140                 echo >&2 "Can't locate profile directory";                      \
141                 exit 1;                                                         \
142         fi;                                                                     \
143                                                                                 \
144         ext="$$profile/extensions/$(UUID)";                                     \
145         mkdir -p "$$(dirname "$$ext")";                                         \
146         rm -rf "$$ext.xpi" "$$ext";                                             \
147         echo "Installing to $$ext";                                             \
148         if which cygpath >/dev/null 2>&1;                                       \
149         then cygpath -wa .;                                                     \
150         else pwd;                                                               \
151         fi >"$$ext"
152 installxpi: xpi
153         $(HOSTAPP) $(XPI)
154
155 $(RDF): $(RDF_IN) Makefile
156         @echo "Preparing release..."
157         $(SED) -e "s,@VERSION@,$(VERSION),g" \
158                    -e "s,@DATE@,$(BUILD_DATE),g" \
159                    < $< > $@
160         @echo "SUCCESS: $@"
161
162 clean:
163         @echo "General $(NAME) cleanup..."
164         rm -f $(JAR) $(XPI)
165
166 distclean:
167         @echo "More $(NAME) cleanup..."
168         rm -rf $(BUILD_DIR)
169
170 test: xpi
171         @echo "Running $(NAME) functional tests..."
172         $(IDNAME)_INIT="set loadplugins=" \
173                 $(MOZMILL) --show-all -l $(TEST_LOG) -b $(HOSTAPP_PATH) --addons $(XPI) -t $(TEST_DIR)
174
175 #### xpi
176
177 xpi: $(CHROME)
178         @echo "Building XPI..."
179         mkdir -p "$(XPI_PATH)"
180         
181         $(AWK) -v 'name=$(NAME)' -v 'suffix=$(MANGLE)' \
182                -f $(BASE)/process_manifest.awk \
183                "$(TOP)/chrome.manifest" >"$(XPI_PATH)/chrome.manifest"
184         
185         version="$(VERSION)";                   \
186         hg root >/dev/null 2>&1 &&              \
187         case "$$version" in                     \
188         *pre) version="$$version-hg$$(hg log -r . --template '{rev}')-$$(hg branch)";; \
189         esac;                                   \
190         $(SED) -e 's/(em:version(>|="))([^"<]+)/\1'"$$version/" \
191                 <"$(TOP)/install.rdf" >"$(XPI_PATH)/install.rdf"
192         
193         $(MAKE_JAR) "$(XPI)" "$(XPI_BASES)" "$(XPI_DIRS)" "$(XPI_TEXTS)" "$(XPI_BINS)" "$(XPI_FILES)"
194         rm -r -- $(CHROME)
195         @echo "Built XPI: $(XPI)"
196
197 #### jar
198
199 $(CHROME) $(JAR):
200         @echo "Packaging chrome..."
201         $(MAKE_JAR) -r "$(@)" "$(JAR_BASES)" "$(JAR_DIRS)" "$(JAR_TEXTS)" "$(JAR_BINS)" "$(JAR_FILES)"
202         @echo "SUCCESS: $@"
203