summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIan Moffett <ian@osmora.org>2025-09-25 16:21:41 -0400
committerIan Moffett <ian@osmora.org>2025-09-25 16:21:41 -0400
commit0e25563b4aaad1aea65535b5936e2cad9cc9fd88 (patch)
tree0f0be9225fabdd3b242ef2852a865914b16885b5
parentdb666b02a12666951ca7d1a099903beee0bb22f1 (diff)
build: Generate shared library API for o.1p
Signed-off-by: Ian Moffett <ian@osmora.org>
-rw-r--r--.gitignore2
-rw-r--r--Makefile27
-rw-r--r--examples/hello.c (renamed from src/main.c)16
3 files changed, 25 insertions, 20 deletions
diff --git a/.gitignore b/.gitignore
index e660fd9..b5cdb72 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1 +1,3 @@
bin/
+*.o
+*.so
diff --git a/Makefile b/Makefile
index e949046..bb7b2c8 100644
--- a/Makefile
+++ b/Makefile
@@ -1,12 +1,23 @@
CFILES = $(shell find src/ -name "*.c")
-CFLAGS = -Isrc/include/ -pedantic
-OUTPUT = bin/otrx
+OBJ = $(CFILES:.c=.o)
+CFLAGS = -Isrc/include/ -pedantic -fPIC
+OUTPUT = libonet.so
CC = gcc
-.PHONY: all
-all: bin
- $(CC) $(CFILES) $(CFLAGS) -o $(OUTPUT)
+$(OUTPUT): $(OBJ)
+ $(CC) -shared -o $@ $(OBJ)
-.PHONY: bin
-bin:
- mkdir -p $@
+%.o: %.c
+ $(CC) -c $(CFLAGS) $< -o $@
+
+.PHONY: install
+install:
+ mkdir -p /usr/include/onet/
+ cp -r src/include/* /usr/include/onet/
+ cp libonet.so /usr/lib/
+ chmod 0755 /usr/lib/libonet.so
+ ldconfig
+
+.PHONY: clean
+clean:
+ rm -f $(OBJ)
diff --git a/src/main.c b/examples/hello.c
index c2087e7..dfa7767 100644
--- a/src/main.c
+++ b/examples/hello.c
@@ -27,20 +27,12 @@
* POSSIBILITY OF SUCH DAMAGE.
*/
-#include <sys/socket.h>
-#include <sys/ioctl.h>
-#include <linux/if_packet.h>
-#include <netinet/in.h>
-#include <net/if.h>
-#include <net/ethernet.h>
+#include <string.h>
#include <stdio.h>
-#include <stdlib.h>
-#include <stdbool.h>
#include <unistd.h>
-#include <string.h>
-#include "if_ether.h"
-#include "dgram.h"
-#include "link.h"
+#include <onet/if_ether.h>
+#include <onet/dgram.h>
+#include <onet/link.h>
#define TEST_STR "Hello from o.1p!! Meow meow!"