Skip to content

Add support for extra c files in sys directory #19

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 18 additions & 5 deletions priv/patches/otp-19.3.6.patch.mustache
Original file line number Diff line number Diff line change
@@ -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
Expand Down
23 changes: 18 additions & 5 deletions priv/patches/otp-20.2.patch.mustache
Original file line number Diff line number Diff line change
@@ -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
Expand Down
35 changes: 25 additions & 10 deletions src/rebar3_grisp_build.erl
Original file line number Diff line number Diff line change
Expand Up @@ -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) ->
Expand Down Expand Up @@ -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}]),
Expand Down