Makefile 5.02 KB
Newer Older
Oscar Olsson's avatar
Oscar Olsson committed
1
## Macros
2
include os_compat.mk
3

4
ALL_DEPS=liblabcomm.a liblabcomm.so.1 liblabcomm2006.a liblabcomm2006.so.1  liblabcomm2014.a liblabcomm2014.so.1
5

6
# TODO: Support for Codesourcery ARM toolchain.
7

Sven Gestegård Robertz's avatar
Sven Gestegård Robertz committed
8
9
10
11
12
OBJS2006=2006/labcomm2006_memory.o \
     2006/labcomm2006_error.o \
     2006/labcomm2006_default_error_handler.o \
     2006/labcomm2006_default_memory.o \
     2006/labcomm2006_default_scheduler.o \
13
14
     2006/labcomm2006_time.o 2006/labcomm2006_scheduler.o \
     2006/labcomm2006_encoder.o 2006/labcomm2006_decoder.o \
Sven Gestegård Robertz's avatar
Sven Gestegård Robertz committed
15
16
     2006/labcomm2006.o \
     2006/labcomm2006_dynamic_buffer_writer.o \
17
     2006/labcomm2006_fd_reader.o 2006/labcomm2006_fd_writer.o \
Sven Gestegård Robertz's avatar
Sven Gestegård Robertz committed
18
19
     2006/labcomm2006_pthread_scheduler.o 

20
21
22
23
24
25
26
27
28
29
30
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
31

32
#FIXME: labcomm_mem_reader.o labcomm_mem_writer.o
33
LABCOMM_JAR=../../compiler/labcomm_compiler.jar
Anders Blomdell's avatar
Anders Blomdell committed
34
LABCOMM=java -jar $(LABCOMM_JAR) 
Oscar Olsson's avatar
Oscar Olsson committed
35

36
TESTS=test_labcomm_basic_type_encoding test_labcomm_generated_encoding \
37
38
      test_signature_numbers \
      test_labcomm \
39
      test_labcomm_pthread_scheduler \
Tommy Olofsson's avatar
Tommy Olofsson committed
40
      test_labcomm_copy
41
42
#
#FIXME: test_labcomm test_labcomm_errors
Oscar Olsson's avatar
Oscar Olsson committed
43
44
TEST_DIR=test

45
46
47
VPATH=$(TEST_DIR)

# Enable experimental objects by invoking make like `make LABCOMM_EXPERIMENTAL=true`
48
ifeq ($(LABCOMM_EXPERIMENTAL),true)
Oscar Olsson's avatar
Oscar Olsson committed
49
50
51
52
53
54
55
56
57
58
59
	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

60
all: $(ALL_DEPS)
Sven Gestegård Robertz's avatar
Sven Gestegård Robertz committed
61
62
63
64
65
66

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

liblabcomm.so.1: $(OBJS:%.o=%.pic.o) $(OBJS2006:%.o=%.pic.o)
	$(call MAKESHARED,$@,$@,$^)
Oscar Olsson's avatar
Oscar Olsson committed
67

68
liblabcomm2014.a: $(OBJS)
69
70
	ar -r $@ $^

71
liblabcomm2014.so.1: $(OBJS:%.o=%.pic.o)
Sven Gestegård Robertz's avatar
Sven Gestegård Robertz committed
72
73
74
75
76
77
	$(call MAKESHARED,$@,$@,$^)

liblabcomm2006.a: $(OBJS2006)
	ar -r $@ $^

liblabcomm2006.so.1: $(OBJS2006:%.o=%.pic.o)
Anders Blomdell's avatar
Anders Blomdell committed
78
	$(call MAKESHARED,$@,$@,$^)
Oscar Olsson's avatar
Oscar Olsson committed
79

Sven Robertz's avatar
Sven Robertz committed
80
81
82
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
83

Sven Gestegård Robertz's avatar
Sven Gestegård Robertz committed
84
85
86
87
2006/labcomm2006.o : 2006/labcomm2006.c 2006/labcomm2006.h  2006/labcomm2006_private.h

2006/labcomm2006_fd_reader_writer.o : 2006/labcomm2006_fd_reader_writer.c  2006/labcomm2006_fd_reader_writer.h  labcomm.h  2006/labcomm2006_private.h

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

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

92
ethaddr.o: ethaddr.c
Sven Robertz's avatar
Sven Robertz committed
93

94
95
96
97
run-test: $(TESTS:%=run-test-%)

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

99
100
$(TEST_DIR)/%.o: $(TEST_DIR)/%.c
	$(CC) $(CFLAGS) -o $@ -c $<
Oscar Olsson's avatar
Oscar Olsson committed
101

102
.PRECIOUS: $(TEST_DIR)/%
103
$(TEST_DIR)/%: $(TEST_DIR)/%.o 
Anders Blomdell's avatar
Anders Blomdell committed
104
	$(CC) $(LDFLAGS) -o $@ $^ $(LDLIBS) 
Oscar Olsson's avatar
Oscar Olsson committed
105

106
107
108
$(TEST_DIR)/gen:
	mkdir -p $@

109
110
.PRECIOUS: $(TEST_DIR)/gen/%.c
.PRECIOUS: $(TEST_DIR)/gen/%.h
111
$(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
	$(RM) *.o
134
	$(RM) 2006/*.o
Oscar Olsson's avatar
Oscar Olsson committed
135
136
137
138
	$(RM) experimental/*.o experimental/ThrottleDrv/*.o
	$(RM) test/*.o
	$(RM) test/*.gch
	$(RM) test/test_labcomm_errors
139
	$(RM) test/testdata/gen/*.[cho]
140
	$(RM) test/gen/*.[cho]
141
	-rmdir test/gen
142
143
144
	for x in $(TESTS); do \
		$(RM) $(TEST_DIR)/$$x ; \
	done
Sven Robertz's avatar
Sven Robertz committed
145
146

distclean: clean
147
	$(RM) liblabcomm.so.1
Oscar Olsson's avatar
Oscar Olsson committed
148
	$(RM) liblabcomm.a
Sven Gestegård Robertz's avatar
Sven Gestegård Robertz committed
149
150
	$(RM) liblabcomm2006.so.1
	$(RM) liblabcomm2006.a
151
152
	$(RM) liblabcomm2014.so.1
	$(RM) liblabcomm2014.a
153
154

# Extra dependencies
155
$(TEST_DIR)/test_labcomm_basic_type_encoding.o: labcomm_private.h
156
157
158

$(TEST_DIR)/test_labcomm_generated_encoding.o: labcomm_private.h
$(TEST_DIR)/test_labcomm_generated_encoding.o: $(TEST_DIR)/gen/generated_encoding.h
159
$(TEST_DIR)/test_labcomm_generated_encoding : $(TEST_DIR)/gen/generated_encoding.o
160

161
$(TEST_DIR)/test_labcomm:  $(TEST_DIR)/gen/test_sample.o
162
163
164
165
$(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
166
$(TEST_DIR)/test_labcomm_copy:  $(TEST_DIR)/gen/generated_encoding.o $(TEST_DIR)/gen/test_sample.o $(TEST_DIR)/gen/more_types.o
167
168
169
labcomm_fd_reader.o: labcomm_private.h
labcomm_fd_writer.o: labcomm_private.h
labcomm_dynamic_buffer_writer.o: labcomm_private.h