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