1*1c60b9acSAndroid Build Coastguard Worker# Guidance for porting to new platform 2*1c60b9acSAndroid Build Coastguard Worker 3*1c60b9acSAndroid Build Coastguard WorkerWhere differences existed between the initial POSIX platform for lws and other 4*1c60b9acSAndroid Build Coastguard Workersupported platforms like Windows, `lws_plat_...()` apis were added to move 5*1c60b9acSAndroid Build Coastguard Workerhandling to platform-specific code in `./lib/plat/`. 6*1c60b9acSAndroid Build Coastguard Worker 7*1c60b9acSAndroid Build Coastguard WorkerDepending o which platform is built, different platform-specific implementations 8*1c60b9acSAndroid Build Coastguard Workerof these `lws_plat...()` apis get built. 9*1c60b9acSAndroid Build Coastguard Worker 10*1c60b9acSAndroid Build Coastguard Worker## 1) Prepare the cmake cross-build file if necessary 11*1c60b9acSAndroid Build Coastguard Worker 12*1c60b9acSAndroid Build Coastguard WorkerCMake isolates its settings for cross-build into a separate file, which can be 13*1c60b9acSAndroid Build Coastguard Workerused to different cmake projects for the same platform as well. 14*1c60b9acSAndroid Build Coastguard Worker 15*1c60b9acSAndroid Build Coastguard WorkerFind a similar examples already in `./contrib/cross-*` and copy and adapt it 16*1c60b9acSAndroid Build Coastguard Workeras needed, 17*1c60b9acSAndroid Build Coastguard Worker 18*1c60b9acSAndroid Build Coastguard WorkerAll settings related to toolchain should go in there. For cross-toolchain, 19*1c60b9acSAndroid Build Coastguard Workerthe convention is to pass the path to its installed directory in `CROSS_PATH` 20*1c60b9acSAndroid Build Coastguard Workerenvironment variable. 21*1c60b9acSAndroid Build Coastguard Worker 22*1c60b9acSAndroid Build Coastguard Worker## 2) Copy the closest platform dir in ./lib/plat 23*1c60b9acSAndroid Build Coastguard Worker 24*1c60b9acSAndroid Build Coastguard WorkerWholesale copy the closest existing platform dir to `/lib/plat/myplatform` and 25*1c60b9acSAndroid Build Coastguard Workerrename the files. 26*1c60b9acSAndroid Build Coastguard Worker 27*1c60b9acSAndroid Build Coastguard WorkerRemove stuff specific to the original platform. 28*1c60b9acSAndroid Build Coastguard Worker 29*1c60b9acSAndroid Build Coastguard Worker## 3) Add a flag in CMakeLists.txt 30*1c60b9acSAndroid Build Coastguard Worker 31*1c60b9acSAndroid Build Coastguard WorkerCut and paste a flag to select your platform, preferably `LWS_PLAT_MYPLATFORM` or so 32*1c60b9acSAndroid Build Coastguard Worker 33*1c60b9acSAndroid Build Coastguard Worker## 4) Add a section to force-select and deselect other cmake options based on platform flag 34*1c60b9acSAndroid Build Coastguard Worker 35*1c60b9acSAndroid Build Coastguard WorkerSome options on by default may not make sense on your platform, and others off 36*1c60b9acSAndroid Build Coastguard Workerby default may be mandatory. After the options() section in CMakeLists.txt, you 37*1c60b9acSAndroid Build Coastguard Workercan use this kind of structure 38*1c60b9acSAndroid Build Coastguard Worker 39*1c60b9acSAndroid Build Coastguard Worker``` 40*1c60b9acSAndroid Build Coastguard Worker if (LWS_PLAT_MYPLATFORM) 41*1c60b9acSAndroid Build Coastguard Worker set(LWS_WITH_XXXX 0) 42*1c60b9acSAndroid Build Coastguard Worker endif() 43*1c60b9acSAndroid Build Coastguard Worker``` 44*1c60b9acSAndroid Build Coastguard Worker 45*1c60b9acSAndroid Build Coastguard Workerto enforce implicit requirements of your platform. Optional stuff should be set by 46*1c60b9acSAndroid Build Coastguard Workerrunning cmake commandline as usual. 47*1c60b9acSAndroid Build Coastguard Worker 48*1c60b9acSAndroid Build Coastguard Worker## 5) Add building your platform files into CMakeLists.txt 49*1c60b9acSAndroid Build Coastguard Worker 50*1c60b9acSAndroid Build Coastguard WorkerAdd entries in CMakeLists.txt for building stuff in `./lib/plat/myplatform` when 51*1c60b9acSAndroid Build Coastguard Worker`LWS_PLAT_MYPLATFORM` is enabled. 52*1c60b9acSAndroid Build Coastguard Worker 53*1c60b9acSAndroid Build Coastguard Worker## 6) Adapt your copied ./lib/plat/myplatform/ files 54*1c60b9acSAndroid Build Coastguard Worker 55*1c60b9acSAndroid Build Coastguard WorkerYou can now do test builds using the cross-build file, your platform flag in 56*1c60b9acSAndroid Build Coastguard Workercmake, and your copied ./lib/plat content... this last part since it was 57*1c60b9acSAndroid Build Coastguard Workercopied from another platform will initially be a plentiful source of errors. 58*1c60b9acSAndroid Build Coastguard Worker 59*1c60b9acSAndroid Build Coastguard WorkerYou can iteratively build and adapt the platform files. 60*1c60b9acSAndroid Build Coastguard Worker 61