Skip to content

Commit

Permalink
Merge branch 'mr/gitweb-jsmin'
Browse files Browse the repository at this point in the history
* mr/gitweb-jsmin:
  gitweb: update INSTALL to use shorter make target
  gitweb: add documentation to INSTALL regarding gitweb.js
  instaweb: add minification awareness
  Gitweb: add autoconfigure support for minifiers
  Gitweb: add support for minifying gitweb.css
  Gitweb: add ignore and clean rules for minified files
  • Loading branch information
Junio C Hamano committed Apr 10, 2010
2 parents 055e1e2 + e391859 commit b92cbb6
Show file tree
Hide file tree
Showing 7 changed files with 83 additions and 36 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@
/git-core-*/?*
/gitk-git/gitk-wish
/gitweb/gitweb.cgi
/gitweb/gitweb.min.*
/test-chmtime
/test-ctype
/test-date
Expand Down
33 changes: 23 additions & 10 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,9 @@ all::
# Define JSMIN to point to JavaScript minifier that functions as
# a filter to have gitweb.js minified.
#
# Define CSSMIN to point to a CSS minifier in order to generate a minified
# version of gitweb.css
#
# Define DEFAULT_PAGER to a sensible pager command (defaults to "less") if
# you want to use something different. The value will be interpreted by the
# shell at runtime when it is used.
Expand Down Expand Up @@ -279,9 +282,6 @@ lib = lib
# DESTDIR=
pathsep = :

# JavaScript minifier invocation that can function as filter
JSMIN =

export prefix bindir sharedir sysconfdir

CC = gcc
Expand Down Expand Up @@ -1561,18 +1561,29 @@ gitweb:
$(QUIET_SUBDIR0)gitweb $(QUIET_SUBDIR1) all

ifdef JSMIN
OTHER_PROGRAMS += gitweb/gitweb.cgi gitweb/gitweb.min.js
gitweb/gitweb.cgi: gitweb/gitweb.perl gitweb/gitweb.min.js
GITWEB_PROGRAMS += gitweb/gitweb.min.js
GITWEB_JS = gitweb/gitweb.min.js
else
OTHER_PROGRAMS += gitweb/gitweb.cgi
gitweb/gitweb.cgi: gitweb/gitweb.perl
GITWEB_JS = gitweb/gitweb.js
endif
ifdef CSSMIN
GITWEB_PROGRAMS += gitweb/gitweb.min.css
GITWEB_CSS = gitweb/gitweb.min.css
else
GITWEB_CSS = gitweb/gitweb.css
endif
OTHER_PROGRAMS += gitweb/gitweb.cgi $(GITWEB_PROGRAMS)
gitweb/gitweb.cgi: gitweb/gitweb.perl $(GITWEB_PROGRAMS)
$(QUIET_SUBDIR0)gitweb $(QUIET_SUBDIR1) $(patsubst gitweb/%,%,$@)

ifdef JSMIN
gitweb/gitweb.min.js: gitweb/gitweb.js
$(QUIET_SUBDIR0)gitweb $(QUIET_SUBDIR1) $(patsubst gitweb/%,%,$@)
endif # JSMIN
ifdef CSSMIN
gitweb/gitweb.min.css: gitweb/gitweb.css
$(QUIET_SUBDIR0)gitweb $(QUIET_SUBDIR1) $(patsubst gitweb/%,%,$@)
endif # CSSMIN


git-instaweb: git-instaweb.sh gitweb/gitweb.cgi gitweb/gitweb.css gitweb/gitweb.js
Expand All @@ -1582,11 +1593,13 @@ git-instaweb: git-instaweb.sh gitweb/gitweb.cgi gitweb/gitweb.css gitweb/gitweb.
-e 's/@@NO_CURL@@/$(NO_CURL)/g' \
-e '/@@GITWEB_CGI@@/r gitweb/gitweb.cgi' \
-e '/@@GITWEB_CGI@@/d' \
-e '/@@GITWEB_CSS@@/r gitweb/gitweb.css' \
-e '/@@GITWEB_CSS@@/r $(GITWEB_CSS)' \
-e '/@@GITWEB_CSS@@/d' \
-e '/@@GITWEB_JS@@/r gitweb/gitweb.js' \
-e '/@@GITWEB_JS@@/r $(GITWEB_JS)' \
-e '/@@GITWEB_JS@@/d' \
-e 's|@@PERL@@|$(PERL_PATH_SQ)|g' \
-e 's|@@GITWEB_CSS_NAME@@|$(GITWEB_CSS)|' \
-e 's|@@GITWEB_JS_NAME@@|$(GITWEB_JS)|' \
$@.sh > $@+ && \
chmod +x $@+ && \
mv $@+ $@
Expand Down Expand Up @@ -2085,7 +2098,7 @@ clean:
$(RM) $(htmldocs).tar.gz $(manpages).tar.gz
$(MAKE) -C Documentation/ clean
ifndef NO_PERL
$(RM) gitweb/gitweb.cgi
$(RM) gitweb/gitweb.cgi gitweb/gitweb.min.*
$(MAKE) -C perl clean
endif
ifndef NO_PYTHON
Expand Down
20 changes: 20 additions & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,26 @@ fi],
AC_MSG_NOTICE([Will try -pthread then -lpthread to enable POSIX Threads.])
])

