Skip to content

Commit a21a0cc

Browse files
committed
2023/4/9 Add so many things.
1.更新了GNU Make规则 2.完善了README.md文档,添加了多种生成方式的说明和使用手册的链接 3.添加了使用手册文档 4.完善了Windows下make.cmd的生成方式 5.将lparchs中__arch_xxx__和__arch__的值改为数字,方便预处理判断 6.优化了lparchs宏的实现逻辑,避免某些编译器出错 7.将lpcomps中的__has_acc__改为__has_acc_compiler__,统一命名 8.删除lpstds的__has_c89__,因为它是世界上C语言的第一个标准,标准C语言都支持 8.添加了Python版本的生成规则 9.添加了MS-DOS下的生成方式 修改: Makefile 修改: README.md 新文件: doc/archs.md 新文件: doc/compilers.md 新文件: doc/doc.md 新文件: doc/platforms.md 新文件: doc/stds.md 修改: make.cmd 修改: src/lparchs.h 修改: src/lpcomps.h 修改: src/lpplat.h 修改: src/lpstds.h 新文件: tools/build.py 新文件: tools/dos-make.bat
1 parent 51bb49a commit a21a0cc

File tree

14 files changed

+1023
-65
lines changed

14 files changed

+1023
-65
lines changed

Makefile

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
# Makefile for libplatform
2+
# Written by ChenPi11 <wushengwuxi-msctinoulk@outlook.com>
3+
24
# Prefix settings
35
PREFIX ?= /usr/local
46
SRCDIR ?= $(PWD)/src
57
PWD ?= .
8+
69
# Command settings
710
CAT ?= cat
811
MKDIR ?= mkdir -p
@@ -31,22 +34,28 @@ INSTALL_LIBRARY_DIR = $(PREFIX)/lib
3134
INSTALL_LIST = $(PWD)/install.list
3235

3336
# Targets
37+
# All build
3438
all: platform_predef.h
3539

40+
# Build 'platform_predef.h' to 'build/include'
3641
platform_predef.h:
3742
$(MKDIR) $(OUT_INCLUDE_DIR)
3843
$(CAT) $(SRC_FILE_TITLE) $(SRC_FILES) $(SRC_FILE_END) > $(OUT_INCLUDE_DIR)/$@
3944

45+
# Clean up build results
4046
clean:
4147
$(RM) -r $(BUILD_OUTPUT)
4248

49+
# Install 'platform_predef.h'
4350
install-platform_predef.h:
4451
$(MKDIR) $(INSTALL_INCLUDE_DIR)
4552
$(INSTALL) $(OUT_INCLUDE_DIR)/platform_predef.h $(INSTALL_INCLUDE_DIR)
4653
echo $(INSTALL_INCLUDE_DIR)/platform_predef.h >> $(INSTALL_LIST)
4754

55+
# Uninstall build results
4856
uninstall:
4957
$(RM) $(shell $(CAT) $(INSTALL_LIST))
5058
$(RM) $(INSTALL_LIST)
5159

60+
# Install build results
5261
install: install-platform_predef.h

