Makefile
author Mahlon E. Smith <mahlon@martini.nu>
Wed, 28 Sep 2011 09:04:16 -0700
changeset 9 bdf20e6eefd7
parent 8 8d0f25ef038e
child 10 d07309450285
permissions -rw-r--r--
Ansi-fy getopt function and variable declarations.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
8
8d0f25ef038e Add common archive files (LICENCE, README, etc) and a 'release' Makefile
Mahlon E. Smith <mahlon@martini.nu>
parents: 6
diff changeset
     1
UNAME       := $(shell uname)
6
85718bc3ff47 Use pkg-config to find dependency locations, add gdb debug flags.
Mahlon E. Smith <mahlon@martini.nu>
parents: 4
diff changeset
     2
DEPS         = sqlite3
85718bc3ff47 Use pkg-config to find dependency locations, add gdb debug flags.
Mahlon E. Smith <mahlon@martini.nu>
parents: 4
diff changeset
     3
DEPS_DEBUG   = sqlite3 libprofiler
85718bc3ff47 Use pkg-config to find dependency locations, add gdb debug flags.
Mahlon E. Smith <mahlon@martini.nu>
parents: 4
diff changeset
     4
CFLAGS       = $(shell pkg-config --cflags-only-I --libs-only-L $(DEPS)) -O2
85718bc3ff47 Use pkg-config to find dependency locations, add gdb debug flags.
Mahlon E. Smith <mahlon@martini.nu>
parents: 4
diff changeset
     5
LIBS         = $(shell pkg-config --libs-only-l $(DEPS))
1
823d42546cea Dial in the Makefile and command line option parsing. Better debug
Mahlon E. Smith <mahlon@laika.com>
parents: 0
diff changeset
     6
#OBJS         = $(patsubst %.c,%.o,$(wildcard *.c)) parser.o
8
8d0f25ef038e Add common archive files (LICENCE, README, etc) and a 'release' Makefile
Mahlon E. Smith <mahlon@martini.nu>
parents: 6
diff changeset
     7
OBJS         = accept_loop.o db.o main.o parser.o process.o util.o
6
85718bc3ff47 Use pkg-config to find dependency locations, add gdb debug flags.
Mahlon E. Smith <mahlon@martini.nu>
parents: 4
diff changeset
     8
RAGEL_FLAGS  = -LCe -G2
0
eac7211fe522 Initial commit of an experimental little Squid redirector.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
     9
8
8d0f25ef038e Add common archive files (LICENCE, README, etc) and a 'release' Makefile
Mahlon E. Smith <mahlon@martini.nu>
parents: 6
diff changeset
    10
.PHONY : parsegraph profile clean cleanall release
8d0f25ef038e Add common archive files (LICENCE, README, etc) and a 'release' Makefile
Mahlon E. Smith <mahlon@martini.nu>
parents: 6
diff changeset
    11
1
823d42546cea Dial in the Makefile and command line option parsing. Better debug
Mahlon E. Smith <mahlon@laika.com>
parents: 0
diff changeset
    12
########################################################################
2
8c88756f81b0 Ensure that parsing can't be subverted by requests larger than the
Mahlon E. Smith <mahlon@martini.nu>
parents: 1
diff changeset
    13
### P R O D U C T I O N
1
823d42546cea Dial in the Makefile and command line option parsing. Better debug
Mahlon E. Smith <mahlon@laika.com>
parents: 0
diff changeset
    14
########################################################################
823d42546cea Dial in the Makefile and command line option parsing. Better debug
Mahlon E. Smith <mahlon@laika.com>
parents: 0
diff changeset
    15
823d42546cea Dial in the Makefile and command line option parsing. Better debug
Mahlon E. Smith <mahlon@laika.com>
parents: 0
diff changeset
    16
volta: $(OBJS)
823d42546cea Dial in the Makefile and command line option parsing. Better debug
Mahlon E. Smith <mahlon@laika.com>
parents: 0
diff changeset
    17
	$(CC) $(CFLAGS) $(LIBS) -o $@ $(OBJS)
