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

3
CC=gcc
4
5
#CFLAGS=-g -Wall -Werror -O3  -I. -Itest -DLABCOMM_ENCODER_LINEAR_SEARCH
CFLAGS=-g -Wall -Werror -O3  -I. -Itest 
6
7
LDFLAGS=-L.
#LDLIBS_TEST=-Tlabcomm.linkscript  -lcunit -llabcomm
8
9
10
11
12
13
14
15
16
17
18
19
20
21
LDLIBS_TEST=-llabcomm -Tlabcomm.linkscript -lrt
LDLIBS_TEST_PLAIN_C=-llabcomm_plain_c -lrt

OBJS_PLAIN_C=labcomm_memory.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 
OBJS=$(OBJS_PLAIN_C) \
Anders Blomdell's avatar
Anders Blomdell committed
22
     labcomm_signature_gnu_ld_tricks.o
Oscar Olsson's avatar
Oscar Olsson committed
23

24
#FIXME: labcomm_mem_reader.o labcomm_mem_writer.o
Anders Blomdell's avatar
Anders Blomdell committed
25
26
LABCOMM_JAR=../../compiler/labComm.jar
LABCOMM=java -jar $(LABCOMM_JAR) 
Oscar Olsson's avatar
Oscar Olsson committed
27

28
TESTS=test_labcomm_basic_type_encoding test_labcomm_generated_encoding \
29
30
      test_labcomm_pthread_scheduler \
      test_signature_plain_c
31
32
#
#FIXME: test_labcomm test_labcomm_errors
Oscar Olsson's avatar
Oscar Olsson committed
33
34
35
36
TEST_DIR=test
TESTDATA_DIR=$(TEST_DIR)/testdata
TEST_GEN_DIR=$(TESTDATA_DIR)/gen

37
38
VPATH=$(TEST_DIR)

Oscar Olsson's avatar
Oscar Olsson committed
39
40
CREATED_DIRS=$(TEST_DIR) $(TESTDATA_DIR) $(TEST_GEN_DIR)

41
# Enable experimental objects by invoking make like `make LABCOMM_EXPERIMENTAL=true`
42
ifeq ($(LABCOMM_EXPERIMENTAL),true)
Oscar Olsson's avatar
Oscar Olsson committed
43
44
45
46
47
48
49
50
51
52
53
	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

54
55
all: liblabcomm.a liblabcomm_plain_c.a \
     liblabcomm.so.1  liblabcomm_plain_c.so.1 
Oscar Olsson's avatar
Oscar Olsson committed
56
57

liblabcomm.a: $(OBJS)
58
59
60
61
	ar -r $@ $^

liblabcomm_plain_c.a: $(OBJS_PLAIN_C)
	ar -r $@ $^
Sven Robertz's avatar
Sven Robertz committed
62

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

66
67
68
liblabcomm_plain_c.so.1: $(OBJS_PLAIN_C:%.o=%.pic.o)
	gcc -shared -Wl,-soname,$@ -o $@ $^ -lc -lrt

Sven Robertz's avatar
Sven Robertz committed
69
70
71
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
72

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

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

77
ethaddr.o: ethaddr.c
Sven Robertz's avatar
Sven Robertz committed
78

Oscar Olsson's avatar
Oscar Olsson committed
79
80
81
$(CREATED_DIRS):
	mkdir -p $@

82
## NB! the tests need CUnit to be installed
83
84
85
86
run-test: $(TESTS:%=run-test-%)

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

88
89
$(TEST_DIR)/%.o: $(TEST_DIR)/%.c
	$(CC) $(CFLAGS) -o $@ -c $<
Oscar Olsson's avatar
Oscar Olsson committed
90

91
.PRECIOUS: $(TEST_DIR)/%
92
$(TEST_DIR)/%: $(TEST_DIR)/%.o liblabcomm.a
93
	$(CC) $(LDFLAGS) -o $@ $^ $(LDLIBS) $(LDLIBS_TEST)
Oscar Olsson's avatar
Oscar Olsson committed
94

