mirror of
https://github.com/janet-lang/janet
synced 2025-07-20 10:52:54 +00:00
Add stuff.
This commit is contained in:
parent
77344b3f79
commit
9808680413
@ -1,9 +1,14 @@
|
|||||||
# A script to help generate build files on different platforms
|
# A script to help generate build files on different platforms
|
||||||
|
|
||||||
(def- make-cflags "-std=c99 -Wall -Wextra -O2 -shared -fpic")
|
# The Makefile generator
|
||||||
(def- make-ldflags "")
|
|
||||||
|
|
||||||
(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"
|
"Do and get the value of a subshell command"
|
||||||
[command]
|
[command]
|
||||||
(def f (file.popen command))
|
(def f (file.popen command))
|
||||||
@ -25,7 +30,7 @@
|
|||||||
"\n\n")
|
"\n\n")
|
||||||
out)
|
out)
|
||||||
|
|
||||||
(defn generate-make
|
(defn- generate-make
|
||||||
"Generate a makefile"
|
"Generate a makefile"
|
||||||
[out-path sources target]
|
[out-path sources target]
|
||||||
(def out (file.open out-path :w))
|
(def out (file.open out-path :w))
|
||||||
@ -35,8 +40,8 @@
|
|||||||
out
|
out
|
||||||
"# Autogenerated Makefile, do not edit\n"
|
"# Autogenerated Makefile, do not edit\n"
|
||||||
"# Generated at " ($ `date`)
|
"# Generated at " ($ `date`)
|
||||||
"\nCFLAGS:=" make-cflags
|
"\nCFLAGS:=" (string.join make-cflags " ")
|
||||||
"\nLDFLAGS:=" make-ldflags
|
"\nLDFLAGS:=" (string.join make-ldflags " ")
|
||||||
"\nSOURCES:=" (string.join csources " ")
|
"\nSOURCES:=" (string.join csources " ")
|
||||||
"\nHEADERS:=" (string.join hsources " ")
|
"\nHEADERS:=" (string.join hsources " ")
|
||||||
"\nOBJECTS:=$(patsubst %.c,%.o,${SOURCES})"
|
"\nOBJECTS:=$(patsubst %.c,%.o,${SOURCES})"
|
||||||
@ -50,3 +55,49 @@
|
|||||||
# Phony targets
|
# Phony targets
|
||||||
(emit-rule out ".PHONY" @["all" "clean"])
|
(emit-rule out ".PHONY" @["all" "clean"])
|
||||||
nil)
|
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))
|
||||||
|
|
||||||
|
@ -1,49 +1,25 @@
|
|||||||
@rem Build dst on windows
|
@rem Generated batch script, run in 'Visual Studio Developer Prompt'
|
||||||
@rem
|
|
||||||
@rem Open a "Windows SDK Command Shell" and cd to the dst directory
|
@rem
|
||||||
@rem Then run this script with no arguments to build the executable
|
|
||||||
|
|
||||||
@echo off
|
@echo off
|
||||||
|
|
||||||
@rem Ensure correct command prompt
|
cl /nologo /I..\..\src\include /c /O2 /W3 hello.c
|
||||||
@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
|
|
||||||
@if errorlevel 1 goto :BUILDFAIL
|
@if errorlevel 1 goto :BUILDFAIL
|
||||||
|
|
||||||
echo === Successfully built hello.dll for Windows ===
|
link /nologo /dll ..\..\dst.lib /out:hello.dll *.obj
|
||||||
echo === Run 'build clean' to delete build artifacts. ===
|
if errorlevel 1 goto :BUILDFAIL
|
||||||
|
|
||||||
|
@echo .
|
||||||
|
@echo ======
|
||||||
|
@echo Build Succeeded.
|
||||||
|
@echo =====
|
||||||
exit /b 0
|
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
|
:BUILDFAIL
|
||||||
@echo.
|
@echo .
|
||||||
@echo *******************************************************
|
@echo =====
|
||||||
@echo *** Build FAILED -- Please check the error messages ***
|
@echo BUILD FAILED. See Output For Details.
|
||||||
@echo *******************************************************
|
@echo =====
|
||||||
|
@echo .
|
||||||
exit /b 1
|
exit /b 1
|
||||||
|
@ -1080,7 +1080,7 @@
|
|||||||
env)
|
env)
|
||||||
|
|
||||||
(defn default-error-handler
|
(defn default-error-handler
|
||||||
[source t x f]
|
@[source t x f]
|
||||||
(file.write stdout (string t " error in " source ": "))
|
(file.write stdout (string t " error in " source ": "))
|
||||||
(if (bytes? x)
|
(if (bytes? x)
|
||||||
(do (file.write stdout x)
|
(do (file.write stdout x)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user