Skip to content

Commit 51bb49a

Browse files
committed
2023/4/5 Add CMake and cmd build
1.添加了CMake生成方式和cmd.exe生成方式 2.完善了项目结构 3.完善了Makefile 4.删除Python生成方式:make.py 5.修复了一些bug 6.将所有文件结尾由CR LF改为LF,make.cmd除外 7.完善了README.md文档,添加生成方式和用法的说明 8.修改了输出文件名,libplatform.h改名为platform_predef.h 9.更新.gitignore 修改: .gitignore 新文件: CMakeLists.txt 修改: LICENSE 修改: Makefile 修改: README.md 删除: include/end.h 新文件: make.cmd 重命名: src/lpcomps_make.py -> src/_lpcomps_make.py 新文件: src/end.h 重命名: include/lparchs.h -> src/lparchs.h 重命名: include/lpcomps.h -> src/lpcomps.h 重命名: include/lpplat.h -> src/lpplat.h 重命名: include/lpstds.h -> src/lpstds.h 删除: src/make.py 重命名: include/title.h -> src/title.h
1 parent b3080e1 commit 51bb49a

File tree

15 files changed

+1352
-1226
lines changed

15 files changed

+1352
-1226
lines changed

.gitignore

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
# Build output dir
2-
build/
3-
# Editor config
4-
.vscode/
1+
# libplatform .gitignore
2+
# Build output dir
3+
build/
4+
# Editor config
5+
.vscode/
6+
# Makefile install data
7+
install.list

CMakeLists.txt

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# CMakeLists for libplatform
2+
cmake_minimum_required(VERSION 3.0)
3+
4+
# Project
5+
project(libplatform)
6+
7+
# Source path
8+
set(LP_SOURCE ${CMAKE_SOURCE_DIR})
9+
set(LP_SRCDIR ${LP_SOURCE}/src)
10+
set(LP_FILE_TITLE ${LP_SRCDIR}/title.h)
11+
set(LP_FILE_END ${LP_SRCDIR}/end.h)
12+
set(LP_FILES ${LP_FILE_TITLE} ${LP_SRCDIR}/lparchs.h ${LP_SRCDIR}/lpcomps.h ${LP_SRCDIR}/lpplat.h ${LP_SRCDIR}/lpstds.h ${LP_FILE_END})
13+
14+
# Build path
15+
set(LP_BUILD_OUTPUT ${CMAKE_BINARY_DIR})
16+
set(LP_OUT_INCLUDE_DIR ${LP_BUILD_OUTPUT}/include)
17+
set(LP_OUT_RUNTIME_DIR ${LP_BUILD_OUTPUT}/bin)
18+
set(LP_OUT_LIBRARY_DIR ${LP_BUILD_OUTPUT}/lib)
19+
20+
# Make include
21+
file(REMOVE ${LP_OUT_INCLUDE_DIR}/platform_predef.h)
22+
foreach(FILE ${LP_FILES})
23+
message("Adding ${FILE}...")
24+
file(READ ${FILE} _DATA )
25+
write_file(${LP_OUT_INCLUDE_DIR}/platform_predef.h ${_DATA} APPEND)
26+
endforeach()

LICENSE

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,24 @@
1-
This is free and unencumbered software released into the public domain.
2-
3-
Anyone is free to copy, modify, publish, use, compile, sell, or
4-
distribute this software, either in source code form or as a compiled
5-
binary, for any purpose, commercial or non-commercial, and by any
6-
means.
7-
8-
In jurisdictions that recognize copyright laws, the author or authors
9-
of this software dedicate any and all copyright interest in the
10-
software to the public domain. We make this dedication for the benefit
11-
of the public at large and to the detriment of our heirs and
12-
successors. We intend this dedication to be an overt act of
13-
relinquishment in perpetuity of all present and future rights to this
14-
software under copyright law.
15-
16-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17-
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18-
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19-
IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
20-
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21-
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22-
OTHER DEALINGS IN THE SOFTWARE.
23-
24-
For more information, please refer to <https://unlicense.org>
1+
This is free and unencumbered software released into the public domain.
2+
3+
Anyone is free to copy, modify, publish, use, compile, sell, or
4+
distribute this software, either in source code form or as a compiled
5+
binary, for any purpose, commercial or non-commercial, and by any
6+
means.
7+
8+
In jurisdictions that recognize copyright laws, the author or authors
9+
of this software dedicate any and all copyright interest in the
10+
software to the public domain. We make this dedication for the benefit
11+
of the public at large and to the detriment of our heirs and
12+
successors. We intend this dedication to be an overt act of
13+
relinquishment in perpetuity of all present and future rights to this
14+
software under copyright law.
15+
16+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19+
IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
20+
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21+
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22+
OTHER DEALINGS IN THE SOFTWARE.
23+
24+
For more information, please refer to <https://unlicense.org>