README.md

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,16 @@ libplatform is a platform check library
1010
make
1111
make install
1212
```
13+
The build results are in the 'build' directory.
1314
### Build on Windows
1415
#### Dependence
1516
+ cmd.exe on Windows
1617
#### Make
1718
```shell
18-
make.cmd
19+
call make.cmd
1920
```
20-
make.cmd don't support install.
21+
make.cmd does not support install.
22+
The build results are in the 'build' directory.
2123
### Build with CMake
2224
#### Dependence
2325
+ CMake (version >= 3.0)
@@ -26,12 +28,39 @@ make.cmd don't support install.
2628
mkdir build
2729
cd build
2830
cmake ..
29-
# Now, build output is in 'build/include'
3031
```
32+
The build results are in the 'build' directory.
33+
### Build with Python
34+
#### Dependence
35+
+ Python 3.x or Python 2.x
36+
+ Python base libraries (platform, shutil)
37+
+ Python build-in libraries (sys, os)
38+
#### Make and Install
39+
```shell
40+
python tools/build.py
41+
python tools/build.py install
42+
```
43+
Try 'python tools/build.py' --help for help
44+
### Build on MS-DOS
45+
**MS-DOS does not support long file names, so include output 'include\platform_predef.h' will be replaced to 'include\libplat.h'**
46+
#### Dependence
47+
+ MS-DOS shell (COMMAND.COM)
48+
#### Make and Install
49+
```shell
50+
cd tools
51+
call dos-make.bat
52+
```
53+
dos-make.bat will chdir to repository root directory automatic.
54+
dos-make.bat does not support install.
55+
The build results are in the 'build' directory.
56+
57+
**Do not use dos-make.bat for build on Windows!**
58+
3159
## Usage
3260
After install, you can use libplatform in C/C++
3361
```c
3462
#include <platform_predef.h>
63+
/*On MS-DOS, <platform_predef.h> is renamed to <libplat.h>*/
3564
#include <stdio.h>
3665
int main()
3766
{
@@ -48,3 +77,6 @@ int main()
4877
printf("Pointer width:%d\n",__POINTER_WIDTH__);
4978
}
5079
```
80+
81+
## Manual
82+
[User Manual](doc/doc.md)

doc/archs.md

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
# Architectures
2+
## Source
3+
src/lparchs.h
4+
## Content
5+
### \_\_arch\_\_
6+
#### Type
7+
macro
8+
#### Description
9+
Represents the processor architecture type
10+
If the judgment fails, the value is '\_\_arch_unknown\_\_'
11+
##### We provide preset architecture types
12+
```c
13+
/*Alpha*/
14+
#define __arch_alpha__ 1
15+
/*x86*/
16+
#define __arch_x86__ 2
17+
/*ARM*/
18+
#define __arch_arm__ 3
19+
/*Blackfin*/
20+
#define __arch_blackfin__ 4
21+
/*Convex*/
22+
#define __arch_convex__ 5
23+
/*Epiphany*/
24+
#define __arch_epiphany__ 6
25+
/*HP/PA RISC*/
26+
#define __arch_hppa__ 7
27+
/*Itanium*/
28+
#define __arch_itanium__ 8
29+
/*Motorola 68k*/
30+
#define __arch_motorola68k__ 9
31+
/*MIPS*/
32+
#define __arch_mips__ 10
33+
/*PowerPC*/
34+
#define __arch_ppc__ 11
35+
/*Pyramid 9810*/
36+
#define __arch_pyramid9810__ 12
37+
/*RS/6000*/
38+
#define __arch_rs6000__ 13
39+
/*SPARC*/
40+
#define __arch_sparc__ 14
41+
/*SuperH*/
42+
#define __arch_superh__ 15
43+
/*SystemZ*/
44+
#define __arch_systemz__ 16
45+
/*TMS320*/
46+
#define __arch_tms320__ 17
47+
/*TMS470*/
48+
#define __arch_tms470__ 18
49+
/*unknown arch*/
50+
#define __arch_unknown__ 0
51+
```
52+
#### Usage
53+
```c
54+
#include <platform_predef.h>
55+
#if (__arch__ == __arch_x86__)
56+
#pragma message "Build in x86 arch"
57+
#elif (__arch__ == __arch_arm__)
58+
#pragma message "Build in arm arch"
59+
#elif
60+
#pragma message "Build in other arch"
61+
#endif
62+
int main(){}
63+
```
64+
### \_\_arch_name\_\_
65+
#### Type
66+
macro
67+
#### Description
68+
Architecture name, like 'uname -m'
69+
If the judgment fails, the value is "unknown"
70+
#### Usage
71+
```c
72+
#include <platform_predef.h>
73+
#include <stdio.h>
74+
int main()
75+
{
76+
printf("Arch name: %s\n", __arch_name__);
77+
}
78+
```
79+
### \_\_POINTER_WIDTH\_\_
80+
#### Type
81+
macro
82+
#### Description
83+
This represents the calculation formula for pointer length
84+
The value is generally 32 or 64
85+
#### Usage
86+
```c
87+
#include <platform_predef.h>
88+
#include <stdio.h>
89+
int main()
90+
{
91+
printf("Pointer width: %ld\n", __POINTER_WIDTH__);
92+
}
93+
```