0
eac7211fe522 Initial commit of an experimental little Squid redirector.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    18
	strip $@
eac7211fe522 Initial commit of an experimental little Squid redirector.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    19
1
823d42546cea Dial in the Makefile and command line option parsing. Better debug
Mahlon E. Smith <mahlon@laika.com>
parents: 0
diff changeset
    20
$(OBJS): volta.h
823d42546cea Dial in the Makefile and command line option parsing. Better debug
Mahlon E. Smith <mahlon@laika.com>
parents: 0
diff changeset
    21
2
8c88756f81b0 Ensure that parsing can't be subverted by requests larger than the
Mahlon E. Smith <mahlon@martini.nu>
parents: 1
diff changeset
    22
# don't actually depend on parser.rl, so distributions don't require ragel
8c88756f81b0 Ensure that parsing can't be subverted by requests larger than the
Mahlon E. Smith <mahlon@martini.nu>
parents: 1
diff changeset
    23
parser.c:
6
85718bc3ff47 Use pkg-config to find dependency locations, add gdb debug flags.
Mahlon E. Smith <mahlon@martini.nu>
parents: 4
diff changeset
    24
	ragel $(RAGEL_FLAGS) -s parser.rl -o $@
0
eac7211fe522 Initial commit of an experimental little Squid redirector.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    25
1
823d42546cea Dial in the Makefile and command line option parsing. Better debug
Mahlon E. Smith <mahlon@laika.com>
parents: 0
diff changeset
    26
823d42546cea Dial in the Makefile and command line option parsing. Better debug
Mahlon E. Smith <mahlon@laika.com>
parents: 0
diff changeset
    27
########################################################################
823d42546cea Dial in the Makefile and command line option parsing. Better debug
Mahlon E. Smith <mahlon@laika.com>
parents: 0
diff changeset
    28
### D E B U G
823d42546cea Dial in the Makefile and command line option parsing. Better debug
Mahlon E. Smith <mahlon@laika.com>
parents: 0
diff changeset
    29
########################################################################
0
eac7211fe522 Initial commit of an experimental little Squid redirector.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    30
8
8d0f25ef038e Add common archive files (LICENCE, README, etc) and a 'release' Makefile
Mahlon E. Smith <mahlon@martini.nu>
parents: 6
diff changeset
    31
# proftools doesn't currently register a .pc file on Ubuntu, hence these
8d0f25ef038e Add common archive files (LICENCE, README, etc) and a 'release' Makefile
Mahlon E. Smith <mahlon@martini.nu>
parents: 6
diff changeset
    32
# Makefile gymnastics
8d0f25ef038e Add common archive files (LICENCE, README, etc) and a 'release' Makefile
Mahlon E. Smith <mahlon@martini.nu>
parents: 6
diff changeset
    33
ifeq ($(UNAME), Linux)
8d0f25ef038e Add common archive files (LICENCE, README, etc) and a 'release' Makefile
Mahlon E. Smith <mahlon@martini.nu>
parents: 6
diff changeset
    34
debug: CFLAGS = -ggdb -Wall -DDEBUG -DPROG='"volta (debugmode)"'
8d0f25ef038e Add common archive files (LICENCE, README, etc) and a 'release' Makefile
Mahlon E. Smith <mahlon@martini.nu>
parents: 6
diff changeset
    35
debug: LIBS = -lsqlite3 -lprofiler
8d0f25ef038e Add common archive files (LICENCE, README, etc) and a 'release' Makefile
Mahlon E. Smith <mahlon@martini.nu>
parents: 6
diff changeset
    36
else
6
85718bc3ff47 Use pkg-config to find dependency locations, add gdb debug flags.
Mahlon E. Smith <mahlon@martini.nu>
parents: 4
diff changeset
    37
debug: CFLAGS = -ggdb -Wall -DDEBUG -DPROG='"volta (debugmode)"'\
85718bc3ff47 Use pkg-config to find dependency locations, add gdb debug flags.
Mahlon E. Smith <mahlon@martini.nu>
parents: 4
diff changeset
    38
	$(shell pkg-config --cflags-only-I --libs-only-L $(DEPS_DEBUG))