# Define option to enable JavaScript minification
AC_ARG_ENABLE([jsmin],
[AS_HELP_STRING([--enable-jsmin=PATH],
[PATH is the name of a JavaScript minifier or the absolute path to one.])],
[
JSMIN=$enableval;
AC_MSG_NOTICE([Setting JSMIN to '$JSMIN' to enable JavaScript minifying])
GIT_CONF_APPEND_LINE(JSMIN=$enableval);
])

# Define option to enable CSS minification
AC_ARG_ENABLE([cssmin],
[AS_HELP_STRING([--enable-cssmin=PATH],
[PATH is the name of a CSS minifier or the absolute path to one.])],
[
CSSMIN=$enableval;
AC_MSG_NOTICE([Setting CSSMIN to '$CSSMIN' to enable CSS minifying])
GIT_CONF_APPEND_LINE(CSSMIN=$enableval);
])

## Site configuration (override autodetection)
## --with-PACKAGE[=ARG] and --without-PACKAGE
AC_MSG_NOTICE([CHECKS for site configuration])
Expand Down
6 changes: 4 additions & 2 deletions git-instaweb.sh
Original file line number Diff line number Diff line change
Expand Up @@ -391,18 +391,20 @@ EOFGITWEB
gitweb_css () {
cat > "$1" <<\EOFGITWEB
@@GITWEB_CSS@@
EOFGITWEB
}

gitweb_js () {
cat > "$1" <<\EOFGITWEB
@@GITWEB_JS@@
EOFGITWEB
}

gitweb_cgi "$GIT_DIR/gitweb/gitweb.cgi"
gitweb_css "$GIT_DIR/gitweb/gitweb.css"
gitweb_js "$GIT_DIR/gitweb/gitweb.js"
gitweb_css "$GIT_DIR/@@GITWEB_CSS_NAME@@"
gitweb_js "$GIT_DIR/@@GITWEB_JS_NAME@@"

case "$httpd" in
*lighttpd*)
Expand Down
26 changes: 16 additions & 10 deletions gitweb/INSTALL
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ GIT web Interface (gitweb) Installation
=======================================

First you have to generate gitweb.cgi from gitweb.perl using
"make gitweb/gitweb.cgi", then copy appropriate files (gitweb.cgi,
"make gitweb", then copy appropriate files (gitweb.cgi, gitweb.js,
gitweb.css, git-logo.png and git-favicon.png) to their destination.
For example if git was (or is) installed with /usr prefix, you can do

$ make prefix=/usr gitweb/gitweb.cgi ;# as yourself
$ make prefix=/usr gitweb ;# as yourself
# cp gitweb/git* /var/www/cgi-bin/ ;# as root

Alternatively you can use autoconf generated ./configure script to
Expand All @@ -15,7 +15,7 @@ instead

$ make configure ;# as yourself
$ ./configure --prefix=/usr ;# as yourself
$ make gitweb/gitweb.cgi ;# as yourself
$ make gitweb ;# as yourself
# cp gitweb/git* /var/www/cgi-bin/ ;# as root

The above example assumes that your web server is configured to run
Expand All @@ -31,8 +31,7 @@ file for gitweb (in gitweb/README).

- There are many configuration variables which affect building of
gitweb.cgi; see "default configuration for gitweb" section in main
(top dir) Makefile, and instructions for building gitweb/gitweb.cgi
target.
(top dir) Makefile, and instructions for building gitweb target.

One of the most important is where to find the git wrapper binary. Gitweb
tries to find the git wrapper at $(bindir)/git, so you have to set $bindir
Expand Down Expand Up @@ -62,9 +61,15 @@ file for gitweb (in gitweb/README).
a suggestion).

