diff options
| author | Bruce Hill <bruce@bruce-hill.com> | 2025-04-15 18:22:07 -0400 |
|---|---|---|
| committer | Bruce Hill <bruce@bruce-hill.com> | 2025-04-15 18:22:07 -0400 |
| commit | 5846f9dd9c80cc1db52984323d445874c69fb766 (patch) | |
| tree | ad1f3f9fc08be89af931bd96f44c8f74fc7f8832 | |
| parent | 6d68174bdd5bcd1a7e1a6161b578cd39eaf03bef (diff) | |
Change compilation configuration so Tomo is fully capable of running
locally from the build directory, including with TCC.
| -rw-r--r-- | .gitignore | 3 | ||||
| -rw-r--r-- | Makefile | 38 | ||||
| -rw-r--r-- | README.md | 54 | ||||
| l--------- | build/include/tomo | 1 | ||||
| -rwxr-xr-x | local-tomo | 12 | ||||
| -rw-r--r-- | src/tomo.c | 12 |
6 files changed, 85 insertions, 35 deletions
@@ -14,7 +14,8 @@ !/lib/!(*)/*.h .build -build +/build/bin +/build/lib *.o *.so *.dylib @@ -75,20 +75,20 @@ COMPILER_OBJS=$(patsubst %.c,%.o,$(wildcard src/*.c)) STDLIB_OBJS=$(patsubst %.c,%.o,$(wildcard src/stdlib/*.c)) TESTS=$(patsubst test/%.tm,test/results/%.tm.testresult,$(wildcard test/*.tm)) -all: config.mk build/$(LIB_FILE) build/$(AR_FILE) build/tomo +all: config.mk build/lib/$(LIB_FILE) build/lib/$(AR_FILE) build/bin/tomo -build/tomo: $(STDLIB_OBJS) $(COMPILER_OBJS) - @mkdir -p build +build/bin/tomo: $(STDLIB_OBJS) $(COMPILER_OBJS) + @mkdir -p build/bin @echo $(CC) $(CFLAGS_PLACEHOLDER) $(LDFLAGS) $^ $(LDLIBS) -o $@ @$(CC) $(CFLAGS) $(LDFLAGS) $^ $(LDLIBS) -o $@ -build/$(LIB_FILE): $(STDLIB_OBJS) - @mkdir -p build +build/lib/$(LIB_FILE): $(STDLIB_OBJS) + @mkdir -p build/lib @echo $(CC) $^ $(CFLAGS_PLACEHOLDER) $(OSFLAGS) $(LDFLAGS) $(LDLIBS) $(LIBTOMO_FLAGS) -o $@ @$(CC) $^ $(CFLAGS) $(OSFLAGS) $(LDFLAGS) $(LDLIBS) $(LIBTOMO_FLAGS) -o $@ -build/$(AR_FILE): $(STDLIB_OBJS) - @mkdir -p build +build/lib/$(AR_FILE): $(STDLIB_OBJS) + @mkdir -p build/lib @echo ar -rcs $@ $^ @ar -rcs $@ $^ @@ -103,13 +103,13 @@ config.mk: configure.sh @$(CC) $(CFLAGS) -c $< -o $@ %: %.tm - tomo -e $< + ./local-tomo -e $< -test/results/%.tm.testresult: test/%.tm build/tomo +test/results/%.tm.testresult: test/%.tm build/bin/tomo @mkdir -p test/results @printf '\033[33;1;4m%s\033[m\n' $< @set -o pipefail; \ - if ! VERBOSE=0 COLOR=1 LC_ALL=C ./build/tomo --c-compiler=$(CC) -O 1 $< 2>&1 | tee $@; then \ + if ! COLOR=1 LC_ALL=C ./local-tomo -O 1 $< 2>&1 | tee $@; then \ rm -f $@; \ false; \ fi @@ -118,16 +118,16 @@ test: $(TESTS) @printf '\033[32;7m ALL TESTS PASSED! \033[m\n' clean: - rm -rf build/* $(COMPILER_OBJS) $(STDLIB_OBJS) test/*.tm.testresult test/.build lib/*/.build examples/.build examples/*/.build + rm -rf build/{lib,bin}/* $(COMPILER_OBJS) $(STDLIB_OBJS) test/*.tm.testresult test/.build lib/*/.build examples/.build examples/*/.build %: %.md pandoc --lua-filter=docs/.pandoc/bold-code.lua -s $< -t man -o $@ examples: - ./build/tomo -qIL examples/log examples/ini examples/vectors examples/http examples/wrap examples/colorful - ./build/tomo -e examples/game/game.tm examples/http-server/http-server.tm \ + ./build/bin/tomo -qIL examples/log examples/ini examples/vectors examples/http examples/wrap examples/colorful + ./build/bin/tomo -e examples/game/game.tm examples/http-server/http-server.tm \ examples/tomodeps/tomodeps.tm examples/tomo-install/tomo-install.tm - ./build/tomo examples/learnxiny.tm + ./build/bin/tomo examples/learnxiny.tm deps: check-gcc ./install_dependencies.sh @@ -142,7 +142,7 @@ check-gcc: exit 1; \ fi -install-files: build/tomo build/$(LIB_FILE) build/$(AR_FILE) +install-files: build/bin/tomo build/lib/$(LIB_FILE) build/lib/$(AR_FILE) @if ! echo "$$PATH" | tr ':' '\n' | grep -qx "$(PREFIX)/bin"; then \ echo $$PATH; \ printf "\033[31;1mError: '$(PREFIX)/bin' is not in your \$$PATH variable!\033[m\n" >&2; \ @@ -153,13 +153,13 @@ install-files: build/tomo build/$(LIB_FILE) build/$(AR_FILE) fi mkdir -p -m 755 "$(PREFIX)/man/man1" "$(PREFIX)/bin" "$(PREFIX)/include/tomo" "$(PREFIX)/lib" "$(PREFIX)/share/tomo/modules" cp -v src/stdlib/*.h "$(PREFIX)/include/tomo/" - cp -v build/$(LIB_FILE) build/$(AR_FILE) "$(PREFIX)/lib/" + cp -v build/lib/$(LIB_FILE) build/lib/$(AR_FILE) "$(PREFIX)/lib/" rm -f "$(PREFIX)/bin/tomo" - cp -v build/tomo "$(PREFIX)/bin/" + cp -v build/bin/tomo "$(PREFIX)/bin/" cp -v docs/tomo.1 "$(PREFIX)/man/man1/" -install-libs: build/tomo - ./build/tomo -qIL lib/patterns lib/time lib/commands lib/shell lib/random lib/base64 lib/pthreads lib/uuid lib/core +install-libs: build/bin/tomo + ./local-tomo -qIL lib/patterns lib/time lib/commands lib/shell lib/random lib/base64 lib/pthreads lib/uuid lib/core install: install-files install-libs @@ -103,42 +103,68 @@ success. ## Building The Tomo compiler can be compiled with either GCC or Clang by running `make`. -The resulting compiler and shared library will be put into `./build/`. +The first time you build, you will need to specify the Tomo installation +location (the place where the installer will put the `tomo` binary, the shared +library, and the header files), the Tomo home directory (where Tomo libraries +will be installed), and the default C compiler for Tomo to use when compiling +and running your programs. The answers you give will be saved in `config.mk`, +which you can edit at any time. -## Usage +Once the configuration options have been set, `make` will continue along with +building `tomo`. The resulting compiler and shared library will be put into +`./build/`. -Run Tomo interactively as a REPL (limited functionality): +You can run `make test` to verify that everything works correctly. + +## Running Locally + +To run Tomo locally (without installing), you can use the script +`./local-tomo`, which sets some environment variables and runs the version +of Tomo that you have built in this directory. + +You can run a program like this: -```bash -tomo -# Starts a REPL session ``` +./local-tomo my-program.tm +``` + +## Installing -Run a Tomo file directly: +To install Tomo, run: + +``` +make install +``` + +This will install it to the location you gave during initial configuration. +After this point, you can now run `tomo` to invoke the compiler and run your +Tomo programs. + +## Usage + +To run a Tomo file directly: ```bash tomo foo.tm -# Runs the program ``` -Compile a Tomo file into an object file: +To compile a Tomo file into an object file: ```bash tomo -c foo.tm # Output: .build/foo.tm.o ``` -Transpile a Tomo file into a C header and source file: +To transpile a Tomo file into a C header and source file: + ```bash tomo -t foo.tm # Outputs: .build/foo.tm.h .build/foo.tm.c ``` -## Installing +You can see the full list of compiler options by running `man tomo` or `tomo +--help`. -``` -make && sudo make install -``` ## License diff --git a/build/include/tomo b/build/include/tomo new file mode 120000 index 00000000..82be04c8 --- /dev/null +++ b/build/include/tomo @@ -0,0 +1 @@ +../../src/stdlib
\ No newline at end of file diff --git a/local-tomo b/local-tomo new file mode 100755 index 00000000..f6548058 --- /dev/null +++ b/local-tomo @@ -0,0 +1,12 @@ +#!/bin/sh +here="$(realpath "$(dirname "$0")")" +if [ ! -e "$here/build/bin/tomo" ]; then + echo "Tomo hasn't been compiled yet! Run \`make\` to compile it!" + exit 1; +fi + +PATH="$here/build/bin:$PATH" \ +LD_LIBRARY_PATH="$here/build/lib:$LD_LIBRARY_PATH" \ +LIBRARY_PATH="$here/build/lib:$LIBRARY_PATH" \ +C_INCLUDE_PATH="$here/build/include:$C_INCLUDE_PATH" \ +tomo "$@" @@ -68,7 +68,7 @@ static OptionalText_t #endif " -DGC_THREADS" " -I'" TOMO_PREFIX "/include' -I'" TOMO_HOME "/installed' -I/usr/local/include"), - ldlibs = Text("-lgc -lm -lgmp -lunistring '"TOMO_PREFIX"'/lib/libtomo.so"), + ldlibs = Text("-lgc -lm -lgmp -lunistring -ltomo"), ldflags = Text("-Wl,-rpath,'"TOMO_PREFIX"/lib',-rpath,'" TOMO_HOME "/lib',-rpath,/usr/local/lib " "-L'" TOMO_HOME "/lib' -L/usr/local/lib"), optimization = Text("2"), @@ -125,6 +125,16 @@ int main(int argc, char *argv[]) if (getenv("NO_COLOR") && getenv("NO_COLOR")[0] != '\0') USE_COLOR = false; + // Set up environment variables: + const char *PATH = getenv("PATH"); + setenv("PATH", PATH ? String(TOMO_PREFIX"/bin:", PATH) : TOMO_PREFIX"/bin", 1); + const char *LD_LIBRARY_PATH = getenv("LD_LIBRARY_PATH"); + setenv("LD_LIBRARY_PATH", LD_LIBRARY_PATH ? String(TOMO_PREFIX"/lib:", LD_LIBRARY_PATH) : TOMO_PREFIX"/lib", 1); + const char *LIBRARY_PATH = getenv("LIBRARY_PATH"); + setenv("LIBRARY_PATH", LIBRARY_PATH ? String(TOMO_PREFIX"/lib:", LIBRARY_PATH) : TOMO_PREFIX"/lib", 1); + const char *C_INCLUDE_PATH = getenv("C_INCLUDE_PATH"); + setenv("C_INCLUDE_PATH", C_INCLUDE_PATH ? String(TOMO_PREFIX"/include:", C_INCLUDE_PATH) : TOMO_PREFIX"/include", 1); + // Run a tool: if ((streq(argv[1], "-r") || streq(argv[1], "--run")) && argc >= 3) { if (strcspn(argv[2], "/;$") == strlen(argv[2])) { |
