From 1e94f53c6c71eb457c2112227b889a5e831f2aa2 Mon Sep 17 00:00:00 2001 From: Sebastien Merle Date: Mon, 5 Feb 2018 19:38:41 +0100 Subject: [PATCH] Add support for extra c files in sys directory --- priv/patches/otp-19.3.6.patch.mustache | 23 +++++++++++++---- priv/patches/otp-20.2.patch.mustache | 23 +++++++++++++---- src/rebar3_grisp_build.erl | 35 ++++++++++++++++++-------- 3 files changed, 61 insertions(+), 20 deletions(-) diff --git a/priv/patches/otp-19.3.6.patch.mustache b/priv/patches/otp-19.3.6.patch.mustache index 56f7cda..b84df23 100644 --- a/priv/patches/otp-19.3.6.patch.mustache +++ b/priv/patches/otp-19.3.6.patch.mustache @@ -1,17 +1,30 @@ {{#erts_emulator_makefile_in}} diff --git a/erts/emulator/Makefile.in b/erts/emulator/Makefile.in -index 3579a97c5..d3dfd69e0 100644 +index ff239e155..2e951ae1e 100644 --- a/erts/emulator/Makefile.in +++ b/erts/emulator/Makefile.in -@@ -835,6 +835,{{lines}} @@ DRV_OBJS = \ +@@ -739,6 +739,{{sys_lines}} @@ $(ERL_TOP)/lib/%.beam: + + INIT_OBJS = $(OBJDIR)/erl_main.o $(PRELOAD_OBJ) + ++ifeq ($(findstring rtems,$(TARGET)),rtems) +{{#sys_objs}} ++ INIT_OBJS += $(OBJDIR)/{{sys_name}}.o +{{/sys_objs}} ++endif ++ + EMU_OBJS = \ + $(OBJDIR)/beam_emu.o $(OBJDIR)/beam_opcodes.o \ + $(OBJDIR)/beam_load.o $(OBJDIR)/beam_bif_load.o \ +@@ -833,6 +839,{{drv_lines}} @@ DRV_OBJS = \ $(OBJDIR)/zlib_drv.o \ $(OBJDIR)/ram_file_drv.o \ $(OBJDIR)/ttsl_drv.o + +ifeq ($(findstring rtems,$(TARGET)),rtems) -{{#drivers}} -+ DRV_OBJS += $(OBJDIR)/{{name}}.o -{{/drivers}} +{{#drv_objs}} ++ DRV_OBJS += $(OBJDIR)/{{drv_name}}.o +{{/drv_objs}} +endif + endif diff --git a/priv/patches/otp-20.2.patch.mustache b/priv/patches/otp-20.2.patch.mustache index bb23a2e..b317c76 100644 --- a/priv/patches/otp-20.2.patch.mustache +++ b/priv/patches/otp-20.2.patch.mustache @@ -1,17 +1,30 @@ {{#erts_emulator_makefile_in}} diff --git a/erts/emulator/Makefile.in b/erts/emulator/Makefile.in -index 799f6dd1fd..44fac9d5be 100644 +index 799f6dd1f..0dcd1e4f5 100644 --- a/erts/emulator/Makefile.in +++ b/erts/emulator/Makefile.in -@@ -865,6 +865,{{lines}} @@ DRV_OBJS = \ +@@ -770,6 +770,{{sys_lines}} @@ $(ERL_TOP)/lib/%.beam: + + INIT_OBJS = $(OBJDIR)/erl_main.o $(PRELOAD_OBJ) + ++ifeq ($(findstring rtems,$(TARGET)),rtems) +{{#sys_objs}} ++ INIT_OBJS += $(OBJDIR)/{{sys_name}}.o +{{/sys_objs}} ++endif ++ + EMU_OBJS = \ + $(OBJDIR)/beam_emu.o $(OBJDIR)/beam_opcodes.o \ + $(OBJDIR)/beam_load.o $(OBJDIR)/beam_bif_load.o \ +@@ -865,6 +871,{{drv_lines}} @@ DRV_OBJS = \ $(OBJDIR)/inet_drv.o \ $(OBJDIR)/ram_file_drv.o \ $(OBJDIR)/ttsl_drv.o + +ifeq ($(findstring rtems,$(TARGET)),rtems) -{{#drivers}} -+ DRV_OBJS += $(OBJDIR)/{{name}}.o -{{/drivers}} +{{#drv_objs}} ++ DRV_OBJS += $(OBJDIR)/{{drv_name}}.o +{{/drv_objs}} +endif + endif diff --git a/src/rebar3_grisp_build.erl b/src/rebar3_grisp_build.erl index cb602ce..e4b9017 100644 --- a/src/rebar3_grisp_build.erl +++ b/src/rebar3_grisp_build.erl @@ -144,18 +144,28 @@ config_file(Apps, Board, PathParts, DefaultConf) -> copy_code(Apps, Board, OTPRoot, Version) -> console("* Copying C code..."), + SysFiles = lists:foldl( + fun(A, D) -> + copy_app_sys(A, Board, OTPRoot, D) + end, + [], + Apps + ), Drivers = lists:foldl( fun(A, D) -> - copy_app_code(A, Board, OTPRoot, D) + copy_app_drivers(A, Board, OTPRoot, D) end, [], - Apps + Apps ), - patch_otp(OTPRoot, Drivers, Version). + patch_otp(OTPRoot, SysFiles, Drivers, Version). + +copy_app_sys(App, Board, OTPRoot, SysFiles) -> + Source = filename:join([rebar_app_info:dir(App), "grisp", Board]), + SysFiles ++ copy_sys(Source, OTPRoot). -copy_app_code(App, Board, OTPRoot, Drivers) -> +copy_app_drivers(App, Board, OTPRoot, Drivers) -> Source = filename:join([rebar_app_info:dir(App), "grisp", Board]), - copy_sys(Source, OTPRoot), Drivers ++ copy_drivers(Source, OTPRoot). copy_sys(Source, OTPRoot) -> @@ -190,22 +200,27 @@ copy_file(Source, {TargetRoot, TargetDir}) -> {ok, _} = file:copy(Source, Target), TargetFile. -patch_otp(OTPRoot, Drivers, Version) -> +patch_otp(OTPRoot, SysFiles, Drivers, Version) -> TemplateFile = filename:join([ code:priv_dir(rebar3_grisp), "patches/otp-" ++ Version ++ ".patch.mustache" ]), case filelib:is_file(TemplateFile) of - true -> apply_patch(TemplateFile, Drivers, OTPRoot); + true -> apply_patch(TemplateFile, SysFiles, Drivers, OTPRoot); false -> abort("Patch file for OTP ~s missing", [Version]) end. -apply_patch(TemplateFile, Drivers, OTPRoot) -> +apply_patch(TemplateFile, SysFiles, Drivers, OTPRoot) -> Template = bbmustache:parse_file(TemplateFile), + SysObjs = [[{sys_name, filename:basename(N, ".c")}] || N <- SysFiles, + filename:basename(N) =/= "erl_main.c"], + DrvObjs = [[{drv_name, filename:basename(N, ".c")}] || N <- Drivers], Context = [ {erts_emulator_makefile_in, [ - {lines, 10 + length(Drivers)}, - {drivers, [[{name, filename:basename(N, ".c")}] || N <- Drivers]} + {sys_lines, 9 + length(SysObjs)}, + {sys_objs, SysObjs}, + {drv_lines, 10 + length(DrvObjs)}, + {drv_objs, DrvObjs} ]} ], Patch = bbmustache:compile(Template, Context, [{key_type, atom}]),