คุณมี project ที่บางครั้งคุณไม่ต้องการที่จะเปิดเผย function บางอย่างบน Internet คือหมายความว่าไฟล์ที่คุณไม่ต้องการ
เปิดเผยให้ผู้ใช้งานนำไปเปลียนแปลงหรือกระทำการใดๆ คุณก็สามารถที่จะใช้วิธีการสร้างไฟล์ที่เรียกว่า LIB เพื่อการนำำไปเรียกใช้
ยกตัวอย่าง เป็น full code ที่สามารถเปิดและทำการแก้ไขได้ คือ files นั้นถูกเปิดหมด ผู้ที่ download สามารถทำการแก้ไขได้ทุกอย่าง ลองดาวโหลดมา
เพื่อเปรียบเทียบในขั้นตอนที่ 1 และขั้นตอนที่ 2
ขั้นตอนที่ 1 ยกตัวอย่างว่า ในโปรแกรมบาง Files ที่ไม่ต้องการที่จะ Open source แต่จะต้องสามารถให้มีการเรียกใช้ได้ จึงต้องมีวิธีการที่จะเปลี่ยน
รูปแบบของไฟล์ที่ต้องการให้เป็นรูปแบบอื่น ซึ่งภาษาเรียกของนักเขียนโปรแกรมเรียกว่า การสร้าง LIB วิธีการนี้จะทำให้ไฟล์นั้นไม่สามารถถูกเปิด
ออกมาเพื่อทำการแก้ไข หรือ เปิดมาเพื่อมองเห็นส่วนต่างๆ ที่อยู่ในไฟล์ ผมขอยกตัวอย่างไฟล์ LCD.C ซึ่งเป็นไฟล์ที่ไม่ต้องการเปิด จึงต้องมีการ
เปลียนไฟล์นี้ให้เป็น LIB วิธีการคือ ปกติแล้วการ make file output ที่ได้จะเป็น HEX เพื่อนำไปโปรแกรมลงตัว MCU วิํธีการสร้าง LIB นี้
จะต้องมีการกำหนด Output ของไฟล์ของการคอมไพล์ ซึ่งหลังจากที่คอมไำพล์แล้ว จะได้ไฟล์ชื่อ "lcdlib.lib" จากตัวอย่างเป็นการสร้างจากไฟล์ lcd.c
แต่เราสามารถมีไฟล์อื่นมาสร้างร่วมได้ ซึ่งเอาจะต้องมีการกำหนดไฟล์ ที่นำมาสร้างร่วมใน makefile ลองดูในตัวอย่าง
# Tools and directories ############################################################################ ############################################################################ # Target # C-source files # Compiler flags # Assembler flags # Linker flags #---------------- Library Options ---------------- # Floating point printf version (requires MATH_LIB = -lm below) # If this is left blank, then it will use the Standard printf version. #-------------------------------------------------------------------------- # Floating point + %[ scanf version (requires MATH_LIB = -lm below) # If this is left blank, then it will use the Standard scanf version. MATH_LIB = -lm #define all project specific object files #compile: instructions to create assembler and/or object files from C source %s : %c all: $(TRG).lib <---- Target Output #make instruction to delete created files ############################################################################ lcd.o : lcd.c lcd.h makefile ํyou can add more files here xxx.o xxx.c xxx.h makefile yyy.o yyy.c yyy.h makefile
|
ขั้นตอนที่ 2 หลังจากที่ผ่านขั้นตอนที่ 1 ให้ทำการ copy "lcdlib.lib" มาที่ Folder นี้ แล้วให้สังเกตุว่าไม่มี file "lcd.c" นั้นหมายความว่า "lcd.c" จะถูก
สร้างมาเป็น files "lcdlib.lib" แทน แล้วนำมาเรียกใช้ ทางผู้ที่ download ไปใช้งานไม่สามารถเข้าไปทำการแก้ไข files "lcdlib.lib" ได้และการ make file
ในขั้นตอนนี้ สามารถมี file อื่นๆ เพิ่มเติมได้ โดยไฟล์เหล่านี้ เป็นการ Open Code ที่นำมา make ร่วมการใช้งานใน ขั้นตอนที่ 1 และขั้นตอนที่ 2
ให้ดูวิธีการที่ file "makefile"
# Tools and directories # Target # C-source files # Libraries # Compiler flags # Assembler flags # Linker flags #---------------- Library Options ---------------- # Floating point printf version (requires MATH_LIB = -lm below) # If this is left blank, then it will use the Standard printf version. #-------------------------------------------------------------------------- # Floating point + %[ scanf version (requires MATH_LIB = -lm below) # If this is left blank, then it will use the Standard scanf version. MATH_LIB = -lm ############################################################################################ #define all project specific object files #compile: instructions to create assembler and/or object files from C source %s : %c #assemble: instructions to create object file from assembler files #link: instructions to create elf output file from object files #create avrobj file from elf output file #create bin (ihex, srec) file from elf output file %hex: %elf avr-size $(TRG).elf #make instruction to delete created files clean_before: |
จ๊าบไหมผิดถูกตรงไหนก็บอกกันได้ ผมแค่งูๆ ปลาๆทีนี้ไม่ต้องกลัว จะปิดตรงไหน เปิดตรงไหน แล้วแต่
แต่เปิดดีกว่านะจะได้นำไปพัฒนาต่อได้อีกจริงไหม