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