Skip to content

Commit

Permalink
Re-jigger Makefile.
Browse files Browse the repository at this point in the history
- Uses more standard $CFLAGS and $CPPFLAGS variables to populate the set
  of flags to build with.
- Allow extending compilation and linking flags with
  $CPPFLAGS_DEBUG_EXTRA, $CPPFLAGS_FAST_EXTRA, $CFLAGS_DEBUG_EXTRA, and
  $CFLAGS_FAST_EXTRA.

Closes nodejs#40.
  • Loading branch information
pgriess committed Jun 19, 2011
1 parent 0aa3e52 commit 8e83445
Showing 1 changed file with 22 additions and 16 deletions.
38 changes: 22 additions & 16 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,39 +1,45 @@
CPPFLAGS?=-Wall -Wextra -Werror -I.
OPT_DEBUG=$(CPPFLAGS) -O0 -g -DHTTP_PARSER_STRICT=1 -DHTTP_PARSER_DEBUG=1
OPT_FAST=$(CPPFLAGS) -O3 -DHTTP_PARSER_STRICT=0 -DHTTP_PARSER_DEBUG=0

CC?=gcc
AR?=ar

CPPFLAGS += -I.
CPPFLAGS_DEBUG = $(CPPFLAGS) -DHTTP_PARSER_STRICT=1 -DHTTP_PARSER_DEBUG=1
CPPFLAGS_DEBUG += $(CPPFLAGS_DEBUG_EXTRA)
CPPFLAGS_FAST = $(CPPFLAGS) -DHTTP_PARSER_STRICT=0 -DHTTP_PARSER_DEBUG=0
CPPFLAGS_FAST += $(CPPFLAGS_FAST_EXTRA)

CFLAGS += -Wall -Wextra -Werror
CFLAGS_DEBUG = $(CFLAGS) -O0 -g $(CFLAGS_DEBUG_EXTRA)
CFLAGS_FAST = $(CFLAGS) -O3 $(CFLAGS_FAST_EXTRA)


test: test_g test_fast
./test_g
./test_fast

test_g: http_parser_g.o test_g.o
$(CC) $(OPT_DEBUG) http_parser_g.o test_g.o -o $@
$(CC) $(CFLAGS_DEBUG) $(LDFLAGS) http_parser_g.o test_g.o -o $@

test_g.o: test.c http_parser.h Makefile
$(CC) $(OPT_DEBUG) -c test.c -o $@

test.o: test.c http_parser.h Makefile
$(CC) $(OPT_FAST) -c test.c -o $@
$(CC) $(CPPFLAGS_DEBUG) $(CFLAGS_DEBUG) -c test.c -o $@

http_parser_g.o: http_parser.c http_parser.h Makefile
$(CC) $(OPT_DEBUG) -c http_parser.c -o $@
$(CC) $(CPPFLAGS_DEBUG) $(CFLAGS_DEBUG) -c http_parser.c -o $@

test-valgrind: test_g
valgrind ./test_g
test_fast: http_parser.o test.o http_parser.h
$(CC) $(CFLAGS_FAST) $(LDFLAGS) http_parser.o test.o -o $@

http_parser.o: http_parser.c http_parser.h Makefile
$(CC) $(OPT_FAST) -c http_parser.c
test.o: test.c http_parser.h Makefile
$(CC) $(CPPFLAGS_FAST) $(CFLAGS_FAST) -c test.c -o $@

test_fast: http_parser.o test.c http_parser.h
$(CC) $(OPT_FAST) http_parser.o test.c -o $@
http_parser.o: http_parser.c http_parser.h Makefile
$(CC) $(CPPFLAGS_FAST) $(CFLAGS_FAST) -c http_parser.c

test-run-timed: test_fast
while(true) do time ./test_fast > /dev/null; done

test-valgrind: test_g
valgrind ./test_g

package: http_parser.o
$(AR) rcs libhttp_parser.a http_parser.o

Expand Down

0 comments on commit 8e83445

Please sign in to comment.