[m-rev.] diff: build the POSIX binding using mmc --make
Julien Fischer
jfischer at opturion.com
Thu Mar 21 16:30:27 AEDT 2019
Build the POSIX binding using mmc --make.
Building the POSIX binding using mmc --make by default and just have mmake
forward its work to that. Using mmc --make means things like library grade
exclusions will work properly.
Exclude non-C grades from the grade set in which to install the POSIX binding.
Shift a POSIX binding sample into the samples subdirectory.
extras/posix/Makefile:
extras/posix/Mercury.options:
Build the POSIX binding using mmc --make.
extras/posix/Mmakefile:
Redirect mmake to use the normal Makefile.
extras/posix/hello.m:
Shift this file into the samples subdirectory.
extras/samples/Makefile:
Set up things to build the samples against a libposix in the
parent directory.
extras/samples/Mmakefile:
Delete this file.
Julien.
diff --git a/extras/posix/Makefile b/extras/posix/Makefile
new file mode 100644
index 0000000..7eebef0
--- /dev/null
+++ b/extras/posix/Makefile
@@ -0,0 +1,29 @@
+#-----------------------------------------------------------------------------#
+# vim: ts=8 sw=8 noexpandtab
+#-----------------------------------------------------------------------------#
+# Copyright (C) 2011 The University of Melbourne.
+# Copyright (C) 2015, 2018-2019 The Mercury team.
+# This file is distributed under the terms specified in COPYING.LIB.
+#-----------------------------------------------------------------------------#
+
+# Build the posix library using mmc --make.
+
+TARGET = posix
+MMC = mmc
+
+.PHONY: build
+build: posix_workarounds.o
+ $(MMC) --make lib$(TARGET)
+
+.PHONY: install
+install: posix_workarounds.o
+ $(MMC) --make lib$(TARGET).install
+
+posix_workarounds.o: posix_workarounds.c
+
+.PHONY: realclean
+realclean:
+ cd samples && $(MAKE) realclean
+ $(MMC) --make $(TARGET).realclean
+ /bin/rm -f posix_workarounds.o
+ /bin/rm -rf Mercury
diff --git a/extras/posix/Mercury.options b/extras/posix/Mercury.options
new file mode 100644
index 0000000..47a332e
--- /dev/null
+++ b/extras/posix/Mercury.options
@@ -0,0 +1,6 @@
+MCFLAGS = \
+ --libgrades-exclude java \
+ --libgrades-exclude csharp \
+ --libgrades-exclude erlang \
+ --link-object posix_workarounds.o \
+ --extra-library-header posix_workarounds.h
diff --git a/extras/posix/Mmakefile b/extras/posix/Mmakefile
index 1372b6e..921078f 100644
--- a/extras/posix/Mmakefile
+++ b/extras/posix/Mmakefile
@@ -6,42 +6,27 @@
# This file is distributed under the terms specified in COPYING.LIB.
#-----------------------------------------------------------------------------#
-INSTALL_PREFIX := $(INSTALL_PREFIX)/extras
+# This is file exists so that do an `mmake' from the top-level of the extras
+# distribution works. The actual work of building this library is done
+# using the Makefile and mmc --make. This file just forwards all the work
+# to there.
--include ../Mmake.params
+MAIN_TARGET=build
-# The following is needed (on some systems) to enable declarations of
-# Posix functions in standard C header files.
-MGNUCFLAGS = --no-ansi
-
-# This library has some parts that are implemented in C
-# rather than in Mercury. The following lines ensure that
-# the .h and .o files for those parts get included in the library.
-ADDITIONAL_HDRS = posix_workarounds.h
-MLOBJS = posix_workarounds.$O
-MLPICOBJS = posix_workarounds.$(EXT_FOR_PIC_OBJECTS)
-
-.PHONY: default_target
-default_target: all
+.PHONY: build
+build:
+ $(MAKE) build
+# The depend target does nothing, mmc --make will handle dependencies
+# automatically.
+#
.PHONY: depend
-depend: posix.depend hello.depend
-
-.PHONY: all
-all: libposix hello
-
-.PHONY: check
-check: hello
- ./hello
+depend:
.PHONY: install
-install: libposix.install
- cp $(ADDITIONAL_HDRS) $(INSTALL_PREFIX)/lib/mercury/inc
-
-.PHONY: clean
-clean:
- -/bin/rm -f posix_workarounds.$(O)
- -/bin/rm -f posix_workarounds.$(EXT_FOR_PIC_OBJECTS)
+install:
+ $(MAKE) install INSTALL_PREFIX=$(INSTALL_PREFIX)/extras
.PHONY: realclean
-realclean: clean
+realclean:
+ $(MAKE) realclean
diff --git a/extras/posix/hello.m b/extras/posix/hello.m
deleted file mode 100644
index c886956..0000000
--- a/extras/posix/hello.m
+++ /dev/null
@@ -1,62 +0,0 @@
-% vim: ft=mercury ts=4 sw=4 et
-:- module hello.
-:- interface.
-
-:- import_module io.
-
-:- pred main(io::di, io::uo) is det.
-
-:- implementation.
-
-:- import_module posix.
-:- import_module posix.open.
-:- import_module posix.write.
-
-:- import_module bitmap.
-:- import_module char.
-:- import_module int.
-:- import_module list.
-:- import_module string.
-
-main(!IO) :-
- open("/dev/tty", [wronly], Res0, !IO),
- (
- Res0 = ok(Fd),
- Str = "hello world.\n",
- length(Str, Len),
- write(Fd, Len, string_to_bitmap(Str), Res1, !IO),
- (
- Res1 = ok(NWritten),
- ( NWritten \= Len ->
- % We didn't write all of it!
- io.write_string("failed to write it all\n", !IO)
- ;
- true
- )
- ;
- Res1 = error(Err),
- io.write(Err, !IO),
- io.nl(!IO)
- )
- ;
- Res0 = error(Err),
- io.write(Err, !IO),
- io.nl(!IO)
- ).
-
-:- func string_to_bitmap(string::in) = (bitmap::bitmap_uo) is det.
-
-string_to_bitmap(String) = Bitmap :-
- NumBytes = string.length(String),
- Bitmap0 = bitmap.init(NumBytes * bits_per_byte),
- string.to_char_list(String, Chars),
- char_list_to_bitmap(Chars, 0, Bitmap0, Bitmap).
-
-:- pred char_list_to_bitmap(list(char)::in, int::in,
- bitmap::bitmap_di, bitmap::bitmap_uo) is det.
-
-char_list_to_bitmap([], _, !Bitmap).
-char_list_to_bitmap([C | Cs], Index, !Bitmap) :-
- char.to_int(C, I),
- !:Bitmap = !.Bitmap ^ byte(Index) := I,
- char_list_to_bitmap(Cs, Index + 1, !Bitmap).
diff --git a/extras/posix/samples/Makefile b/extras/posix/samples/Makefile
new file mode 100644
index 0000000..77f5ab2
--- /dev/null
+++ b/extras/posix/samples/Makefile
@@ -0,0 +1,16 @@
+DEMOS = mdprof_cgid hello
+MMC = mmc
+
+# The following target builds the demos and links them against the posix
+# library in the parent directory in situ.
+#
+all:
+ $(MMC) --search-lib-files-dir .. \
+ --init-file ../posix.init \
+ --link-object ../libposix.a \
+ --make $(DEMOS)
+
+.PHONY: realclean
+realclean:
+ $(MMC) --make $(DEMOS:%=%.realclean)
+ /bin/rm -rf Mercury
diff --git a/extras/posix/samples/Mmakefile b/extras/posix/samples/Mmakefile
deleted file mode 100644
index a3550ab..0000000
--- a/extras/posix/samples/Mmakefile
+++ /dev/null
@@ -1,28 +0,0 @@
-#-----------------------------------------------------------------------------#
-# vim: ts=8 sw=8 noexpandtab
-#-----------------------------------------------------------------------------#
-# Copyright (C) 2007 The University of Melbourne.
-# Copyright (C) 2015, 2018 The Mercury team.
-# This file is distributed under the terms specified in COPYING.LIB.
-#-----------------------------------------------------------------------------#
-
-POSIX_DIR = ..
-
-DEMOS = mdprof_cgid
-
-depend: $(DEMOS:%=%.depend)
-all: demos
-clean: $(DEMOS:%=%.clean)
-realclean: $(DEMOS:%=%.realclean)
-demos: $(DEMOS)
-
-# The following stuff tells Mmake to use the posix library.
-VPATH = $(POSIX_DIR):$(MMAKE_VPATH)
-MCFLAGS = -I$(POSIX_DIR) $(EXTRA_MCFLAGS)
-MGNUCFLAGS = -I$(POSIX_DIR)
-MLFLAGS = -R$(POSIX_DIR) $(EXTRA_MLFLAGS) \
- -L$(POSIX_DIR)
-MLLIBS = -lposix $(EXTRA_MLLIBS)
-C2INITARGS = $(POSIX_DIR)/posix.init
-
-MAIN_TARGET = mdprof_cgid
diff --git a/extras/posix/samples/hello.m b/extras/posix/samples/hello.m
new file mode 100644
index 0000000..c886956
--- /dev/null
+++ b/extras/posix/samples/hello.m
@@ -0,0 +1,62 @@
+% vim: ft=mercury ts=4 sw=4 et
+:- module hello.
+:- interface.
+
+:- import_module io.
+
+:- pred main(io::di, io::uo) is det.
+
+:- implementation.
+
+:- import_module posix.
+:- import_module posix.open.
+:- import_module posix.write.
+
+:- import_module bitmap.
+:- import_module char.
+:- import_module int.
+:- import_module list.
+:- import_module string.
+
+main(!IO) :-
+ open("/dev/tty", [wronly], Res0, !IO),
+ (
+ Res0 = ok(Fd),
+ Str = "hello world.\n",
+ length(Str, Len),
+ write(Fd, Len, string_to_bitmap(Str), Res1, !IO),
+ (
+ Res1 = ok(NWritten),
+ ( NWritten \= Len ->
+ % We didn't write all of it!
+ io.write_string("failed to write it all\n", !IO)
+ ;
+ true
+ )
+ ;
+ Res1 = error(Err),
+ io.write(Err, !IO),
+ io.nl(!IO)
+ )
+ ;
+ Res0 = error(Err),
+ io.write(Err, !IO),
+ io.nl(!IO)
+ ).
+
+:- func string_to_bitmap(string::in) = (bitmap::bitmap_uo) is det.
+
+string_to_bitmap(String) = Bitmap :-
+ NumBytes = string.length(String),
+ Bitmap0 = bitmap.init(NumBytes * bits_per_byte),
+ string.to_char_list(String, Chars),
+ char_list_to_bitmap(Chars, 0, Bitmap0, Bitmap).
+
+:- pred char_list_to_bitmap(list(char)::in, int::in,
+ bitmap::bitmap_di, bitmap::bitmap_uo) is det.
+
+char_list_to_bitmap([], _, !Bitmap).
+char_list_to_bitmap([C | Cs], Index, !Bitmap) :-
+ char.to_int(C, I),
+ !:Bitmap = !.Bitmap ^ byte(Index) := I,
+ char_list_to_bitmap(Cs, Index + 1, !Bitmap).
More information about the reviews
mailing list