Commit 86bab810 authored by Anders Blomdell's avatar Anders Blomdell
Browse files

More C cleanups

parent 9056ba1e
...@@ -23,7 +23,7 @@ OBJS=labcomm$(VERSION).o \ ...@@ -23,7 +23,7 @@ OBJS=labcomm$(VERSION).o \
labcomm$(VERSION)_fd_writer.o \ labcomm$(VERSION)_fd_writer.o \
labcomm$(VERSION)_pthread_scheduler.o labcomm$(VERSION)_pthread_scheduler.o
LABCOMM_JAR=../../../compiler/labcomm$(VERSION)_compiler.jar LABCOMM_JAR=../../../compiler/labcomm$(LIBVERSION)_compiler.jar
LABCOMM=java -jar $(LABCOMM_JAR) LABCOMM=java -jar $(LABCOMM_JAR)
TESTS=test_labcomm_basic_type_encoding \ TESTS=test_labcomm_basic_type_encoding \
...@@ -36,8 +36,6 @@ TESTS=test_labcomm_basic_type_encoding \ ...@@ -36,8 +36,6 @@ TESTS=test_labcomm_basic_type_encoding \
TEST_DIR=test TEST_DIR=test
#VPATH=$(TEST_DIR)
## Targets ## Targets
.PHONY: all .PHONY: all
...@@ -57,9 +55,6 @@ clean: ...@@ -57,9 +55,6 @@ clean:
$(RM) test/testdata/gen/*.[cho] $(RM) test/testdata/gen/*.[cho]
$(RM) test/gen/*.[cho] $(RM) test/gen/*.[cho]
$(RM) -rf test/gen $(RM) -rf test/gen
for x in $(TESTS); do \
$(RM) $(TEST_DIR)/$$x ; \
done
.PHONY: distclean .PHONY: distclean
distclean: clean distclean: clean
...@@ -80,35 +75,46 @@ distclean: clean ...@@ -80,35 +75,46 @@ distclean: clean
%.o: %.c %.h %.o: %.c %.h
$(CC) $(CFLAGS) -c -o $@ $< $(CC) $(CFLAGS) -c -o $@ $<
# rules invoked by 'test' # rules invoked by 'test'
.PHONY: run-test-% .PHONY: run-test-%
run-test-%: $(TEST_DIR)/gen/% | $(TEST_DIR)/gen run-test-%: $(TEST_DIR)/gen/% | $(TEST_DIR)/gen
$< $<
.PRECIOUS: $(TEST_DIR)/gen/%
$(TEST_DIR)/gen/%: $(TEST_DIR)/gen/%.o | $(TEST_DIR)/gen $(TEST_DIR)/gen/%: $(TEST_DIR)/gen/%.o | $(TEST_DIR)/gen
$(LD) $(LDFLAGS) -o $@ $^ $(LDLIBS) $(LD) $(LDFLAGS) -o $@ $^ $(LDLIBS)
$(TEST_DIR)/gen/%.o: $(TEST_DIR)/%.c | $(TEST_DIR)/gen $(TEST_DIR)/gen/%.o: $(TEST_DIR)/%.c | $(TEST_DIR)/gen
$(CC) $(CFLAGS_TEST) -o $@ -c $< $(CC) $(CFLAGS_TEST) -o $@ -c $<
# Extra compilation dependencies $(TEST_DIR)/gen/%.c $(TEST_DIR)/gen/%.h: $(TEST_DIR)/%.lc | $(TEST_DIR)/gen
labcomm_fd_reader.o: \ $(LABCOMM) \
labcomm_private.h --c=$(TEST_DIR)/gen/$*.c \
labcomm_fd_writer.o: \ --h=$(TEST_DIR)/gen/$*.h \
labcomm_private.h $<
labcomm_dynamic_buffer_writer.o: \
labcomm_private.h
$(LABCOMM_JAR):
@echo "======Building LabComm compiler======"
cd $(shell dirname $(LABCOMM_JAR)); ant jar
@echo "======End building LabComm compiler======"
$(TEST_DIR)/gen:
mkdir -p $@
# Extra compilation dependencies
labcomm$(VERSION).o: \ labcomm$(VERSION).o: \
labcomm$(VERSION).c \ labcomm$(VERSION).c \
labcomm$(VERSION).h \ labcomm$(VERSION).h \
labcomm$(VERSION)_private.h labcomm$(VERSION)_private.h
labcomm$(VERSION)_fd_reader_writer.o: \ labcomm$(VERSION)_fd_reader.o: \
labcomm$(VERSION)_fd_reader_writer.c \ labcomm$(VERSION)_private.h
labcomm$(VERSION)_fd_reader_writer.h \
labcomm$(VERSION).h \ labcomm$(VERSION)_fd_writer.o: \
labcomm$(VERSION)_private.h
labcomm$(VERSION)_dynamic_buffer_writer.o: \
labcomm$(VERSION)_private.h labcomm$(VERSION)_private.h
$(TEST_DIR)/gen/test_labcomm_basic_type_encoding.o: \ $(TEST_DIR)/gen/test_labcomm_basic_type_encoding.o: \
...@@ -136,34 +142,3 @@ $(TEST_DIR)/gen/test_labcomm_copy: \ ...@@ -136,34 +142,3 @@ $(TEST_DIR)/gen/test_labcomm_copy: \
$(TEST_DIR)/gen/generated_encoding.o \ $(TEST_DIR)/gen/generated_encoding.o \
$(TEST_DIR)/gen/test_sample.o \ $(TEST_DIR)/gen/test_sample.o \
$(TEST_DIR)/gen/more_types.o $(TEST_DIR)/gen/more_types.o
#$(TEST_DIR)/labcomm_mem_reader.o: labcomm_fd_reader_writer.c labcomm_fd_reader_writer.h
#$(TEST_DIR)/labcomm_mem_writer.o: labcomm_mem_writer.c labcomm_mem_writer.h cppmacros.h
ethaddr.o: ethaddr.c
.PRECIOUS: $(TEST_DIR)/%
$(TEST_DIR)/gen:
mkdir -p $@
.PRECIOUS: $(TEST_DIR)/gen/%.c
.PRECIOUS: $(TEST_DIR)/gen/%.h
$(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 \
$<
$(TEST_GEN_DIR)/%.c $(TEST_GEN_DIR)/%.h: $(TESTDATA_DIR)/%.lc \
$(LABCOMM_JAR) | $(TEST_GEN_DIR)
$(LABCOMM) \
--c=$(patsubst %.h,%.c,$@) --h=$(patsubst %.c,%.h,$@) $<
$(LABCOMM_JAR):
@echo "======Building LabComm compiler======"
cd $(shell dirname $(LABCOMM_JAR)); ant jar
@echo "======End building LabComm compiler======"
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
#ifdef __INT64_MAX__ #ifdef __INT64_MAX__
#undef INT64_MAX #undef INT64_MAX
#define INT64_MAX __INT64_MAX__ #define INT64_MAX __INT64_MAX__
#endif
#if (CPU == PPC603) #if (CPU == PPC603)
#undef _LITTLE_ENDIAN #undef _LITTLE_ENDIAN
......
...@@ -23,42 +23,39 @@ OBJS=labcomm$(VERSION).o \ ...@@ -23,42 +23,39 @@ OBJS=labcomm$(VERSION).o \
labcomm$(VERSION)_fd_writer.o \ labcomm$(VERSION)_fd_writer.o \
labcomm$(VERSION)_pthread_scheduler.o labcomm$(VERSION)_pthread_scheduler.o
#FIXME: labcomm_mem_reader.o labcomm_mem_writer.o # Enable experimental objects by `make LABCOMM_EXPERIMENTAL=true`
LABCOMM_JAR=../../../compiler/labcomm_compiler.jar 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
LABCOMM=java -jar $(LABCOMM_JAR) LABCOMM=java -jar $(LABCOMM_JAR)
TESTS=test_labcomm_basic_type_encoding test_labcomm_generated_encoding \ TESTS=test_labcomm_basic_type_encoding \
test_labcomm_generated_encoding \
test_signature_numbers \ test_signature_numbers \
test_labcomm \ test_labcomm \
test_labcomm_pthread_scheduler \ test_labcomm_pthread_scheduler \
test_labcomm_copy test_labcomm_copy
# #FIXME: test_labcomm_errors
#FIXME: test_labcomm test_labcomm_errors
TEST_DIR=test
VPATH=$(TEST_DIR) TEST_DIR=test
# Enable experimental objects by invoking make like `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
experimental/test_sig_parser : experimental/labcomm_sig_parser.o experimental/test_sig_parser.c
endif
## Targets ## Targets
.PHONY: all run-test clean distclean .PHONY: all
all: $(ALL_DEPS) all: $(ALL_DEPS)
.PHONY: test
test: all $(TESTS:%=run-test-%) test: all $(TESTS:%=run-test-%)
.PHONY: clean
clean: clean:
$(RM) *.o $(RM) *.o
$(RM) experimental/*.o $(RM) experimental/*.o
...@@ -68,102 +65,96 @@ clean: ...@@ -68,102 +65,96 @@ clean:
$(RM) test/test_labcomm_errors $(RM) test/test_labcomm_errors
$(RM) test/testdata/gen/*.[cho] $(RM) test/testdata/gen/*.[cho]
$(RM) test/gen/*.[cho] $(RM) test/gen/*.[cho]
-rmdir test/gen $(RM) -rf test/gen
for x in $(TESTS); do \
$(RM) $(TEST_DIR)/$$x ; \
done
.PHONY: distclean
distclean: clean distclean: clean
$(RM) ../liblabcomm$(LIBVERSION).so.1 $(RM) ../liblabcomm$(LIBVERSION).so.1
$(RM) ../liblabcomm$(LIBVERSION).a $(RM) ../liblabcomm$(LIBVERSION).a
# rules invoked by 'all' # rules invoked by 'all'
../liblabcomm$(LIBVERSION).so.1: $(OBJS:%.o=%.pic.o)
$(call MAKESHARED,$@,$@,$^)
../liblabcomm$(LIBVERSION).a: $(OBJS) ../liblabcomm$(LIBVERSION).a: $(OBJS)
ar -r $@ $^ ar -r $@ $^
../liblabcomm$(LIBVERSION).so.1: $(OBJS:%.o=%.pic.o) # Enable experimental objects by `make LABCOMM_EXPERIMENTAL=true`
$(call MAKESHARED,$@,$@,$^) ifeq ($(LABCOMM_EXPERIMENTAL),true)
experimental/test_sig_parser : experimental/labcomm_sig_parser.o experimental/test_sig_parser.c
endif
# compilation rules # compilation rules
%.pic.o: %.c %.pic.o: %.c
$(CC) -fPIC $(CFLAGS) -c -o $@ $< $(CC) -fPIC $(CFLAGS) -c -o $@ $<
%.o: %.c %.h %.o: %.c %.h
$(CC) $(CFLAGS) -c -o $@ $<
# rules invoked by 'test' # rules invoked by 'test'
.PHONY: run-test-%
# Extra compilation dependencies run-test-%: $(TEST_DIR)/gen/% | $(TEST_DIR)/gen
labcomm$(VERSION).o: \
labcomm$(VERSION).c \
labcomm$(VERSION).h \
labcomm$(VERSION)_private.h
labcomm$(VERSION)_fd_reader_writer.o: \
labcomm$(VERSION)_fd_reader_writer.c \
labcomm$(VERSION)_fd_reader_writer.h \
labcomm$(VERSION).h \
labcomm$(VERSION)_private.h
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
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
#$(TEST_DIR)/labcomm_mem_reader.o: labcomm_fd_reader_writer.c labcomm_fd_reader_writer.h
#$(TEST_DIR)/labcomm_mem_writer.o: labcomm_mem_writer.c labcomm_mem_writer.h cppmacros.h
ethaddr.o: ethaddr.c
run-test-%: $(TEST_DIR)/% | $(TEST_DIR)
$< $<
$(TEST_DIR)/%.o: $(TEST_DIR)/%.c .PRECIOUS: $(TEST_DIR)/gen/%
$(CC) $(CFLAGS) -o $@ -c $<
.PRECIOUS: $(TEST_DIR)/% $(TEST_DIR)/gen/%: $(TEST_DIR)/gen/%.o | $(TEST_DIR)/gen
$(TEST_DIR)/%: $(TEST_DIR)/%.o $(LD) $(LDFLAGS) -o $@ $^ $(LDLIBS)
$(CC) $(LDFLAGS) -o $@ $^ $(LDLIBS)
$(TEST_DIR)/gen: $(TEST_DIR)/gen/%.o: $(TEST_DIR)/%.c | $(TEST_DIR)/gen
mkdir -p $@ $(CC) $(CFLAGS_TEST) -o $@ -c $<
.PRECIOUS: $(TEST_DIR)/gen/%.c
.PRECIOUS: $(TEST_DIR)/gen/%.h
$(TEST_DIR)/gen/%.c $(TEST_DIR)/gen/%.h: $(TEST_DIR)/%.lc | $(TEST_DIR)/gen $(TEST_DIR)/gen/%.c $(TEST_DIR)/gen/%.h: $(TEST_DIR)/%.lc | $(TEST_DIR)/gen
$(LABCOMM) \ $(LABCOMM) \
--c=$(TEST_DIR)/gen/$*.c \ --c=$(TEST_DIR)/gen/$*.c \
--h=$(TEST_DIR)/gen/$*.h \ --h=$(TEST_DIR)/gen/$*.h \
$< $<
$(TEST_GEN_DIR)/%.c $(TEST_GEN_DIR)/%.h: $(TESTDATA_DIR)/%.lc \
$(LABCOMM_JAR) | $(TEST_GEN_DIR)
$(LABCOMM) \
--c=$(patsubst %.h,%.c,$@) --h=$(patsubst %.c,%.h,$@) $<
$(LABCOMM_JAR): $(LABCOMM_JAR):
@echo "======Building LabComm compiler======" @echo "======Building LabComm compiler======"
cd $(shell dirname $(LABCOMM_JAR)); ant jar cd $(shell dirname $(LABCOMM_JAR)); ant jar
@echo "======End building LabComm compiler======" @echo "======End building LabComm compiler======"
$(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
# Extra dependencies $(TEST_DIR)/gen/test_signature_numbers: \
$(TEST_DIR)/test_labcomm_basic_type_encoding.o: labcomm_private.h $(TEST_DIR)/gen/another_encoding.o \
$(TEST_DIR)/gen/generated_encoding.o
$(TEST_DIR)/test_labcomm_generated_encoding.o: labcomm_private.h $(TEST_DIR)/gen/test_labcomm: \
$(TEST_DIR)/test_labcomm_generated_encoding.o: $(TEST_DIR)/gen/generated_encoding.h $(TEST_DIR)/gen/test_sample.o
$(TEST_DIR)/test_labcomm_generated_encoding : $(TEST_DIR)/gen/generated_encoding.o
$(TEST_DIR)/test_labcomm: $(TEST_DIR)/gen/test_sample.o $(TEST_DIR)/gen/test_labcomm_copy: \
$(TEST_DIR)/test_signature_numbers.c: $(TEST_DIR)/gen/another_encoding.h $(TEST_DIR)/gen/generated_encoding.o \
$(TEST_DIR)/test_signature_numbers.c: $(TEST_DIR)/gen/generated_encoding.h $(TEST_DIR)/gen/test_sample.o \
$(TEST_DIR)/test_signature_numbers: $(TEST_DIR)/gen/another_encoding.o $(TEST_DIR)/gen/more_types.o
$(TEST_DIR)/test_signature_numbers: $(TEST_DIR)/gen/generated_encoding.o
$(TEST_DIR)/test_labcomm_copy: $(TEST_DIR)/gen/generated_encoding.o $(TEST_DIR)/gen/test_sample.o $(TEST_DIR)/gen/more_types.o
labcomm_fd_reader.o: labcomm_private.h
labcomm_fd_writer.o: labcomm_private.h
labcomm_dynamic_buffer_writer.o: labcomm_private.h
...@@ -186,6 +186,8 @@ int main(void) ...@@ -186,6 +186,8 @@ int main(void)
labcomm_default_error_handler, labcomm_default_error_handler,
labcomm_default_memory, labcomm_default_memory,
labcomm_pthread_scheduler_new(labcomm_default_memory)); labcomm_pthread_scheduler_new(labcomm_default_memory));
EXPECT({ 0x01, 0x0c, 0x0b,
'L', 'a', 'b', 'C', 'o', 'm', 'm', '2','0', '1', '4' });
labcomm_encoder_ioctl(encoder, IOCTL_WRITER_RESET); labcomm_encoder_ioctl(encoder, IOCTL_WRITER_RESET);
/* Register twice to make sure that only one registration gets encoded */ /* Register twice to make sure that only one registration gets encoded */
......
...@@ -48,8 +48,12 @@ if __name__ == '__main__': ...@@ -48,8 +48,12 @@ if __name__ == '__main__':
print "Only in %s:" %sys.argv[4], b.path print "Only in %s:" %sys.argv[4], b.path
b = B.next() b = B.next()
else: else:
print a.path, b.path equal = True
print ''.join(difflib.unified_diff(a.lines, b.lines, for l in difflib.unified_diff(a.lines, b.lines, a.path, b.path):
a.path, b.path)) print l,
equal = False
if equal:
print "Identical", a.path, b.path
a = A.next() a = A.next()
b = B.next() b = B.next()
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment