改进的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

相关文章

mybatis映射器配置小结

《mybatis映射器配置小结》本文详解MyBatis映射器配置,重点讲解字段映射的三种解决方案(别名、自动驼峰映射、resultMap),文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定... 目录select中字段的映射问题使用SQL语句中的别名功能使用mapUnderscoreToCame

Linux下MySQL数据库定时备份脚本与Crontab配置教学

《Linux下MySQL数据库定时备份脚本与Crontab配置教学》在生产环境中,数据库是核心资产之一,定期备份数据库可以有效防止意外数据丢失,本文将分享一份MySQL定时备份脚本,并讲解如何通过cr... 目录备份脚本详解脚本功能说明授权与可执行权限使用 Crontab 定时执行编辑 Crontab添加定

Java使用jar命令配置服务器端口的完整指南

《Java使用jar命令配置服务器端口的完整指南》本文将详细介绍如何使用java-jar命令启动应用,并重点讲解如何配置服务器端口,同时提供一个实用的Web工具来简化这一过程,希望对大家有所帮助... 目录1. Java Jar文件简介1.1 什么是Jar文件1.2 创建可执行Jar文件2. 使用java

SpringBoot 多环境开发实战(从配置、管理与控制)

《SpringBoot多环境开发实战(从配置、管理与控制)》本文详解SpringBoot多环境配置,涵盖单文件YAML、多文件模式、MavenProfile分组及激活策略,通过优先级控制灵活切换环境... 目录一、多环境开发基础(单文件 YAML 版)(一)配置原理与优势(二)实操示例二、多环境开发多文件版

Vite 打包目录结构自定义配置小结

《Vite打包目录结构自定义配置小结》在Vite工程开发中,默认打包后的dist目录资源常集中在asset目录下,不利于资源管理,本文基于Rollup配置原理,本文就来介绍一下通过Vite配置自定义... 目录一、实现原理二、具体配置步骤1. 基础配置文件2. 配置说明(1)js 资源分离(2)非 JS 资

MySQL8 密码强度评估与配置详解

《MySQL8密码强度评估与配置详解》MySQL8默认启用密码强度插件,实施MEDIUM策略(长度8、含数字/字母/特殊字符),支持动态调整与配置文件设置,推荐使用STRONG策略并定期更新密码以提... 目录一、mysql 8 密码强度评估机制1.核心插件:validate_password2.密码策略级

ShardingProxy读写分离之原理、配置与实践过程

《ShardingProxy读写分离之原理、配置与实践过程》ShardingProxy是ApacheShardingSphere的数据库中间件,通过三层架构实现读写分离,解决高并发场景下数据库性能瓶... 目录一、ShardingProxy技术定位与读写分离核心价值1.1 技术定位1.2 读写分离核心价值二

QT Creator配置Kit的实现示例

《QTCreator配置Kit的实现示例》本文主要介绍了使用Qt5.12.12与VS2022时,因MSVC编译器版本不匹配及WindowsSDK缺失导致配置错误的问题解决,感兴趣的可以了解一下... 目录0、背景:qt5.12.12+vs2022一、症状:二、原因:(可以跳过,直奔后面的解决方法)三、解决方

SpringBoot路径映射配置的实现步骤

《SpringBoot路径映射配置的实现步骤》本文介绍了如何在SpringBoot项目中配置路径映射,使得除static目录外的资源可被访问,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一... 目录SpringBoot路径映射补:springboot 配置虚拟路径映射 @RequestMapp

Nginx中配置使用非默认80端口进行服务的完整指南

《Nginx中配置使用非默认80端口进行服务的完整指南》在实际生产环境中,我们经常需要将Nginx配置在其他端口上运行,本文将详细介绍如何在Nginx中配置使用非默认端口进行服务,希望对大家有所帮助... 目录一、为什么需要使用非默认端口二、配置Nginx使用非默认端口的基本方法2.1 修改listen指令