Makefile 4.2 KB
Newer Older
Anders Blomdell's avatar
Anders Blomdell committed
1 2 3 4 5 6
## Macros
VERSION=
LIBVERSION=2014

include ../os_compat.mk

7
ALL_DEPS=../liblabcomm$(LIBVERSION).a ../liblabcomm$(LIBVERSION).so
Anders Blomdell's avatar
Anders Blomdell committed
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25

# TODO: Support for Codesourcery ARM toolchain.

OBJS=labcomm$(VERSION).o \
     labcomm$(VERSION)_memory.o \
     labcomm$(VERSION)_error.o \
     labcomm$(VERSION)_default_error_handler.o \
     labcomm$(VERSION)_default_memory.o \
     labcomm$(VERSION)_default_scheduler.o \
     labcomm$(VERSION)_time.o \
     labcomm$(VERSION)_scheduler.o \
     labcomm$(VERSION)_encoder.o \
     labcomm$(VERSION)_decoder.o \
     labcomm$(VERSION)_dynamic_buffer_writer.o \
     labcomm$(VERSION)_fd_reader.o \
     labcomm$(VERSION)_fd_writer.o \
     labcomm$(VERSION)_pthread_scheduler.o 

Anders Blomdell's avatar
Anders Blomdell committed
26 27 28 29 30 31 32 33 34 35 36
# Enable experimental objects by `make LABCOMM_EXPERIMENTAL=true`
ifeq ($(LABCOMM_EXPERIMENTAL),true)
    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\
	    experimental/labcomm_sig_parser.o 
endif

LABCOMM_JAR=../../../compiler/labcomm$(LIBVERSION)_compiler.jar
Anders Blomdell's avatar
Anders Blomdell committed
37 38
LABCOMM=java -jar $(LABCOMM_JAR) 

Anders Blomdell's avatar
Anders Blomdell committed
39 40
TESTS=test_labcomm_basic_type_encoding \
      test_labcomm_generated_encoding \
Anders Blomdell's avatar
Anders Blomdell committed
41 42 43 44
      test_signature_numbers \
      test_labcomm \
      test_labcomm_pthread_scheduler \
      test_labcomm_copy
Anders Blomdell's avatar
Anders Blomdell committed
45
#FIXME: test_labcomm_errors
Anders Blomdell's avatar
Anders Blomdell committed
46

Anders Blomdell's avatar
Anders Blomdell committed
47
TEST_DIR=test
Anders Blomdell's avatar
Anders Blomdell committed
48 49 50 51


## Targets

Anders Blomdell's avatar
Anders Blomdell committed
52
.PHONY: all 
Anders Blomdell's avatar
Anders Blomdell committed
53 54
all: $(ALL_DEPS)

Anders Blomdell's avatar
Anders Blomdell committed
55
.PHONY: test 
Anders Blomdell's avatar
Anders Blomdell committed
56 57
test: all $(TESTS:%=run-test-%)