85718bc3ff47 Use pkg-config to find dependency locations, add gdb debug flags.
Mahlon E. Smith <mahlon@martini.nu>
parents: 4
diff changeset
    39
debug: LIBS = $(shell pkg-config --libs-only-l $(DEPS_DEBUG))
8
8d0f25ef038e Add common archive files (LICENCE, README, etc) and a 'release' Makefile
Mahlon E. Smith <mahlon@martini.nu>
parents: 6
diff changeset
    40
endif
2
8c88756f81b0 Ensure that parsing can't be subverted by requests larger than the
Mahlon E. Smith <mahlon@martini.nu>
parents: 1
diff changeset
    41
8
8d0f25ef038e Add common archive files (LICENCE, README, etc) and a 'release' Makefile
Mahlon E. Smith <mahlon@martini.nu>
parents: 6
diff changeset
    42
debug: RAGEL_FLAGS = -Ce -G2
8d0f25ef038e Add common archive files (LICENCE, README, etc) and a 'release' Makefile
Mahlon E. Smith <mahlon@martini.nu>
parents: 6
diff changeset
    43
debug: $(OBJS)
8d0f25ef038e Add common archive files (LICENCE, README, etc) and a 'release' Makefile
Mahlon E. Smith <mahlon@martini.nu>
parents: 6
diff changeset
    44
	ctags *.h *.c
2
8c88756f81b0 Ensure that parsing can't be subverted by requests larger than the
Mahlon E. Smith <mahlon@martini.nu>
parents: 1
diff changeset
    45
	$(CC) $(CFLAGS) $(LIBS) -o volta $(OBJS)
0
eac7211fe522 Initial commit of an experimental little Squid redirector.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    46
8
8d0f25ef038e Add common archive files (LICENCE, README, etc) and a 'release' Makefile
Mahlon E. Smith <mahlon@martini.nu>
parents: 6
diff changeset
    47
parsegraph: parser_graph.xml parser_graph.pdf parser_graph.dot
6
85718bc3ff47 Use pkg-config to find dependency locations, add gdb debug flags.
Mahlon E. Smith <mahlon@martini.nu>
parents: 4
diff changeset
    48
parser_graph.xml parser_graph.pdf parser_graph.dot: parser.rl
8
8d0f25ef038e Add common archive files (LICENCE, README, etc) and a 'release' Makefile
Mahlon E. Smith <mahlon@martini.nu>
parents: 6
diff changeset
    49
	ragel -Vp parser.rl > parser_graph.dot
8d0f25ef038e Add common archive files (LICENCE, README, etc) and a 'release' Makefile
Mahlon E. Smith <mahlon@martini.nu>
parents: 6
diff changeset
    50
	ragel $(RAGEL_FLAGS) -x parser.rl -o parser_graph.xml
8d0f25ef038e Add common archive files (LICENCE, README, etc) and a 'release' Makefile
Mahlon E. Smith <mahlon@martini.nu>
parents: 6
diff changeset
    51
	dot -Tpdf parser_graph.dot > parser_graph.pdf
2
8c88756f81b0 Ensure that parsing can't be subverted by requests larger than the
Mahlon E. Smith <mahlon@martini.nu>
parents: 1
diff changeset
    52
8c88756f81b0 Ensure that parsing can't be subverted by requests larger than the
Mahlon E. Smith <mahlon@martini.nu>
parents: 1
diff changeset
    53
# export CPUPROFILE="cpu.prof" before running volta for cpu profiling
8c88756f81b0 Ensure that parsing can't be subverted by requests larger than the
Mahlon E. Smith <mahlon@martini.nu>
parents: 1
diff changeset
    54
# export CPUPROFILE_FREQUENCY=100 (default)
8c88756f81b0 Ensure that parsing can't be subverted by requests larger than the
Mahlon E. Smith <mahlon@martini.nu>
parents: 1
diff changeset
    55
