Makefile 5.06 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
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 \
30
     labcomm_bytearray_reader.o \
31
     labcomm_pthread_scheduler.o 
Oscar Olsson's avatar
Oscar Olsson committed
32

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

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

46 47 48
VPATH=$(TEST_DIR)

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

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

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
68

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

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

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

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

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

Sven Gestegård Robertz's avatar
Sven Gestegård Robertz committed
85 86 87 88
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

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

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

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

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

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

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

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

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

110 111
.PRECIOUS: $(TEST_DIR)/gen/%.c
.PRECIOUS: $(TEST_DIR)/gen/%.h
112
$(TEST_DIR)/gen/%.c $(TEST_DIR)/gen/%.h: $(TEST_DIR)/%.lc | $(TEST_DIR)/gen
Anders Blomdell's avatar
Anders Blomdell committed
113
	$(LABCOMM) \
114 115 116 117
		--c=$(TEST_DIR)/gen/$*.c \
		--h=$(TEST_DIR)/gen/$*.h \
		$<

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

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

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

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

Sven Robertz's avatar
Sven Robertz committed
133
clean:
Oscar Olsson's avatar
Oscar Olsson committed
134
	$(RM) *.o
135
	$(RM) 2006/*.o
Oscar Olsson's avatar
Oscar Olsson committed
136 137 138 139
	$(RM) experimental/*.o experimental/ThrottleDrv/*.o
	$(RM) test/*.o
	$(RM) test/*.gch
	$(RM) test/test_labcomm_errors
140
	$(RM) test/testdata/gen/*.[cho]
141
	$(RM) test/gen/*.[cho]
142
	-rmdir test/gen
143 144 145
	for x in $(TESTS); do \
		$(RM) $(TEST_DIR)/$$x ; \
	done
Sven Robertz's avatar
Sven Robertz committed
146 147

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

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

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

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