2018-03-18 18:03:26 +00:00
|
|
|
# Copyright (c) 2018 Calvin Rose
|
|
|
|
#
|
|
|
|
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
# of this software and associated documentation files (the "Software"), to
|
|
|
|
# deal in the Software without restriction, including without limitation the
|
|
|
|
# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
|
|
|
# sell copies of the Software, and to permit persons to whom the Software is
|
|
|
|
# furnished to do so, subject to the following conditions:
|
|
|
|
#
|
|
|
|
# The above copyright notice and this permission notice shall be included in
|
|
|
|
# all copies or substantial portions of the Software.
|
|
|
|
#
|
|
|
|
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
|
|
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
|
|
|
# IN THE SOFTWARE.
|
|
|
|
|
|
|
|
################################
|
|
|
|
##### Set global variables #####
|
|
|
|
################################
|
|
|
|
|
2018-05-15 01:52:51 +00:00
|
|
|
PREFIX?=/usr
|
|
|
|
|
|
|
|
INCLUDEDIR=$(PREFIX)/include/dst
|
|
|
|
LIBDIR=$(PREFIX)/lib
|
2018-03-18 18:03:26 +00:00
|
|
|
BINDIR=$(PREFIX)/bin
|
|
|
|
|
2018-04-26 17:13:31 +00:00
|
|
|
# CFLAGS=-std=c99 -Wall -Wextra -Isrc/include -Wl,--dynamic-list=src/exported.list -s -O3
|
|
|
|
# TODO - when api is finalized, only export public symbols instead of using rdynamic
|
2018-05-15 01:52:51 +00:00
|
|
|
# which exports all symbols. Saves a few KB in binary.
|
2018-04-26 17:13:31 +00:00
|
|
|
|
2018-08-21 17:09:01 +00:00
|
|
|
#CFLAGS=-std=c99 -Wall -Wextra -Isrc/include -fpic -g
|
2018-08-07 04:54:47 +00:00
|
|
|
CFLAGS=-std=c99 -Wall -Wextra -Isrc/include -fpic -O2 -fvisibility=hidden
|
2018-03-18 18:03:26 +00:00
|
|
|
CLIBS=-lm -ldl
|
|
|
|
PREFIX=/usr/local
|
|
|
|
DST_TARGET=dst
|
2018-05-15 01:52:51 +00:00
|
|
|
DST_LIBRARY=libdst.so
|
2018-03-18 18:03:26 +00:00
|
|
|
DEBUGGER=gdb
|
|
|
|
|
2018-05-22 02:08:16 +00:00
|
|
|
UNAME:=$(shell uname -s)
|
2018-06-26 18:10:17 +00:00
|
|
|
LDCONFIG:=ldconfig
|
2018-05-22 02:08:16 +00:00
|
|
|
ifeq ($(UNAME), Darwin)
|
|
|
|
# Add other macos/clang flags
|
2018-06-26 18:10:17 +00:00
|
|
|
LDCONFIG:=
|
2018-05-22 02:08:16 +00:00
|
|
|
else
|
|
|
|
CFLAGS:=$(CFLAGS) -rdynamic
|
|
|
|
endif
|
|
|
|
|
2018-03-18 18:03:26 +00:00
|
|
|
# Source headers
|
2018-07-04 04:17:34 +00:00
|
|
|
DST_GENERATED_HEADERS= \
|
|
|
|
src/include/generated/core.h \
|
|
|
|
src/include/generated/init.h
|
2018-03-18 18:03:26 +00:00
|
|
|
DST_HEADERS=$(sort $(wildcard src/include/dst/*.h))
|
2018-07-01 15:52:15 +00:00
|
|
|
DST_LOCAL_HEADERS=$(sort $(wildcard src/*/*.h))
|
2018-03-18 18:03:26 +00:00
|
|
|
|
|
|
|
# Source files
|
|
|
|
DST_CORE_SOURCES=$(sort $(wildcard src/core/*.c))
|
|
|
|
DST_MAINCLIENT_SOURCES=$(sort $(wildcard src/mainclient/*.c))
|
|
|
|
|
2018-05-15 01:52:51 +00:00
|
|
|
all: $(DST_TARGET) $(DST_LIBRARY)
|
2018-03-18 18:03:26 +00:00
|
|
|
|
|
|
|
###################################
|
|
|
|
##### The code generator tool #####
|
|
|
|
###################################
|
|
|
|
|
|
|
|
xxd: src/tools/xxd.c
|
|
|
|
$(CC) $< -o $@
|
|
|
|
|
|
|
|
#############################
|
|
|
|
##### Generated Headers #####
|
|
|
|
#############################
|
|
|
|
|
2018-07-04 03:07:35 +00:00
|
|
|
src/include/generated/init.h: src/mainclient/init.dst xxd
|
2018-07-04 04:17:34 +00:00
|
|
|
./xxd $< $@ dst_gen_init
|
2018-03-18 18:03:26 +00:00
|
|
|
|
2018-07-04 04:17:34 +00:00
|
|
|
src/include/generated/core.h: src/core/core.dst xxd
|
|
|
|
./xxd $< $@ dst_gen_core
|
2018-03-18 18:03:26 +00:00
|
|
|
|
2018-07-04 03:07:35 +00:00
|
|
|
# Only a few files depend on the generated headers
|
2018-07-04 04:17:34 +00:00
|
|
|
src/core/corelib.o: src/include/generated/core.h
|
2018-07-04 03:07:35 +00:00
|
|
|
src/mainclient/main.o: src/include/generated/init.h
|
|
|
|
|
2018-05-15 01:52:51 +00:00
|
|
|
##########################################################
|
|
|
|
##### The main interpreter program and shared object #####
|
|
|
|
##########################################################
|
2018-03-18 18:03:26 +00:00
|
|
|
|
2018-07-04 03:07:35 +00:00
|
|
|
DST_ALL_SOURCES=$(DST_CORE_SOURCES) \
|
2018-05-15 01:52:51 +00:00
|
|
|
$(DST_MAINCLIENT_SOURCES)
|
|
|
|
|
2018-07-04 03:07:35 +00:00
|
|
|
DST_CORE_OBJECTS=$(patsubst %.c,%.o,$(DST_CORE_SOURCES))
|
2018-05-10 15:11:18 +00:00
|
|
|
DST_ALL_OBJECTS=$(patsubst %.c,%.o,$(DST_ALL_SOURCES))
|
2018-03-18 18:03:26 +00:00
|
|
|
|
2018-07-04 03:07:35 +00:00
|
|
|
%.o: %.c $(DST_HEADERS) $(DST_LOCAL_HEADERS)
|
2018-05-10 15:11:18 +00:00
|
|
|
$(CC) $(CFLAGS) -o $@ -c $<
|
2018-03-18 18:03:26 +00:00
|
|
|
|
2018-05-10 15:11:18 +00:00
|
|
|
$(DST_TARGET): $(DST_ALL_OBJECTS)
|
2018-05-15 01:52:51 +00:00
|
|
|
$(CC) $(CFLAGS) -o $(DST_TARGET) $^ $(CLIBS)
|
|
|
|
|
2018-07-04 03:07:35 +00:00
|
|
|
$(DST_LIBRARY): $(DST_CORE_OBJECTS)
|
2018-05-15 01:52:51 +00:00
|
|
|
$(CC) $(CFLAGS) -shared -o $(DST_LIBRARY) $^ $(CLIBS)
|
2018-03-18 18:03:26 +00:00
|
|
|
|
|
|
|
###################
|
|
|
|
##### Testing #####
|
|
|
|
###################
|
|
|
|
|
|
|
|
repl: $(DST_TARGET)
|
2018-03-18 19:05:31 +00:00
|
|
|
./$(DST_TARGET)
|
2018-03-18 18:03:26 +00:00
|
|
|
|
|
|
|
debug: $(DST_TARGET)
|
2018-03-18 19:05:31 +00:00
|
|
|
$(DEBUGGER) ./$(DST_TARGET)
|
2018-03-18 18:03:26 +00:00
|
|
|
|
|
|
|
valgrind: $(DST_TARGET)
|
2018-03-18 19:05:31 +00:00
|
|
|
valgrind --leak-check=full -v ./$(DST_TARGET)
|
2018-03-18 18:03:26 +00:00
|
|
|
|
|
|
|
test: $(DST_TARGET)
|
2018-03-18 19:05:31 +00:00
|
|
|
./$(DST_TARGET) test/suite0.dst
|
|
|
|
./$(DST_TARGET) test/suite1.dst
|
2018-08-21 17:09:01 +00:00
|
|
|
./$(DST_TARGET) test/suite2.dst
|
2018-03-18 18:03:26 +00:00
|
|
|
|
|
|
|
valtest: $(DST_TARGET)
|
|
|
|
valgrind --leak-check=full -v ./$(DST_TARGET) test/suite0.dst
|
2018-05-15 01:52:51 +00:00
|
|
|
valgrind --leak-check=full -v ./$(DST_TARGET) test/suite1.dst
|
2018-08-21 17:09:01 +00:00
|
|
|
valgrind --leak-check=full -v ./$(DST_TARGET) test/suite2.dst
|
2018-03-18 18:03:26 +00:00
|
|
|
|
2018-06-23 23:19:26 +00:00
|
|
|
###################
|
|
|
|
##### Natives #####
|
|
|
|
###################
|
|
|
|
|
|
|
|
natives: $(DST_TARGET)
|
|
|
|
$(MAKE) -C natives/hello
|
|
|
|
$(MAKE) -j 8 -C natives/sqlite3
|
|
|
|
|
2018-07-17 02:55:45 +00:00
|
|
|
clean-natives:
|
|
|
|
$(MAKE) -C natives/hello clean
|
|
|
|
$(MAKE) -C natives/sqlite3 clean
|
|
|
|
|
2018-03-18 18:03:26 +00:00
|
|
|
#################
|
|
|
|
##### Other #####
|
|
|
|
#################
|
|
|
|
|
|
|
|
clean:
|
2018-06-29 03:36:31 +00:00
|
|
|
-rm $(DST_TARGET)
|
|
|
|
-rm src/**/*.o
|
|
|
|
-rm vgcore.*
|
|
|
|
-rm $(DST_GENERATED_HEADERS)
|
2018-03-18 18:03:26 +00:00
|
|
|
|
|
|
|
install: $(DST_TARGET)
|
2018-05-15 01:52:51 +00:00
|
|
|
cp $(DST_TARGET) $(BINDIR)/$(DST_TARGET)
|
|
|
|
mkdir -p $(INCLUDEDIR)
|
|
|
|
cp $(DST_HEADERS) $(INCLUDEDIR)
|
|
|
|
cp $(DST_LIBRARY) $(LIBDIR)/$(DST_LIBRARY)
|
2018-06-26 18:10:17 +00:00
|
|
|
$(LDCONFIG)
|
2018-03-18 18:03:26 +00:00
|
|
|
|
|
|
|
uninstall:
|
2018-06-29 03:36:31 +00:00
|
|
|
-rm $(BINDIR)/$(DST_TARGET)
|
|
|
|
-rm $(LIBDIR)/$(DST_LIBRARY)
|
|
|
|
-rm -rf $(INCLUDEDIR)
|
2018-06-26 18:10:17 +00:00
|
|
|
$(LDCONFIG)
|
2018-03-18 18:03:26 +00:00
|
|
|
|
|
|
|
.PHONY: clean install repl debug valgrind test valtest install uninstall
|