95
96
97
98
99
100
101
102
103
104
105
106
107
$(TEST_DIR)/test_signature_plain_c_index.o: \
			labcomm_signature_plain_c.c \
			$(TEST_DIR)/gen/generated_encoding.c \
			$(TEST_DIR)/gen/another_encoding.h \
			$(TEST_DIR)/gen/another_encoding.c
	$(CC) $(CFLAGS) -o $@ -c $< \
		-DALL_LABCOMM_FILES=\"test/test_signature_plain_c.h\"

$(TEST_DIR)/test_signature_plain_c: \
			$(TEST_DIR)/test_signature_plain_c.o \
			$(TEST_DIR)/test_signature_plain_c_index.o 
	$(CC) $(LDFLAGS) -o $@ $^ $(LDLIBS_TEST_PLAIN_C) 

108
109
110
111
$(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
112
	$(LABCOMM) \
113
114
115
116
		--c=$(TEST_DIR)/gen/$*.c \
		--h=$(TEST_DIR)/gen/$*.h \
		$<

117
$(TEST_GEN_DIR)/%.c $(TEST_GEN_DIR)/%.h: $(TESTDATA_DIR)/%.lc \
Anders Blomdell's avatar
Anders Blomdell committed
118
119
					 $(LABCOMM_JAR) | $(TEST_GEN_DIR)
	$(LABCOMM) \
120
		--c=$(patsubst %.h,%.c,$@) --h=$(patsubst %.c,%.h,$@) $<
Oscar Olsson's avatar
Oscar Olsson committed
121

Anders Blomdell's avatar
Anders Blomdell committed
122
$(LABCOMM_JAR):
Oscar Olsson's avatar
Oscar Olsson committed
123
	@echo "======Building LabComm compiler======"
Anders Blomdell's avatar
Anders Blomdell committed
124
	cd $(shell dirname $(LABCOMM_JAR)); ant jar
Oscar Olsson's avatar
Oscar Olsson committed
125
126
	@echo "======End building LabComm compiler======"

127
128
129
%.pic.o:	%.c
	$(CC) -fPIC $(CFLAGS) -c -o $@ $<

Oscar Olsson's avatar
Oscar Olsson committed
130
%.o: %.c %.h
Sven Robertz's avatar
Sven Robertz committed
131

Sven Robertz's avatar
Sven Robertz committed
132
clean:
Oscar Olsson's avatar
Oscar Olsson committed
133
134
135
136
137
	$(RM) *.o
	$(RM) experimental/*.o experimental/ThrottleDrv/*.o
	$(RM) test/*.o
	$(RM) test/*.gch
	$(RM) test/test_labcomm_errors
138
	$(RM) test/testdata/gen/*.[cho]
139
	$(RM) test/gen/*.[cho]
Oscar Olsson's avatar
Oscar Olsson committed
140
	$(RM) $(TEST_DIR)/test_labcomm
Sven Robertz's avatar
Sven Robertz committed
141
142

distclean: clean
143
	$(RM) liblabcomm.so.1
Oscar Olsson's avatar
Oscar Olsson committed
144
	$(RM) liblabcomm.a
145
146
	$(RM) liblabcomm_plain_c.a
	$(RM) liblabcomm_plain_c.so.1
147
148

# Extra dependencies
149
$(TEST_DIR)/test_labcomm_basic_type_encoding.o: labcomm_private.h
150
151
152

$(TEST_DIR)/test_labcomm_generated_encoding.o: labcomm_private.h
$(TEST_DIR)/test_labcomm_generated_encoding.o: $(TEST_DIR)/gen/generated_encoding.h
153
$(TEST_DIR)/test_labcomm_generated_encoding : $(TEST_DIR)/gen/generated_encoding.o
154
$(TEST_DIR)/test_labcomm:  $(TEST_GEN_DIR)/test_sample.o
155
156
$(TEST_DIR)/test_signature_plain_c.o: $(TEST_DIR)/gen/another_encoding.h
$(TEST_DIR)/test_signature_plain_c.o: $(TEST_DIR)/gen/generated_encoding.h
157
158
159
labcomm_fd_reader.o: labcomm_private.h
labcomm_fd_writer.o: labcomm_private.h
labcomm_dynamic_buffer_writer.o: labcomm_private.h