doc/compilers.md

Lines changed: 165 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,165 @@
1+
# Compilers
2+
## Source
3+
src/lpcomps.h
4+
## Content
5+
## \_\_has_xxx_compiler\_\_
6+
#### Type
7+
macros
8+
#### Description
9+
1 if there is a corresponding compiler, otherwise 0.
10+
The 'xxx' here refers to the compiler name, and details can be found in the 'src/lpcomps.h' source code.
11+
12+
**Note: An environment may contain multiple compiler environments**
13+
#### Usage
14+
```c
15+
#include <platform_predef.h>
16+
#if __has_msvc_compiler__
17+
#error "You are compile with MSVC!"
18+
#endif
19+
int main(){}
20+
```
21+
#### Prototype
22+
```c
23+
/*ACC*/
24+
#define __has_acc_compiler__ 0
25+
/*Altium MicroBlaze C*/
26+
#define __has_has_altium_microblaze_c_compiler__ 0
27+
/*Altium C-to-Hardware*/
28+
#define __has_altium_c_to_hardware_compiler__ 0
29+
/*Amsterdam Compiler Kit*/
30+
#define __has_amsterdam_compiler__ 0
31+
/*ARM Compiler*/
32+
#define __has_arm_compiler__ 0
33+
/*Aztec C*/
34+
#define __has_aztec_c_compiler__ 0
35+
/*Borland C/C++*/
36+
#define __has_borland_compiler__ 0
37+
/*CC65*/
38+
#define __has_cc65_compiler__ 0
39+
/*Clang*/
40+
#define __has_clang_compiler__ 0
41+
/*Comeau*/
42+
#define __has_comeau_compiler__ 0
43+
/*Compaq C/C++*/
44+
#define __has_compaq_compiler__ 0
45+
/*Convex C*/
46+
#define __has_convex_c_compiler__ 0
47+
/*CompCert*/
48+
#define __has_compcert_compiler__ 0
49+
/*Coverity C/C++ Static Analyzer*/
50+
#define __has_coverity_compiler__ 0
51+
/*Cray C*/
52+
#define __has_cray_c_compiler__ 0
53+
/*Diab C/C++*/
54+
#define __has_diab_compiler__ 0
55+
/*DICE C*/
56+
#define __has_dice_c_compiler__ 0
57+
/*Digital Mars*/
58+
#define __has_digital_mars_compiler__ 0
59+
/*Dignus Systems/C++*/
60+
#define __has_dignus_systems_compiler__ 0
61+
/*DJGPP*/
62+
#define __has_djgpp_compiler__ 0
63+
/*EDG C++ Frontend*/
64+
#define __has_edg_compiler__ 0
65+
/*EKOPath*/
66+
#define __has_ekopath_compiler__ 0
67+
/*Fujitsu C++*/
68+
#define __has_fujitsu_compiler__ 0
69+
/*GCC C/C++*/
70+
#define __has_gcc_compiler__ 0
71+
/*Green Hill C/C++*/
72+
#define __has_greenhill_compiler__ 0
73+
/*HP ANSI C*/
74+
#define __has_hpansi_c_compiler__ 0
75+
/*HP aC++*/
76+
#define __has_hpa_compiler__ 0
77+
/*IAR C/C++*/
78+
#define __has_iar_compiler__ 0
79+
/*ImageCraft C*/
80+
#define __has_imagecraft_c_compiler__ 0
81+
/*Intel C/C++*/
82+
#define __has_intel_compiler__ 0
83+
/*KAI C++*/
84+
#define __has_kai_compiler__ 0
85+
/*KEIL CARM*/
86+
#define __has_keil_carm_compiler__ 0
87+
/*KEIL C166*/
88+
#define __has_keil_c166_compiler__ 0
89+
/*KEIL C51*/
90+
#define __has_keil_c51_compiler__ 0
91+
/*LCC*/
92+
#define __has_lcc_compiler__ 0
93+
/*LLVM*/
94+
#define __has_llvm_compiler__ 0
95+
/*MetaWare High C/C++*/
96+
#define __has_metaware_high_compiler__ 0
97+
/*Metrowerks CodeWarrior*/
98+
#define __has_metrowerks_codewarrior_compiler__ 0
99+
/*Microsoft Visual C++*/
100+
#define __has_msvc_compiler__ 0
101+
/*Microtec C/C++*/
102+
#define __has_microtec_compiler__ 0
103+
/*Microway NDP C*/
104+
#define __has_microway_ndp_c_compiler__ 0
105+
/*MinGW*/
106+
#define __has_mingw_compiler__ 0
107+
/*MIPSpro*/
108+
#define __has_mipspro_compiler__ 0
109+
/*Miracle C*/
110+
#define __has_miracle_c_compiler__ 0
111+
/*MPW C++*/
112+
#define __has_mpr_compiler__ 0
113+
/*Norcroft C*/
114+
#define __has_norcroft_c_compiler__ 0
115+
/*NWCC*/
116+
#define __has_nwcc_compiler__ 0
117+
/*Open64*/
118+
#define __has_open64_compiler__ 0
119+
/*Oracle Pro*C Precompiler*/
120+
#define __has_oracle_pro_compiler__ 0
121+
/*Oracle Solaris Studio*/
122+
#define __has_oracle_solaris_studio_compiler__ 0
123+
/*Pacific C*/
124+
#define __has_pacific_c_compiler__ 0
125+
/*Palm C/C++*/
126+
#define __has_palm_compiler__ 0
127+
/*Pelles C*/
128+
#define __has_pelles_c_compiler__ 0
129+
/*Portland Group C/C++*/
130+
#define __has_portland_group_compiler__ 0
131+
/*Renesas C/C++*/
132+
#define __has_renesas_compiler__ 0
133+
/*SAS/C*/
134+
#define __has_sas_c_compiler__ 0
135+
/*SCO OpenServer*/
136+
#define __has_sco_compiler__ 0
137+
/*Small Device C Compiler*/
138+
#define __has_small_device_compiler__ 0
139+
/*SN Compiler*/
140+
#define __has_sn_compiler__ 0
141+
/*Stratus VOS C*/
142+
#define __has_stratus_vos_c_compiler__ 0
143+
/*Symantec C++*/
144+
#define __has_symantec_compiler__ 0
145+
/*TenDRA C/C++*/
146+
#define __has_tendra_compiler__ 0
147+
/*Texas Instruments C/C++ Compiler*/
148+
#define __has_texas_instruments_compiler__ 0
149+
/*THINK C*/
150+
#define __has_think_c_compiler__ 0
151+
/*Tiny C*/
152+
#define __has_tiny_c_compiler__ 0
153+
/*Turbo C/C++*/
154+
#define __has_turboc_compiler__ 0
155+
/*Ultimate C/C++*/
156+
#define __has_ultimate_compiler__ 0
157+
/*USL C*/
158+
#define __has_usl_c_compiler__ 0
159+
/*VBCC*/
160+
#define __has_vbcc_compiler__ 0
161+
/*Watcom C++*/
162+
#define __has_watcom_compiler__ 0
163+
/*Zortech C++*/
164+
#define __has_zortech_compiler__ 0
165+
```

doc/doc.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Libplatform User Manual
2+
[Architectures](./archs.md)
3+
4+
[Compilers](./compilers.md)
5+
6+
[Platforms](./platforms.md)
7+
8+
[C/C++ Standards](./stds.md)

0 commit comments

Comments
 (0)