profile:
8c88756f81b0 Ensure that parsing can't be subverted by requests larger than the
Mahlon E. Smith <mahlon@martini.nu>
parents: 1
diff changeset
    56
	pprof --dot ./volta $(CPUPROFILE) | dot -Tpng > $(CPUPROFILE).png
8c88756f81b0 Ensure that parsing can't be subverted by requests larger than the
Mahlon E. Smith <mahlon@martini.nu>
parents: 1
diff changeset
    57
	pprof --text ./volta $(CPUPROFILE)
0
eac7211fe522 Initial commit of an experimental little Squid redirector.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    58
1
823d42546cea Dial in the Makefile and command line option parsing. Better debug
Mahlon E. Smith <mahlon@laika.com>
parents: 0
diff changeset
    59
823d42546cea Dial in the Makefile and command line option parsing. Better debug
Mahlon E. Smith <mahlon@laika.com>
parents: 0
diff changeset
    60
########################################################################
823d42546cea Dial in the Makefile and command line option parsing. Better debug
Mahlon E. Smith <mahlon@laika.com>
parents: 0
diff changeset
    61
### U T I L
823d42546cea Dial in the Makefile and command line option parsing. Better debug
Mahlon E. Smith <mahlon@laika.com>
parents: 0
diff changeset
    62
########################################################################
823d42546cea Dial in the Makefile and command line option parsing. Better debug
Mahlon E. Smith <mahlon@laika.com>
parents: 0
diff changeset
    63
2
8c88756f81b0 Ensure that parsing can't be subverted by requests larger than the
Mahlon E. Smith <mahlon@martini.nu>
parents: 1
diff changeset
    64
cleanall: clean
8
8d0f25ef038e Add common archive files (LICENCE, README, etc) and a 'release' Makefile
Mahlon E. Smith <mahlon@martini.nu>
parents: 6
diff changeset
    65
	rm -f parser.c volta.db ChangeLog tags
2
8c88756f81b0 Ensure that parsing can't be subverted by requests larger than the
Mahlon E. Smith <mahlon@martini.nu>
parents: 1
diff changeset
    66
0
eac7211fe522 Initial commit of an experimental little Squid redirector.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    67
clean:
2
8c88756f81b0 Ensure that parsing can't be subverted by requests larger than the
Mahlon E. Smith <mahlon@martini.nu>
parents: 1
diff changeset
    68
	-rm -f volta volta_debug* parser_graph.* *.o *.prof*
0
eac7211fe522 Initial commit of an experimental little Squid redirector.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    69
8
8d0f25ef038e Add common archive files (LICENCE, README, etc) and a 'release' Makefile
Mahlon E. Smith <mahlon@martini.nu>
parents: 6
diff changeset
    70
release: VERSION = $(shell hg id -t | awk '{ print $$1 }')
8d0f25ef038e Add common archive files (LICENCE, README, etc) and a 'release' Makefile
Mahlon E. Smith <mahlon@martini.nu>
parents: 6
diff changeset
    71
release: cleanall parser.c
8d0f25ef038e Add common archive files (LICENCE, README, etc) and a 'release' Makefile
Mahlon E. Smith <mahlon@martini.nu>
parents: 6
diff changeset
    72
	hg log --style changelog > ChangeLog
8d0f25ef038e Add common archive files (LICENCE, README, etc) and a 'release' Makefile
Mahlon E. Smith <mahlon@martini.nu>
parents: 6
diff changeset
    73
	tar -C .. --exclude misc --exclude .\*  -s '/^volta/volta-$(VERSION)/' -czvf /tmp/volta-$(VERSION).tgz volta
8d0f25ef038e Add common archive files (LICENCE, README, etc) and a 'release' Makefile
Mahlon E. Smith <mahlon@martini.nu>
parents: 6
diff changeset
    74
	mv /tmp/volta-$(VERSION).tgz .
8d0f25ef038e Add common archive files (LICENCE, README, etc) and a 'release' Makefile
Mahlon E. Smith <mahlon@martini.nu>
parents: 6
diff changeset
    75