Makefile

Lines changed: 52 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,52 @@
1-
all:
2-
cd src && python make.py
3-
clean:
4-
rm -r build
1+
# Makefile for libplatform
2+
# Prefix settings
3+
PREFIX ?= /usr/local
4+
SRCDIR ?= $(PWD)/src
5+
PWD ?= .
6+
# Command settings
7+
CAT ?= cat
8+
MKDIR ?= mkdir -p
9+
INSTALL ?= install
10+
RM ?= rm -f
11+
12+
# Source path
13+
SRC_FILES = \
14+
$(SRCDIR)/lparchs.h \
15+
$(SRCDIR)/lpcomps.h \
16+
$(SRCDIR)/lpplat.h \
17+
$(SRCDIR)/lpstds.h
18+
SRC_FILE_TITLE = $(SRCDIR)/title.h
19+
SRC_FILE_END = $(SRCDIR)/end.h
20+
21+
# Build path
22+
BUILD_OUTPUT = $(PWD)/build
23+
OUT_INCLUDE_DIR = $(BUILD_OUTPUT)/include
24+
OUT_RUNIME_DIR = $(BUILD_OUTPUT)/bin
25+
OUT_LIBRARY_DIR = $(BUILD_OUTPUT)/lib
26+
27+
# Install path
28+
INSTALL_INCLUDE_DIR = $(PREFIX)/include
29+
INSTALL_RUNTIME_DIR = $(PREFIX)/bin
30+
INSTALL_LIBRARY_DIR = $(PREFIX)/lib
31+
INSTALL_LIST = $(PWD)/install.list
32+
33+
# Targets
34+
all: platform_predef.h
35+
36+
platform_predef.h:
37+
$(MKDIR) $(OUT_INCLUDE_DIR)
38+
$(CAT) $(SRC_FILE_TITLE) $(SRC_FILES) $(SRC_FILE_END) > $(OUT_INCLUDE_DIR)/$@
39+
40+
clean:
41+
$(RM) -r $(BUILD_OUTPUT)
42+
43+
install-platform_predef.h:
44+
$(MKDIR) $(INSTALL_INCLUDE_DIR)
45+
$(INSTALL) $(OUT_INCLUDE_DIR)/platform_predef.h $(INSTALL_INCLUDE_DIR)
46+
echo $(INSTALL_INCLUDE_DIR)/platform_predef.h >> $(INSTALL_LIST)
47+
48+
uninstall:
49+
$(RM) $(shell $(CAT) $(INSTALL_LIST))
50+
$(RM) $(INSTALL_LIST)
51+
52+
install: install-platform_predef.h

README.md

