summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEdoardo La Greca2025-05-02 19:56:50 +0200
committerEdoardo La Greca2025-05-02 19:58:55 +0200
commitd5263fdfc89ecf9a5d2386b8b4ba8aad1d6ce105 (patch)
treea32a42f8760d2b6aa5656b2652bf50db6425df72
parentbf4350b9ad80948d7e79ab64fe5cdff7c10a813a (diff)
add a proper way to make platform-dependent code, update readme with compilation instructions
-rw-r--r--Makefile13
-rw-r--r--README16
-rwxr-xr-xsh/platdep.sh17
3 files changed, 38 insertions, 8 deletions
diff --git a/Makefile b/Makefile
index 3c3dfd1..ccd5b0a 100644
--- a/Makefile
+++ b/Makefile
@@ -5,12 +5,15 @@ LDFLAGS =
OUTNAME = libfemtokit.a
TESTFILE = hello.c
-# All object files are listed here
-OBJS =
+# All object files are listed here:
+OBJS = $(OBJS_PLATDEP)
-# Add platform-dependent object files in separate variables (e.g. OBJS_LINUX)
-# and then, when running the make file, make sure to concatenate the appropriate
-# variable (e.g. OBJS = $(OBJS) $(OBJS_LINUX) ).
+# Add platform dependent object files here:
+OBJS_PLATDEP =
+
+# Add platform-dependent object files in separate variables ("OBJS_NAME", e.g.
+# OBJS_LINUX) and then, when running the make file, make sure to assign the
+# appropriate variable to OBJS_PLATDEP (e.g. OBJS_PLATDEP = $(OBJS_LINUX) ).
all: $(OBJS)
ar -rs $(OUTNAME) *.o
diff --git a/README b/README
index 3c933a8..bb89090 100644
--- a/README
+++ b/README
@@ -20,14 +20,24 @@ Compilation and usage
As I may have said somewhere else, you need **OpenGL** (development version, that with header files) and **freeGLUT** (development version for this one as well).
-Using the make file in the repository's root:
+After installing the required dependencies, run the following command.
-- **`make`** builds all the translation units, skipping those which have been built already.
+ ./sh/platdep.sh
+
+If the command printed one or more make file macros, consider the macro that most closely represents your platform. For example, if the script outputs both `OBJS_LINUX` and `OBJS_DEBIAN`, you might want to go with `OBJS_DEBIAN` as it's more specific and should provide better support. Then, run the following line after replacing `MACRO` with the name you just chose.
+
+ make 'OBJS_PLATDEP=$(MACRO)'
+
+This is going to compile all source files into object files and then build a static library out of them.
+
+These below are other useful make file targets. It is advised to specify the macro definition above for all targets since some of them may depend on it. Alternatively, you could edit the make file to make the definition permanent.
+
+- **`make`** or **`make all`** builds all the translation units, skipping those which have been built already.
- **`make install`** moves all object files to the respective directories in the machine's file system.
- **`make uninstall`** removes all object files from the machine's file system.
- **`make clean`** removes all object files produced by `make` from the repository's directory.
-The ultimate object file is a library called `libfemtokit`, which is
+The ultimate object file is a library called `libfemtokit`, which is essentially what you're going to link your programs against.
Repository structure
--------------------
diff --git a/sh/platdep.sh b/sh/platdep.sh
new file mode 100755
index 0000000..dda0588
--- /dev/null
+++ b/sh/platdep.sh
@@ -0,0 +1,17 @@
+#! /bin/sh
+
+# Of all the available platform-dependent object file sets defined in the
+# working directory's make file of the form 'OBJS_...', list all those that
+# could be relevant to the current platform.
+
+keywords=$(uname -a)
+
+sets=""
+for k in $keywords
+do
+ sets="$sets\n$(echo "$k" | tr '[:lower:]' '[:upper:]' | xargs -I '%' grep '^OBJS_%[ =]' Makefile)"
+
+done
+
+echo "$sets" | sort | uniq | awk '/\n\n/ { print '\n' }'
+