- You can control where gitweb tries to find its main CSS style file,
its favicon and logo with the GITWEB_CSS, GITWEB_FAVICON and GITWEB_LOGO
build configuration variables. By default gitweb tries to find them
in the same directory as gitweb.cgi script.
its JavaScript file, its favicon and logo with the GITWEB_CSS, GITWEB_JS
GITWEB_FAVICON and GITWEB_LOGO build configuration variables. By default
gitweb tries to find them in the same directory as gitweb.cgi script.

- You can optionally generate minified versions of gitweb.js and gitweb.css
by defining the JSMIN and CSSMIN build configuration variables. By default
the non-minified versions will be used. NOTE: if you enable this option,
substitute gitweb.min.js and gitweb.min.css for all uses of gitweb.js and
gitweb.css in the help files.

Build example
~~~~~~~~~~~~~
Expand All @@ -74,13 +79,14 @@ Build example
we want to display are under /home/local/scm, you can do

make GITWEB_PROJECTROOT="/home/local/scm" \
GITWEB_JS="/gitweb/gitweb.js" \
GITWEB_CSS="/gitweb/gitweb.css" \
GITWEB_LOGO="/gitweb/git-logo.png" \
GITWEB_FAVICON="/gitweb/git-favicon.png" \
bindir=/usr/local/bin \
gitweb/gitweb.cgi
gitweb

cp -fv ~/git/gitweb/gitweb.{cgi,css} \
cp -fv ~/git/gitweb/gitweb.{cgi,js,css} \
~/git/gitweb/git-{favicon,logo}.png \
/var/www/cgi-bin/gitweb/

Expand Down
30 changes: 17 additions & 13 deletions gitweb/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ all::
# Define JSMIN to point to JavaScript minifier that functions as
# a filter to have gitweb.js minified.
#
# Define CSSMIN to point to a CSS minifier in order to generate a minified
# version of gitweb.css
#

prefix ?= $(HOME)
bindir ?= $(prefix)/bin
RM ?= rm -f

# JavaScript minifier invocation that can function as filter
JSMIN ?=

# default configuration for gitweb
GITWEB_CONFIG = gitweb_config.perl
GITWEB_CONFIG_SYSTEM = /etc/gitweb.conf
Expand All @@ -29,11 +29,7 @@ GITWEB_HOMETEXT = indextext.html
GITWEB_CSS = gitweb.css
GITWEB_LOGO = git-logo.png
GITWEB_FAVICON = git-favicon.png
ifdef JSMIN
GITWEB_JS = gitweb.min.js
else
GITWEB_JS = gitweb.js
endif
GITWEB_SITE_HEADER =
GITWEB_SITE_FOOTER =

Expand Down Expand Up @@ -84,13 +80,16 @@ endif

all:: gitweb.cgi

FILES = gitweb.cgi
ifdef JSMIN
FILES=gitweb.cgi gitweb.min.js
gitweb.cgi: gitweb.perl gitweb.min.js
else # !JSMIN
FILES=gitweb.cgi
gitweb.cgi: gitweb.perl
endif # JSMIN
FILES += gitweb.min.js
GITWEB_JS = gitweb.min.js
endif
ifdef CSSMIN
FILES += gitweb.min.css
GITWEB_CSS = gitweb.min.css
endif
gitweb.cgi: gitweb.perl $(GITWEB_JS) $(GITWEB_CSS)

gitweb.cgi:
$(QUIET_GEN)$(RM) $@ $@+ && \
Expand Down Expand Up @@ -123,6 +122,11 @@ gitweb.min.js: gitweb.js
$(QUIET_GEN)$(JSMIN) <$< >$@
endif # JSMIN

ifdef CSSMIN
gitweb.min.css: gitweb.css
$(QUIET_GEN)$(CSSMIN) <$ >$@
endif

clean:
$(RM) $(FILES)

Expand Down
3 changes: 2 additions & 1 deletion gitweb/README
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,8 @@ You can specify the following configuration variables when building GIT:
Points to the location where you put gitweb.css on your web server
(or to be more generic, the URI of gitweb stylesheet). Relative to the
base URI of gitweb. Note that you can setup multiple stylesheets from
the gitweb config file. [Default: gitweb.css]
the gitweb config file. [Default: gitweb.css (or gitweb.min.css if the
CSSMIN variable is defined / CSS minifier is used)]
* GITWEB_LOGO
Points to the location where you put git-logo.png on your web server
(or to be more generic URI of logo, 72x27 size, displayed in top right
Expand Down

0 comments on commit b92cbb6

Please sign in to comment.