Anders Blomdell's avatar
Anders Blomdell committed
58
.PHONY: clean 
Anders Blomdell's avatar
Anders Blomdell committed
59 60 61 62 63 64 65 66 67
clean:
	$(RM) *.o
	$(RM) experimental/*.o 
	$(RM) experimental/ThrottleDrv/*.o
	$(RM) test/*.o
	$(RM) test/*.gch
	$(RM) test/test_labcomm_errors
	$(RM) test/testdata/gen/*.[cho]
	$(RM) test/gen/*.[cho]
Anders Blomdell's avatar
Anders Blomdell committed
68
	$(RM) -rf test/gen
Anders Blomdell's avatar
Anders Blomdell committed
69

Anders Blomdell's avatar
Anders Blomdell committed
70
.PHONY: distclean
Anders Blomdell's avatar
Anders Blomdell committed
71 72 73 74 75
distclean: clean
	$(RM) ../liblabcomm$(LIBVERSION).so.1
	$(RM) ../liblabcomm$(LIBVERSION).a

# rules invoked by 'all'
76 77 78 79
../liblabcomm$(LIBVERSION).so: ../liblabcomm$(LIBVERSION).so.1
	if [ -h $@ ] ; then rm $@ ; fi
	ln -s $(<:../%=%) $@

Anders Blomdell's avatar
Anders Blomdell committed
80
../liblabcomm$(LIBVERSION).so.1: $(OBJS:%.o=%.pic.o)
81
	$(call MAKESHARED,$@,$(@:../%=%),$^)
Anders Blomdell's avatar
Anders Blomdell committed
82

Anders Blomdell's avatar
Anders Blomdell committed
83 84 85
../liblabcomm$(LIBVERSION).a: $(OBJS)
	ar -r $@ $^

Anders Blomdell's avatar
Anders Blomdell committed
86 87 88 89
# Enable experimental objects by `make LABCOMM_EXPERIMENTAL=true`
ifeq ($(LABCOMM_EXPERIMENTAL),true)
experimental/test_sig_parser : experimental/labcomm_sig_parser.o experimental/test_sig_parser.c
endif
Anders Blomdell's avatar
Anders Blomdell committed
90 91 92 93 94 95

# compilation rules 
%.pic.o:	%.c
	$(CC) -fPIC $(CFLAGS) -c -o $@ $<

%.o: %.c %.h
Anders Blomdell's avatar
Anders Blomdell committed
96
	$(CC) $(CFLAGS) -c -o $@ $<
Anders Blomdell's avatar
Anders Blomdell committed
97 98

# rules invoked by 'test'
Anders Blomdell's avatar
Anders Blomdell committed
99 100
.PHONY: run-test-%
run-test-%: $(TEST_DIR)/gen/% | $(TEST_DIR)/gen
Anders Blomdell's avatar
Anders Blomdell committed
101 102
	$<

Anders Blomdell's avatar
Anders Blomdell committed
103
.PRECIOUS: $(TEST_DIR)/gen/%
Anders Blomdell's avatar
Anders Blomdell committed
104

Anders Blomdell's avatar
Anders Blomdell committed
105 106
$(TEST_DIR)/gen/%: $(TEST_DIR)/gen/%.o | $(TEST_DIR)/gen
	$(LD) $(LDFLAGS) -o $@ $^ $(LDLIBS) 
Anders Blomdell's avatar
Anders Blomdell committed
107

Anders Blomdell's avatar
Anders Blomdell committed
108 109
$(TEST_DIR)/gen/%.o: $(TEST_DIR)/%.c | $(TEST_DIR)/gen
	$(CC) $(CFLAGS_TEST) -o $@ -c $<
Anders Blomdell's avatar
Anders Blomdell committed
110

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

$(LABCOMM_JAR):
	@echo "======Building LabComm compiler======"
	cd $(shell dirname $(LABCOMM_JAR)); ant jar
	@echo "======End building LabComm compiler======"

Anders Blomdell's avatar
Anders Blomdell committed
124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154
$(TEST_DIR)/gen:
	mkdir -p $@

# Extra compilation dependencies
labcomm$(VERSION).o: \
	labcomm$(VERSION).c \
	labcomm$(VERSION).h \
	labcomm$(VERSION)_private.h

labcomm$(VERSION)_fd_reader.o: \
	labcomm$(VERSION)_private.h

labcomm$(VERSION)_fd_writer.o: \
	labcomm$(VERSION)_private.h

labcomm$(VERSION)_dynamic_buffer_writer.o: \
	labcomm$(VERSION)_private.h

$(TEST_DIR)/gen/test_labcomm_basic_type_encoding.o: \
	labcomm$(VERSION)_private.h

$(TEST_DIR)/gen/test_labcomm_generated_encoding.o: \
	labcomm$(VERSION)_private.h \
	$(TEST_DIR)/gen/generated_encoding.h

$(TEST_DIR)/gen/test_labcomm_generated_encoding: \
	$(TEST_DIR)/gen/generated_encoding.o

$(TEST_DIR)/gen/test_signature_numbers.c: \
	$(TEST_DIR)/gen/another_encoding.h \
	$(TEST_DIR)/gen/generated_encoding.h				
Anders Blomdell's avatar
Anders Blomdell committed
155

Anders Blomdell's avatar
Anders Blomdell committed
156 157 158
$(TEST_DIR)/gen/test_signature_numbers: \
	$(TEST_DIR)/gen/another_encoding.o \
	$(TEST_DIR)/gen/generated_encoding.o
Anders Blomdell's avatar
Anders Blomdell committed
159

Anders Blomdell's avatar
Anders Blomdell committed
160 161
$(TEST_DIR)/gen/test_labcomm:  \
	$(TEST_DIR)/gen/test_sample.o
Anders Blomdell's avatar
Anders Blomdell committed
162

Anders Blomdell's avatar
Anders Blomdell committed
163 164 165 166
$(TEST_DIR)/gen/test_labcomm_copy: \
	$(TEST_DIR)/gen/generated_encoding.o \
	$(TEST_DIR)/gen/test_sample.o \
	$(TEST_DIR)/gen/more_types.o