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