1
0
mirror of https://github.com/janet-lang/janet synced 2024-11-10 10:49:54 +00:00

Add stuff.

This commit is contained in:
Calvin Rose 2018-08-13 17:40:55 -04:00
parent 77344b3f79
commit 9808680413
3 changed files with 74 additions and 47 deletions

View File

@ -1,9 +1,14 @@
# A script to help generate build files on different platforms
(def- make-cflags "-std=c99 -Wall -Wextra -O2 -shared -fpic")
(def- make-ldflags "")
# The Makefile generator
(defn $
(def- make-cflags @["-std=c99" "-Wall" "-Wextra" "-O2" "-shared" "-fpic"])
(def- make-ldflags @[])
(if (= :macos (os.which))
(array.push make-cflags "undefined -dynamic_lookup"))
(defn- $
"Do and get the value of a subshell command"
[command]
(def f (file.popen command))
@ -25,7 +30,7 @@
"\n\n")
out)
(defn generate-make
(defn- generate-make
"Generate a makefile"
[out-path sources target]
(def out (file.open out-path :w))
@ -35,8 +40,8 @@
out
"# Autogenerated Makefile, do not edit\n"
"# Generated at " ($ `date`)
"\nCFLAGS:=" make-cflags
"\nLDFLAGS:=" make-ldflags
"\nCFLAGS:=" (string.join make-cflags " ")
"\nLDFLAGS:=" (string.join make-ldflags " ")
"\nSOURCES:=" (string.join csources " ")
"\nHEADERS:=" (string.join hsources " ")
"\nOBJECTS:=$(patsubst %.c,%.o,${SOURCES})"
@ -50,3 +55,49 @@
# Phony targets
(emit-rule out ".PHONY" @["all" "clean"])
nil)
# The batch script generator (windows)
(defn- batch-crule
"Create a snippet to compile a single C file to an .obj file"
[file-path]
(string
`cl /nologo /I..\..\src\include /c /O2 /W3 `
file-path
"\n@if errorlevel 1 goto :BUILDFAIL"))
(defn- generate-batch
"Generate a batch file for windows"
[out-path sources target]
(def out (file.open out-path :w))
(def csources (filter (fn [x] (= ".c" (string.slice x -2))) sources))
(file.write
out
"@rem Generated batch script, run in 'Visual Studio Developer Prompt'\n"
"\n@rem \n\n"
"@echo off\n\n"
(string.join (map batch-crule csources) "\n\n")
"\n\n"
`link /nologo /dll ..\..\dst.lib /out:` target `.dll *.obj`
"\nif errorlevel 1 goto :BUILDFAIL"
"\n\n@echo .\n@echo ======\n@echo Build Succeeded.\n@echo =====\n"
"exit /b 0\n\n"
":BUILDFAIL\n"
"@echo .\n"
"@echo =====\n"
"@echo BUILD FAILED. See Output For Details.\n"
"@echo =====\n"
"@echo .\n"
"exit /b 1\n")
(file.flush out)
(file.close out)
nil)
(defn generate
"Generate the build files for a given library."
[out-path sources target]
((if (= :windows (os.which)) generate-batch generate-make)
out-path
sources
target))

View File

@ -1,49 +1,25 @@
@rem Build dst on windows
@rem
@rem Open a "Windows SDK Command Shell" and cd to the dst directory
@rem Then run this script with no arguments to build the executable
@rem Generated batch script, run in 'Visual Studio Developer Prompt'
@rem
@echo off
@rem Ensure correct command prompt
@if not defined INCLUDE goto :BADCMD
@rem Subcommands
@if "%1"=="clean" goto CLEAN
@rem Set compile and link options here
@setlocal
@set DST_COMPILE=cl /nologo /I..\..\src\include /c /O2 /W3
@set DST_LINK=link /nologo /dll ..\..\dst.lib
@rem Build the sources
for %%f in (*.c) do (
@%DST_COMPILE% %%f
@if errorlevel 1 goto :BUILDFAIL
)
%DST_LINK% /out:hello.dll *.obj
cl /nologo /I..\..\src\include /c /O2 /W3 hello.c
@if errorlevel 1 goto :BUILDFAIL
echo === Successfully built hello.dll for Windows ===
echo === Run 'build clean' to delete build artifacts. ===
link /nologo /dll ..\..\dst.lib /out:hello.dll *.obj
if errorlevel 1 goto :BUILDFAIL
@echo .
@echo ======
@echo Build Succeeded.
@echo =====
exit /b 0
@rem Not using correct command line
:BADCMD
@echo Use a Visual Studio Developer Command Prompt to run this script
exit /b 1
@rem Clean build artifacts
:CLEAN
del *.obj
del hello.*
exit /b 0
@rem Build failed
:BUILDFAIL
@echo.
@echo *******************************************************
@echo *** Build FAILED -- Please check the error messages ***
@echo *******************************************************
@echo .
@echo =====
@echo BUILD FAILED. See Output For Details.
@echo =====
@echo .
exit /b 1

View File

@ -1080,7 +1080,7 @@
env)
(defn default-error-handler
[source t x f]
@[source t x f]
(file.write stdout (string t " error in " source ": "))
(if (bytes? x)
(do (file.write stdout x)