Skip to content

Commit

Permalink
Reorganize sources, fix amalgamation and tests
Browse files Browse the repository at this point in the history
No substantive changes
  • Loading branch information
rojer committed May 29, 2021
1 parent 4c870e5 commit ae2e6c6
Show file tree
Hide file tree
Showing 226 changed files with 568 additions and 589 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
build/
60 changes: 29 additions & 31 deletions mjs/Makefile → Makefile
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
REPO_ROOT = ..
SRCPATH = src
VPATH = $(REPO_ROOT)/common $(REPO_ROOT)/frozen src
BUILD_DIR = build

R ?= $(abspath $(REPO_ROOT))
RD ?= docker run -v $(R):$(R) -w $(CURDIR)
DOCKER_GCC ?= $(RD) docker.cesanta.com/gcc
DOCKER_CLANG ?= $(RD) docker.cesanta.com/clang
RD ?= docker run -v $(CURDIR):$(CURDIR) --user=$(shell id -u):$(shell id -g) -w $(CURDIR)
DOCKER_GCC ?= $(RD) mgos/gcc
DOCKER_CLANG ?= $(RD) mgos/clang

include $(SRCPATH)/mjs_sources.mk

Expand All @@ -15,7 +12,7 @@ TOP_HEADERS = $(addprefix $(SRCPATH)/, $(HEADERS))
TOP_SOURCES_DIRS = $(sort $(dir $(TOP_SOURCES)))
TOP_HEADERS_DIRS = $(sort $(dir $(TOP_HEADERS)))

MFLAGS += -I. -I$(REPO_ROOT) -Isrc
MFLAGS += -I. -Isrc
MFLAGS += -DMJS_MAIN -DMJS_EXPOSE_PRIVATE -DCS_ENABLE_STDIO -DMJS_ENABLE_DEBUG -I../frozen
MFLAGS += $(CFLAGS_EXTRA)
CFLAGS += -lm -std=c99 -Wall -Wextra -pedantic -g $(MFLAGS)
Expand Down Expand Up @@ -50,24 +47,25 @@ PROG = $(BUILD_DIR)/mjs

all: $(PROG)

TESTUTIL_FILES = $(REPO_ROOT)/common/cs_dirent.c \
$(REPO_ROOT)/common/cs_time.c \
$(REPO_ROOT)/common/test_main.c \
$(REPO_ROOT)/common/test_util.c
TESTUTIL_FILES = $(SRCPATH)/common/cs_dirent.c \
$(SRCPATH)/common/cs_time.c \
$(SRCPATH)/common/test_main.c \
$(SRCPATH)/common/test_util.c

mjs.c: $(TOP_SOURCES) mjs.h Makefile
@printf "AMALGAMATING\tmjs.c\n"
$(Q) (cd .. && tools/amalgam.py \
--autoinc --exportable-headers -I frozen -I mjs --prefix MJS \
--public-header mjs.h --ignore mjs/mjs.h \
--first mjs/src/license.h,mjs/src/internal.h,common/platform.h,common/platforms/platform_windows.h,common/platforms/platform_unix.h,common/platforms/platform_esp_lwip.h $(TOP_SOURCES)) > $@

mjs.h: $(TOP_HEADERS) $(TOP_SOURCES) Makefile
@printf "AMALGAMATING\tmjs.h\n"
$(Q) (cd .. && tools/amalgam.py \
--autoinc --exportable-headers -I frozen -I mjs --prefix MJS \
--ignore mjs/mjs.h \
--first mjs/src/license.h,common/platform.h $(filter %_public.h,$(TOP_HEADERS))) > $@
@printf "AMALGAMATING mjs.c\n"
$(Q) (tools/amalgam.py \
--autoinc --exportable-headers -I src -I src/frozen --prefix MJS \
--public-header mjs.h --ignore mjs.h \
--first common/platform.h,common/platforms/platform_windows.h,common/platforms/platform_unix.h,common/platforms/platform_esp_lwip.h \
$(TOP_SOURCES)) > $@

