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

3
CC=gcc
4
CFLAGS=-g -Wall -Werror -O3  -I. -Itest 
5
LDFLAGS=-L.
6
7
8
9
10
11
12
13
14
15
16
17
18
LDLIBS_TEST=-llabcomm -lrt

OBJS=labcomm_memory.o \
     labcomm_error.o \
     labcomm_default_error_handler.o \
     labcomm_default_memory.o \
     labcomm_default_scheduler.o \
     labcomm_time.o labcomm_scheduler.o \
     labcomm_encoder.o labcomm_decoder.o \
     labcomm.o \
     labcomm_dynamic_buffer_writer.o \
     labcomm_fd_reader.o labcomm_fd_writer.o \
     labcomm_pthread_scheduler.o 
Oscar Olsson's avatar
Oscar Olsson committed
19

20
#FIXME: labcomm_mem_reader.o labcomm_mem_writer.o
Anders Blomdell's avatar
Anders Blomdell committed
21
22
LABCOMM_JAR=../../compiler/labComm.jar
LABCOMM=java -jar $(LABCOMM_JAR) 
Oscar Olsson's avatar
Oscar Olsson committed
23

24
TESTS=test_labcomm_basic_type_encoding test_labcomm_generated_encoding \
25
26
      test_signature_numbers \
      test_labcomm \
27
      test_labcomm_pthread_scheduler \
28
29
#
#FIXME: test_labcomm test_labcomm_errors
Oscar Olsson's avatar
Oscar Olsson committed
30
31
TEST_DIR=test

32
33
34
VPATH=$(TEST_DIR)

# Enable experimental objects by invoking make like `make LABCOMM_EXPERIMENTAL=true`
35
ifeq ($(LABCOMM_EXPERIMENTAL),true)
Oscar Olsson's avatar
Oscar Olsson committed
36
37
38
39
40
41
42
43
44
45
46
	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

47
all: liblabcomm.a liblabcomm.so.1
Oscar Olsson's avatar
Oscar Olsson committed
48
49

liblabcomm.a: $(OBJS)
50
51
	ar -r $@ $^

52
liblabcomm.so.1: $(OBJS:%.o=%.pic.o)
53
	gcc -shared -Wl,-soname,$@ -o $@ $^ -lc -lrt
Oscar Olsson's avatar
Oscar Olsson committed
54

Sven Robertz's avatar
Sven Robertz committed
55
56
57
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
58

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

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

63
ethaddr.o: ethaddr.c
Sven Robertz's avatar
Sven Robertz committed
64

65
66
67
68
run-test: $(TESTS:%=run-test-%)

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

70
71
$(TEST_DIR)/%.o: $(TEST_DIR)/%.c
	$(CC) $(CFLAGS) -o $@ -c $<
Oscar Olsson's avatar
Oscar Olsson committed
72

73
.PRECIOUS: $(TEST_DIR)/%
74
$(TEST_DIR)/%: $(TEST_DIR)/%.o 
75
	$(CC) $(LDFLAGS) -o $@ $^ $(LDLIBS) $(LDLIBS_TEST)
Oscar Olsson's avatar
Oscar Olsson committed
76

77
78
79
$(TEST_DIR)/gen:
	mkdir -p $@

80
81
.PRECIOUS: $(TEST_DIR)/gen/%.c
.PRECIOUS: $(TEST_DIR)/gen/%.h
82
$(TEST_DIR)/gen/%.c $(TEST_DIR)/gen/%.h: $(TEST_DIR)/%.lc | $(TEST_DIR)/gen
Anders Blomdell's avatar
Anders Blomdell committed
83
	$(LABCOMM) \
84
85
86
87
		--c=$(TEST_DIR)/gen/$*.c \
		--h=$(TEST_DIR)/gen/$*.h \
		$<

88
$(TEST_GEN_DIR)/%.c $(TEST_GEN_DIR)/%.h: $(TESTDATA_DIR)/%.lc \
Anders Blomdell's avatar
Anders Blomdell committed
89
90
					 $(LABCOMM_JAR) | $(TEST_GEN_DIR)
	$(LABCOMM) \
91
		--c=$(patsubst %.h,%.c,$@) --h=$(patsubst %.c,%.h,$@) $<
Oscar Olsson's avatar
Oscar Olsson committed
92

Anders Blomdell's avatar
Anders Blomdell committed
93
$(LABCOMM_JAR):
Oscar Olsson's avatar
Oscar Olsson committed
94
	@echo "======Building LabComm compiler======"
Anders Blomdell's avatar
Anders Blomdell committed
95
	cd $(shell dirname $(LABCOMM_JAR)); ant jar
Oscar Olsson's avatar
Oscar Olsson committed
96
97
	@echo "======End building LabComm compiler======"

98
99
100
%.pic.o:	%.c
	$(CC) -fPIC $(CFLAGS) -c -o $@ $<

Oscar Olsson's avatar
Oscar Olsson committed
101
%.o: %.c %.h
Sven Robertz's avatar
Sven Robertz committed
102

Sven Robertz's avatar
Sven Robertz committed
103
clean:
Oscar Olsson's avatar
Oscar Olsson committed
104
105
106
107
108
	$(RM) *.o
	$(RM) experimental/*.o experimental/ThrottleDrv/*.o
	$(RM) test/*.o
	$(RM) test/*.gch
	$(RM) test/test_labcomm_errors
109
	$(RM) test/testdata/gen/*.[cho]
110
	$(RM) test/gen/*.[cho]
Oscar Olsson's avatar
Oscar Olsson committed
111
	$(RM) $(TEST_DIR)/test_labcomm
Sven Robertz's avatar
Sven Robertz committed
112
113

distclean: clean
114
	$(RM) liblabcomm.so.1
Oscar Olsson's avatar
Oscar Olsson committed
115
	$(RM) liblabcomm.a
116
117

# Extra dependencies
118
$(TEST_DIR)/test_labcomm_basic_type_encoding.o: labcomm_private.h
119
120
121

$(TEST_DIR)/test_labcomm_generated_encoding.o: labcomm_private.h
$(TEST_DIR)/test_labcomm_generated_encoding.o: $(TEST_DIR)/gen/generated_encoding.h
122
$(TEST_DIR)/test_labcomm_generated_encoding : $(TEST_DIR)/gen/generated_encoding.o
123

124
$(TEST_DIR)/test_labcomm:  $(TEST_DIR)/gen/test_sample.o
125
126
127
128
$(TEST_DIR)/test_signature_numbers.c: $(TEST_DIR)/gen/another_encoding.h
$(TEST_DIR)/test_signature_numbers.c: $(TEST_DIR)/gen/generated_encoding.h
$(TEST_DIR)/test_signature_numbers: $(TEST_DIR)/gen/another_encoding.o
$(TEST_DIR)/test_signature_numbers: $(TEST_DIR)/gen/generated_encoding.o
129
130
131
labcomm_fd_reader.o: labcomm_private.h
labcomm_fd_writer.o: labcomm_private.h
labcomm_dynamic_buffer_writer.o: labcomm_private.h