Makefile 2.94 KB
Newer Older
Oscar Olsson's avatar
Oscar Olsson committed
1
## Macros
2

Oscar Olsson's avatar
Oscar Olsson committed
3
4
# Use LLVM clang if it's found.
CC = $(shell hash clang 2>/dev/null && echo clang || echo gcc)
5
CFLAGS = -g -Wall -Werror -O3  -I. -Itest -DLABCOMM_ENCODER_LINEAR_SEARCH
6
LDFLAGS = -L.
7
LDLIBS_TEST = -Tlabcomm.linkscript  -lcunit -llabcomm
Oscar Olsson's avatar
Oscar Olsson committed
8

9
10
OBJS= labcomm.o labcomm_dynamic_buffer_writer.o labcomm_fd_reader.o labcomm_fd_writer.o 
#FIXME: labcomm_mem_reader.o labcomm_mem_writer.o
Anders Blomdell's avatar
Anders Blomdell committed
11
12
LABCOMM_JAR=../../compiler/labComm.jar
LABCOMM=java -jar $(LABCOMM_JAR) 
Oscar Olsson's avatar
Oscar Olsson committed
13

14
TESTS=test_labcomm_basic_type_encoding test_labcomm_generated_encoding 
15
16
#
#FIXME: test_labcomm test_labcomm_errors
Oscar Olsson's avatar
Oscar Olsson committed
17
18
19
20
TEST_DIR=test
TESTDATA_DIR=$(TEST_DIR)/testdata
TEST_GEN_DIR=$(TESTDATA_DIR)/gen

21
22
VPATH=$(TEST_DIR)

Oscar Olsson's avatar
Oscar Olsson committed
23
24
CREATED_DIRS=$(TEST_DIR) $(TESTDATA_DIR) $(TEST_GEN_DIR)

25
# Enable experimental objects by invoking make like `make LABCOMM_EXPERIMENTAL=true`
26
ifeq ($(LABCOMM_EXPERIMENTAL),true)
Oscar Olsson's avatar
Oscar Olsson committed
27
28
29
30
31
32
33
34
35
36
37
	OBJS += experimental/udp_hack.o experimental/ethaddr.o \
		experimental/labcomm_thr_reader_writer.o \
		experimental/ThrottleDrv/ethernet_drv.o \
		experimental/ThrottleDrv/throttle_drv.o \
		experimental/labcomm_udp_reader_writer.o
endif

## Targets

.PHONY: all run-test clean distclean

Anders Blomdell's avatar
Anders Blomdell committed
38
all: liblabcomm.a 
Oscar Olsson's avatar
Oscar Olsson committed
39
40

liblabcomm.a: $(OBJS)
Sven Robertz's avatar
Sven Robertz committed
41
	ar -r liblabcomm.a $^
Sven Robertz's avatar
Sven Robertz committed
42

Oscar Olsson's avatar
Oscar Olsson committed
43

Sven Robertz's avatar
Sven Robertz committed
44
45
46
labcomm.o : labcomm.c labcomm.h  labcomm_private.h

labcomm_fd_reader_writer.o : labcomm_fd_reader_writer.c  labcomm_fd_reader_writer.h  labcomm.h  labcomm_private.h
47

48
#$(TEST_DIR)/labcomm_mem_reader.o: labcomm_fd_reader_writer.c labcomm_fd_reader_writer.h
Oscar Olsson's avatar
Oscar Olsson committed
49

50
#$(TEST_DIR)/labcomm_mem_writer.o: labcomm_mem_writer.c labcomm_mem_writer.h cppmacros.h
Oscar Olsson's avatar
Oscar Olsson committed
51

52
ethaddr.o: ethaddr.c
Sven Robertz's avatar
Sven Robertz committed
53

Oscar Olsson's avatar
Oscar Olsson committed
54
55
56
$(CREATED_DIRS):
	mkdir -p $@

57
## NB! the tests need CUnit to be installed
58
59
60
61
run-test: $(TESTS:%=run-test-%)

run-test-%: $(TEST_DIR)/% | $(TEST_DIR)
	$<
Oscar Olsson's avatar
Oscar Olsson committed
62

63
64
$(TEST_DIR)/%.o: $(TEST_DIR)/%.c
	$(CC) $(CFLAGS) -o $@ -c $<
Oscar Olsson's avatar
Oscar Olsson committed
65

66
$(TEST_DIR)/%: $(TEST_DIR)/%.o liblabcomm.a
67
	$(CC) $(LDFLAGS) -o $@ $^ $(LDLIBS) $(LDLIBS_TEST)
Oscar Olsson's avatar
Oscar Olsson committed
68

69
70
71
72
$(TEST_DIR)/gen:
	mkdir -p $@

$(TEST_DIR)/gen/%.c $(TEST_DIR)/gen/%.h: $(TEST_DIR)/%.lc | $(TEST_DIR)/gen
Anders Blomdell's avatar
Anders Blomdell committed
73
	$(LABCOMM) \
74
75
76
77
		--c=$(TEST_DIR)/gen/$*.c \
		--h=$(TEST_DIR)/gen/$*.h \
		$<

78
$(TEST_GEN_DIR)/%.c $(TEST_GEN_DIR)/%.h: $(TESTDATA_DIR)/%.lc \
Anders Blomdell's avatar
Anders Blomdell committed
79
80
					 $(LABCOMM_JAR) | $(TEST_GEN_DIR)
	$(LABCOMM) \
81
		--c=$(patsubst %.h,%.c,$@) --h=$(patsubst %.c,%.h,$@) $<
Oscar Olsson's avatar
Oscar Olsson committed
82

Anders Blomdell's avatar
Anders Blomdell committed
83
$(LABCOMM_JAR):
Oscar Olsson's avatar
Oscar Olsson committed
84
	@echo "======Building LabComm compiler======"
Anders Blomdell's avatar
Anders Blomdell committed
85
	cd $(shell dirname $(LABCOMM_JAR)); ant jar
Oscar Olsson's avatar
Oscar Olsson committed
86
87
88
	@echo "======End building LabComm compiler======"

%.o: %.c %.h
Sven Robertz's avatar
Sven Robertz committed
89

Sven Robertz's avatar
Sven Robertz committed
90
clean:
Oscar Olsson's avatar
Oscar Olsson committed
91
92
93
94
95
	$(RM) *.o
	$(RM) experimental/*.o experimental/ThrottleDrv/*.o
	$(RM) test/*.o
	$(RM) test/*.gch
	$(RM) test/test_labcomm_errors
96
	$(RM) test/testdata/gen/*.[cho]
97
	$(RM) test/gen/*.[cho]
Oscar Olsson's avatar
Oscar Olsson committed
98
	$(RM) $(TEST_DIR)/test_labcomm
Sven Robertz's avatar
Sven Robertz committed
99
100

distclean: clean
Oscar Olsson's avatar
Oscar Olsson committed
101
	$(RM) liblabcomm.a
102
103

# Extra dependencies
104
105
106
$(TEST_DIR)/test_labcomm_basic_type_encoding.o: labcomm_private.h
$(TEST_DIR)/test_labcomm_generated_encoding.o : $(TEST_DIR)/gen/generated_encoding.h
$(TEST_DIR)/test_labcomm_generated_encoding : $(TEST_DIR)/gen/generated_encoding.o
107
$(TEST_DIR)/test_labcomm:  $(TEST_GEN_DIR)/test_sample.o