Remove sed from post-build code, due to portability issues between GNU and BSD versions.
[jquery.git] / Makefile
1 V ?= 0
2
3 SRC_DIR = src
4 TEST_DIR = test
5 BUILD_DIR = build
6
7 PREFIX = .
8 DIST_DIR = ${PREFIX}/dist
9
10 JS_ENGINE ?= `which node nodejs`
11 COMPILER = ${JS_ENGINE} ${BUILD_DIR}/uglify.js --unsafe
12 POST_COMPILER = ${JS_ENGINE} ${BUILD_DIR}/post-compile.js
13
14 BASE_FILES = ${SRC_DIR}/core.js\
15         ${SRC_DIR}/support.js\
16         ${SRC_DIR}/data.js\
17         ${SRC_DIR}/queue.js\
18         ${SRC_DIR}/attributes.js\
19         ${SRC_DIR}/event.js\
20         ${SRC_DIR}/selector.js\
21         ${SRC_DIR}/traversing.js\
22         ${SRC_DIR}/manipulation.js\
23         ${SRC_DIR}/css.js\
24         ${SRC_DIR}/ajax.js\
25         ${SRC_DIR}/ajax/jsonp.js\
26         ${SRC_DIR}/ajax/script.js\
27         ${SRC_DIR}/ajax/xhr.js\
28         ${SRC_DIR}/effects.js\
29         ${SRC_DIR}/offset.js\
30         ${SRC_DIR}/dimensions.js
31
32 MODULES = ${SRC_DIR}/intro.js\
33         ${BASE_FILES}\
34         ${SRC_DIR}/outro.js
35
36 JQ = ${DIST_DIR}/jquery.js
37 JQ_MIN = ${DIST_DIR}/jquery.min.js
38
39 SIZZLE_DIR = ${SRC_DIR}/sizzle
40 QUNIT_DIR = ${TEST_DIR}/qunit
41
42 JQ_VER = $(shell cat version.txt)
43 VER = sed "s/@VERSION/${JQ_VER}/"
44
45 DATE=$(shell git log -1 --pretty=format:%ad)
46
47 all: jquery min lint
48         @@echo "jQuery build complete."
49
50 ${DIST_DIR}:
51         @@mkdir -p ${DIST_DIR}
52
53 ifeq ($(strip $(V)),0)
54 verbose = --quiet
55 else ifeq ($(strip $(V)),1)
56 verbose =
57 else
58 verbose = --verbose
59 endif
60
61 define clone_or_pull
62 -@@if test ! -d $(strip ${1})/.git; then \
63                 echo "Cloning $(strip ${1})..."; \
64                 git clone $(strip ${verbose}) --depth=1 $(strip ${2}) $(strip ${1}); \
65         else \
66                 echo "Pulling $(strip ${1})..."; \
67                 git --git-dir=$(strip ${1})/.git pull $(strip ${verbose}) origin master; \
68         fi
69
70 endef
71
72 ${QUNIT_DIR}:
73         $(call clone_or_pull, ${QUNIT_DIR}, git://github.com/jquery/qunit.git)
74
75 ${SIZZLE_DIR}:
76         $(call clone_or_pull, ${SIZZLE_DIR}, git://github.com/jeresig/sizzle.git)
77
78 init: ${QUNIT_DIR} ${SIZZLE_DIR}
79
80 jquery: init ${JQ}
81 jq: init ${JQ}
82
83 ${JQ}: ${MODULES} | ${DIST_DIR}
84         @@echo "Building" ${JQ}
85
86         @@cat ${MODULES} | \
87                 sed 's/.function..jQuery...{//' | \
88                 sed 's/}...jQuery..;//' | \
89                 sed 's/@DATE/'"${DATE}"'/' | \
90                 ${VER} > ${JQ};
91
92 ${SRC_DIR}/selector.js: ${SIZZLE_DIR}/sizzle.js
93         @@echo "Building selector code from Sizzle"
94         @@sed '/EXPOSE/r src/sizzle-jquery.js' ${SIZZLE_DIR}/sizzle.js | grep -v window.Sizzle > ${SRC_DIR}/selector.js
95
96 lint: jquery
97         @@if test ! -z ${JS_ENGINE}; then \
98                 echo "Checking jQuery against JSLint..."; \
99                 ${JS_ENGINE} build/jslint-check.js; \
100         else \
101                 echo "You must have NodeJS installed in order to test jQuery against JSLint."; \
102         fi
103
104 min: ${JQ_MIN}
105
106 ${JQ_MIN}: jquery
107         @@if test ! -z ${JS_ENGINE}; then \
108                 echo "Minifying jQuery" ${JQ_MIN}; \
109                 ${COMPILER} ${JQ} > ${JQ_MIN}.tmp; \
110                 ${POST_COMPILER} ${JQ_MIN}.tmp > ${JQ_MIN}; \
111                 rm -f ${JQ_MIN}.tmp; \
112         else \
113                 echo "You must have NodeJS installed in order to minify jQuery."; \
114         fi
115         
116
117 clean:
118         @@echo "Removing Distribution directory:" ${DIST_DIR}
119         @@rm -rf ${DIST_DIR}
120
121         @@echo "Removing built copy of Sizzle"
122         @@rm -f src/selector.js
123
124         @@echo "Removing cloned directories"
125         @@rm -rf test/qunit src/sizzle
126
127 .PHONY: all jquery lint min init jq clean