Lines changed: 50 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,50 @@
1-
# libplatform
2-
libplatform is a platform check library
1+
# libplatform
2+
libplatform is a platform check library
3+
## Build
4+
### Build with GNU Makefile
5+
#### Dependence
6+
+ GNU Make
7+
+ GNU/Linux commands: **cat, mkdir, install, rm, echo**
8+
#### Make and Install
9+
```shell
10+
make
11+
make install
12+
```
13+
### Build on Windows
14+
#### Dependence
15+
+ cmd.exe on Windows
16+
#### Make
17+
```shell
18+
make.cmd
19+
```
20+
make.cmd don't support install.
21+
### Build with CMake
22+
#### Dependence
23+
+ CMake (version >= 3.0)
24+
#### Make
25+
```shell
26+
mkdir build
27+
cd build
28+
cmake ..
29+
# Now, build output is in 'build/include'
30+
```
31+
## Usage
32+
After install, you can use libplatform in C/C++
33+
```c
34+
#include <platform_predef.h>
35+
#include <stdio.h>
36+
int main()
37+
{
38+
if(__has_windows__)
39+
{
40+
printf("Compile in Windows!\n");
41+
}
42+
else
43+
{
44+
printf("Compile non-Windows!\n");
45+
}
46+
printf("Target arch:%s\n",__arch__);
47+
printf("Target arch name:%s\n",__arch_name__);
48+
printf("Pointer width:%d\n",__POINTER_WIDTH__);
49+
}
50+
```

include/end.h

Lines changed: 0 additions & 1 deletion
This file was deleted.

make.cmd

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
@echo off
2+
rem Maker for libplatform on Windows
3+
echo This is maker for libplatform on Windows.
4+
echo This tool can only make include to 'build\include' but not support install.
5+
echo.
6+
7+
rem Source path
8+
set SRCDIR = "."
9+
echo %SRCDIR%
10+
exit 0
11+
rem Remove old output
12+
rmdir /s /q build
13+
14+
rem Make build output dir
15+
mkdir build
16+
17+
rem Make include
18+
mkdir build\include
19+
type src\title.h src\lparchs.h src\lpcomps.h src\lpplat.h src\lpstds.h src\end.h > build\include\platform_predef.h
20+
21+
22+
rem Make done.
23+
echo.
24+
echo done.
Lines changed: 38 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,38 @@
1-
#!/usr/bin/env python
2-
f=open("lpcomps.h")
3-
import sys
4-
for i in range(10):
5-
f.readline()
6-
defs=[]
7-
8-
class Has:
9-
zs=""
10-
name=""
11-
12-
while(1):
13-
zs=f.readline().strip()
14-
name=f.readline().strip().replace("#define ","").replace(" 0","").strip()
15-
if(zs=="" or name==""):
16-
break
17-
h=Has()
18-
h.zs=zs
19-
h.name=name
20-
defs.append(h)
21-
22-
23-
for i in defs:
24-
print(i.zs,i.name,end="\n>")
25-
t=input().split(",")
26-
for j in range(len(t)):
27-
t[j]="defined("+t[j]+")"
28-
pd=" || ".join(t)
29-
print(pd)
30-
print("#elif "+pd,file=sys.stderr)
31-
print("#undef "+i.name,file=sys.stderr)
32-
print(i.zs,file=sys.stderr)
33-
print("#define "+i.name+" 1",file=sys.stderr)
34-
f.close()
1+
#! /usr/bin/env python
2+
# This is the developer's script
3+
# Don't use it unless you know exactly what you do!
4+
if(input("This is the developer's script,don't use it unless you know exactly what you do (Y/N)")!="Y"):
5+
raise SystemExit
6+
f=open("lpcomps_make.h")
7+
import sys
8+
for i in range(10):
9+
f.readline()
10+
defs=[]
11+
12+
class Has:
13+
zs=""
14+
name=""
15+
16+
while(1):
17+
zs=f.readline().strip()
18+
name=f.readline().strip().replace("#define ","").replace(" 0","").strip()
19+
if(zs=="" or name==""):
20+
break
21+
h=Has()
22+
h.zs=zs
23+
h.name=name
24+
defs.append(h)
25+
26+
27+
for i in defs:
28+
print(i.zs,i.name,end="\n>")
29+
t=input().split(",")
30+
for j in range(len(t)):
31+
t[j]="defined("+t[j]+")"
32+
pd=" || ".join(t)
33+
print(pd)
34+
print("#elif "+pd,file=sys.stderr)
35+
print("#undef "+i.name,file=sys.stderr)
36+
print(i.zs,file=sys.stderr)
37+
print("#define "+i.name+" 1",file=sys.stderr)
38+
f.close()

src/end.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
#endif

0 commit comments

Comments
 (0)