ref: ca22ed48824493c5d7270717172007b11f947a82
parent: 03c889d58174d96446aba61750b9de755b8f62b3
author: Tor Andersson <tor.andersson@gmail.com>
date: Wed Jun 14 08:37:09 EDT 2017
Add pkgconfig file and shared library target.
--- a/Makefile
+++ b/Makefile
@@ -1,7 +1,8 @@
SRCS := $(wildcard js*.c utf*.c regexp.c)
HDRS := $(wildcard js*.h mujs.h utf.h regexp.h)
-OBJS := $(SRCS:%.c=build/%.o)
+VERSION = $(shell git describe --tags --always)
+
prefix ?= /usr/local
bindir ?= $(prefix)/bin
incdir ?= $(prefix)/include
@@ -13,6 +14,11 @@
CFLAGS += -Wunreachable-code
endif
+ifeq "$(shell uname)" "Linux"
+CFLAGS += -ffunction-sections -fdata-sections
+LDFLAGS += -Wl,--gc-sections -Wl,-s
+endif
+
ifeq "$(build)" "debug"
CFLAGS += -g
else ifeq "$(build)" "sanitize"
@@ -20,23 +26,10 @@
LDFLAGS += -fsanitize=address
else
CFLAGS += -Os
-ifeq "$(shell uname)" "Linux"
-CFLAGS += -ffunction-sections -fdata-sections
-LDFLAGS += -Wl,--gc-sections -Wl,-s
endif
-endif
-default: build build/mujs build/mujsone
+default: build build/mujs build/libmujs.a build/libmujs.so build/mujs.pc
-debug:
- $(MAKE) build=debug clean default
-
-sanitize:
- $(MAKE) build=sanitize clean default
-
-release:
- $(MAKE) build=release clean default
-
astnames.h: jsparse.h
grep -E '(AST|EXP|STM)_' jsparse.h | sed 's/^[^A-Z]*\(AST_\)*/"/;s/,.*/",/' | tr A-Z a-z > $@
@@ -51,28 +44,42 @@
build:
mkdir -p build
-build/%.o: %.c $(HDRS)
+build/main.o: main.c $(HDRS)
$(CC) $(CFLAGS) -o $@ -c $<
-build/libmujs.a: $(OBJS)
+build/libmujs.o: one.c $(HDRS)
+ $(CC) $(CFLAGS) -o $@ -c $<
+
+build/libmujs.a: build/libmujs.o
$(AR) cru $@ $^
-build/mujs: build/main.o build/libmujs.a
- $(CC) $(LDFLAGS) -o $@ $^ -lm
+build/libmujs.so: one.c $(HDRS)
+ $(CC) $(CFLAGS) -fPIC -shared -o $@ $< -lm
-build/mujsone: build/main.o build/one.o
+build/mujs: build/libmujs.o build/main.o
$(CC) $(LDFLAGS) -o $@ $^ -lm
+build/mujs.pc:
+ @ echo Creating $@
+ @ echo > $@ Name: mujs
+ @ echo >> $@ Description: MuJS embeddable Javascript interpreter
+ @ echo >> $@ Version: $(VERSION)
+ @ echo >> $@ URL: http://dev.mujs.com/
+ @ echo >> $@ Cflags: -I$(incdir)
+ @ echo >> $@ Libs: -L$(libdir) -lmujs
+ @ echo >> $@ Libs.private: -lm
+
install: release
install -d $(DESTDIR)$(incdir)
install -d $(DESTDIR)$(libdir)
+ install -d $(DESTDIR)$(libdir)/pkgconfig
install -d $(DESTDIR)$(bindir)
- install mujs.h $(DESTDIR)$(incdir)
- install build/libmujs.a $(DESTDIR)$(libdir)
- install build/mujs $(DESTDIR)$(bindir)
+ install -m 644 mujs.h $(DESTDIR)$(incdir)
+ install -m 644 build/libmujs.a $(DESTDIR)$(libdir)
+ install -m 755 build/libmujs.so $(DESTDIR)$(libdir)
+ install -m 644 build/mujs.pc $(DESTDIR)$(libdir)/pkgconfig
+ install -m 755 build/mujs $(DESTDIR)$(bindir)
-VERSION = $(shell git describe --tags --always)
-
tarball:
git archive --format=zip --prefix=mujs-$(VERSION)/ HEAD > mujs-$(VERSION).zip
git archive --format=tar --prefix=mujs-$(VERSION)/ HEAD | gzip > mujs-$(VERSION).tar.gz
@@ -81,10 +88,16 @@
tags: $(SRCS) main.c $(HDRS)
ctags $^
-test: build/mujs
- python tests/sputniktests/tools/sputnik.py --tests=tests/sputniktests --command ./build/mujs --summary
-
clean:
rm -f astnames.h opnames.h one.c build/*
-.PHONY: default test clean install debug release
+debug:
+ $(MAKE) build=debug clean default
+
+sanitize:
+ $(MAKE) build=sanitize clean default
+
+release:
+ $(MAKE) build=release clean default
+
+.PHONY: default clean install debug sanitize release