mjs.h: $(TOP_HEADERS) $(TOP_SOURCES) Makefile tools/amalgam.py
@printf "AMALGAMATING mjs.h\n"
$(Q) (tools/amalgam.py \
--autoinc --exportable-headers -I src --prefix MJS --strict \
--ignore mjs.h \
--first common/platform.h $(filter %_public.h,$(TOP_HEADERS))) > $@

CFLAGS += $(COMMON_CFLAGS)

Expand All @@ -82,9 +80,9 @@ $(BUILD_DIR):
$(BUILD_DIR)/%.o: %.c $(TOP_HEADERS)
$(CLANG) $(CFLAGS) $(CPPFLAGS) -c -o $@ $<

COMMON_TEST_FLAGS = -W -Wall -I. -I$(REPO_ROOT) -g3 -O0 $(COMMON_CFLAGS) $< $(TESTUTIL_FILES) -DMJS_MEMORY_STATS
COMMON_TEST_FLAGS = -W -Wall -I. -Isrc -g3 -O0 $(COMMON_CFLAGS) $< $(TESTUTIL_FILES) -DMJS_MEMORY_STATS

include $(REPO_ROOT)/common.mk
#include $(REPO_ROOT)/common.mk

# ==== Test Variants ====
#
Expand Down Expand Up @@ -153,9 +151,9 @@ endef
# 2: binary name component, like "O0" or whatever
# 3: additional compiler flags
define compile_test_with_opt
$(eval $(call compile_test_with_compiler,docker.cesanta.com/clang,/usr/bin/clang-3.6,clang_$2,$(ASAN_CFLAGS) $1 $3))
$(eval $(call compile_test_with_compiler,docker.cesanta.com/clang,/usr/bin/clang-3.6,clang_32bit_$2,-m32 $1 $3))
$(eval $(call compile_test_with_compiler,docker.cesanta.com/gcc,/usr/bin/gcc,gcc_$2,$1 $3))
$(eval $(call compile_test_with_compiler,mgos/clang,/usr/bin/clang-3.6,clang_$2,$(ASAN_CFLAGS) $1 $3))
$(eval $(call compile_test_with_compiler,mgos/clang,/usr/bin/clang-3.6,clang_32bit_$2,-m32 $1 $3))
$(eval $(call compile_test_with_compiler,mgos/gcc,/usr/bin/gcc,gcc_$2,$1 $3))
endef

# params:
Expand Down Expand Up @@ -218,11 +216,11 @@ difftest:
ci-test: $(BUILD_DIR) vc98 vc2017 test_full

$(PROG).exe: $(BUILD_DIR) $(TOP_HEADERS) mjs.c
$(RD) docker.cesanta.com/vc98 wine cl mjs.c $(CLFLAGS) $(MFLAGS) /Fe$@
$(RD) mgos/vc98 wine cl mjs.c $(CLFLAGS) $(MFLAGS) /Fe$@

TEST_SOURCES = tests/unit_test.c $(TESTUTIL_FILES)
CLFLAGS = /DWIN32_LEAN_AND_MEAN /MD /O1 /TC /W2 /WX /I.. /I. /DNDEBUG /DMJS_MEMORY_STATS
vc98 vc2017: mjs.c mjs.h
$(RD) docker.cesanta.com/$@ wine cl $(TEST_SOURCES) $(CLFLAGS) /Fe$@.exe
$(RD) docker.cesanta.com/$@ wine ./$@.exe
$(RD) mgos/$@ wine cl $(TEST_SOURCES) $(CLFLAGS) /Fe$@.exe
$(RD) mgos/$@ wine ./$@.exe

42 changes: 0 additions & 42 deletions common.mk

This file was deleted.

File renamed without changes.
File renamed without changes.
File renamed without changes.
Loading

0 comments on commit ae2e6c6

Please sign in to comment.