改进的newlisp编译脚本,只需要配置

2023-11-27 01:32

本文主要是介绍改进的newlisp编译脚本,只需要配置,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

前面有一篇Say bye to CMake and Makefile我开始用自己编写的newlisp脚本替代CMake,今天对前面的进行改进。

改进部分是:

1. newlisp armory模块的引入和初始化 部分可以重用

2. 将头文件所在目录,cpp或者cc文件所在目录以及依赖库名称等 作为配置单独抽出来,可以根据不同的项目进行配置


现在看改过后的代码:

rebuild.lsp是主要执行脚本

#!/usr/bin/newlisp ;; init
(load "/opt/armory_config.lsp")
(load "build_config.lsp");; clean view/*.cpp files generated from cppcms_tmpl_cc
(set 'view-dir "../codes/main/src/view")
(if (directory? view-dir)(file:clean-folder view-dir)(make-dir view-dir))(set 'tmpl-dir "../codes/main/template");; generate .cc files in view folder
(load "tmpl.lsp")
(tmpl-to-cc tmpl-dir view-dir);; compile all c++ files to .o file in ./o folder
(load "g++.lsp")
(compile include-paths src-paths o-dir);; link all .o files
(dynamic-link o-dir bin-dir binary-name libs)(exit)

依赖的/opt/armory_config.lsp用来配置newlisp_armory模块:

(env "NEWLISP_ARMORY_HOME" "/home/dean/github/newlisp_armory")
(set 'armory-folder (env "NEWLISP_ARMORY_HOME"))
(println (append "newlisp armory home folder: " armory-folder))
(load (append armory-folder "/codes/file/file.lsp"))
(file:init)

现在有了一个新的build_config.lsp文件,用来专门做配置:

(set 'include-paths (list "../codes/main/include""../codes/main/src/../../loki-0.1.7/include"))(set 'src-paths (list "../codes/main/src""../codes/main/src/bean""../codes/main/src/controller""../codes/main/src/helper""../codes/main/src/module""../codes/main/src/service""../codes/main/src/view"))
(set 'libs (list "pthread""cppcms""mongoclient""booster""loki""cryptopp""boost_system""boost_thread""boost_filesystem"))(set 'o-dir "./o")
(set 'bin-dir "bin")
(set 'binary-name "sports_lottery_d")

上面配置了5项,不包含cppcms的部分,cppcms的tmpl文件编译还没有抽出来,仍然在rebuild.lsp脚本文件中。不过对于其他不用CppCMS的GCC编译来讲,直接删除即可。


g++.lsp文件不变。

;; @syntax (compile include-dirs src-dirs o-dir)
;; @parameter include-dir a list contains one or more relative or absolute include directories
;; @parameter src-dirs a list contains one or more relative or absolute src dirs
(define (compile include-dirs src-dirs o-dir)(if (directory? o-dir)(file:clean-folder o-dir)(make-dir o-dir))(set 'path1 "")(dolist (path include-dirs)(set 'path1 (append path1 "-I" path " ")))(set 'cmd-template (format "/usr/bin/c++ -g %s -Wall -o %s/" path1 o-dir))(dolist (dir src-dirs)(compile-dir dir cmd-template)));; @syntax (compile-dir dir cmd-template)
;; @parameter dir one folder which contains many .cc or .cpp files
;; @parameter cmd-template the command template that has -g, -Wall and -I args 
(define (compile-dir dir cmd-template)(set 'file-list (directory dir "\\.cc$|\\.cpp$"))(println "dir: " dir)(dolist (cc-path file-list)(set 'str (append cc-path ".o"))(set 'cmd (append cmd-template  str " -c "  dir "/" cc-path))(println cmd)(exec cmd)));; @syntax (dynamic-link o-dir bin-dir binary-name libs)
;; @parameter o-dir the direcotry includs all .o files
;; @parameter bin-dir the location of linked binary file
;; @libs the list of all dependencies
(define (dynamic-link o-dir bin-dir binary-name libs)(if (directory? bin-dir)(file:clean-folder bin-dir)(make-dir bin-dir))(set 'cmd "/usr/bin/c++ -g")(set 'o-files (directory o-dir "\\.o"))(dolist (o-file o-files)(set 'cmd (append cmd " " (real-path o-dir) "/" o-file)))(set 'cmd (append cmd " -o " bin-dir "/" binary-name " -rdynamic"))(dolist (lib libs)(set 'cmd (append cmd " -l" lib)))(println cmd)(exec cmd));; @syntax (static-link o-dir bin-dir binary-name libs)
;; @parameter o-dir the direcotry includs all .o files
;; @parameter bin-dir the location of linked binary file
;; @libs the list of all dependencies
(define (static-link o-dir bin-dir binary-name libs)(if (directory? bin-dir)(file:clean-folder bin-dir)(make-dir bin-dir))(set 'cmd "/usr/bin/c++ -g ")(set 'o-files (directory o-dir "\\.o"))(dolist (o-file o-files)(set 'cmd (append cmd " " (real-path o-dir) "/" o-file)))(set 'cmd (append cmd " -o " bin-dir "/" binary-name " -static-libgcc -static-libstdc++ -static -L/usr/lib/x86_64-linux-gnu"))(dolist (lib libs)(set 'cmd (append cmd " -l" lib))(println cmd))(exec cmd))


tmpl.lsp文件内容也不变:

(define (get-extension name)(first (regex "[^.]*$" name)));; @syntax (remove-extension name)
;; @return file name without extension
;; @note remove extension name e.g a.b .b is extension, it will be removed
(define (remove-extension name)((regex "(.*)\\.(.*)$" name) 3));; @syntax (tmpl-to-cc)
;; @note find all tmpl files in tmpl-folder, translate them into *.cc files
(define (tmpl-to-cc tmpl-folder cc-folder)(set 'tmpl-files (directory tmpl-folder "\\.tmpl"))(set 'cmd-tmpl (append "cppcms_tmpl_cc " tmpl-folder "/%s -o " cc-folder "/%s.cc"))(dolist (tmpl-file tmpl-files)(set 'cmd (format cmd-tmpl tmpl-file (remove-extension tmpl-file)))(println cmd)(exec cmd))
)



这篇关于改进的newlisp编译脚本,只需要配置的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/426706

相关文章

Nginx 配置跨域的实现及常见问题解决

《Nginx配置跨域的实现及常见问题解决》本文主要介绍了Nginx配置跨域的实现及常见问题解决,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来... 目录1. 跨域1.1 同源策略1.2 跨域资源共享(CORS)2. Nginx 配置跨域的场景2.1

gitlab安装及邮箱配置和常用使用方式

《gitlab安装及邮箱配置和常用使用方式》:本文主要介绍gitlab安装及邮箱配置和常用使用方式,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录1.安装GitLab2.配置GitLab邮件服务3.GitLab的账号注册邮箱验证及其分组4.gitlab分支和标签的

MySQL MCP 服务器安装配置最佳实践

《MySQLMCP服务器安装配置最佳实践》本文介绍MySQLMCP服务器的安装配置方法,本文结合实例代码给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友参考下... 目录mysql MCP 服务器安装配置指南简介功能特点安装方法数据库配置使用MCP Inspector进行调试开发指

Redis Cluster模式配置

《RedisCluster模式配置》:本文主要介绍RedisCluster模式配置,本文给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友参考下吧... 目录分片 一、分片的本质与核心价值二、分片实现方案对比 ‌三、分片算法详解1. ‌范围分片(顺序分片)‌2. ‌哈希分片3. ‌虚

Linux脚本(shell)的使用方式

《Linux脚本(shell)的使用方式》:本文主要介绍Linux脚本(shell)的使用方式,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录概述语法详解数学运算表达式Shell变量变量分类环境变量Shell内部变量自定义变量:定义、赋值自定义变量:引用、修改、删

SpringBoot项目配置logback-spring.xml屏蔽特定路径的日志

《SpringBoot项目配置logback-spring.xml屏蔽特定路径的日志》在SpringBoot项目中,使用logback-spring.xml配置屏蔽特定路径的日志有两种常用方式,文中的... 目录方案一:基础配置(直接关闭目标路径日志)方案二:结合 Spring Profile 按环境屏蔽关

Maven 配置中的 <mirror>绕过 HTTP 阻断机制的方法

《Maven配置中的<mirror>绕过HTTP阻断机制的方法》:本文主要介绍Maven配置中的<mirror>绕过HTTP阻断机制的方法,本文给大家分享问题原因及解决方案,感兴趣的朋友一... 目录一、问题场景:升级 Maven 后构建失败二、解决方案:通过 <mirror> 配置覆盖默认行为1. 配置示

Springboot3+将ID转为JSON字符串的详细配置方案

《Springboot3+将ID转为JSON字符串的详细配置方案》:本文主要介绍纯后端实现Long/BigIntegerID转为JSON字符串的详细配置方案,s基于SpringBoot3+和Spr... 目录1. 添加依赖2. 全局 Jackson 配置3. 精准控制(可选)4. OpenAPI (Spri

maven私服配置全过程

《maven私服配置全过程》:本文主要介绍maven私服配置全过程,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录使用Nexus作为 公司maven私服maven 私服setttings配置maven项目 pom配置测试效果总结使用Nexus作为 公司maven私

springboot加载不到nacos配置中心的配置问题处理

《springboot加载不到nacos配置中心的配置问题处理》:本文主要介绍springboot加载不到nacos配置中心的配置问题处理,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑... 目录springboot加载不到nacos配置中心的配置两种可能Spring Boot 版本Nacos